diff options
author | sergeyu <sergeyu@chromium.org> | 2016-02-11 15:47:01 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-11 23:48:38 +0000 |
commit | c3c43e8732254dedcbd313629f8c9eba93dff6fa (patch) | |
tree | dec7b5fa7233c9063fa651e7dbebe1242b303826 /remoting/protocol | |
parent | cb092cd91ca95112508d2b86af2b8199e1b90e77 (diff) | |
download | chromium_src-c3c43e8732254dedcbd313629f8c9eba93dff6fa.zip chromium_src-c3c43e8732254dedcbd313629f8c9eba93dff6fa.tar.gz chromium_src-c3c43e8732254dedcbd313629f8c9eba93dff6fa.tar.bz2 |
Use UrlRequest in PortAllocator.
PepperPortAllocator and ChromiumPortAllocator were different only in
how they were sending HTTP requests to allocate relay session. They were
using pp::URLLoader and net::URLFetcher respectively, but otherwise
contained largely the same logic. Now URL request logic is abstracted
with remoting::UrlRequest interface and so a single PortAllocator
implementation can be used in all cases.
BUG=577954
Review URL: https://codereview.chromium.org/1681393006
Cr-Commit-Position: refs/heads/master@{#375042}
Diffstat (limited to 'remoting/protocol')
-rw-r--r-- | remoting/protocol/chromium_port_allocator.cc | 140 | ||||
-rw-r--r-- | remoting/protocol/chromium_port_allocator.h | 72 | ||||
-rw-r--r-- | remoting/protocol/chromium_port_allocator_factory.cc | 26 | ||||
-rw-r--r-- | remoting/protocol/chromium_port_allocator_factory.h | 34 | ||||
-rw-r--r-- | remoting/protocol/ice_transport_unittest.cc | 11 | ||||
-rw-r--r-- | remoting/protocol/jingle_session_unittest.cc | 2 | ||||
-rw-r--r-- | remoting/protocol/port_allocator.cc (renamed from remoting/protocol/port_allocator_base.cc) | 74 | ||||
-rw-r--r-- | remoting/protocol/port_allocator.h (renamed from remoting/protocol/port_allocator_base.h) | 53 | ||||
-rw-r--r-- | remoting/protocol/port_allocator_factory.h | 1 | ||||
-rw-r--r-- | remoting/protocol/transport_context.cc | 12 | ||||
-rw-r--r-- | remoting/protocol/transport_context.h | 9 | ||||
-rw-r--r-- | remoting/protocol/webrtc_transport.cc | 1 | ||||
-rw-r--r-- | remoting/protocol/webrtc_transport.h | 1 |
13 files changed, 153 insertions, 283 deletions
diff --git a/remoting/protocol/chromium_port_allocator.cc b/remoting/protocol/chromium_port_allocator.cc deleted file mode 100644 index 607fc22..0000000 --- a/remoting/protocol/chromium_port_allocator.cc +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "remoting/protocol/chromium_port_allocator.h" - -#include <utility> - -#include "base/bind.h" -#include "base/macros.h" -#include "base/stl_util.h" -#include "base/strings/string_number_conversions.h" -#include "net/http/http_status_code.h" -#include "net/url_request/url_fetcher.h" -#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 { -namespace protocol { - -namespace { - -class ChromiumPortAllocatorSession : public PortAllocatorSessionBase, - public net::URLFetcherDelegate { - public: - ChromiumPortAllocatorSession(ChromiumPortAllocator* allocator, - const std::string& content_name, - int component, - const std::string& ice_username_fragment, - const std::string& ice_password); - ~ChromiumPortAllocatorSession() override; - - // PortAllocatorBase overrides. - void SendSessionRequest(const std::string& host) override; - - // net::URLFetcherDelegate interface. - void OnURLFetchComplete(const net::URLFetcher* url_fetcher) override; - - private: - scoped_refptr<net::URLRequestContextGetter> url_context_; - std::set<const net::URLFetcher*> url_fetchers_; - - DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocatorSession); -}; - -ChromiumPortAllocatorSession::ChromiumPortAllocatorSession( - ChromiumPortAllocator* allocator, - const std::string& content_name, - int component, - const std::string& ice_username_fragment, - const std::string& ice_password) - : PortAllocatorSessionBase(allocator, - content_name, - component, - ice_username_fragment, - ice_password), - url_context_(allocator->url_context()) {} - -ChromiumPortAllocatorSession::~ChromiumPortAllocatorSession() { - STLDeleteElements(&url_fetchers_); -} - -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->AddExtraRequestHeader("X-Talk-Google-Relay-Auth: " + - relay_token()); - url_fetcher->AddExtraRequestHeader("X-Google-Relay-Auth: " + relay_token()); - url_fetcher->AddExtraRequestHeader("X-Stream-Type: chromoting"); - url_fetcher->Start(); - url_fetchers_.insert(url_fetcher.release()); -} - -void ChromiumPortAllocatorSession::OnURLFetchComplete( - const net::URLFetcher* source) { - int response_code = source->GetResponseCode(); - std::string response; - source->GetResponseAsString(&response); - - url_fetchers_.erase(source); - delete source; - - if (response_code != net::HTTP_OK) { - LOG(WARNING) << "Received error when allocating relay session: " - << response_code; - TryCreateRelaySession(); - return; - } - - ReceiveSessionResponse(response); -} - -} // namespace - -ChromiumPortAllocator::ChromiumPortAllocator( - scoped_ptr<rtc::NetworkManager> network_manager, - 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() {} - -cricket::PortAllocatorSession* ChromiumPortAllocator::CreateSessionInternal( - const std::string& content_name, - 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); -} - -ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory( - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) - : url_request_context_getter_(url_request_context_getter) {} - -ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {} - -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 -} // namespace remoting diff --git a/remoting/protocol/chromium_port_allocator.h b/remoting/protocol/chromium_port_allocator.h deleted file mode 100644 index d01497a..0000000 --- a/remoting/protocol/chromium_port_allocator.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef REMOTING_PROTOCOL_CHROMIUM_PORT_ALLOCATOR_H_ -#define REMOTING_PROTOCOL_CHROMIUM_PORT_ALLOCATOR_H_ - -#include <set> - -#include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "remoting/protocol/port_allocator_base.h" -#include "remoting/protocol/port_allocator_factory.h" - -namespace net { -class URLRequestContextGetter; -} // namespace net - -namespace remoting { -namespace protocol { - -struct NetworkSettings; - -// An implementation of cricket::PortAllocator that uses Chromium's network -// stack. -class ChromiumPortAllocator : public PortAllocatorBase { - public: - ChromiumPortAllocator( - scoped_ptr<rtc::NetworkManager> network_manager, - scoped_ptr<rtc::PacketSocketFactory> socket_factory, - scoped_refptr<TransportContext> transport_context, - scoped_refptr<net::URLRequestContextGetter> url_context); - ~ChromiumPortAllocator() override; - - scoped_refptr<net::URLRequestContextGetter> url_context() { - return url_context_; - } - - // PortAllocatorBase overrides. - cricket::PortAllocatorSession* CreateSessionInternal( - const std::string& content_name, - int component, - const std::string& ice_username_fragment, - const std::string& ice_password) override; - - private: - scoped_refptr<net::URLRequestContextGetter> url_context_; - - DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocator); -}; - -class ChromiumPortAllocatorFactory : public PortAllocatorFactory { - public: - ChromiumPortAllocatorFactory( - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); - ~ChromiumPortAllocatorFactory() override; - - // PortAllocatorFactory interface. - scoped_ptr<cricket::PortAllocator> CreatePortAllocator( - scoped_refptr<TransportContext> transport_context) override; - - private: - scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; - - DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocatorFactory); -}; - -} // namespace protocol -} // namespace remoting - -#endif // REMOTING_HOST_HOST_PORT_ALLOCATOR_H_ diff --git a/remoting/protocol/chromium_port_allocator_factory.cc b/remoting/protocol/chromium_port_allocator_factory.cc new file mode 100644 index 0000000..26e65bb --- /dev/null +++ b/remoting/protocol/chromium_port_allocator_factory.cc @@ -0,0 +1,26 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "remoting/protocol/chromium_port_allocator_factory.h" + +#include "remoting/protocol/chromium_socket_factory.h" +#include "remoting/protocol/port_allocator.h" +#include "remoting/protocol/transport_context.h" + +namespace remoting { +namespace protocol { + +ChromiumPortAllocatorFactory::ChromiumPortAllocatorFactory() {} +ChromiumPortAllocatorFactory::~ChromiumPortAllocatorFactory() {} + +scoped_ptr<cricket::PortAllocator> +ChromiumPortAllocatorFactory::CreatePortAllocator( + scoped_refptr<TransportContext> transport_context) { + return make_scoped_ptr(new PortAllocator( + make_scoped_ptr(new rtc::BasicNetworkManager()), + make_scoped_ptr(new ChromiumPacketSocketFactory()), transport_context)); +} + +} // namespace protocol +} // namespace remoting diff --git a/remoting/protocol/chromium_port_allocator_factory.h b/remoting/protocol/chromium_port_allocator_factory.h new file mode 100644 index 0000000..3da8cca --- /dev/null +++ b/remoting/protocol/chromium_port_allocator_factory.h @@ -0,0 +1,34 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef REMOTING_PROTOCOL_CHROMIUM_PORT_ALLOCATOR_FACTORY_H_ +#define REMOTING_PROTOCOL_CHROMIUM_PORT_ALLOCATOR_FACTORY_H_ + +#include <set> + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "remoting/protocol/port_allocator_factory.h" + +namespace remoting { +namespace protocol { + +class ChromiumPortAllocatorFactory : public PortAllocatorFactory { + public: + ChromiumPortAllocatorFactory(); + ~ChromiumPortAllocatorFactory() override; + + // PortAllocatorFactory interface. + scoped_ptr<cricket::PortAllocator> CreatePortAllocator( + scoped_refptr<TransportContext> transport_context) override; + + private: + DISALLOW_COPY_AND_ASSIGN(ChromiumPortAllocatorFactory); +}; + +} // namespace protocol +} // namespace remoting + +#endif // REMOTING_PROTOCOL_CHROMIUM_PORT_ALLOCATOR_FACTORY_H_ diff --git a/remoting/protocol/ice_transport_unittest.cc b/remoting/protocol/ice_transport_unittest.cc index 21164ab..467fb1a 100644 --- a/remoting/protocol/ice_transport_unittest.cc +++ b/remoting/protocol/ice_transport_unittest.cc @@ -15,7 +15,8 @@ #include "base/thread_task_runner_handle.h" #include "jingle/glue/thread_wrapper.h" #include "net/url_request/url_request_context_getter.h" -#include "remoting/protocol/chromium_port_allocator.h" +#include "remoting/base/url_request.h" +#include "remoting/protocol/chromium_port_allocator_factory.h" #include "remoting/protocol/connection_tester.h" #include "remoting/protocol/fake_authenticator.h" #include "remoting/protocol/message_channel_factory.h" @@ -117,8 +118,8 @@ class IceTransportTest : public testing::Test { host_transport_.reset(new IceTransport( new TransportContext( - nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), - network_settings_, TransportRole::SERVER), + nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory()), + nullptr, network_settings_, TransportRole::SERVER), &host_event_handler_)); if (!host_authenticator_) { host_authenticator_.reset(new FakeAuthenticator( @@ -127,8 +128,8 @@ class IceTransportTest : public testing::Test { client_transport_.reset(new IceTransport( new TransportContext( - nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory(nullptr)), - network_settings_, TransportRole::CLIENT), + nullptr, make_scoped_ptr(new ChromiumPortAllocatorFactory()), + nullptr, network_settings_, TransportRole::CLIENT), &client_event_handler_)); if (!client_authenticator_) { client_authenticator_.reset(new FakeAuthenticator( diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index adb1fc4..6701338 100644 --- a/remoting/protocol/jingle_session_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -17,7 +17,7 @@ #include "remoting/base/constants.h" #include "remoting/protocol/authenticator.h" #include "remoting/protocol/channel_authenticator.h" -#include "remoting/protocol/chromium_port_allocator.h" +#include "remoting/protocol/chromium_port_allocator_factory.h" #include "remoting/protocol/connection_tester.h" #include "remoting/protocol/fake_authenticator.h" #include "remoting/protocol/jingle_session_manager.h" diff --git a/remoting/protocol/port_allocator_base.cc b/remoting/protocol/port_allocator.cc index acc26c7..8f9a423 100644 --- a/remoting/protocol/port_allocator_base.cc +++ b/remoting/protocol/port_allocator.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "remoting/protocol/port_allocator_base.h" +#include "remoting/protocol/port_allocator.h" #include <algorithm> #include <map> @@ -12,6 +12,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "net/base/escape.h" +#include "net/http/http_status_code.h" #include "remoting/protocol/network_settings.h" #include "remoting/protocol/transport_context.h" @@ -32,14 +33,14 @@ StringMap ParseMap(const std::string& string) { return map; } +const int kNumRetries = 5; + } // namespace namespace remoting { namespace protocol { -const int PortAllocatorBase::kNumRetries = 5; - -PortAllocatorBase::PortAllocatorBase( +PortAllocator::PortAllocator( scoped_ptr<rtc::NetworkManager> network_manager, scoped_ptr<rtc::PacketSocketFactory> socket_factory, scoped_refptr<TransportContext> transport_context) @@ -68,14 +69,22 @@ PortAllocatorBase::PortAllocatorBase( network_settings.port_range.max_port); } -PortAllocatorBase::~PortAllocatorBase() {} +PortAllocator::~PortAllocator() {} -PortAllocatorSessionBase::PortAllocatorSessionBase( - PortAllocatorBase* allocator, +cricket::PortAllocatorSession* PortAllocator::CreateSessionInternal( const std::string& content_name, int component, - const std::string& ice_ufrag, - const std::string& ice_pwd) + const std::string& ice_username_fragment, + const std::string& ice_password) { + return new PortAllocatorSession(this, content_name, component, + ice_username_fragment, ice_password); +} + +PortAllocatorSession::PortAllocatorSession(PortAllocator* allocator, + const std::string& content_name, + int component, + const std::string& ice_ufrag, + const std::string& ice_pwd) : BasicPortAllocatorSession(allocator, content_name, component, @@ -84,14 +93,14 @@ PortAllocatorSessionBase::PortAllocatorSessionBase( transport_context_(allocator->transport_context()), weak_factory_(this) {} -PortAllocatorSessionBase::~PortAllocatorSessionBase() {} +PortAllocatorSession::~PortAllocatorSession() {} -void PortAllocatorSessionBase::GetPortConfigurations() { +void PortAllocatorSession::GetPortConfigurations() { transport_context_->GetJingleInfo(base::Bind( - &PortAllocatorSessionBase::OnJingleInfo, weak_factory_.GetWeakPtr())); + &PortAllocatorSession::OnJingleInfo, weak_factory_.GetWeakPtr())); } -void PortAllocatorSessionBase::OnJingleInfo( +void PortAllocatorSession::OnJingleInfo( std::vector<rtc::SocketAddress> stun_hosts, std::vector<std::string> relay_hosts, std::string relay_token) { @@ -115,11 +124,11 @@ void PortAllocatorSessionBase::OnJingleInfo( TryCreateRelaySession(); } -void PortAllocatorSessionBase::TryCreateRelaySession() { +void PortAllocatorSession::TryCreateRelaySession() { if (flags() & cricket::PORTALLOCATOR_DISABLE_RELAY) return; - if (attempts_ == PortAllocatorBase::kNumRetries) { + if (attempts_ == kNumRetries) { LOG(ERROR) << "PortAllocator: maximum number of requests reached; " << "giving up on relay."; return; @@ -138,20 +147,33 @@ void PortAllocatorSessionBase::TryCreateRelaySession() { // Choose the next host to try. std::string host = relay_hosts_[attempts_ % relay_hosts_.size()]; attempts_++; - SendSessionRequest(host); -} -std::string PortAllocatorSessionBase::GetSessionRequestUrl() { - ASSERT(!username().empty()); - ASSERT(!password().empty()); - return "/create_session?username=" + - net::EscapeUrlEncodedData(username(), false) + "&password=" + - net::EscapeUrlEncodedData(password(), false); + DCHECK(!username().empty()); + DCHECK(!password().empty()); + std::string url = "https://" + host + "/create_session?username=" + + net::EscapeUrlEncodedData(username(), false) + + "&password=" + + net::EscapeUrlEncodedData(password(), false) + "&sn=1"; + scoped_ptr<UrlRequest> url_request = + transport_context_->url_request_factory()->CreateUrlRequest(url); + url_request->AddHeader("X-Talk-Google-Relay-Auth: " + relay_token()); + url_request->AddHeader("X-Google-Relay-Auth: " + relay_token()); + url_request->AddHeader("X-Stream-Type: chromoting"); + url_request->Start(base::Bind(&PortAllocatorSession::OnSessionRequestResult, + base::Unretained(this))); + url_requests_.insert(std::move(url_request)); } -void PortAllocatorSessionBase::ReceiveSessionResponse( - const std::string& response) { - StringMap map = ParseMap(response); +void PortAllocatorSession::OnSessionRequestResult( + const UrlRequest::Result& result) { + if (!result.success || result.status != net::HTTP_OK) { + LOG(WARNING) << "Received error when allocating relay session: " + << result.status; + TryCreateRelaySession(); + return; + } + + StringMap map = ParseMap(result.response_body); if (!username().empty() && map["username"] != username()) { LOG(WARNING) << "Received unexpected username value from relay server."; diff --git a/remoting/protocol/port_allocator_base.h b/remoting/protocol/port_allocator.h index 1ad080f..048cc58 100644 --- a/remoting/protocol/port_allocator_base.h +++ b/remoting/protocol/port_allocator.h @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ -#define REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ +#ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_H_ +#define REMOTING_PROTOCOL_PORT_ALLOCATOR_H_ #include <string> #include <vector> #include "base/memory/weak_ptr.h" +#include "remoting/base/url_request.h" #include "third_party/webrtc/p2p/client/basicportallocator.h" namespace remoting { @@ -16,27 +17,22 @@ namespace protocol { class TransportContext; -class PortAllocatorBase : public cricket::BasicPortAllocator { +class PortAllocator : public cricket::BasicPortAllocator { public: - // The number of HTTP requests we should attempt before giving up. - static const int kNumRetries; - - PortAllocatorBase(scoped_ptr<rtc::NetworkManager> network_manager, - scoped_ptr<rtc::PacketSocketFactory> socket_factory, - scoped_refptr<TransportContext> transport_context); - ~PortAllocatorBase() override; + PortAllocator(scoped_ptr<rtc::NetworkManager> network_manager, + scoped_ptr<rtc::PacketSocketFactory> socket_factory, + scoped_refptr<TransportContext> transport_context); + ~PortAllocator() override; scoped_refptr<TransportContext> transport_context() { return transport_context_; } - // CreateSession is defined in cricket::BasicPortAllocator but is - // redefined here as pure virtual. cricket::PortAllocatorSession* CreateSessionInternal( const std::string& content_name, int component, const std::string& ice_ufrag, - const std::string& ice_pwd) override = 0; + const std::string& ice_pwd) override; private: scoped_ptr<rtc::NetworkManager> network_manager_; @@ -44,30 +40,25 @@ class PortAllocatorBase : public cricket::BasicPortAllocator { scoped_refptr<TransportContext> transport_context_; }; -class PortAllocatorSessionBase : public cricket::BasicPortAllocatorSession { +class PortAllocatorSession : public cricket::BasicPortAllocatorSession { public: - PortAllocatorSessionBase(PortAllocatorBase* allocator, - const std::string& content_name, - int component, - const std::string& ice_ufrag, - const std::string& ice_pwd); - ~PortAllocatorSessionBase() override; - - virtual void SendSessionRequest(const std::string& host) = 0; - void ReceiveSessionResponse(const std::string& response); - - protected: - std::string GetSessionRequestUrl(); - + PortAllocatorSession(PortAllocator* allocator, + const std::string& content_name, + int component, + const std::string& ice_ufrag, + const std::string& ice_pwd); + ~PortAllocatorSession() override; + +private: void GetPortConfigurations() override; void OnJingleInfo(std::vector<rtc::SocketAddress> stun_hosts, std::vector<std::string> relay_hosts, std::string relay_token); void TryCreateRelaySession(); + void OnSessionRequestResult(const UrlRequest::Result& result); const std::string& relay_token() const { return relay_token_; } - private: scoped_refptr<TransportContext> transport_context_; std::vector<rtc::SocketAddress> stun_hosts_; @@ -76,10 +67,12 @@ class PortAllocatorSessionBase : public cricket::BasicPortAllocatorSession { int attempts_ = 0; - base::WeakPtrFactory<PortAllocatorSessionBase> weak_factory_; + std::set<scoped_ptr<UrlRequest>> url_requests_; + + base::WeakPtrFactory<PortAllocatorSession> weak_factory_; }; } // namespace protocol } // namespace remoting -#endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_BASE_H_ +#endif // REMOTING_PROTOCOL_PORT_ALLOCATOR_H_ diff --git a/remoting/protocol/port_allocator_factory.h b/remoting/protocol/port_allocator_factory.h index 907b6b5..830cd92 100644 --- a/remoting/protocol/port_allocator_factory.h +++ b/remoting/protocol/port_allocator_factory.h @@ -5,6 +5,7 @@ #ifndef REMOTING_PROTOCOL_PORT_ALLOCATOR_FACTORY_H_ #define REMOTING_PROTOCOL_PORT_ALLOCATOR_FACTORY_H_ +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" namespace cricket { diff --git a/remoting/protocol/transport_context.cc b/remoting/protocol/transport_context.cc index 62b1df2..b8ed300 100644 --- a/remoting/protocol/transport_context.cc +++ b/remoting/protocol/transport_context.cc @@ -10,13 +10,14 @@ #include "base/location.h" #include "base/single_thread_task_runner.h" #include "base/thread_task_runner_handle.h" +#include "remoting/base/url_request.h" #include "remoting/protocol/port_allocator_factory.h" #include "third_party/webrtc/base/socketaddress.h" #if !defined(OS_NACL) #include "jingle/glue/thread_wrapper.h" #include "net/url_request/url_request_context_getter.h" -#include "remoting/protocol/chromium_port_allocator.h" +#include "remoting/protocol/chromium_port_allocator_factory.h" #endif // !defined(OS_NACL) namespace remoting { @@ -30,10 +31,9 @@ static const int kJingleInfoUpdatePeriodSeconds = 3600; scoped_refptr<TransportContext> TransportContext::ForTests(TransportRole role) { jingle_glue::JingleThreadWrapper::EnsureForCurrentMessageLoop(); return new protocol::TransportContext( - nullptr, - make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory(nullptr)), - protocol::NetworkSettings( - protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING), + nullptr, make_scoped_ptr(new protocol::ChromiumPortAllocatorFactory()), + nullptr, protocol::NetworkSettings( + protocol::NetworkSettings::NAT_TRAVERSAL_OUTGOING), role); } #endif // !defined(OS_NACL) @@ -41,10 +41,12 @@ scoped_refptr<TransportContext> TransportContext::ForTests(TransportRole role) { TransportContext::TransportContext( SignalStrategy* signal_strategy, scoped_ptr<PortAllocatorFactory> port_allocator_factory, + scoped_ptr<UrlRequestFactory> url_request_factory, const NetworkSettings& network_settings, TransportRole role) : signal_strategy_(signal_strategy), port_allocator_factory_(std::move(port_allocator_factory)), + url_request_factory_(std::move(url_request_factory)), network_settings_(network_settings), role_(role) {} diff --git a/remoting/protocol/transport_context.h b/remoting/protocol/transport_context.h index fbe0b37..46b9f36 100644 --- a/remoting/protocol/transport_context.h +++ b/remoting/protocol/transport_context.h @@ -16,13 +16,11 @@ #include "remoting/protocol/transport.h" #include "remoting/signaling/jingle_info_request.h" -namespace cricket { -class PortAllocator; -} // namespace cricket namespace remoting { class SignalStrategy; +class UrlRequestFactory; namespace protocol { @@ -41,6 +39,7 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { TransportContext(SignalStrategy* signal_strategy, scoped_ptr<PortAllocatorFactory> port_allocator_factory, + scoped_ptr<UrlRequestFactory> url_request_factory, const NetworkSettings& network_settings, TransportRole role); @@ -55,6 +54,9 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { PortAllocatorFactory* port_allocator_factory() { return port_allocator_factory_.get(); } + UrlRequestFactory* url_request_factory() { + return url_request_factory_.get(); + } const NetworkSettings& network_settings() const { return network_settings_; } TransportRole role() const { return role_; } @@ -70,6 +72,7 @@ class TransportContext : public base::RefCountedThreadSafe<TransportContext> { SignalStrategy* signal_strategy_; scoped_ptr<PortAllocatorFactory> port_allocator_factory_; + scoped_ptr<UrlRequestFactory> url_request_factory_; NetworkSettings network_settings_; TransportRole role_; diff --git a/remoting/protocol/webrtc_transport.cc b/remoting/protocol/webrtc_transport.cc index 105330c..c342a12 100644 --- a/remoting/protocol/webrtc_transport.cc +++ b/remoting/protocol/webrtc_transport.cc @@ -13,6 +13,7 @@ #include "base/task_runner_util.h" #include "base/thread_task_runner_handle.h" #include "jingle/glue/thread_wrapper.h" +#include "remoting/protocol/port_allocator_factory.h" #include "remoting/protocol/stream_message_pipe_adapter.h" #include "remoting/protocol/transport_context.h" #include "third_party/webrtc/api/test/fakeconstraints.h" diff --git a/remoting/protocol/webrtc_transport.h b/remoting/protocol/webrtc_transport.h index bf42467..0001377 100644 --- a/remoting/protocol/webrtc_transport.h +++ b/remoting/protocol/webrtc_transport.h @@ -12,7 +12,6 @@ #include "base/memory/weak_ptr.h" #include "base/threading/thread_checker.h" #include "base/timer/timer.h" -#include "remoting/protocol/port_allocator_factory.h" #include "remoting/protocol/transport.h" #include "remoting/protocol/webrtc_data_stream_adapter.h" #include "remoting/signaling/signal_strategy.h" |