summaryrefslogtreecommitdiffstats
path: root/remoting/host
diff options
context:
space:
mode:
authorsolb@chromium.org <solb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-21 22:42:56 +0000
committersolb@chromium.org <solb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-21 22:42:56 +0000
commit83ed59be229f3ad5236ab913a7a0199648b60441 (patch)
treeee7512b8824f675ca36038f08abf5d458bc6086a /remoting/host
parent086651227011828b8709473ef6e78fb55a8a57fb (diff)
downloadchromium_src-83ed59be229f3ad5236ab913a7a0199648b60441.zip
chromium_src-83ed59be229f3ad5236ab913a7a0199648b60441.tar.gz
chromium_src-83ed59be229f3ad5236ab913a7a0199648b60441.tar.bz2
Add static Create method to LibjingleTransportFactory
This allows the class's easy use in future client implementations. Review URL: https://chromiumcodereview.appspot.com/17101034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207942 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r--remoting/host/host_port_allocator.cc185
-rw-r--r--remoting/host/host_port_allocator.h57
-rw-r--r--remoting/host/network_settings.h54
-rw-r--r--remoting/host/plugin/host_script_object.cc2
-rw-r--r--remoting/host/remoting_me2me_host.cc2
-rw-r--r--remoting/host/session_manager_factory.cc23
-rw-r--r--remoting/host/session_manager_factory.h9
7 files changed, 16 insertions, 316 deletions
diff --git a/remoting/host/host_port_allocator.cc b/remoting/host/host_port_allocator.cc
deleted file mode 100644
index 4fdd790..0000000
--- a/remoting/host/host_port_allocator.cc
+++ /dev/null
@@ -1,185 +0,0 @@
-// Copyright (c) 2012 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/host/host_port_allocator.h"
-
-#include "base/bind.h"
-#include "base/stl_util.h"
-#include "base/strings/string_number_conversions.h"
-#include "googleurl/src/gurl.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/host/network_settings.h"
-#include "remoting/jingle_glue/chromium_socket_factory.h"
-
-namespace remoting {
-
-namespace {
-
-class HostPortAllocatorSession
- : public cricket::HttpPortAllocatorSessionBase,
- public net::URLFetcherDelegate {
- public:
- HostPortAllocatorSession(
- cricket::HttpPortAllocatorBase* allocator,
- const std::string& content_name,
- int component,
- const std::string& ice_username_fragment,
- const std::string& ice_password,
- const std::vector<talk_base::SocketAddress>& stun_hosts,
- const std::vector<std::string>& relay_hosts,
- const std::string& relay,
- const scoped_refptr<net::URLRequestContextGetter>& url_context);
- virtual ~HostPortAllocatorSession();
-
- // cricket::HttpPortAllocatorBase overrides.
- virtual void ConfigReady(cricket::PortConfiguration* config) OVERRIDE;
- virtual void SendSessionRequest(const std::string& host, int port) OVERRIDE;
-
- // net::URLFetcherDelegate interface.
- virtual 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(HostPortAllocatorSession);
-};
-
-HostPortAllocatorSession::HostPortAllocatorSession(
- cricket::HttpPortAllocatorBase* allocator,
- const std::string& content_name,
- int component,
- const std::string& ice_username_fragment,
- const std::string& ice_password,
- const std::vector<talk_base::SocketAddress>& stun_hosts,
- const std::vector<std::string>& relay_hosts,
- const std::string& relay,
- const scoped_refptr<net::URLRequestContextGetter>& url_context)
- : HttpPortAllocatorSessionBase(allocator,
- content_name,
- component,
- ice_username_fragment,
- ice_password,
- stun_hosts,
- relay_hosts,
- relay,
- std::string()),
- url_context_(url_context) {}
-
-HostPortAllocatorSession::~HostPortAllocatorSession() {
- STLDeleteElements(&url_fetchers_);
-}
-
-void HostPortAllocatorSession::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 HostPortAllocatorSession::SendSessionRequest(const std::string& host,
- int port) {
- GURL url("https://" + host + ":" + base::IntToString(port) +
- 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 HostPortAllocatorSession::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
-
-// static
-scoped_ptr<HostPortAllocator> HostPortAllocator::Create(
- const scoped_refptr<net::URLRequestContextGetter>& url_context,
- const NetworkSettings& network_settings) {
- scoped_ptr<talk_base::NetworkManager> network_manager(
- new talk_base::BasicNetworkManager());
- scoped_ptr<talk_base::PacketSocketFactory> socket_factory(
- new remoting::ChromiumPacketSocketFactory());
- scoped_ptr<HostPortAllocator> result(
- new HostPortAllocator(url_context, network_manager.Pass(),
- socket_factory.Pass()));
-
- // We always use PseudoTcp to provide a reliable channel. It
- // provides poor performance when combined with TCP-based transport,
- // so we have to disable TCP ports.
- // ENABLE_SHARED_UFRAG flag is
- // specified so that the same username fragment is shared between
- // all candidates for this channel.
- int flags = cricket::PORTALLOCATOR_DISABLE_TCP |
- cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG;
- if (network_settings.nat_traversal_mode !=
- NetworkSettings::NAT_TRAVERSAL_ENABLED) {
- flags |= cricket::PORTALLOCATOR_DISABLE_STUN |
- cricket::PORTALLOCATOR_DISABLE_RELAY;
- }
- result->set_flags(flags);
- result->SetPortRange(network_settings.min_port,
- network_settings.max_port);
-
- return result.Pass();
-}
-
-HostPortAllocator::HostPortAllocator(
- const scoped_refptr<net::URLRequestContextGetter>& url_context,
- scoped_ptr<talk_base::NetworkManager> network_manager,
- scoped_ptr<talk_base::PacketSocketFactory> socket_factory)
- : HttpPortAllocatorBase(network_manager.get(),
- socket_factory.get(),
- std::string()),
- url_context_(url_context),
- network_manager_(network_manager.Pass()),
- socket_factory_(socket_factory.Pass()) {}
-
-HostPortAllocator::~HostPortAllocator() {
-}
-
-cricket::PortAllocatorSession* HostPortAllocator::CreateSessionInternal(
- const std::string& content_name,
- int component,
- const std::string& ice_username_fragment,
- const std::string& ice_password) {
- return new HostPortAllocatorSession(
- this, content_name, component, ice_username_fragment, ice_password,
- stun_hosts(), relay_hosts(), relay_token(), url_context_);
-}
-
-} // namespace remoting
diff --git a/remoting/host/host_port_allocator.h b/remoting/host/host_port_allocator.h
deleted file mode 100644
index 47d0893..0000000
--- a/remoting/host/host_port_allocator.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright (c) 2012 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_HOST_HOST_PORT_ALLOCATOR_H_
-#define REMOTING_HOST_HOST_PORT_ALLOCATOR_H_
-
-#include <set>
-
-#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
-#include "third_party/libjingle/source/talk/p2p/client/httpportallocator.h"
-
-namespace net {
-class URLRequestContextGetter;
-} // namespace net
-
-namespace remoting {
-
-struct NetworkSettings;
-
-// An implementation of cricket::PortAllocator for libjingle that is
-// used by the remoting host. The main difference from
-// cricket::HttpPortAllocator is that it uses Chromium's HTTP stack
-// when creating relay sessions. It also configures itself according
-// to the specified NetworkSettings.
-class HostPortAllocator : public cricket::HttpPortAllocatorBase {
- public:
- static scoped_ptr<HostPortAllocator> Create(
- const scoped_refptr<net::URLRequestContextGetter>& url_context,
- const NetworkSettings& network_settings);
-
- virtual ~HostPortAllocator();
-
- // cricket::HttpPortAllocatorBase overrides.
- virtual cricket::PortAllocatorSession* CreateSessionInternal(
- const std::string& content_name,
- int component,
- const std::string& ice_username_fragment,
- const std::string& ice_password) OVERRIDE;
-
- private:
- HostPortAllocator(
- const scoped_refptr<net::URLRequestContextGetter>& url_context,
- scoped_ptr<talk_base::NetworkManager> network_manager,
- scoped_ptr<talk_base::PacketSocketFactory> socket_factory);
-
- scoped_refptr<net::URLRequestContextGetter> url_context_;
- scoped_ptr<talk_base::NetworkManager> network_manager_;
- scoped_ptr<talk_base::PacketSocketFactory> socket_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(HostPortAllocator);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_HOST_HOST_PORT_ALLOCATOR_H_
diff --git a/remoting/host/network_settings.h b/remoting/host/network_settings.h
deleted file mode 100644
index 3c1ed97..0000000
--- a/remoting/host/network_settings.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2012 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_HOST_NETWORK_SETTINGS_H_
-#define REMOTING_HOST_NETWORK_SETTINGS_H_
-
-namespace remoting {
-
-struct NetworkSettings {
-
- // When hosts are configured with NAT traversal disabled they will
- // typically also limit their P2P ports to this range, so that
- // sessions may be blocked or un-blocked via firewall rules.
- static const int kDefaultMinPort = 12400;
- static const int kDefaultMaxPort = 12409;
-
- enum NatTraversalMode {
- // Active NAT traversal using STUN and relay servers.
- NAT_TRAVERSAL_ENABLED,
-
- // Don't use STUN or relay servers. Accept incoming P2P connection
- // attempts, but don't initiate any. This ensures that the peer is
- // on the same network. Note that connection will always fail if
- // both ends use this mode.
- NAT_TRAVERSAL_DISABLED,
-
- // Don't use STUN or relay servers but make outgoing connections.
- NAT_TRAVERSAL_OUTGOING,
- };
-
- NetworkSettings()
- : nat_traversal_mode(NAT_TRAVERSAL_DISABLED),
- min_port(0),
- max_port(0) {
- }
-
- explicit NetworkSettings(NatTraversalMode nat_traversal_mode)
- : nat_traversal_mode(nat_traversal_mode),
- min_port(0),
- max_port(0) {
- }
-
- NatTraversalMode nat_traversal_mode;
-
- // |min_port| and |max_port| specify range (inclusive) of ports used by
- // P2P sessions. Any port can be used when both values are set to 0.
- int min_port;
- int max_port;
-};
-
-} // namespace remoting
-
-#endif // REMOTING_HOST_NETWORK_SETTINGS_H_
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index 8a5e133..ff60292 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -26,13 +26,13 @@
#include "remoting/host/host_secret.h"
#include "remoting/host/host_status_observer.h"
#include "remoting/host/it2me_desktop_environment.h"
-#include "remoting/host/network_settings.h"
#include "remoting/host/pin_hash.h"
#include "remoting/host/plugin/host_log_handler.h"
#include "remoting/host/policy_hack/policy_watcher.h"
#include "remoting/host/register_support_host_request.h"
#include "remoting/host/service_urls.h"
#include "remoting/host/session_manager_factory.h"
+#include "remoting/jingle_glue/network_settings.h"
#include "remoting/jingle_glue/xmpp_signal_strategy.h"
#include "remoting/protocol/it2me_host_authenticator_factory.h"
#include "third_party/npapi/bindings/npruntime.h"
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index 252390a..9df3657 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -57,7 +57,6 @@
#include "remoting/host/log_to_server.h"
#include "remoting/host/logging.h"
#include "remoting/host/me2me_desktop_environment.h"
-#include "remoting/host/network_settings.h"
#include "remoting/host/policy_hack/policy_watcher.h"
#include "remoting/host/service_urls.h"
#include "remoting/host/session_manager_factory.h"
@@ -65,6 +64,7 @@
#include "remoting/host/token_validator_factory_impl.h"
#include "remoting/host/ui_strings.h"
#include "remoting/host/usage_stats_consent.h"
+#include "remoting/jingle_glue/network_settings.h"
#include "remoting/jingle_glue/xmpp_signal_strategy.h"
#include "remoting/protocol/me2me_host_authenticator_factory.h"
#include "remoting/protocol/pairing_registry.h"
diff --git a/remoting/host/session_manager_factory.cc b/remoting/host/session_manager_factory.cc
index df21786..bbaa8ef 100644
--- a/remoting/host/session_manager_factory.cc
+++ b/remoting/host/session_manager_factory.cc
@@ -4,11 +4,11 @@
#include "remoting/host/session_manager_factory.h"
-#include "net/url_request/url_request_context_getter.h"
-#include "remoting/host/host_port_allocator.h"
-#include "remoting/host/network_settings.h"
-#include "remoting/protocol/libjingle_transport_factory.h"
+#include "remoting/jingle_glue/chromium_port_allocator.h"
+#include "remoting/jingle_glue/network_settings.h"
#include "remoting/protocol/jingle_session_manager.h"
+#include "remoting/protocol/libjingle_transport_factory.h"
+#include "remoting/protocol/session_manager.h"
namespace remoting {
@@ -16,20 +16,9 @@ scoped_ptr<protocol::SessionManager> CreateHostSessionManager(
const NetworkSettings& network_settings,
const scoped_refptr<net::URLRequestContextGetter>&
url_request_context_getter) {
- // Use Chrome's network stack to allocate ports for peer-to-peer channels.
- scoped_ptr<HostPortAllocator> port_allocator(
- HostPortAllocator::Create(url_request_context_getter,
- network_settings));
-
- bool incoming_only = network_settings.nat_traversal_mode ==
- NetworkSettings::NAT_TRAVERSAL_DISABLED;
-
- // Use libjingle for negotiation of peer-to-peer channels over
- // HostPortAllocator allocated ports.
scoped_ptr<protocol::TransportFactory> transport_factory(
- new protocol::LibjingleTransportFactory(
- port_allocator.PassAs<cricket::HttpPortAllocatorBase>(),
- incoming_only));
+ protocol::LibjingleTransportFactory::Create(network_settings,
+ url_request_context_getter));
// Use the Jingle protocol for channel-negotiation signalling between
// peer TransportFactories.
diff --git a/remoting/host/session_manager_factory.h b/remoting/host/session_manager_factory.h
index fb289bc..2c0a1b6 100644
--- a/remoting/host/session_manager_factory.h
+++ b/remoting/host/session_manager_factory.h
@@ -7,12 +7,19 @@
#include "base/memory/scoped_ptr.h"
#include "net/url_request/url_request_context_getter.h"
-#include "remoting/protocol/session_manager.h"
+
+namespace net {
+class URLRequestContextGetter;
+} // namespace net
namespace remoting {
struct NetworkSettings;
+namespace protocol {
+ class SessionManager;
+} // namespace protocol
+
scoped_ptr<protocol::SessionManager> CreateHostSessionManager(
const NetworkSettings& network_settings,
const scoped_refptr<net::URLRequestContextGetter>&