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_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
13 #include "remoting/host/network_settings.h" | 13 #include "remoting/host/network_settings.h" |
14 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" | 14 #include "third_party/libjingle/source/talk/base/basicpacketsocketfactory.h" |
15 | 15 |
16 namespace remoting { | 16 namespace remoting { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 class HostPortAllocatorSession | 20 class HostPortAllocatorSession |
21 : public cricket::HttpPortAllocatorSessionBase { | 21 : public cricket::HttpPortAllocatorSessionBase { |
22 public: | 22 public: |
23 HostPortAllocatorSession( | 23 HostPortAllocatorSession( |
24 cricket::HttpPortAllocatorBase* allocator, | 24 cricket::HttpPortAllocatorBase* allocator, |
25 const std::string& channel_name, | |
26 int component, | 25 int component, |
| 26 const std::string& ice_username_fragment, |
| 27 const std::string& ice_password, |
27 const std::vector<talk_base::SocketAddress>& stun_hosts, | 28 const std::vector<talk_base::SocketAddress>& stun_hosts, |
28 const std::vector<std::string>& relay_hosts, | 29 const std::vector<std::string>& relay_hosts, |
29 const std::string& relay, | 30 const std::string& relay, |
30 const scoped_refptr<net::URLRequestContextGetter>& url_context); | 31 const scoped_refptr<net::URLRequestContextGetter>& url_context); |
31 virtual ~HostPortAllocatorSession(); | 32 virtual ~HostPortAllocatorSession(); |
32 | 33 |
33 // cricket::HttpPortAllocatorBase overrides. | 34 // cricket::HttpPortAllocatorBase overrides. |
34 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; | 35 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; |
35 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; | 36 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; |
36 | 37 |
37 private: | 38 private: |
38 void OnSessionRequestDone(UrlFetcher* url_fetcher, | 39 void OnSessionRequestDone(UrlFetcher* url_fetcher, |
39 const net::URLRequestStatus& status, | 40 const net::URLRequestStatus& status, |
40 int response_code, | 41 int response_code, |
41 const std::string& response); | 42 const std::string& response); |
42 | 43 |
43 scoped_refptr<net::URLRequestContextGetter> url_context_; | 44 scoped_refptr<net::URLRequestContextGetter> url_context_; |
44 std::set<UrlFetcher*> url_fetchers_; | 45 std::set<UrlFetcher*> url_fetchers_; |
45 | 46 |
46 DISALLOW_COPY_AND_ASSIGN(HostPortAllocatorSession); | 47 DISALLOW_COPY_AND_ASSIGN(HostPortAllocatorSession); |
47 }; | 48 }; |
48 | 49 |
49 HostPortAllocatorSession::HostPortAllocatorSession( | 50 HostPortAllocatorSession::HostPortAllocatorSession( |
50 cricket::HttpPortAllocatorBase* allocator, | 51 cricket::HttpPortAllocatorBase* allocator, |
51 const std::string& channel_name, | |
52 int component, | 52 int component, |
| 53 const std::string& ice_username_fragment, |
| 54 const std::string& ice_password, |
53 const std::vector<talk_base::SocketAddress>& stun_hosts, | 55 const std::vector<talk_base::SocketAddress>& stun_hosts, |
54 const std::vector<std::string>& relay_hosts, | 56 const std::vector<std::string>& relay_hosts, |
55 const std::string& relay, | 57 const std::string& relay, |
56 const scoped_refptr<net::URLRequestContextGetter>& url_context) | 58 const scoped_refptr<net::URLRequestContextGetter>& url_context) |
57 : HttpPortAllocatorSessionBase( | 59 : HttpPortAllocatorSessionBase( |
58 allocator, channel_name, component, stun_hosts, relay_hosts, relay, ""), | 60 allocator, component, ice_username_fragment, ice_password, |
| 61 stun_hosts, relay_hosts, relay, ""), |
59 url_context_(url_context) { | 62 url_context_(url_context) { |
60 } | 63 } |
61 | 64 |
62 HostPortAllocatorSession::~HostPortAllocatorSession() { | 65 HostPortAllocatorSession::~HostPortAllocatorSession() { |
63 STLDeleteElements(&url_fetchers_); | 66 STLDeleteElements(&url_fetchers_); |
64 } | 67 } |
65 | 68 |
66 void HostPortAllocatorSession::ConfigReady(cricket::PortConfiguration* config) { | 69 void HostPortAllocatorSession::ConfigReady(cricket::PortConfiguration* config) { |
67 // Filter out non-UDP relay ports, so that we don't try using TCP. | 70 // Filter out non-UDP relay ports, so that we don't try using TCP. |
68 for (cricket::PortConfiguration::RelayList::iterator relay = | 71 for (cricket::PortConfiguration::RelayList::iterator relay = |
(...skipping 11 matching lines...) Expand all Loading... |
80 } | 83 } |
81 | 84 |
82 void HostPortAllocatorSession::SendSessionRequest(const std::string& host, | 85 void HostPortAllocatorSession::SendSessionRequest(const std::string& host, |
83 int port) { | 86 int port) { |
84 GURL url("https://" + host + ":" + base::IntToString(port) + | 87 GURL url("https://" + host + ":" + base::IntToString(port) + |
85 GetSessionRequestUrl() + "&sn=1"); | 88 GetSessionRequestUrl() + "&sn=1"); |
86 scoped_ptr<UrlFetcher> url_fetcher(new UrlFetcher(url, UrlFetcher::GET)); | 89 scoped_ptr<UrlFetcher> url_fetcher(new UrlFetcher(url, UrlFetcher::GET)); |
87 url_fetcher->SetRequestContext(url_context_); | 90 url_fetcher->SetRequestContext(url_context_); |
88 url_fetcher->SetHeader("X-Talk-Google-Relay-Auth", relay_token()); | 91 url_fetcher->SetHeader("X-Talk-Google-Relay-Auth", relay_token()); |
89 url_fetcher->SetHeader("X-Google-Relay-Auth", relay_token()); | 92 url_fetcher->SetHeader("X-Google-Relay-Auth", relay_token()); |
90 url_fetcher->SetHeader("X-Stream-Type", channel_name()); | 93 url_fetcher->SetHeader("X-Stream-Type", "chromoting"); |
91 url_fetcher->Start(base::Bind(&HostPortAllocatorSession::OnSessionRequestDone, | 94 url_fetcher->Start(base::Bind(&HostPortAllocatorSession::OnSessionRequestDone, |
92 base::Unretained(this), url_fetcher.get())); | 95 base::Unretained(this), url_fetcher.get())); |
93 url_fetchers_.insert(url_fetcher.release()); | 96 url_fetchers_.insert(url_fetcher.release()); |
94 } | 97 } |
95 | 98 |
96 void HostPortAllocatorSession::OnSessionRequestDone( | 99 void HostPortAllocatorSession::OnSessionRequestDone( |
97 UrlFetcher* url_fetcher, | 100 UrlFetcher* url_fetcher, |
98 const net::URLRequestStatus& status, | 101 const net::URLRequestStatus& status, |
99 int response_code, | 102 int response_code, |
100 const std::string& response) { | 103 const std::string& response) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 scoped_ptr<talk_base::PacketSocketFactory> socket_factory) | 150 scoped_ptr<talk_base::PacketSocketFactory> socket_factory) |
148 : HttpPortAllocatorBase(network_manager.get(), socket_factory.get(), ""), | 151 : HttpPortAllocatorBase(network_manager.get(), socket_factory.get(), ""), |
149 url_context_(url_context), | 152 url_context_(url_context), |
150 network_manager_(network_manager.Pass()), | 153 network_manager_(network_manager.Pass()), |
151 socket_factory_(socket_factory.Pass()) { | 154 socket_factory_(socket_factory.Pass()) { |
152 } | 155 } |
153 | 156 |
154 HostPortAllocator::~HostPortAllocator() { | 157 HostPortAllocator::~HostPortAllocator() { |
155 } | 158 } |
156 | 159 |
157 cricket::PortAllocatorSession* HostPortAllocator::CreateSession( | 160 cricket::PortAllocatorSession* HostPortAllocator::CreateSessionInternal( |
158 const std::string& channel_name, | 161 int component, |
159 int component) { | 162 const std::string& ice_username_fragment, |
| 163 const std::string& ice_password) { |
160 return new HostPortAllocatorSession( | 164 return new HostPortAllocatorSession( |
161 this, channel_name, component, stun_hosts(), | 165 this, component, ice_username_fragment, ice_password, |
162 relay_hosts(), relay_token(), url_context_); | 166 stun_hosts(), relay_hosts(), relay_token(), url_context_); |
163 } | 167 } |
164 | 168 |
165 } // namespace remoting | 169 } // namespace remoting |
OLD | NEW |