| 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/strings/string_number_conversions.h" | 8 #include "base/strings/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 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 class PepperPortAllocatorSession | 29 class PepperPortAllocatorSession |
| 30 : public cricket::HttpPortAllocatorSessionBase { | 30 : public cricket::HttpPortAllocatorSessionBase { |
| 31 public: | 31 public: |
| 32 PepperPortAllocatorSession( | 32 PepperPortAllocatorSession( |
| 33 cricket::HttpPortAllocatorBase* allocator, | 33 cricket::HttpPortAllocatorBase* allocator, |
| 34 const std::string& content_name, | 34 const std::string& content_name, |
| 35 int component, | 35 int component, |
| 36 const std::string& ice_username_fragment, | 36 const std::string& ice_username_fragment, |
| 37 const std::string& ice_password, | 37 const std::string& ice_password, |
| 38 const std::vector<talk_base::SocketAddress>& stun_hosts, | 38 const std::vector<rtc::SocketAddress>& stun_hosts, |
| 39 const std::vector<std::string>& relay_hosts, | 39 const std::vector<std::string>& relay_hosts, |
| 40 const std::string& relay_token, | 40 const std::string& relay_token, |
| 41 const pp::InstanceHandle& instance); | 41 const pp::InstanceHandle& instance); |
| 42 virtual ~PepperPortAllocatorSession(); | 42 virtual ~PepperPortAllocatorSession(); |
| 43 | 43 |
| 44 // cricket::HttpPortAllocatorBase overrides. | 44 // cricket::HttpPortAllocatorBase overrides. |
| 45 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; | 45 virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE; |
| 46 virtual void GetPortConfigurations() OVERRIDE; | 46 virtual void GetPortConfigurations() OVERRIDE; |
| 47 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; | 47 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 void ResolveStunServerAddress(); | 50 void ResolveStunServerAddress(); |
| 51 void OnStunAddressResolved(int32_t result); | 51 void OnStunAddressResolved(int32_t result); |
| 52 | 52 |
| 53 void OnUrlOpened(int32_t result); | 53 void OnUrlOpened(int32_t result); |
| 54 void ReadResponseBody(); | 54 void ReadResponseBody(); |
| 55 void OnResponseBodyRead(int32_t result); | 55 void OnResponseBodyRead(int32_t result); |
| 56 | 56 |
| 57 pp::InstanceHandle instance_; | 57 pp::InstanceHandle instance_; |
| 58 | 58 |
| 59 pp::HostResolver stun_address_resolver_; | 59 pp::HostResolver stun_address_resolver_; |
| 60 talk_base::SocketAddress stun_address_; | 60 rtc::SocketAddress stun_address_; |
| 61 int stun_port_; | 61 int stun_port_; |
| 62 | 62 |
| 63 scoped_ptr<pp::URLLoader> relay_url_loader_; | 63 scoped_ptr<pp::URLLoader> relay_url_loader_; |
| 64 std::vector<char> relay_response_body_; | 64 std::vector<char> relay_response_body_; |
| 65 bool relay_response_received_; | 65 bool relay_response_received_; |
| 66 | 66 |
| 67 pp::CompletionCallbackFactory<PepperPortAllocatorSession> callback_factory_; | 67 pp::CompletionCallbackFactory<PepperPortAllocatorSession> callback_factory_; |
| 68 | 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(PepperPortAllocatorSession); | 69 DISALLOW_COPY_AND_ASSIGN(PepperPortAllocatorSession); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 PepperPortAllocatorSession::PepperPortAllocatorSession( | 72 PepperPortAllocatorSession::PepperPortAllocatorSession( |
| 73 cricket::HttpPortAllocatorBase* allocator, | 73 cricket::HttpPortAllocatorBase* allocator, |
| 74 const std::string& content_name, | 74 const std::string& content_name, |
| 75 int component, | 75 int component, |
| 76 const std::string& ice_username_fragment, | 76 const std::string& ice_username_fragment, |
| 77 const std::string& ice_password, | 77 const std::string& ice_password, |
| 78 const std::vector<talk_base::SocketAddress>& stun_hosts, | 78 const std::vector<rtc::SocketAddress>& stun_hosts, |
| 79 const std::vector<std::string>& relay_hosts, | 79 const std::vector<std::string>& relay_hosts, |
| 80 const std::string& relay_token, | 80 const std::string& relay_token, |
| 81 const pp::InstanceHandle& instance) | 81 const pp::InstanceHandle& instance) |
| 82 : HttpPortAllocatorSessionBase(allocator, | 82 : HttpPortAllocatorSessionBase(allocator, |
| 83 content_name, | 83 content_name, |
| 84 component, | 84 component, |
| 85 ice_username_fragment, | 85 ice_username_fragment, |
| 86 ice_password, | 86 ice_password, |
| 87 stun_hosts, | 87 stun_hosts, |
| 88 relay_hosts, | 88 relay_hosts, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 125 } |
| 126 relay->ports = filtered_ports; | 126 relay->ports = filtered_ports; |
| 127 } | 127 } |
| 128 cricket::BasicPortAllocatorSession::ConfigReady(config); | 128 cricket::BasicPortAllocatorSession::ConfigReady(config); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void PepperPortAllocatorSession::GetPortConfigurations() { | 131 void PepperPortAllocatorSession::GetPortConfigurations() { |
| 132 // Add an empty configuration synchronously, so a local connection | 132 // Add an empty configuration synchronously, so a local connection |
| 133 // can be started immediately. | 133 // can be started immediately. |
| 134 ConfigReady(new cricket::PortConfiguration( | 134 ConfigReady(new cricket::PortConfiguration( |
| 135 talk_base::SocketAddress(), std::string(), std::string())); | 135 rtc::SocketAddress(), std::string(), std::string())); |
| 136 | 136 |
| 137 ResolveStunServerAddress(); | 137 ResolveStunServerAddress(); |
| 138 TryCreateRelaySession(); | 138 TryCreateRelaySession(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void PepperPortAllocatorSession::ResolveStunServerAddress() { | 141 void PepperPortAllocatorSession::ResolveStunServerAddress() { |
| 142 if (stun_address_.IsNil()) { | 142 if (stun_address_.IsNil()) { |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 | 145 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 286 } |
| 287 | 287 |
| 288 ReadResponseBody(); | 288 ReadResponseBody(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 } // namespace | 291 } // namespace |
| 292 | 292 |
| 293 // static | 293 // static |
| 294 scoped_ptr<PepperPortAllocator> PepperPortAllocator::Create( | 294 scoped_ptr<PepperPortAllocator> PepperPortAllocator::Create( |
| 295 const pp::InstanceHandle& instance) { | 295 const pp::InstanceHandle& instance) { |
| 296 scoped_ptr<talk_base::NetworkManager> network_manager( | 296 scoped_ptr<rtc::NetworkManager> network_manager( |
| 297 new PepperNetworkManager(instance)); | 297 new PepperNetworkManager(instance)); |
| 298 scoped_ptr<talk_base::PacketSocketFactory> socket_factory( | 298 scoped_ptr<rtc::PacketSocketFactory> socket_factory( |
| 299 new PepperPacketSocketFactory(instance)); | 299 new PepperPacketSocketFactory(instance)); |
| 300 scoped_ptr<PepperPortAllocator> result(new PepperPortAllocator( | 300 scoped_ptr<PepperPortAllocator> result(new PepperPortAllocator( |
| 301 instance, network_manager.Pass(), socket_factory.Pass())); | 301 instance, network_manager.Pass(), socket_factory.Pass())); |
| 302 return result.Pass(); | 302 return result.Pass(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 PepperPortAllocator::PepperPortAllocator( | 305 PepperPortAllocator::PepperPortAllocator( |
| 306 const pp::InstanceHandle& instance, | 306 const pp::InstanceHandle& instance, |
| 307 scoped_ptr<talk_base::NetworkManager> network_manager, | 307 scoped_ptr<rtc::NetworkManager> network_manager, |
| 308 scoped_ptr<talk_base::PacketSocketFactory> socket_factory) | 308 scoped_ptr<rtc::PacketSocketFactory> socket_factory) |
| 309 : HttpPortAllocatorBase(network_manager.get(), | 309 : HttpPortAllocatorBase(network_manager.get(), |
| 310 socket_factory.get(), | 310 socket_factory.get(), |
| 311 std::string()), | 311 std::string()), |
| 312 instance_(instance), | 312 instance_(instance), |
| 313 network_manager_(network_manager.Pass()), | 313 network_manager_(network_manager.Pass()), |
| 314 socket_factory_(socket_factory.Pass()) { | 314 socket_factory_(socket_factory.Pass()) { |
| 315 // TCP transport is disabled becase PseudoTCP works poorly over | 315 // TCP transport is disabled becase PseudoTCP works poorly over |
| 316 // it. ENABLE_SHARED_UFRAG flag is specified so that the same | 316 // it. ENABLE_SHARED_UFRAG flag is specified so that the same |
| 317 // username fragment is shared between all candidates for this | 317 // username fragment is shared between all candidates for this |
| 318 // channel. | 318 // channel. |
| 319 set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | | 319 set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 320 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG| | 320 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG| |
| 321 cricket::PORTALLOCATOR_ENABLE_IPV6); | 321 cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 322 } | 322 } |
| 323 | 323 |
| 324 PepperPortAllocator::~PepperPortAllocator() { | 324 PepperPortAllocator::~PepperPortAllocator() { |
| 325 } | 325 } |
| 326 | 326 |
| 327 cricket::PortAllocatorSession* PepperPortAllocator::CreateSessionInternal( | 327 cricket::PortAllocatorSession* PepperPortAllocator::CreateSessionInternal( |
| 328 const std::string& content_name, | 328 const std::string& content_name, |
| 329 int component, | 329 int component, |
| 330 const std::string& ice_username_fragment, | 330 const std::string& ice_username_fragment, |
| 331 const std::string& ice_password) { | 331 const std::string& ice_password) { |
| 332 return new PepperPortAllocatorSession( | 332 return new PepperPortAllocatorSession( |
| 333 this, content_name, component, ice_username_fragment, ice_password, | 333 this, content_name, component, ice_username_fragment, ice_password, |
| 334 stun_hosts(), relay_hosts(), relay_token(), instance_); | 334 stun_hosts(), relay_hosts(), relay_token(), instance_); |
| 335 } | 335 } |
| 336 | 336 |
| 337 } // namespace remoting | 337 } // namespace remoting |
| OLD | NEW |