| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 virtual void GetPortConfigurations() OVERRIDE; | 44 virtual void GetPortConfigurations() OVERRIDE; |
| 45 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; | 45 virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE; |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 void OnUrlOpened(int32_t result); | 48 void OnUrlOpened(int32_t result); |
| 49 void ReadResponseBody(); | 49 void ReadResponseBody(); |
| 50 void OnResponseBodyRead(int32_t result); | 50 void OnResponseBodyRead(int32_t result); |
| 51 | 51 |
| 52 pp::InstanceHandle instance_; | 52 pp::InstanceHandle instance_; |
| 53 | 53 |
| 54 rtc::SocketAddress stun_address_; | 54 cricket::ServerAddresses stun_hosts_; |
| 55 int stun_port_; | |
| 56 | 55 |
| 57 scoped_ptr<pp::URLLoader> relay_url_loader_; | 56 scoped_ptr<pp::URLLoader> relay_url_loader_; |
| 58 std::vector<char> relay_response_body_; | 57 std::vector<char> relay_response_body_; |
| 59 bool relay_response_received_; | 58 bool relay_response_received_; |
| 60 | 59 |
| 61 pp::CompletionCallbackFactory<PepperPortAllocatorSession> callback_factory_; | 60 pp::CompletionCallbackFactory<PepperPortAllocatorSession> callback_factory_; |
| 62 | 61 |
| 63 DISALLOW_COPY_AND_ASSIGN(PepperPortAllocatorSession); | 62 DISALLOW_COPY_AND_ASSIGN(PepperPortAllocatorSession); |
| 64 }; | 63 }; |
| 65 | 64 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 76 : HttpPortAllocatorSessionBase(allocator, | 75 : HttpPortAllocatorSessionBase(allocator, |
| 77 content_name, | 76 content_name, |
| 78 component, | 77 component, |
| 79 ice_username_fragment, | 78 ice_username_fragment, |
| 80 ice_password, | 79 ice_password, |
| 81 stun_hosts, | 80 stun_hosts, |
| 82 relay_hosts, | 81 relay_hosts, |
| 83 relay_token, | 82 relay_token, |
| 84 std::string()), | 83 std::string()), |
| 85 instance_(instance), | 84 instance_(instance), |
| 86 stun_port_(0), | 85 stun_hosts_(stun_hosts.begin(), stun_hosts.end()), |
| 87 relay_response_received_(false), | 86 relay_response_received_(false), |
| 88 callback_factory_(this) { | 87 callback_factory_(this) { |
| 89 if (stun_hosts.size() > 0) { | |
| 90 stun_address_ = stun_hosts[0]; | |
| 91 } | |
| 92 } | 88 } |
| 93 | 89 |
| 94 PepperPortAllocatorSession::~PepperPortAllocatorSession() { | 90 PepperPortAllocatorSession::~PepperPortAllocatorSession() { |
| 95 } | 91 } |
| 96 | 92 |
| 97 void PepperPortAllocatorSession::ConfigReady( | 93 void PepperPortAllocatorSession::ConfigReady( |
| 98 cricket::PortConfiguration* config) { | 94 cricket::PortConfiguration* config) { |
| 99 // Filter out non-UDP relay ports, so that we don't try using TCP. | 95 // Filter out non-UDP relay ports, so that we don't try using TCP. |
| 100 for (cricket::PortConfiguration::RelayList::iterator relay = | 96 for (cricket::PortConfiguration::RelayList::iterator relay = |
| 101 config->relays.begin(); relay != config->relays.end(); ++relay) { | 97 config->relays.begin(); relay != config->relays.end(); ++relay) { |
| 102 cricket::PortList filtered_ports; | 98 cricket::PortList filtered_ports; |
| 103 for (cricket::PortList::iterator port = | 99 for (cricket::PortList::iterator port = |
| 104 relay->ports.begin(); port != relay->ports.end(); ++port) { | 100 relay->ports.begin(); port != relay->ports.end(); ++port) { |
| 105 if (port->proto == cricket::PROTO_UDP) { | 101 if (port->proto == cricket::PROTO_UDP) { |
| 106 filtered_ports.push_back(*port); | 102 filtered_ports.push_back(*port); |
| 107 } | 103 } |
| 108 } | 104 } |
| 109 relay->ports = filtered_ports; | 105 relay->ports = filtered_ports; |
| 110 } | 106 } |
| 111 cricket::BasicPortAllocatorSession::ConfigReady(config); | 107 cricket::BasicPortAllocatorSession::ConfigReady(config); |
| 112 } | 108 } |
| 113 | 109 |
| 114 void PepperPortAllocatorSession::GetPortConfigurations() { | 110 void PepperPortAllocatorSession::GetPortConfigurations() { |
| 115 // Add a configuration without relay response first so local and STUN | 111 // Add a configuration without relay response first so local and STUN |
| 116 // candidates can be allocated without waiting for the relay response. | 112 // candidates can be allocated without waiting for the relay response. |
| 117 ConfigReady(new cricket::PortConfiguration( | 113 ConfigReady(new cricket::PortConfiguration( |
| 118 stun_address_, std::string(), std::string())); | 114 stun_hosts_, std::string(), std::string())); |
| 119 | 115 |
| 120 TryCreateRelaySession(); | 116 TryCreateRelaySession(); |
| 121 } | 117 } |
| 122 | 118 |
| 123 void PepperPortAllocatorSession::SendSessionRequest( | 119 void PepperPortAllocatorSession::SendSessionRequest( |
| 124 const std::string& host, | 120 const std::string& host, |
| 125 int port) { | 121 int port) { |
| 126 relay_url_loader_.reset(new pp::URLLoader(instance_)); | 122 relay_url_loader_.reset(new pp::URLLoader(instance_)); |
| 127 pp::URLRequestInfo request_info(instance_); | 123 pp::URLRequestInfo request_info(instance_); |
| 128 std::string url = "https://" + host + ":" + base::IntToString(port) + | 124 std::string url = "https://" + host + ":" + base::IntToString(port) + |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 const std::string& content_name, | 241 const std::string& content_name, |
| 246 int component, | 242 int component, |
| 247 const std::string& ice_username_fragment, | 243 const std::string& ice_username_fragment, |
| 248 const std::string& ice_password) { | 244 const std::string& ice_password) { |
| 249 return new PepperPortAllocatorSession( | 245 return new PepperPortAllocatorSession( |
| 250 this, content_name, component, ice_username_fragment, ice_password, | 246 this, content_name, component, ice_username_fragment, ice_password, |
| 251 stun_hosts(), relay_hosts(), relay_token(), instance_); | 247 stun_hosts(), relay_hosts(), relay_token(), instance_); |
| 252 } | 248 } |
| 253 | 249 |
| 254 } // namespace remoting | 250 } // namespace remoting |
| OLD | NEW |