Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: remoting/protocol/chromium_port_allocator.cc

Issue 1571943002: Simplify PortAllocatorBase and make PortAllocator creation synchronous. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/protocol/chromium_port_allocator.h ('k') | remoting/protocol/ice_transport_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/protocol/chromium_port_allocator.h" 5 #include "remoting/protocol/chromium_port_allocator.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "net/http/http_status_code.h" 13 #include "net/http/http_status_code.h"
14 #include "net/url_request/url_fetcher.h" 14 #include "net/url_request/url_fetcher.h"
15 #include "net/url_request/url_fetcher_delegate.h" 15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "net/url_request/url_request_context_getter.h" 16 #include "net/url_request/url_request_context_getter.h"
17 #include "remoting/protocol/chromium_socket_factory.h" 17 #include "remoting/protocol/chromium_socket_factory.h"
18 #include "remoting/protocol/transport_context.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
20 namespace remoting { 21 namespace remoting {
21 namespace protocol { 22 namespace protocol {
22 23
23 namespace { 24 namespace {
24 25
25 class ChromiumPortAllocatorSession : public PortAllocatorSessionBase, 26 class ChromiumPortAllocatorSession : public PortAllocatorSessionBase,
26 public net::URLFetcherDelegate { 27 public net::URLFetcherDelegate {
27 public: 28 public:
28 ChromiumPortAllocatorSession( 29 ChromiumPortAllocatorSession(ChromiumPortAllocator* allocator,
29 PortAllocatorBase* allocator, 30 const std::string& content_name,
30 const std::string& content_name, 31 int component,
31 int component, 32 const std::string& ice_username_fragment,
32 const std::string& ice_username_fragment, 33 const std::string& ice_password);
33 const std::string& ice_password,
34 const std::vector<rtc::SocketAddress>& stun_hosts,
35 const std::vector<std::string>& relay_hosts,
36 const std::string& relay,
37 const scoped_refptr<net::URLRequestContextGetter>& url_context);
38 ~ChromiumPortAllocatorSession() override; 34 ~ChromiumPortAllocatorSession() override;
39 35
40 // PortAllocatorBase overrides. 36 // PortAllocatorBase overrides.
41 void ConfigReady(cricket::PortConfiguration* config) override;
42 void SendSessionRequest(const std::string& host) override; 37 void SendSessionRequest(const std::string& host) override;
43 38
44 // net::URLFetcherDelegate interface. 39 // net::URLFetcherDelegate interface.
45 void OnURLFetchComplete(const net::URLFetcher* url_fetcher) override; 40 void OnURLFetchComplete(const net::URLFetcher* url_fetcher) override;
46 41
47 private: 42 private:
48 scoped_refptr<net::URLRequestContextGetter> url_context_; 43 scoped_refptr<net::URLRequestContextGetter> url_context_;
49 std::set<const net::URLFetcher*> url_fetchers_; 44 std::set<const net::URLFetcher*> url_fetchers_;
50 45
51 DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocatorSession); 46 DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocatorSession);
52 }; 47 };
53 48
54 ChromiumPortAllocatorSession::ChromiumPortAllocatorSession( 49 ChromiumPortAllocatorSession::ChromiumPortAllocatorSession(
55 PortAllocatorBase* allocator, 50 ChromiumPortAllocator* allocator,
56 const std::string& content_name, 51 const std::string& content_name,
57 int component, 52 int component,
58 const std::string& ice_username_fragment, 53 const std::string& ice_username_fragment,
59 const std::string& ice_password, 54 const std::string& ice_password)
60 const std::vector<rtc::SocketAddress>& stun_hosts,
61 const std::vector<std::string>& relay_hosts,
62 const std::string& relay,
63 const scoped_refptr<net::URLRequestContextGetter>& url_context)
64 : PortAllocatorSessionBase(allocator, 55 : PortAllocatorSessionBase(allocator,
65 content_name, 56 content_name,
66 component, 57 component,
67 ice_username_fragment, 58 ice_username_fragment,
68 ice_password, 59 ice_password),
69 stun_hosts, 60 url_context_(allocator->url_context()) {}
70 relay_hosts,
71 relay),
72 url_context_(url_context) {}
73 61
74 ChromiumPortAllocatorSession::~ChromiumPortAllocatorSession() { 62 ChromiumPortAllocatorSession::~ChromiumPortAllocatorSession() {
75 STLDeleteElements(&url_fetchers_); 63 STLDeleteElements(&url_fetchers_);
76 } 64 }
77 65
78 void ChromiumPortAllocatorSession::ConfigReady(
79 cricket::PortConfiguration* config) {
80 // Filter out non-UDP relay ports, so that we don't try using TCP.
81 for (cricket::PortConfiguration::RelayList::iterator relay =
82 config->relays.begin(); relay != config->relays.end(); ++relay) {
83 cricket::PortList filtered_ports;
84 for (cricket::PortList::iterator port =
85 relay->ports.begin(); port != relay->ports.end(); ++port) {
86 if (port->proto == cricket::PROTO_UDP) {
87 filtered_ports.push_back(*port);
88 }
89 }
90 relay->ports = filtered_ports;
91 }
92 cricket::BasicPortAllocatorSession::ConfigReady(config);
93 }
94
95 void ChromiumPortAllocatorSession::SendSessionRequest(const std::string& host) { 66 void ChromiumPortAllocatorSession::SendSessionRequest(const std::string& host) {
96 GURL url("https://" + host + GetSessionRequestUrl() + "&sn=1"); 67 GURL url("https://" + host + GetSessionRequestUrl() + "&sn=1");
97 scoped_ptr<net::URLFetcher> url_fetcher = 68 scoped_ptr<net::URLFetcher> url_fetcher =
98 net::URLFetcher::Create(url, net::URLFetcher::GET, this); 69 net::URLFetcher::Create(url, net::URLFetcher::GET, this);
99 url_fetcher->SetRequestContext(url_context_.get()); 70 url_fetcher->SetRequestContext(url_context_.get());
100 url_fetcher->AddExtraRequestHeader("X-Talk-Google-Relay-Auth: " + 71 url_fetcher->AddExtraRequestHeader("X-Talk-Google-Relay-Auth: " +
101 relay_token()); 72 relay_token());
102 url_fetcher->AddExtraRequestHeader("X-Google-Relay-Auth: " + relay_token()); 73 url_fetcher->AddExtraRequestHeader("X-Google-Relay-Auth: " + relay_token());
103 url_fetcher->AddExtraRequestHeader("X-Stream-Type: chromoting"); 74 url_fetcher->AddExtraRequestHeader("X-Stream-Type: chromoting");
104 url_fetcher->Start(); 75 url_fetcher->Start();
(...skipping 14 matching lines...) Expand all
119 << response_code; 90 << response_code;
120 TryCreateRelaySession(); 91 TryCreateRelaySession();
121 return; 92 return;
122 } 93 }
123 94
124 ReceiveSessionResponse(response); 95 ReceiveSessionResponse(response);
125 } 96 }
126 97
127 } // namespace 98 } // namespace
128 99
129 // static
130 scoped_ptr<ChromiumPortAllocator> ChromiumPortAllocator::Create(
131 const scoped_refptr<net::URLRequestContextGetter>& url_context) {
132 scoped_ptr<rtc::NetworkManager> network_manager(
133 new rtc::BasicNetworkManager());
134 scoped_ptr<rtc::PacketSocketFactory> socket_factory(
135 new ChromiumPacketSocketFactory());
136 return make_scoped_ptr(new ChromiumPortAllocator(
137 url_context, std::move(network_manager), std::move(socket_factory)));
138 }
139
140 ChromiumPortAllocator::ChromiumPortAllocator( 100 ChromiumPortAllocator::ChromiumPortAllocator(
141 const scoped_refptr<net::URLRequestContextGetter>& url_context,
142 scoped_ptr<rtc::NetworkManager> network_manager, 101 scoped_ptr<rtc::NetworkManager> network_manager,
143 scoped_ptr<rtc::PacketSocketFactory> socket_factory) 102 scoped_ptr<rtc::PacketSocketFactory> socket_factory,
144 : PortAllocatorBase(network_manager.get(), socket_factory.get()), 103 scoped_refptr<TransportContext> transport_context,
145 url_context_(url_context), 104 scoped_refptr<net::URLRequestContextGetter> url_context)
146 network_manager_(std::move(network_manager)), 105 : PortAllocatorBase(std::move(network_manager),
147 socket_factory_(std::move(socket_factory)) {} 106 std::move(socket_factory),
107 transport_context),
108 url_context_(url_context) {}
148 109
149 ChromiumPortAllocator::~ChromiumPortAllocator() {} 110 ChromiumPortAllocator::~ChromiumPortAllocator() {}
150 111
151 cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal( 112 cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal(
152 const std::string& content_name, 113 const std::string& content_name,
153 int component, 114 int component,
154 const std::string& ice_username_fragment, 115 const std::string& ice_username_fragment,
155 const std::string& ice_password) { 116 const std::string& ice_password) {
156 return new ChromiumPortAllocatorSession( 117 return new ChromiumPortAllocatorSession(this, content_name, component,
157 this, content_name, component, ice_username_fragment, ice_password, 118 ice_username_fragment, ice_password);
158 stun_hosts(), relay_hosts(), relay_token(), url_context_);
159 } 119 }
160 120
161 ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory( 121 ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory(
162 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) 122 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
163 : url_request_context_getter_(url_request_context_getter) {} 123 : url_request_context_getter_(url_request_context_getter) {}
164 124
165 ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {} 125 ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {}
166 126
167 scoped_ptr<PortAllocatorBase> 127 scoped_ptr<cricket::PortAllocator>
168 ChromiumPortAllocatorFactory::CreatePortAllocator() { 128 ChromiumPortAllocatorFactory::CreatePortAllocator(
169 return ChromiumPortAllocator::Create(url_request_context_getter_); 129 scoped_refptr<TransportContext> transport_context) {
130 scoped_ptr<rtc::NetworkManager> network_manager(
131 new rtc::BasicNetworkManager());
132 scoped_ptr<rtc::PacketSocketFactory> socket_factory(
133 new ChromiumPacketSocketFactory());
134 return make_scoped_ptr(new ChromiumPortAllocator(
135 std::move(network_manager), std::move(socket_factory), transport_context,
136 url_request_context_getter_));
170 } 137 }
171 138
172 } // namespace protocol 139 } // namespace protocol
173 } // namespace remoting 140 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/chromium_port_allocator.h ('k') | remoting/protocol/ice_transport_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698