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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/chromium_port_allocator.cc
diff --git a/remoting/protocol/chromium_port_allocator.cc b/remoting/protocol/chromium_port_allocator.cc
index cf656f004e9109d9224c2564c7ab91daebe098cd..d9fb4ab235d41d3b35f8a8e193a696de05e0963d 100644
--- a/remoting/protocol/chromium_port_allocator.cc
+++ b/remoting/protocol/chromium_port_allocator.cc
@@ -15,6 +15,7 @@
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context_getter.h"
#include "remoting/protocol/chromium_socket_factory.h"
+#include "remoting/protocol/transport_context.h"
#include "url/gurl.h"
namespace remoting {
@@ -25,26 +26,25 @@ namespace {
class ChromiumPortAllocatorSession : public PortAllocatorSessionBase,
public net::URLFetcherDelegate {
public:
- ChromiumPortAllocatorSession(
- PortAllocatorBase* allocator,
- const std::string& content_name,
- int component,
- const std::string& ice_username_fragment,
- const std::string& ice_password,
- const std::vector<rtc::SocketAddress>& stun_hosts,
- const std::vector<std::string>& relay_hosts,
- const std::string& relay,
- const scoped_refptr<net::URLRequestContextGetter>& url_context);
+ ChromiumPortAllocatorSession(PortAllocatorBase* allocator,
+ const std::string& content_name,
+ int component,
+ const std::string& ice_username_fragment,
+ const std::string& ice_password);
~ChromiumPortAllocatorSession() override;
// PortAllocatorBase overrides.
- void ConfigReady(cricket::PortConfiguration* config) override;
void SendSessionRequest(const std::string& host) override;
// net::URLFetcherDelegate interface.
void OnURLFetchComplete(const net::URLFetcher* url_fetcher) override;
private:
+ ChromiumPortAllocator* allocator() override {
+ return static_cast<ChromiumPortAllocator*>(
Jamie 2016/01/09 00:12:07 Similarly, consider saving the URL context in the
Sergey Ulanov 2016/01/11 20:01:04 Done. Also removed allocator() override from PortA
+ BasicPortAllocatorSession::allocator());
+ }
+
scoped_refptr<net::URLRequestContextGetter> url_context_;
std::set<const net::URLFetcher*> url_fetchers_;
@@ -56,47 +56,22 @@ ChromiumPortAllocatorSession::ChromiumPortAllocatorSession(
const std::string& content_name,
int component,
const std::string& ice_username_fragment,
- const std::string& ice_password,
- const std::vector<rtc::SocketAddress>& stun_hosts,
- const std::vector<std::string>& relay_hosts,
- const std::string& relay,
- const scoped_refptr<net::URLRequestContextGetter>& url_context)
+ const std::string& ice_password)
: PortAllocatorSessionBase(allocator,
content_name,
component,
ice_username_fragment,
- ice_password,
- stun_hosts,
- relay_hosts,
- relay),
- url_context_(url_context) {}
+ ice_password) {}
ChromiumPortAllocatorSession::~ChromiumPortAllocatorSession() {
STLDeleteElements(&url_fetchers_);
}
-void ChromiumPortAllocatorSession::ConfigReady(
- cricket::PortConfiguration* config) {
- // Filter out non-UDP relay ports, so that we don't try using TCP.
- for (cricket::PortConfiguration::RelayList::iterator relay =
- config->relays.begin(); relay != config->relays.end(); ++relay) {
- cricket::PortList filtered_ports;
- for (cricket::PortList::iterator port =
- relay->ports.begin(); port != relay->ports.end(); ++port) {
- if (port->proto == cricket::PROTO_UDP) {
- filtered_ports.push_back(*port);
- }
- }
- relay->ports = filtered_ports;
- }
- cricket::BasicPortAllocatorSession::ConfigReady(config);
-}
-
void ChromiumPortAllocatorSession::SendSessionRequest(const std::string& host) {
GURL url("https://" + host + GetSessionRequestUrl() + "&sn=1");
scoped_ptr<net::URLFetcher> url_fetcher =
net::URLFetcher::Create(url, net::URLFetcher::GET, this);
- url_fetcher->SetRequestContext(url_context_.get());
+ url_fetcher->SetRequestContext(allocator()->url_context().get());
url_fetcher->AddExtraRequestHeader("X-Talk-Google-Relay-Auth: " +
relay_token());
url_fetcher->AddExtraRequestHeader("X-Google-Relay-Auth: " + relay_token());
@@ -126,25 +101,15 @@ void ChromiumPortAllocatorSession::OnURLFetchComplete(
} // namespace
-// static
-scoped_ptr<ChromiumPortAllocator> ChromiumPortAllocator::Create(
- const scoped_refptr<net::URLRequestContextGetter>& url_context) {
- scoped_ptr<rtc::NetworkManager> network_manager(
- new rtc::BasicNetworkManager());
- scoped_ptr<rtc::PacketSocketFactory> socket_factory(
- new ChromiumPacketSocketFactory());
- return make_scoped_ptr(new ChromiumPortAllocator(
- url_context, std::move(network_manager), std::move(socket_factory)));
-}
-
ChromiumPortAllocator::ChromiumPortAllocator(
- const scoped_refptr<net::URLRequestContextGetter>& url_context,
scoped_ptr<rtc::NetworkManager> network_manager,
- scoped_ptr<rtc::PacketSocketFactory> socket_factory)
- : PortAllocatorBase(network_manager.get(), socket_factory.get()),
- url_context_(url_context),
- network_manager_(std::move(network_manager)),
- socket_factory_(std::move(socket_factory)) {}
+ scoped_ptr<rtc::PacketSocketFactory> socket_factory,
+ scoped_refptr<TransportContext> transport_context,
+ scoped_refptr<net::URLRequestContextGetter> url_context)
+ : PortAllocatorBase(std::move(network_manager),
+ std::move(socket_factory),
+ transport_context),
+ url_context_(url_context) {}
ChromiumPortAllocator::~ChromiumPortAllocator() {}
@@ -153,9 +118,8 @@ cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal(
int component,
const std::string& ice_username_fragment,
const std::string& ice_password) {
- return new ChromiumPortAllocatorSession(
- this, content_name, component, ice_username_fragment, ice_password,
- stun_hosts(), relay_hosts(), relay_token(), url_context_);
+ return new ChromiumPortAllocatorSession(this, content_name, component,
+ ice_username_fragment, ice_password);
}
ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory(
@@ -164,9 +128,16 @@ ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory(
ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {}
-scoped_ptr<PortAllocatorBase>
-ChromiumPortAllocatorFactory::CreatePortAllocator() {
- return ChromiumPortAllocator::Create(url_request_context_getter_);
+scoped_ptr<cricket::PortAllocator>
+ChromiumPortAllocatorFactory::CreatePortAllocator(
+ scoped_refptr<TransportContext> transport_context) {
+ scoped_ptr<rtc::NetworkManager> network_manager(
+ new rtc::BasicNetworkManager());
+ scoped_ptr<rtc::PacketSocketFactory> socket_factory(
+ new ChromiumPacketSocketFactory());
+ return make_scoped_ptr(new ChromiumPortAllocator(
+ std::move(network_manager), std::move(socket_factory), transport_context,
+ url_request_context_getter_));
}
} // namespace protocol

Powered by Google App Engine
This is Rietveld 408576698