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/client/plugin/pepper_port_allocator.h" | 5 #include "remoting/client/plugin/pepper_port_allocator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "net/base/net_util.h" | 9 #include "net/base/net_util.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 PepperPortAllocatorSession::PepperPortAllocatorSession( | 75 PepperPortAllocatorSession::PepperPortAllocatorSession( |
76 cricket::HttpPortAllocatorBase* allocator, | 76 cricket::HttpPortAllocatorBase* allocator, |
77 const std::string& content_name, | 77 const std::string& content_name, |
78 int component, | 78 int component, |
79 const std::string& ice_username_fragment, | 79 const std::string& ice_username_fragment, |
80 const std::string& ice_password, | 80 const std::string& ice_password, |
81 const std::vector<talk_base::SocketAddress>& stun_hosts, | 81 const std::vector<talk_base::SocketAddress>& stun_hosts, |
82 const std::vector<std::string>& relay_hosts, | 82 const std::vector<std::string>& relay_hosts, |
83 const std::string& relay_token, | 83 const std::string& relay_token, |
84 const pp::InstanceHandle& instance) | 84 const pp::InstanceHandle& instance) |
85 : HttpPortAllocatorSessionBase( | 85 : HttpPortAllocatorSessionBase(allocator, |
86 allocator, content_name, component, ice_username_fragment, ice_password, | 86 content_name, |
87 stun_hosts, relay_hosts, relay_token, ""), | 87 component, |
| 88 ice_username_fragment, |
| 89 ice_password, |
| 90 stun_hosts, |
| 91 relay_hosts, |
| 92 relay_token, |
| 93 std::string()), |
88 instance_(instance), | 94 instance_(instance), |
89 stun_address_resolver_(instance_), | 95 stun_address_resolver_(instance_), |
90 stun_port_(0), | 96 stun_port_(0), |
91 relay_response_received_(false), | 97 relay_response_received_(false), |
92 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 98 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
93 if (stun_hosts.size() > 0) { | 99 if (stun_hosts.size() > 0) { |
94 stun_address_ = stun_hosts[0]; | 100 stun_address_ = stun_hosts[0]; |
95 } | 101 } |
96 } | 102 } |
97 | 103 |
(...skipping 24 matching lines...) Expand all Loading... |
122 } | 128 } |
123 relay->ports = filtered_ports; | 129 relay->ports = filtered_ports; |
124 } | 130 } |
125 cricket::BasicPortAllocatorSession::ConfigReady(config); | 131 cricket::BasicPortAllocatorSession::ConfigReady(config); |
126 } | 132 } |
127 | 133 |
128 void PepperPortAllocatorSession::GetPortConfigurations() { | 134 void PepperPortAllocatorSession::GetPortConfigurations() { |
129 // Add an empty configuration synchronously, so a local connection | 135 // Add an empty configuration synchronously, so a local connection |
130 // can be started immediately. | 136 // can be started immediately. |
131 ConfigReady(new cricket::PortConfiguration( | 137 ConfigReady(new cricket::PortConfiguration( |
132 talk_base::SocketAddress(), "", "")); | 138 talk_base::SocketAddress(), std::string(), std::string())); |
133 | 139 |
134 ResolveStunServerAddress(); | 140 ResolveStunServerAddress(); |
135 TryCreateRelaySession(); | 141 TryCreateRelaySession(); |
136 } | 142 } |
137 | 143 |
138 void PepperPortAllocatorSession::ResolveStunServerAddress() { | 144 void PepperPortAllocatorSession::ResolveStunServerAddress() { |
139 if (stun_address_.IsNil()) { | 145 if (stun_address_.IsNil()) { |
140 return; | 146 return; |
141 } | 147 } |
142 | 148 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // and Relay parameters are stored together in PortConfiguration | 194 // and Relay parameters are stored together in PortConfiguration |
189 // and ReceiveSessionResponse() doesn't save relay session | 195 // and ReceiveSessionResponse() doesn't save relay session |
190 // configuration for the case we resolve STUN address later. This | 196 // configuration for the case we resolve STUN address later. This |
191 // method invokes overriden ConfigReady() which then submits | 197 // method invokes overriden ConfigReady() which then submits |
192 // resolved |stun_address_|. | 198 // resolved |stun_address_|. |
193 // | 199 // |
194 // TODO(sergeyu): Refactor HttpPortAllocatorSessionBase to fix this. | 200 // TODO(sergeyu): Refactor HttpPortAllocatorSessionBase to fix this. |
195 ReceiveSessionResponse(std::string(relay_response_body_.begin(), | 201 ReceiveSessionResponse(std::string(relay_response_body_.begin(), |
196 relay_response_body_.end())); | 202 relay_response_body_.end())); |
197 } else { | 203 } else { |
198 ConfigReady(new cricket::PortConfiguration(stun_address_, "", "")); | 204 ConfigReady(new cricket::PortConfiguration( |
| 205 stun_address_, std::string(), std::string())); |
199 } | 206 } |
200 } | 207 } |
201 | 208 |
202 void PepperPortAllocatorSession::SendSessionRequest( | 209 void PepperPortAllocatorSession::SendSessionRequest( |
203 const std::string& host, | 210 const std::string& host, |
204 int port) { | 211 int port) { |
205 relay_url_loader_.reset(new pp::URLLoader(instance_)); | 212 relay_url_loader_.reset(new pp::URLLoader(instance_)); |
206 pp::URLRequestInfo request_info(instance_); | 213 pp::URLRequestInfo request_info(instance_); |
207 std::string url = "https://" + host + ":" + base::IntToString(port) + | 214 std::string url = "https://" + host + ":" + base::IntToString(port) + |
208 GetSessionRequestUrl() + "&sn=1"; | 215 GetSessionRequestUrl() + "&sn=1"; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 new PepperPacketSocketFactory(instance)); | 304 new PepperPacketSocketFactory(instance)); |
298 scoped_ptr<PepperPortAllocator> result(new PepperPortAllocator( | 305 scoped_ptr<PepperPortAllocator> result(new PepperPortAllocator( |
299 instance, network_manager.Pass(), socket_factory.Pass())); | 306 instance, network_manager.Pass(), socket_factory.Pass())); |
300 return result.Pass(); | 307 return result.Pass(); |
301 } | 308 } |
302 | 309 |
303 PepperPortAllocator::PepperPortAllocator( | 310 PepperPortAllocator::PepperPortAllocator( |
304 const pp::InstanceHandle& instance, | 311 const pp::InstanceHandle& instance, |
305 scoped_ptr<talk_base::NetworkManager> network_manager, | 312 scoped_ptr<talk_base::NetworkManager> network_manager, |
306 scoped_ptr<talk_base::PacketSocketFactory> socket_factory) | 313 scoped_ptr<talk_base::PacketSocketFactory> socket_factory) |
307 : HttpPortAllocatorBase(network_manager.get(), socket_factory.get(), ""), | 314 : HttpPortAllocatorBase(network_manager.get(), |
| 315 socket_factory.get(), |
| 316 std::string()), |
308 instance_(instance), | 317 instance_(instance), |
309 network_manager_(network_manager.Pass()), | 318 network_manager_(network_manager.Pass()), |
310 socket_factory_(socket_factory.Pass()) { | 319 socket_factory_(socket_factory.Pass()) { |
311 // TCP transport is disabled becase PseudoTCP works poorly over | 320 // TCP transport is disabled becase PseudoTCP works poorly over |
312 // it. ENABLE_SHARED_UFRAG flag is specified so that the same | 321 // it. ENABLE_SHARED_UFRAG flag is specified so that the same |
313 // username fragment is shared between all candidates for this | 322 // username fragment is shared between all candidates for this |
314 // channel. | 323 // channel. |
315 set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | | 324 set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
316 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG); | 325 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG); |
317 } | 326 } |
318 | 327 |
319 PepperPortAllocator::~PepperPortAllocator() { | 328 PepperPortAllocator::~PepperPortAllocator() { |
320 } | 329 } |
321 | 330 |
322 cricket::PortAllocatorSession* PepperPortAllocator::CreateSessionInternal( | 331 cricket::PortAllocatorSession* PepperPortAllocator::CreateSessionInternal( |
323 const std::string& content_name, | 332 const std::string& content_name, |
324 int component, | 333 int component, |
325 const std::string& ice_username_fragment, | 334 const std::string& ice_username_fragment, |
326 const std::string& ice_password) { | 335 const std::string& ice_password) { |
327 return new PepperPortAllocatorSession( | 336 return new PepperPortAllocatorSession( |
328 this, content_name, component, ice_username_fragment, ice_password, | 337 this, content_name, component, ice_username_fragment, ice_password, |
329 stun_hosts(), relay_hosts(), relay_token(), instance_); | 338 stun_hosts(), relay_hosts(), relay_token(), instance_); |
330 } | 339 } |
331 | 340 |
332 } // namespace remoting | 341 } // namespace remoting |
OLD | NEW |