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

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

Issue 1521883006: Add TransportContext class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/http/http_status_code.h" 10 #include "net/http/http_status_code.h"
11 #include "net/url_request/url_fetcher.h" 11 #include "net/url_request/url_fetcher.h"
12 #include "net/url_request/url_fetcher_delegate.h" 12 #include "net/url_request/url_fetcher_delegate.h"
13 #include "net/url_request/url_request_context_getter.h" 13 #include "net/url_request/url_request_context_getter.h"
14 #include "remoting/protocol/chromium_socket_factory.h" 14 #include "remoting/protocol/chromium_socket_factory.h"
15 #include "remoting/protocol/network_settings.h"
16 #include "url/gurl.h" 15 #include "url/gurl.h"
17 16
18 namespace remoting { 17 namespace remoting {
19 namespace protocol { 18 namespace protocol {
20 19
21 namespace { 20 namespace {
22 21
23 class ChromiumPortAllocatorSession 22 class ChromiumPortAllocatorSession
24 : public cricket::HttpPortAllocatorSessionBase, 23 : public cricket::HttpPortAllocatorSessionBase,
25 public net::URLFetcherDelegate { 24 public net::URLFetcherDelegate {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 return; 123 return;
125 } 124 }
126 125
127 ReceiveSessionResponse(response); 126 ReceiveSessionResponse(response);
128 } 127 }
129 128
130 } // namespace 129 } // namespace
131 130
132 // static 131 // static
133 scoped_ptr<ChromiumPortAllocator> ChromiumPortAllocator::Create( 132 scoped_ptr<ChromiumPortAllocator> ChromiumPortAllocator::Create(
134 const scoped_refptr<net::URLRequestContextGetter>& url_context, 133 const scoped_refptr<net::URLRequestContextGetter>& url_context) {
135 const NetworkSettings& network_settings) {
136 scoped_ptr<rtc::NetworkManager> network_manager( 134 scoped_ptr<rtc::NetworkManager> network_manager(
137 new rtc::BasicNetworkManager()); 135 new rtc::BasicNetworkManager());
138 scoped_ptr<rtc::PacketSocketFactory> socket_factory( 136 scoped_ptr<rtc::PacketSocketFactory> socket_factory(
139 new ChromiumPacketSocketFactory()); 137 new ChromiumPacketSocketFactory());
140 scoped_ptr<ChromiumPortAllocator> result( 138 return make_scoped_ptr(new ChromiumPortAllocator(
141 new ChromiumPortAllocator(url_context, network_manager.Pass(), 139 url_context, network_manager.Pass(), socket_factory.Pass()));
142 socket_factory.Pass()));
143
144 // We always use PseudoTcp to provide a reliable channel. It provides poor
145 // performance when combined with TCP-based transport, so we have to disable
146 // TCP ports. ENABLE_SHARED_UFRAG flag is specified so that the same username
147 // fragment is shared between all candidates for this channel.
148 int flags = cricket::PORTALLOCATOR_DISABLE_TCP |
149 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
150 cricket::PORTALLOCATOR_ENABLE_IPV6;
151
152 if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_STUN))
153 flags |= cricket::PORTALLOCATOR_DISABLE_STUN;
154
155 if (!(network_settings.flags & NetworkSettings::NAT_TRAVERSAL_RELAY))
156 flags |= cricket::PORTALLOCATOR_DISABLE_RELAY;
157
158 result->set_flags(flags);
159 result->SetPortRange(network_settings.port_range.min_port,
160 network_settings.port_range.max_port);
161
162 return result.Pass();
163 } 140 }
164 141
165 ChromiumPortAllocator::ChromiumPortAllocator( 142 ChromiumPortAllocator::ChromiumPortAllocator(
166 const scoped_refptr<net::URLRequestContextGetter>& url_context, 143 const scoped_refptr<net::URLRequestContextGetter>& url_context,
167 scoped_ptr<rtc::NetworkManager> network_manager, 144 scoped_ptr<rtc::NetworkManager> network_manager,
168 scoped_ptr<rtc::PacketSocketFactory> socket_factory) 145 scoped_ptr<rtc::PacketSocketFactory> socket_factory)
169 : HttpPortAllocatorBase(network_manager.get(), 146 : HttpPortAllocatorBase(network_manager.get(),
170 socket_factory.get(), 147 socket_factory.get(),
171 std::string()), 148 std::string()),
172 url_context_(url_context), 149 url_context_(url_context),
173 network_manager_(network_manager.Pass()), 150 network_manager_(network_manager.Pass()),
174 socket_factory_(socket_factory.Pass()) {} 151 socket_factory_(socket_factory.Pass()) {}
175 152
176 ChromiumPortAllocator::~ChromiumPortAllocator() { 153 ChromiumPortAllocator::~ChromiumPortAllocator() {}
177 }
178 154
179 cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal( 155 cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal(
180 const std::string& content_name, 156 const std::string& content_name,
181 int component, 157 int component,
182 const std::string& ice_username_fragment, 158 const std::string& ice_username_fragment,
183 const std::string& ice_password) { 159 const std::string& ice_password) {
184 return new ChromiumPortAllocatorSession( 160 return new ChromiumPortAllocatorSession(
185 this, content_name, component, ice_username_fragment, ice_password, 161 this, content_name, component, ice_username_fragment, ice_password,
186 stun_hosts(), relay_hosts(), relay_token(), url_context_); 162 stun_hosts(), relay_hosts(), relay_token(), url_context_);
187 } 163 }
188 164
165 ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory(
166 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
167 : url_request_context_getter_(url_request_context_getter) {}
168
169 ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {}
170
171 scoped_ptr<cricket::HttpPortAllocatorBase>
172 ChromiumPortAllocatorFactory::CreatePortAllocator() {
173 return ChromiumPortAllocator::Create(url_request_context_getter_);
174 }
175
189 } // namespace protocol 176 } // namespace protocol
190 } // namespace remoting 177 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/chromium_port_allocator.h ('k') | remoting/protocol/chromium_port_allocator_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698