diff options
-rw-r--r-- | remoting/host/chromoting_host.cc | 82 | ||||
-rw-r--r-- | remoting/host/chromoting_host.h | 21 | ||||
-rw-r--r-- | remoting/host/chromoting_host_context.cc | 24 | ||||
-rw-r--r-- | remoting/host/chromoting_host_context.h | 21 | ||||
-rw-r--r-- | remoting/host/chromoting_host_context_unittest.cc | 6 | ||||
-rw-r--r-- | remoting/host/chromoting_host_unittest.cc | 21 | ||||
-rw-r--r-- | remoting/host/desktop_environment_factory.cc | 16 | ||||
-rw-r--r-- | remoting/host/desktop_environment_factory.h | 16 | ||||
-rw-r--r-- | remoting/host/plugin/host_script_object.cc | 17 | ||||
-rw-r--r-- | remoting/host/remoting_me2me_host.cc | 16 | ||||
-rw-r--r-- | remoting/host/simple_host_process.cc | 28 | ||||
-rw-r--r-- | remoting/host/win/session_desktop_environment_factory.cc | 14 | ||||
-rw-r--r-- | remoting/host/win/session_desktop_environment_factory.h | 7 | ||||
-rw-r--r-- | remoting/remoting.gyp | 4 |
14 files changed, 173 insertions, 120 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index 2054eb8..40f136e 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -57,13 +57,17 @@ const net::BackoffEntry::Policy kDefaultBackoffPolicy = { } // namespace ChromotingHost::ChromotingHost( - ChromotingHostContext* context, SignalStrategy* signal_strategy, DesktopEnvironmentFactory* desktop_environment_factory, - scoped_ptr<protocol::SessionManager> session_manager) - : context_(context), - desktop_environment_factory_(desktop_environment_factory), + scoped_ptr<protocol::SessionManager> session_manager, + scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) + : desktop_environment_factory_(desktop_environment_factory), session_manager_(session_manager.Pass()), + capture_task_runner_(capture_task_runner), + encode_task_runner_(encode_task_runner), + network_task_runner_(network_task_runner), signal_strategy_(signal_strategy), clients_count_(0), state_(kInitial), @@ -71,9 +75,8 @@ ChromotingHost::ChromotingHost( login_backoff_(&kDefaultBackoffPolicy), authenticating_client_(false), reject_authenticating_client_(false) { - DCHECK(context_); DCHECK(signal_strategy); - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); if (!desktop_environment_factory_->SupportsAudioCapture()) { protocol::CandidateSessionConfig::DisableAudioChannel( @@ -86,7 +89,7 @@ ChromotingHost::~ChromotingHost() { } void ChromotingHost::Start(const std::string& xmpp_login) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); LOG(INFO) << "Starting host"; @@ -104,8 +107,8 @@ void ChromotingHost::Start(const std::string& xmpp_login) { // This method is called when we need to destroy the host process. void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { - if (!context_->network_task_runner()->BelongsToCurrentThread()) { - context_->network_task_runner()->PostTask( + if (!network_task_runner_->BelongsToCurrentThread()) { + network_task_runner_->PostTask( FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); return; } @@ -116,7 +119,7 @@ void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { // Nothing to do if we are not started. state_ = kStopped; if (!shutdown_task.is_null()) - context_->network_task_runner()->PostTask(FROM_HERE, shutdown_task); + network_task_runner_->PostTask(FROM_HERE, shutdown_task); break; case kStopping: @@ -144,12 +147,12 @@ void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { } void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); status_observers_.AddObserver(observer); } void ChromotingHost::RemoveStatusObserver(HostStatusObserver* observer) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); status_observers_.RemoveObserver(observer); } @@ -160,7 +163,7 @@ void ChromotingHost::RejectAuthenticatingClient() { void ChromotingHost::SetAuthenticatorFactory( scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); session_manager_->set_authenticator_factory(authenticator_factory.Pass()); } @@ -172,7 +175,7 @@ void ChromotingHost::SetMaximumSessionDuration( //////////////////////////////////////////////////////////////////////////// // protocol::ClientSession::EventHandler implementation. void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); login_backoff_.Reset(); @@ -206,7 +209,7 @@ void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { } void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); // Notify observers. FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, @@ -214,7 +217,7 @@ void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { } void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); // Notify observers. FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, @@ -222,7 +225,7 @@ void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { } void ChromotingHost::OnSessionClosed(ClientSession* client) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); ClientList::iterator it = clients_.begin(); for (; it != clients_.end(); ++it) { @@ -243,14 +246,14 @@ void ChromotingHost::OnSessionClosed(ClientSession* client) { void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, int64 sequence_number) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); } void ChromotingHost::OnSessionRouteChange( ClientSession* session, const std::string& channel_name, const protocol::TransportRoute& route) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnClientRouteChange(session->client_jid(), channel_name, route)); @@ -258,13 +261,13 @@ void ChromotingHost::OnSessionRouteChange( void ChromotingHost::OnClientDimensionsChanged(ClientSession* session, const SkISize& size) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnClientDimensionsChanged(session->client_jid(), size)); } void ChromotingHost::OnSessionManagerReady() { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); // Don't need to do anything here, just wait for incoming // connections. } @@ -272,7 +275,7 @@ void ChromotingHost::OnSessionManagerReady() { void ChromotingHost::OnIncomingSession( protocol::Session* session, protocol::SessionManager::IncomingSessionResponse* response) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); if (state_ != kStarted) { *response = protocol::SessionManager::DECLINE; @@ -306,16 +309,16 @@ void ChromotingHost::OnIncomingSession( // Create the desktop integration implementation for the client to use. scoped_ptr<DesktopEnvironment> desktop_environment = - desktop_environment_factory_->Create(context_); + desktop_environment_factory_->Create(); // Create a client object. scoped_ptr<protocol::ConnectionToClient> connection( new protocol::ConnectionToClient(session)); scoped_refptr<ClientSession> client = new ClientSession( this, - context_->capture_task_runner(), - context_->encode_task_runner(), - context_->network_task_runner(), + capture_task_runner_, + encode_task_runner_, + network_task_runner_, connection.Pass(), desktop_environment.Pass(), max_session_duration_); @@ -325,15 +328,15 @@ void ChromotingHost::OnIncomingSession( void ChromotingHost::set_protocol_config( scoped_ptr<protocol::CandidateSessionConfig> config) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); DCHECK(config.get()); DCHECK_EQ(state_, kInitial); protocol_config_ = config.Pass(); } void ChromotingHost::OnLocalMouseMoved(const SkIPoint& new_pos) { - if (!context_->network_task_runner()->BelongsToCurrentThread()) { - context_->network_task_runner()->PostTask( + if (!network_task_runner_->BelongsToCurrentThread()) { + network_task_runner_->PostTask( FROM_HERE, base::Bind(&ChromotingHost::OnLocalMouseMoved, this, new_pos)); return; @@ -346,8 +349,8 @@ void ChromotingHost::OnLocalMouseMoved(const SkIPoint& new_pos) { } void ChromotingHost::PauseSession(bool pause) { - if (!context_->network_task_runner()->BelongsToCurrentThread()) { - context_->network_task_runner()->PostTask( + if (!network_task_runner_->BelongsToCurrentThread()) { + network_task_runner_->PostTask( FROM_HERE, base::Bind(&ChromotingHost::PauseSession, this, pause)); return; } @@ -359,8 +362,8 @@ void ChromotingHost::PauseSession(bool pause) { } void ChromotingHost::DisconnectAllClients() { - if (!context_->network_task_runner()->BelongsToCurrentThread()) { - context_->network_task_runner()->PostTask( + if (!network_task_runner_->BelongsToCurrentThread()) { + network_task_runner_->PostTask( FROM_HERE, base::Bind(&ChromotingHost::DisconnectAllClients, this)); return; } @@ -373,14 +376,14 @@ void ChromotingHost::DisconnectAllClients() { } void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kInitial); ui_strings_ = ui_strings; } void ChromotingHost::OnClientStopped() { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); --clients_count_; if (state_ == kStopping && !clients_count_) @@ -388,13 +391,18 @@ void ChromotingHost::OnClientStopped() { } void ChromotingHost::ShutdownFinish() { - DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); DCHECK_EQ(state_, kStopping); + state_ = kStopped; + // Destroy session manager. session_manager_.reset(); - state_ = kStopped; + // Clear |desktop_environment_factory_| and |signal_strategy_| to + // ensure we don't try to touch them after running shutdown tasks + desktop_environment_factory_ = NULL; + signal_strategy_ = NULL; // Keep reference to |this|, so that we don't get destroyed while // sending notifications. diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h index 4742f94..0a7b739 100644 --- a/remoting/host/chromoting_host.h +++ b/remoting/host/chromoting_host.h @@ -9,6 +9,7 @@ #include <vector> #include "base/memory/scoped_ptr.h" +#include "base/memory/ref_counted.h" #include "base/observer_list.h" #include "base/threading/thread.h" #include "net/base/backoff_entry.h" @@ -22,6 +23,10 @@ #include "remoting/protocol/connection_to_client.h" #include "third_party/skia/include/core/SkSize.h" +namespace base { +class SingleThreadTaskRunner; +} // namespace base + namespace remoting { namespace protocol { @@ -30,7 +35,6 @@ class SessionConfig; class CandidateSessionConfig; } // namespace protocol -class ChromotingHostContext; class DesktopEnvironmentFactory; // A class to implement the functionality of a host process. @@ -61,13 +65,16 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, public protocol::SessionManager::Listener, public MouseMoveObserver { public: - // The caller must ensure that |context|, |signal_strategy| and - // |environment| out-live the host. + // The caller must ensure that |signal_strategy| and + // |desktop_environment_factory| remain valid at least until the + // |shutdown_task| supplied to Shutdown() has been notified. ChromotingHost( - ChromotingHostContext* context, SignalStrategy* signal_strategy, DesktopEnvironmentFactory* desktop_environment_factory, - scoped_ptr<protocol::SessionManager> session_manager); + scoped_ptr<protocol::SessionManager> session_manager, + scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner); // Asynchronously start the host process. // @@ -171,9 +178,11 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, // used on the network thread only. // Parameters specified when the host was created. - ChromotingHostContext* context_; DesktopEnvironmentFactory* desktop_environment_factory_; scoped_ptr<protocol::SessionManager> session_manager_; + scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; // Connection objects. SignalStrategy* signal_strategy_; diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc index 87eeb1b..e3511db 100644 --- a/remoting/host/chromoting_host_context.cc +++ b/remoting/host/chromoting_host_context.cc @@ -17,9 +17,9 @@ ChromotingHostContext::ChromotingHostContext( scoped_refptr<AutoThreadTaskRunner> ui_task_runner) : audio_thread_("ChromotingAudioThread"), capture_thread_("ChromotingCaptureThread"), - desktop_thread_("ChromotingDesktopThread"), encode_thread_("ChromotingEncodeThread"), file_thread_("ChromotingFileIOThread"), + input_thread_("ChromotingInputThread"), network_thread_("ChromotingNetworkThread"), ui_task_runner_(ui_task_runner) { } @@ -31,9 +31,9 @@ void ChromotingHostContext::ReleaseTaskRunners() { url_request_context_getter_ = NULL; audio_task_runner_ = NULL; capture_task_runner_ = NULL; - desktop_task_runner_ = NULL; encode_task_runner_ = NULL; file_task_runner_ = NULL; + input_task_runner_ = NULL; network_task_runner_ = NULL; ui_task_runner_ = NULL; } @@ -43,9 +43,9 @@ bool ChromotingHostContext::Start() { base::Thread::Options io_thread_options(MessageLoop::TYPE_IO, 0); bool started = capture_thread_.Start() && encode_thread_.Start() && audio_thread_.StartWithOptions(io_thread_options) && - network_thread_.StartWithOptions(io_thread_options) && - desktop_thread_.StartWithOptions(io_thread_options) && - file_thread_.StartWithOptions(io_thread_options); + file_thread_.StartWithOptions(io_thread_options) && + input_thread_.StartWithOptions(io_thread_options) && + network_thread_.StartWithOptions(io_thread_options); if (!started) return false; @@ -58,15 +58,15 @@ bool ChromotingHostContext::Start() { capture_task_runner_ = new AutoThreadTaskRunner(capture_thread_.message_loop_proxy(), ui_task_runner_); - desktop_task_runner_ = - new AutoThreadTaskRunner(desktop_thread_.message_loop_proxy(), - ui_task_runner_); encode_task_runner_ = new AutoThreadTaskRunner(encode_thread_.message_loop_proxy(), ui_task_runner_); file_task_runner_ = new AutoThreadTaskRunner(file_thread_.message_loop_proxy(), ui_task_runner_); + input_task_runner_ = + new AutoThreadTaskRunner(input_thread_.message_loop_proxy(), + ui_task_runner_); network_task_runner_ = new AutoThreadTaskRunner(network_thread_.message_loop_proxy(), ui_task_runner_); @@ -85,10 +85,6 @@ base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() { return capture_task_runner_; } -base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() { - return desktop_task_runner_; -} - base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() { return encode_task_runner_; } @@ -97,6 +93,10 @@ base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() { return file_task_runner_; } +base::SingleThreadTaskRunner* ChromotingHostContext::input_task_runner() { + return input_task_runner_; +} + base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() { return network_task_runner_; } diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h index 2e3c8e7..0250f06 100644 --- a/remoting/host/chromoting_host_context.h +++ b/remoting/host/chromoting_host_context.h @@ -18,6 +18,7 @@ class URLRequestContextGetter; } // namespace net namespace remoting { + class AutoThreadTaskRunner; // A class that manages threads and running context for the chromoting host @@ -45,12 +46,6 @@ class ChromotingHostContext { // the screen. virtual base::SingleThreadTaskRunner* capture_task_runner(); - // Task runner for the thread that is used by the EventExecutor. - // - // TODO(sergeyu): Do we need a separate thread for EventExecutor? - // Can we use some other thread instead? - virtual base::SingleThreadTaskRunner* desktop_task_runner(); - // Task runner for the thread used to encode video streams. virtual base::SingleThreadTaskRunner* encode_task_runner(); @@ -59,6 +54,12 @@ class ChromotingHostContext { // configuration and by NatConfig to read policy configs. virtual base::SingleThreadTaskRunner* file_task_runner(); + // Task runner for the thread that is used by the EventExecutor. + // + // TODO(sergeyu): Do we need a separate thread for EventExecutor? + // Can we use some other thread instead? + virtual base::SingleThreadTaskRunner* input_task_runner(); + // Task runner for the thread used for network IO. This thread runs // a libjingle message loop, and is the only thread on which // libjingle code may be run. @@ -80,15 +81,15 @@ class ChromotingHostContext { // A thread that hosts screen capture. base::Thread capture_thread_; - // A thread that hosts input injection. - base::Thread desktop_thread_; - // A thread that hosts all encode operations. base::Thread encode_thread_; // Thread for blocking IO operations. base::Thread file_thread_; + // A thread that hosts input injection. + base::Thread input_thread_; + // A thread that hosts all network operations. base::Thread network_thread_; @@ -96,9 +97,9 @@ class ChromotingHostContext { // the corresponding threads to guarantee proper order of destruction. scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; - scoped_refptr<base::SingleThreadTaskRunner> desktop_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; diff --git a/remoting/host/chromoting_host_context_unittest.cc b/remoting/host/chromoting_host_context_unittest.cc index a4e670f..64010e9 100644 --- a/remoting/host/chromoting_host_context_unittest.cc +++ b/remoting/host/chromoting_host_context_unittest.cc @@ -18,9 +18,13 @@ TEST(ChromotingHostContextTest, StartAndStop) { base::MessageLoopProxy::current())); context.Start(); - EXPECT_TRUE(context.network_task_runner()); + EXPECT_TRUE(context.audio_task_runner()); EXPECT_TRUE(context.capture_task_runner()); EXPECT_TRUE(context.encode_task_runner()); + EXPECT_TRUE(context.file_task_runner()); + EXPECT_TRUE(context.input_task_runner()); + EXPECT_TRUE(context.network_task_runner()); + EXPECT_TRUE(context.ui_task_runner()); } } // namespace remoting diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index ae1687c..e1f3694 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -71,21 +71,20 @@ class MockDesktopEnvironmentFactory : public DesktopEnvironmentFactory { MockDesktopEnvironmentFactory(); virtual ~MockDesktopEnvironmentFactory(); - virtual scoped_ptr<DesktopEnvironment> Create( - ChromotingHostContext* context) OVERRIDE; + virtual scoped_ptr<DesktopEnvironment> Create() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(MockDesktopEnvironmentFactory); }; -MockDesktopEnvironmentFactory::MockDesktopEnvironmentFactory() { +MockDesktopEnvironmentFactory::MockDesktopEnvironmentFactory() + : DesktopEnvironmentFactory(NULL, NULL) { } MockDesktopEnvironmentFactory::~MockDesktopEnvironmentFactory() { } -scoped_ptr<DesktopEnvironment> MockDesktopEnvironmentFactory::Create( - ChromotingHostContext* context) { +scoped_ptr<DesktopEnvironment> MockDesktopEnvironmentFactory::Create() { scoped_ptr<EventExecutor> event_executor(new EventExecutorFake()); scoped_ptr<VideoFrameCapturer> video_capturer(new VideoFrameCapturerFake()); return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment( @@ -122,8 +121,12 @@ class ChromotingHostTest : public testing::Test { session_manager_ = new protocol::MockSessionManager(); host_ = new ChromotingHost( - &context_, &signal_strategy_, desktop_environment_factory_.get(), - scoped_ptr<protocol::SessionManager>(session_manager_)); + &signal_strategy_, + desktop_environment_factory_.get(), + scoped_ptr<protocol::SessionManager>(session_manager_), + context_.capture_task_runner(), + context_.encode_task_runner(), + context_.network_task_runner()); host_->AddStatusObserver(&host_status_observer_); disconnect_window_ = new MockDisconnectWindow(); @@ -223,7 +226,7 @@ class ChromotingHostTest : public testing::Test { PassAs<protocol::ConnectionToClient>(); protocol::ConnectionToClient* connection_ptr = connection.get(); scoped_ptr<DesktopEnvironment> desktop_environment = - host_->desktop_environment_factory_->Create(&context_); + host_->desktop_environment_factory_->Create(); connection_ptr->set_input_stub(desktop_environment->event_executor()); scoped_refptr<ClientSession> client = new ClientSession( @@ -232,7 +235,7 @@ class ChromotingHostTest : public testing::Test { context_.encode_task_runner(), context_.network_task_runner(), connection.Pass(), - host_->desktop_environment_factory_->Create(&context_), + desktop_environment.Pass(), base::TimeDelta()); connection_ptr->set_host_stub(client); diff --git a/remoting/host/desktop_environment_factory.cc b/remoting/host/desktop_environment_factory.cc index 46d6dab..5d9b993 100644 --- a/remoting/host/desktop_environment_factory.cc +++ b/remoting/host/desktop_environment_factory.cc @@ -12,23 +12,23 @@ namespace remoting { -DesktopEnvironmentFactory::DesktopEnvironmentFactory() { +DesktopEnvironmentFactory::DesktopEnvironmentFactory( + scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) + : input_task_runner_(input_task_runner), + ui_task_runner_(ui_task_runner) { } DesktopEnvironmentFactory::~DesktopEnvironmentFactory() { } -scoped_ptr<DesktopEnvironment> DesktopEnvironmentFactory::Create( - ChromotingHostContext* context) { +scoped_ptr<DesktopEnvironment> DesktopEnvironmentFactory::Create() { scoped_ptr<AudioCapturer> audio_capturer = AudioCapturer::Create(); scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( - context->desktop_task_runner(), - context->ui_task_runner()); + input_task_runner_, ui_task_runner_); scoped_ptr<VideoFrameCapturer> video_capturer(VideoFrameCapturer::Create()); return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment( - audio_capturer.Pass(), - event_executor.Pass(), - video_capturer.Pass())); + audio_capturer.Pass(), event_executor.Pass(), video_capturer.Pass())); } bool DesktopEnvironmentFactory::SupportsAudioCapture() const { diff --git a/remoting/host/desktop_environment_factory.h b/remoting/host/desktop_environment_factory.h index c77aef6..9bbd71c16 100644 --- a/remoting/host/desktop_environment_factory.h +++ b/remoting/host/desktop_environment_factory.h @@ -6,26 +6,34 @@ #define REMOTING_HOST_DESKTOP_ENVIRONMENT_FACTORY_H_ #include "base/basictypes.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +namespace base { +class SingleThreadTaskRunner; +} // namespace base + namespace remoting { -class ChromotingHostContext; class DesktopEnvironment; class DesktopEnvironmentFactory { public: - DesktopEnvironmentFactory(); + DesktopEnvironmentFactory( + scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); virtual ~DesktopEnvironmentFactory(); - virtual scoped_ptr<DesktopEnvironment> Create( - ChromotingHostContext* context); + virtual scoped_ptr<DesktopEnvironment> Create(); // Returns |true| if created |DesktopEnvironment| instances support audio // capture. virtual bool SupportsAudioCapture() const; protected: + scoped_refptr<base::SingleThreadTaskRunner> input_task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; + DISALLOW_COPY_AND_ASSIGN(DesktopEnvironmentFactory); }; diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc index e2352a7..16be2b6 100644 --- a/remoting/host/plugin/host_script_object.cc +++ b/remoting/host/plugin/host_script_object.cc @@ -93,7 +93,6 @@ HostNPScriptObject::HostNPScriptObject( np_thread_id_(base::PlatformThread::CurrentId()), plugin_task_runner_( new PluginThreadTaskRunner(plugin_thread_delegate)), - desktop_environment_factory_(new DesktopEnvironmentFactory()), failed_login_attempts_(0), nat_traversal_enabled_(false), policy_received_(false), @@ -134,6 +133,7 @@ bool HostNPScriptObject::Init() { DCHECK(plugin_task_runner_->BelongsToCurrentThread()); VLOG(2) << "Init"; + // Create threads for the Chromoting host & desktop environment to use. scoped_refptr<AutoThreadTaskRunner> auto_plugin_task_runner = new AutoThreadTaskRunner(plugin_task_runner_, base::Bind(&PluginThreadTaskRunner::Quit, @@ -145,6 +145,11 @@ bool HostNPScriptObject::Init() { return false; } + // Create the desktop environment factory. + desktop_environment_factory_.reset(new DesktopEnvironmentFactory( + host_context_->input_task_runner(), host_context_->ui_task_runner())); + + // Start monitoring configured policies. policy_watcher_.reset( policy_hack::PolicyWatcher::Create(host_context_->network_task_runner())); policy_watcher_->StartWatching( @@ -561,10 +566,13 @@ void HostNPScriptObject::FinishConnect( // Create the host. host_ = new ChromotingHost( - host_context_.get(), signal_strategy_.get(), + signal_strategy_.get(), desktop_environment_factory_.get(), CreateHostSessionManager(network_settings, - host_context_->url_request_context_getter())); + host_context_->url_request_context_getter()), + host_context_->capture_task_runner(), + host_context_->encode_task_runner(), + host_context_->network_task_runner()); host_->AddStatusObserver(this); log_to_server_.reset( new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get())); @@ -914,6 +922,9 @@ void HostNPScriptObject::OnShutdownFinished() { // unregister it from this thread). it2me_host_user_interface_.reset(); + // Destroy the DesktopEnvironmentFactory, to free thread references. + desktop_environment_factory_.reset(); + // Release the context's TaskRunner references for the threads, so they can // exit when no objects need them. host_context_->ReleaseTaskRunners(); diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index ce69d50..9e259f6 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -128,9 +128,11 @@ class HostProcess restarting_(false), shutting_down_(false), #if defined(OS_WIN) - desktop_environment_factory_(new SessionDesktopEnvironmentFactory()), + desktop_environment_factory_(new SessionDesktopEnvironmentFactory( + context_->input_task_runner(), context_->ui_task_runner())), #else // !defined(OS_WIN) - desktop_environment_factory_(new DesktopEnvironmentFactory()), + desktop_environment_factory_(new DesktopEnvironmentFactory( + context_->input_task_runner(), context_->ui_task_runner())), #endif // !defined(OS_WIN) desktop_resizer_(DesktopResizer::Create()), exit_code_(kSuccessExitCode) @@ -311,9 +313,10 @@ class HostProcess void ShutdownHostProcess() { DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); + // Tear down resources that use ChromotingHostContext threads. config_watcher_.reset(); - daemon_channel_.reset(); + desktop_environment_factory_.reset(); host_user_interface_.reset(); if (policy_watcher_.get()) { @@ -558,10 +561,13 @@ class HostProcess } host_ = new ChromotingHost( - context_.get(), signal_strategy_.get(), + signal_strategy_.get(), desktop_environment_factory_.get(), CreateHostSessionManager(network_settings, - context_->url_request_context_getter())); + context_->url_request_context_getter()), + context_->capture_task_runner(), + context_->encode_task_runner(), + context_->network_task_runner()); // TODO(simonmorris): Get the maximum session duration from a policy. #if defined(OS_LINUX) diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index bef1447..6caacac 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -42,6 +42,7 @@ #include "remoting/host/desktop_environment_factory.h" #include "remoting/host/dns_blackhole_checker.h" #include "remoting/host/event_executor.h" +#include "remoting/host/event_executor_fake.h" #include "remoting/host/heartbeat_sender.h" #include "remoting/host/host_exit_codes.h" #include "remoting/host/host_key_pair.h" @@ -101,27 +102,24 @@ class FakeDesktopEnvironmentFactory : public DesktopEnvironmentFactory { FakeDesktopEnvironmentFactory(); virtual ~FakeDesktopEnvironmentFactory(); - virtual scoped_ptr<DesktopEnvironment> Create( - ChromotingHostContext* context) OVERRIDE; + virtual scoped_ptr<DesktopEnvironment> Create() OVERRIDE; + private: DISALLOW_COPY_AND_ASSIGN(FakeDesktopEnvironmentFactory); }; -FakeDesktopEnvironmentFactory::FakeDesktopEnvironmentFactory() { + FakeDesktopEnvironmentFactory::FakeDesktopEnvironmentFactory() + : DesktopEnvironmentFactory(NULL, NULL) { } FakeDesktopEnvironmentFactory::~FakeDesktopEnvironmentFactory() { } -scoped_ptr<DesktopEnvironment> FakeDesktopEnvironmentFactory::Create( - ChromotingHostContext* context) { +scoped_ptr<DesktopEnvironment> FakeDesktopEnvironmentFactory::Create() { scoped_ptr<VideoFrameCapturer> capturer(new VideoFrameCapturerFake()); - scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( - context->desktop_task_runner(), - context->ui_task_runner()); - scoped_ptr<AudioCapturer> audio_capturer(NULL); + scoped_ptr<EventExecutor> event_executor(new EventExecutorFake()); return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment( - audio_capturer.Pass(), + scoped_ptr<AudioCapturer>(NULL), event_executor.Pass(), capturer.Pass())); } @@ -263,13 +261,17 @@ class SimpleHost : public HeartbeatSender::Listener { if (fake_) { desktop_environment_factory_.reset(new FakeDesktopEnvironmentFactory()); } else { - desktop_environment_factory_.reset(new DesktopEnvironmentFactory()); + desktop_environment_factory_.reset(new DesktopEnvironmentFactory( + context_.input_task_runner(), context_.ui_task_runner())); } host_ = new ChromotingHost( - &context_, signal_strategy_.get(), desktop_environment_factory_.get(), + signal_strategy_.get(), desktop_environment_factory_.get(), CreateHostSessionManager(network_settings_, - context_.url_request_context_getter())); + context_.url_request_context_getter()), + context_.capture_task_runner(), + context_.encode_task_runner(), + context_.network_task_runner()); ServerLogEntry::Mode mode = is_it2me_ ? ServerLogEntry::IT2ME : ServerLogEntry::ME2ME; diff --git a/remoting/host/win/session_desktop_environment_factory.cc b/remoting/host/win/session_desktop_environment_factory.cc index b90ef33..fda201f 100644 --- a/remoting/host/win/session_desktop_environment_factory.cc +++ b/remoting/host/win/session_desktop_environment_factory.cc @@ -13,21 +13,21 @@ namespace remoting { -SessionDesktopEnvironmentFactory::SessionDesktopEnvironmentFactory() { +SessionDesktopEnvironmentFactory::SessionDesktopEnvironmentFactory( + scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) + : DesktopEnvironmentFactory(input_task_runner, ui_task_runner) { } SessionDesktopEnvironmentFactory::~SessionDesktopEnvironmentFactory() { } -scoped_ptr<DesktopEnvironment> SessionDesktopEnvironmentFactory::Create( - ChromotingHostContext* context) { +scoped_ptr<DesktopEnvironment> SessionDesktopEnvironmentFactory::Create() { scoped_ptr<AudioCapturer> audio_capturer = AudioCapturer::Create(); scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( - context->desktop_task_runner(), - context->ui_task_runner()); + input_task_runner_, ui_task_runner_); event_executor.reset(new SessionEventExecutorWin( - context->desktop_task_runner(), - event_executor.Pass())); + input_task_runner_, event_executor.Pass())); scoped_ptr<VideoFrameCapturer> video_capturer(VideoFrameCapturer::Create()); return scoped_ptr<DesktopEnvironment>(new DesktopEnvironment( audio_capturer.Pass(), diff --git a/remoting/host/win/session_desktop_environment_factory.h b/remoting/host/win/session_desktop_environment_factory.h index 6f71230..5b85e2b 100644 --- a/remoting/host/win/session_desktop_environment_factory.h +++ b/remoting/host/win/session_desktop_environment_factory.h @@ -11,11 +11,12 @@ namespace remoting { class SessionDesktopEnvironmentFactory : public DesktopEnvironmentFactory { public: - SessionDesktopEnvironmentFactory(); + SessionDesktopEnvironmentFactory( + scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); virtual ~SessionDesktopEnvironmentFactory(); - virtual scoped_ptr<DesktopEnvironment> Create( - ChromotingHostContext* context) OVERRIDE; + virtual scoped_ptr<DesktopEnvironment> Create() OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(SessionDesktopEnvironmentFactory); diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index e9d43d9..4afd758 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -1347,6 +1347,8 @@ 'host/dns_blackhole_checker.cc', 'host/dns_blackhole_checker.h', 'host/event_executor.h', + 'host/event_executor_fake.cc', + 'host/event_executor_fake.h', 'host/event_executor_linux.cc', 'host/event_executor_mac.cc', 'host/event_executor_win.cc', @@ -1892,8 +1894,6 @@ 'host/client_session_unittest.cc', 'host/differ_block_unittest.cc', 'host/differ_unittest.cc', - 'host/event_executor_fake.cc', - 'host/event_executor_fake.h', 'host/heartbeat_sender_unittest.cc', 'host/host_key_pair_unittest.cc', 'host/host_mock_objects.cc', |