diff options
-rw-r--r-- | chrome/chrome_renderer.gypi | 2 | ||||
-rw-r--r-- | chrome/renderer/p2p/ipc_network_manager.cc | 25 | ||||
-rw-r--r-- | chrome/renderer/p2p/ipc_network_manager.h | 32 | ||||
-rw-r--r-- | remoting/client/DEPS | 4 | ||||
-rw-r--r-- | remoting/client/plugin/chromoting_instance.cc | 30 | ||||
-rw-r--r-- | remoting/client/x11_client.cc | 3 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_client.cc | 29 | ||||
-rw-r--r-- | remoting/jingle_glue/jingle_client.h | 11 | ||||
-rw-r--r-- | remoting/protocol/connection_to_host.cc | 14 | ||||
-rw-r--r-- | remoting/protocol/connection_to_host.h | 10 | ||||
-rw-r--r-- | remoting/remoting.gyp | 9 |
11 files changed, 155 insertions, 14 deletions
diff --git a/chrome/chrome_renderer.gypi b/chrome/chrome_renderer.gypi index 0b78b88..47d6189 100644 --- a/chrome/chrome_renderer.gypi +++ b/chrome/chrome_renderer.gypi @@ -131,6 +131,8 @@ 'renderer/notification_provider.cc', 'renderer/notification_provider.h', 'renderer/paint_aggregator.cc', + 'renderer/p2p/ipc_network_manager.cc', + 'renderer/p2p/ipc_network_manager.h', 'renderer/p2p/ipc_socket_factory.cc', 'renderer/p2p/ipc_socket_factory.h', 'renderer/p2p/socket_client.cc', diff --git a/chrome/renderer/p2p/ipc_network_manager.cc b/chrome/renderer/p2p/ipc_network_manager.cc new file mode 100644 index 0000000..70e84c6 --- /dev/null +++ b/chrome/renderer/p2p/ipc_network_manager.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2011 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 "chrome/renderer/p2p/ipc_network_manager.h" + +IpcNetworkManager::IpcNetworkManager(P2PSocketDispatcher* socket_dispatcher) + : socket_dispatcher_(socket_dispatcher) { +} + +IpcNetworkManager::~IpcNetworkManager() { +} + +// TODO(sergeyu): Currently this method just adds one fake network in +// the list. This doesn't prevent PortAllocator from allocating ports: +// browser process chooses first IPv4-enabled interface. But this +// approach will not work in case when there is more than one active +// network interface. Implement this properly: get list of networks +// from the browser. +bool IpcNetworkManager::EnumNetworks( + bool include_ignored, std::vector<talk_base::Network*>* networks) { + networks->push_back(new talk_base::Network( + "chrome", "Chrome virtual network", 0, 0)); + return true; +} diff --git a/chrome/renderer/p2p/ipc_network_manager.h b/chrome/renderer/p2p/ipc_network_manager.h new file mode 100644 index 0000000..4775c70 --- /dev/null +++ b/chrome/renderer/p2p/ipc_network_manager.h @@ -0,0 +1,32 @@ +// Copyright (c) 2011 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 CHROME_RENDERER_P2P_IPC_NETWORK_MANAGER_H_ +#define CHROME_RENDERER_P2P_IPC_NETWORK_MANAGER_H_ + +#include <vector> + +#include "base/compiler_specific.h" +#include "third_party/libjingle/source/talk/base/network.h" + +class P2PSocketDispatcher; + +// IpcNetworkManager is a NetworkManager for libjingle that gets a +// list of network interfaces from the browser. +class IpcNetworkManager : public talk_base::NetworkManager { + public: + // Constructor doesn't take ownership of the |socket_dispatcher|. + IpcNetworkManager(P2PSocketDispatcher* socket_dispatcher); + virtual ~IpcNetworkManager(); + + protected: + // Fills the supplied list with all usable networks. + virtual bool EnumNetworks(bool include_ignored, + std::vector<talk_base::Network*>* networks) + OVERRIDE; + + P2PSocketDispatcher* socket_dispatcher_; +}; + +#endif // CHROME_RENDERER_P2P_IPC_NETWORK_MANAGER_H_ diff --git a/remoting/client/DEPS b/remoting/client/DEPS index 4a5a738..73df734 100644 --- a/remoting/client/DEPS +++ b/remoting/client/DEPS @@ -5,4 +5,8 @@ include_rules = [ "+remoting/protocol", "+remoting/jingle_glue", + + # TODO(sergeyu): Remove this dependency: crbug.com/74951 . + "+webkit/plugins/ppapi", + "+chrome/renderer/p2p", ] diff --git a/remoting/client/plugin/chromoting_instance.cc b/remoting/client/plugin/chromoting_instance.cc index 0cdfe62..9c07782 100644 --- a/remoting/client/plugin/chromoting_instance.cc +++ b/remoting/client/plugin/chromoting_instance.cc @@ -11,6 +11,11 @@ #include "base/string_util.h" #include "base/task.h" #include "base/threading/thread.h" +// TODO(sergeyu): We should not depend on renderer here. Instead P2P +// Pepper API should be used. Remove this dependency. +// crbug.com/74951 +#include "chrome/renderer/p2p/ipc_network_manager.h" +#include "chrome/renderer/p2p/ipc_socket_factory.h" #include "ppapi/c/pp_input_event.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/rect.h" @@ -25,6 +30,13 @@ #include "remoting/jingle_glue/jingle_thread.h" #include "remoting/proto/auth.pb.h" #include "remoting/protocol/connection_to_host.h" +// TODO(sergeyu): This is a hack: plugin should not depend on webkit +// glue. It is used here to get P2PPacketDispatcher corresponding to +// the current RenderView. Use P2P Pepper API for connection and +// remove these includes. +// crbug.com/74951 +#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" +#include "webkit/plugins/ppapi/resource_tracker.h" namespace remoting { @@ -68,9 +80,25 @@ bool ChromotingInstance::Init(uint32_t argc, // Start all the threads. context_.Start(); + webkit::ppapi::PluginInstance* plugin_instance = + webkit::ppapi::ResourceTracker::Get()->GetInstance(pp_instance()); + + P2PSocketDispatcher* socket_dispatcher = + plugin_instance->delegate()->GetP2PSocketDispatcher(); + IpcNetworkManager* network_manager = NULL; + IpcPacketSocketFactory* socket_factory = NULL; + + // If we don't have socket dispatcher for IPC (e.g. P2P API is + // disabled), then JingleClient will try to use physical sockets. + if (socket_dispatcher) { + VLOG(1) << "Creating IpcNetworkManager and IpcPacketSocketFactory."; + network_manager = new IpcNetworkManager(socket_dispatcher); + socket_factory = new IpcPacketSocketFactory(socket_dispatcher); + } + // Create the chromoting objects. host_connection_.reset(new protocol::ConnectionToHost( - context_.jingle_thread())); + context_.jingle_thread(), network_manager, socket_factory)); view_.reset(new PepperView(this, &context_)); view_proxy_ = new PepperViewProxy(this, view_.get()); rectangle_decoder_ = new RectangleUpdateDecoder( diff --git a/remoting/client/x11_client.cc b/remoting/client/x11_client.cc index 5d0867f..bed2e55 100644 --- a/remoting/client/x11_client.cc +++ b/remoting/client/x11_client.cc @@ -32,7 +32,8 @@ int main(int argc, char** argv) { MessageLoop ui_loop; remoting::ClientContext context; - remoting::protocol::ConnectionToHost connection(context.jingle_thread()); + remoting::protocol::ConnectionToHost connection(context.jingle_thread(), + NULL, NULL); remoting::X11View view; scoped_refptr<remoting::RectangleUpdateDecoder> rectangle_decoder = new remoting::RectangleUpdateDecoder(context.decode_message_loop(), diff --git a/remoting/jingle_glue/jingle_client.cc b/remoting/jingle_glue/jingle_client.cc index 20d4057..691548d 100644 --- a/remoting/jingle_glue/jingle_client.cc +++ b/remoting/jingle_glue/jingle_client.cc @@ -192,6 +192,21 @@ JingleClient::JingleClient(JingleThread* thread, signal_strategy_(signal_strategy) { } +JingleClient::JingleClient(JingleThread* thread, + SignalStrategy* signal_strategy, + talk_base::NetworkManager* network_manager, + talk_base::PacketSocketFactory* socket_factory, + Callback* callback) + : thread_(thread), + state_(START), + initialized_(false), + closed_(false), + callback_(callback), + signal_strategy_(signal_strategy), + network_manager_(network_manager), + socket_factory_(socket_factory) { +} + JingleClient::~JingleClient() { base::AutoLock auto_lock(state_lock_); DCHECK(!initialized_ || closed_); @@ -211,11 +226,15 @@ void JingleClient::Init() { void JingleClient::DoInitialize() { DCHECK_EQ(message_loop(), MessageLoop::current()); - network_manager_.reset(new talk_base::NetworkManager()); - // TODO(sergeyu): Use IpcPacketSocketFactory here when it is - // implemented. - socket_factory_.reset(new talk_base::BasicPacketSocketFactory( - talk_base::Thread::Current())); + if (!network_manager_.get()) { + VLOG(1) << "Creating talk_base::NetworkManager."; + network_manager_.reset(new talk_base::NetworkManager()); + } + if (!socket_factory_.get()) { + VLOG(1) << "Creating talk_base::BasicPacketSocketFactory."; + socket_factory_.reset(new talk_base::BasicPacketSocketFactory( + talk_base::Thread::Current())); + } port_allocator_.reset( new cricket::HttpPortAllocator(network_manager_.get(), diff --git a/remoting/jingle_glue/jingle_client.h b/remoting/jingle_glue/jingle_client.h index 4d877b5..6b49e24 100644 --- a/remoting/jingle_glue/jingle_client.h +++ b/remoting/jingle_glue/jingle_client.h @@ -139,7 +139,16 @@ class JingleClient : public base::RefCountedThreadSafe<JingleClient>, virtual void OnStateChange(JingleClient* client, State state) = 0; }; - JingleClient(JingleThread* thread, SignalStrategy* signal_strategy, + // Physical sockets are used if |network_manager| and + // |socket_factory| are not specified. Otherwise ownership of these + // objects is given to JingleClient. + JingleClient(JingleThread* thread, + SignalStrategy* signal_strategy, + Callback* callback); + JingleClient(JingleThread* thread, + SignalStrategy* signal_strategy, + talk_base::NetworkManager* network_manager, + talk_base::PacketSocketFactory* socket_factory, Callback* callback); ~JingleClient(); diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc index 27d2da1..3d34997 100644 --- a/remoting/protocol/connection_to_host.cc +++ b/remoting/protocol/connection_to_host.cc @@ -21,8 +21,13 @@ namespace remoting { namespace protocol { -ConnectionToHost::ConnectionToHost(JingleThread* thread) +ConnectionToHost::ConnectionToHost( + JingleThread* thread, + talk_base::NetworkManager* network_manager, + talk_base::PacketSocketFactory* socket_factory) : thread_(thread), + network_manager_(network_manager), + socket_factory_(socket_factory), event_callback_(NULL), dispatcher_(new ClientMessageDispatcher()) { } @@ -61,7 +66,9 @@ void ConnectionToHost::Connect(const std::string& username, kChromotingTokenServiceName)); } - jingle_client_ = new JingleClient(thread_, signal_strategy_.get(), this); + jingle_client_ = new JingleClient(thread_, signal_strategy_.get(), + network_manager_.release(), + socket_factory_.release(), this); jingle_client_->Init(); // Save jid of the host. The actual connection is created later after @@ -72,8 +79,7 @@ void ConnectionToHost::Connect(const std::string& username, void ConnectionToHost::Disconnect() { if (MessageLoop::current() != message_loop()) { message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(this, - &ConnectionToHost::Disconnect)); + FROM_HERE, NewRunnableMethod(this, &ConnectionToHost::Disconnect)); return; } diff --git a/remoting/protocol/connection_to_host.h b/remoting/protocol/connection_to_host.h index 0869a7b..2f661ca 100644 --- a/remoting/protocol/connection_to_host.h +++ b/remoting/protocol/connection_to_host.h @@ -50,8 +50,13 @@ class ConnectionToHost : public JingleClient::Callback { virtual void OnConnectionFailed(ConnectionToHost* conn) = 0; }; + // Takes ownership of |network_manager| and |socket_factory|. Both + // |network_manager| and |socket_factory| may be set to NULL. + // // TODO(sergeyu): Constructor shouldn't need thread here. - explicit ConnectionToHost(JingleThread* thread); + ConnectionToHost(JingleThread* thread, + talk_base::NetworkManager* network_manager, + talk_base::PacketSocketFactory* socket_factory); virtual ~ConnectionToHost(); // TODO(ajwong): We need to generalize this API. @@ -98,6 +103,9 @@ class ConnectionToHost : public JingleClient::Callback { JingleThread* thread_; + scoped_ptr<talk_base::NetworkManager> network_manager_; + scoped_ptr<talk_base::PacketSocketFactory> socket_factory_; + scoped_ptr<SignalStrategy> signal_strategy_; scoped_refptr<JingleClient> jingle_client_; scoped_refptr<SessionManager> session_manager_; diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index fcdc5a0..81a9867 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -73,7 +73,14 @@ 'chromoting_base', 'chromoting_client', 'chromoting_jingle_glue', - '../ppapi/ppapi.gyp:ppapi_cpp_objects', + '<(DEPTH)/ppapi/ppapi.gyp:ppapi_cpp_objects', + + # TODO(sergeyu): This is a hack: plugin should not depend on + # webkit glue. Skia is needed here to add include path webkit glue + # depends on. See comments in chromoting_instance.cc for details. + # crbug.com/74951 + '<(DEPTH)/webkit/support/webkit_support.gyp:glue', + '<(DEPTH)/skia/skia.gyp:skia', ], 'sources': [ 'client/plugin/chromoting_instance.cc', |