Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/host_port_allocator.h" | 5 #include "remoting/host/host_port_allocator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/http/http_status_code.h" | 11 #include "net/http/http_status_code.h" |
| 12 #include "net/url_request/url_fetcher.h" | |
| 13 #include "net/url_request/url_fetcher_delegate.h" | |
| 12 #include "net/url_request/url_request_context_getter.h" | 14 #include "net/url_request/url_request_context_getter.h" |
| 13 #include "remoting/host/network_settings.h" | 15 #include "remoting/host/network_settings.h" |
| 14 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" | 16 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" |
| 15 | 17 |
| 16 namespace remoting { | 18 namespace remoting { |
| 17 | 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 class HostPortAllocatorSession | 22 class HostPortAllocatorSession |
| 21 : public cricket::HttpPortAllocatorSessionBase { | 23 : public cricket::HttpPortAllocatorSessionBase, |
| 24 net::URLFetcherDelegate { | |
|
Wez
2012/06/22 20:14:39
Style guide requires inheritance to be public.
Jamie
2012/06/22 22:42:02
Done.
| |
| 22 public: | 25 public: |
| 23 HostPortAllocatorSession( | 26 HostPortAllocatorSession( |
| 24 cricket::HttpPortAllocatorBase* allocator, | 27 cricket::HttpPortAllocatorBase* allocator, |
| 25 int component, | 28 int component, |
| 26 const std::string& ice_username_fragment, | 29 const std::string& ice_username_fragment, |
| 27 const std::string& ice_password, | 30 const std::string& ice_password, |
| 28 const std::vector<talk_base::SocketAddress>& stun_hosts, | 31 const std::vector<talk_base::SocketAddress>& stun_hosts, |
| 29 const std::vector<std::string>& relay_hosts, | 32 const std::vector<std::string>& relay_hosts, |
| 30 const std::string& relay, | 33 const std::string& relay, |
| 31 const scoped_refptr<net::URLRequestContextGetter>& url_context); | 34 const scoped_refptr<net::URLRequestContextGetter>& url_context); |
| 32 virtual ~HostPortAllocatorSession(); | 35 virtual ~HostPortAllocatorSession(); |
| 33 | 36 |
| 34 // cricket::HttpPortAllocatorBase overrides. | 37 // cricket::HttpPortAllocatorBase overrides. |
| 35 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; | 38 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; |
| 36 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; | 39 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; |
| 37 | 40 |
| 38 private: | 41 private: |
| 39 void OnSessionRequestDone(UrlFetcher* url_fetcher, | 42 void OnURLFetchComplete(const net::URLFetcher* url_fetcher); |
|
Wez
2012/06/22 20:14:39
nit: "net::URLFetcherDelegate interface"
Jamie
2012/06/22 22:42:02
Done.
| |
| 40 const net::URLRequestStatus& status, | |
| 41 int response_code, | |
| 42 const std::string& response); | |
| 43 | 43 |
| 44 scoped_refptr<net::URLRequestContextGetter> url_context_; | 44 scoped_refptr<net::URLRequestContextGetter> url_context_; |
| 45 std::set<UrlFetcher*> url_fetchers_; | 45 std::set<const net::URLFetcher*> url_fetchers_; |
| 46 | 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(HostPortAllocatorSession); | 47 DISALLOW_COPY_AND_ASSIGN(HostPortAllocatorSession); |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 HostPortAllocatorSession::HostPortAllocatorSession( | 50 HostPortAllocatorSession::HostPortAllocatorSession( |
| 51 cricket::HttpPortAllocatorBase* allocator, | 51 cricket::HttpPortAllocatorBase* allocator, |
| 52 int component, | 52 int component, |
| 53 const std::string& ice_username_fragment, | 53 const std::string& ice_username_fragment, |
| 54 const std::string& ice_password, | 54 const std::string& ice_password, |
| 55 const std::vector<talk_base::SocketAddress>& stun_hosts, | 55 const std::vector<talk_base::SocketAddress>& stun_hosts, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 79 } | 79 } |
| 80 relay->ports = filtered_ports; | 80 relay->ports = filtered_ports; |
| 81 } | 81 } |
| 82 cricket::BasicPortAllocatorSession::ConfigReady(config); | 82 cricket::BasicPortAllocatorSession::ConfigReady(config); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void HostPortAllocatorSession::SendSessionRequest(const std::string& host, | 85 void HostPortAllocatorSession::SendSessionRequest(const std::string& host, |
| 86 int port) { | 86 int port) { |
| 87 GURL url("https://" + host + ":" + base::IntToString(port) + | 87 GURL url("https://" + host + ":" + base::IntToString(port) + |
| 88 GetSessionRequestUrl() + "&sn=1"); | 88 GetSessionRequestUrl() + "&sn=1"); |
| 89 scoped_ptr<UrlFetcher> url_fetcher(new UrlFetcher(url, UrlFetcher::GET)); | 89 scoped_ptr<net::URLFetcher> url_fetcher( |
| 90 net::URLFetcher::Create(url, net::URLFetcher::GET, this)); | |
| 90 url_fetcher->SetRequestContext(url_context_); | 91 url_fetcher->SetRequestContext(url_context_); |
| 91 url_fetcher->SetHeader("X-Talk-Google-Relay-Auth", relay_token()); | 92 url_fetcher->AddExtraRequestHeader( |
| 92 url_fetcher->SetHeader("X-Google-Relay-Auth", relay_token()); | 93 "X-Talk-Google-Relay-Auth: " + relay_token()); |
| 93 url_fetcher->SetHeader("X-Stream-Type", "chromoting"); | 94 url_fetcher->AddExtraRequestHeader("X-Google-Relay-Auth: " + relay_token()); |
| 94 url_fetcher->Start(base::Bind(&HostPortAllocatorSession::OnSessionRequestDone, | 95 url_fetcher->AddExtraRequestHeader("X-Stream-Type: chromoting"); |
| 95 base::Unretained(this), url_fetcher.get())); | 96 url_fetcher->Start(); |
| 96 url_fetchers_.insert(url_fetcher.release()); | 97 url_fetchers_.insert(url_fetcher.release()); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void HostPortAllocatorSession::OnSessionRequestDone( | 100 void HostPortAllocatorSession::OnURLFetchComplete( |
| 100 UrlFetcher* url_fetcher, | 101 const net::URLFetcher* source) { |
|
Wez
2012/06/22 20:14:39
nit: source -> url_fetcher?
Wez
2012/06/22 20:14:39
Why does OnURLFetchComplete get passed a const net
Jamie
2012/06/22 22:42:02
It's called source elsewhere, including in the URL
Jamie
2012/06/22 22:42:02
There's a comment on the Start() method that says
| |
| 101 const net::URLRequestStatus& status, | 102 url_fetchers_.erase(source); |
| 102 int response_code, | 103 delete source; |
| 103 const std::string& response) { | |
| 104 url_fetchers_.erase(url_fetcher); | |
| 105 delete url_fetcher; | |
| 106 | 104 |
| 107 if (response_code != net::HTTP_OK) { | 105 if (source->GetResponseCode() != net::HTTP_OK) { |
| 108 LOG(WARNING) << "Received error when allocating relay session: " | 106 LOG(WARNING) << "Received error when allocating relay session: " |
| 109 << response_code; | 107 << source->GetResponseCode(); |
| 110 TryCreateRelaySession(); | 108 TryCreateRelaySession(); |
| 111 return; | 109 return; |
| 112 } | 110 } |
| 113 | 111 |
| 112 std::string response; | |
| 113 source->GetResponseAsString(&response); | |
| 114 ReceiveSessionResponse(response); | 114 ReceiveSessionResponse(response); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace | 117 } // namespace |
| 118 | 118 |
| 119 // static | 119 // static |
| 120 scoped_ptr<HostPortAllocator> HostPortAllocator::Create( | 120 scoped_ptr<HostPortAllocator> HostPortAllocator::Create( |
| 121 const scoped_refptr<net::URLRequestContextGetter>& url_context, | 121 const scoped_refptr<net::URLRequestContextGetter>& url_context, |
| 122 const NetworkSettings& network_settings) { | 122 const NetworkSettings& network_settings) { |
| 123 scoped_ptr<talk_base::NetworkManager> network_manager( | 123 scoped_ptr<talk_base::NetworkManager> network_manager( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 cricket::PortAllocatorSession* HostPortAllocator::CreateSessionInternal( | 160 cricket::PortAllocatorSession* HostPortAllocator::CreateSessionInternal( |
| 161 int component, | 161 int component, |
| 162 const std::string& ice_username_fragment, | 162 const std::string& ice_username_fragment, |
| 163 const std::string& ice_password) { | 163 const std::string& ice_password) { |
| 164 return new HostPortAllocatorSession( | 164 return new HostPortAllocatorSession( |
| 165 this, component, ice_username_fragment, ice_password, | 165 this, component, ice_username_fragment, ice_password, |
| 166 stun_hosts(), relay_hosts(), relay_token(), url_context_); | 166 stun_hosts(), relay_hosts(), relay_token(), url_context_); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace remoting | 169 } // namespace remoting |
| OLD | NEW |