diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-03 00:24:15 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-03 00:24:15 +0000 |
commit | 3c8cfbe7a52cf6de13020ccd4aaffa47443906a9 (patch) | |
tree | e0e121d435e2119d6484cea1188951e4a646f998 /remoting | |
parent | dd8e5fd96f8b25afe11c26ae95f30e4cca80b656 (diff) | |
download | chromium_src-3c8cfbe7a52cf6de13020ccd4aaffa47443906a9.zip chromium_src-3c8cfbe7a52cf6de13020ccd4aaffa47443906a9.tar.gz chromium_src-3c8cfbe7a52cf6de13020ccd4aaffa47443906a9.tar.bz2 |
Use SingleThreadTaskRunner instead of MessageLoopProxy in remoting/host.
Also includes various cleanups. E.g. main_thread was renamed to capture_thread to reflect what the thread is used for.
Review URL: https://chromiumcodereview.appspot.com/10572005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145227 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
27 files changed, 460 insertions, 327 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index db48080..74917e69 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -77,7 +77,7 @@ ChromotingHost::ChromotingHost( DCHECK(context_); DCHECK(signal_strategy); DCHECK(desktop_environment_); - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); } ChromotingHost::~ChromotingHost() { @@ -85,7 +85,7 @@ ChromotingHost::~ChromotingHost() { } void ChromotingHost::Start() { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); LOG(INFO) << "Starting host"; @@ -100,8 +100,8 @@ void ChromotingHost::Start() { // This method is called when we need to destroy the host process. void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { - if (!context_->network_message_loop()->BelongsToCurrentThread()) { - context_->network_message_loop()->PostTask( + if (!context_->network_task_runner()->BelongsToCurrentThread()) { + context_->network_task_runner()->PostTask( FROM_HERE, base::Bind(&ChromotingHost::Shutdown, this, shutdown_task)); return; } @@ -110,7 +110,7 @@ void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { if (state_ == kInitial || state_ == kStopped) { // Nothing to do if we are not started. state_ = kStopped; - context_->network_message_loop()->PostTask(FROM_HERE, shutdown_task); + context_->network_task_runner()->PostTask(FROM_HERE, shutdown_task); return; } if (!shutdown_task.is_null()) @@ -136,12 +136,12 @@ void ChromotingHost::Shutdown(const base::Closure& shutdown_task) { } void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); status_observers_.AddObserver(observer); } void ChromotingHost::RemoveStatusObserver(HostStatusObserver* observer) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); status_observers_.RemoveObserver(observer); } @@ -152,7 +152,7 @@ void ChromotingHost::RejectAuthenticatingClient() { void ChromotingHost::SetAuthenticatorFactory( scoped_ptr<protocol::AuthenticatorFactory> authenticator_factory) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); session_manager_->set_authenticator_factory(authenticator_factory.Pass()); } @@ -164,7 +164,7 @@ void ChromotingHost::SetMaximumSessionDuration( //////////////////////////////////////////////////////////////////////////// // protocol::ClientSession::EventHandler implementation. void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); login_backoff_.Reset(); @@ -199,15 +199,15 @@ void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { } void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); // Then we create a ScreenRecorder passing the message loops that // it should run on. Encoder* encoder = CreateEncoder(client->connection()->session()->config()); - recorder_ = new ScreenRecorder(context_->main_message_loop(), - context_->encode_message_loop(), - context_->network_message_loop(), + recorder_ = new ScreenRecorder(context_->capture_task_runner(), + context_->encode_task_runner(), + context_->network_task_runner(), desktop_environment_->capturer(), encoder); @@ -221,7 +221,7 @@ void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { } void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); // Notify observers. FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, @@ -229,7 +229,7 @@ void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { } void ChromotingHost::OnSessionClosed(ClientSession* client) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); scoped_ptr<ClientSession> client_destroyer(client); @@ -259,7 +259,7 @@ void ChromotingHost::OnSessionClosed(ClientSession* client) { void ChromotingHost::OnSessionSequenceNumber(ClientSession* session, int64 sequence_number) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); if (recorder_.get()) recorder_->UpdateSequenceNumber(sequence_number); } @@ -268,14 +268,14 @@ void ChromotingHost::OnSessionRouteChange( ClientSession* session, const std::string& channel_name, const protocol::TransportRoute& route) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnClientRouteChange(session->client_jid(), channel_name, route)); } void ChromotingHost::OnSessionManagerReady() { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); // Don't need to do anything here, just wait for incoming // connections. } @@ -283,7 +283,7 @@ void ChromotingHost::OnSessionManagerReady() { void ChromotingHost::OnIncomingSession( protocol::Session* session, protocol::SessionManager::IncomingSessionResponse* response) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); if (state_ != kStarted) { *response = protocol::SessionManager::DECLINE; @@ -326,15 +326,15 @@ void ChromotingHost::OnIncomingSession( void ChromotingHost::set_protocol_config( protocol::CandidateSessionConfig* config) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); DCHECK(config); DCHECK_EQ(state_, kInitial); protocol_config_.reset(config); } void ChromotingHost::OnLocalMouseMoved(const SkIPoint& new_pos) { - if (!context_->network_message_loop()->BelongsToCurrentThread()) { - context_->network_message_loop()->PostTask( + if (!context_->network_task_runner()->BelongsToCurrentThread()) { + context_->network_task_runner()->PostTask( FROM_HERE, base::Bind(&ChromotingHost::OnLocalMouseMoved, this, new_pos)); return; @@ -347,8 +347,8 @@ void ChromotingHost::OnLocalMouseMoved(const SkIPoint& new_pos) { } void ChromotingHost::PauseSession(bool pause) { - if (!context_->network_message_loop()->BelongsToCurrentThread()) { - context_->network_message_loop()->PostTask( + if (!context_->network_task_runner()->BelongsToCurrentThread()) { + context_->network_task_runner()->PostTask( FROM_HERE, base::Bind(&ChromotingHost::PauseSession, this, pause)); return; } @@ -360,8 +360,8 @@ void ChromotingHost::PauseSession(bool pause) { } void ChromotingHost::DisconnectAllClients() { - if (!context_->network_message_loop()->BelongsToCurrentThread()) { - context_->network_message_loop()->PostTask( + if (!context_->network_task_runner()->BelongsToCurrentThread()) { + context_->network_task_runner()->PostTask( FROM_HERE, base::Bind(&ChromotingHost::DisconnectAllClients, this)); return; } @@ -374,7 +374,7 @@ void ChromotingHost::DisconnectAllClients() { } void ChromotingHost::SetUiStrings(const UiStrings& ui_strings) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); DCHECK_EQ(state_, kInitial); ui_strings_ = ui_strings; @@ -397,7 +397,7 @@ Encoder* ChromotingHost::CreateEncoder(const protocol::SessionConfig& config) { } void ChromotingHost::StopScreenRecorder() { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); DCHECK(recorder_.get()); ++stopping_recorders_; @@ -407,8 +407,8 @@ void ChromotingHost::StopScreenRecorder() { } void ChromotingHost::OnScreenRecorderStopped() { - if (!context_->network_message_loop()->BelongsToCurrentThread()) { - context_->network_message_loop()->PostTask( + if (!context_->network_task_runner()->BelongsToCurrentThread()) { + context_->network_task_runner()->PostTask( FROM_HERE, base::Bind(&ChromotingHost::OnScreenRecorderStopped, this)); return; } @@ -421,7 +421,7 @@ void ChromotingHost::OnScreenRecorderStopped() { } void ChromotingHost::ShutdownFinish() { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); DCHECK(!stopping_recorders_); state_ = kStopped; diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc index 5e9ff76..6c251fa 100644 --- a/remoting/host/chromoting_host_context.cc +++ b/remoting/host/chromoting_host_context.cc @@ -14,13 +14,13 @@ namespace remoting { ChromotingHostContext::ChromotingHostContext( - base::MessageLoopProxy* ui_message_loop) - : main_thread_("ChromotingMainThread"), + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) + : capture_thread_("ChromotingCaptureThread"), encode_thread_("ChromotingEncodeThread"), desktop_thread_("ChromotingDesktopThread"), io_thread_("ChromotingIOThread"), file_thread_("ChromotingFileIOThread"), - ui_message_loop_(ui_message_loop) { + ui_task_runner_(ui_task_runner) { } ChromotingHostContext::~ChromotingHostContext() { @@ -28,7 +28,7 @@ ChromotingHostContext::~ChromotingHostContext() { bool ChromotingHostContext::Start() { // Start all the threads. - bool started = main_thread_.Start() && encode_thread_.Start() && + bool started = capture_thread_.Start() && encode_thread_.Start() && jingle_thread_.Start() && desktop_thread_.Start() && io_thread_.StartWithOptions( base::Thread::Options(MessageLoop::TYPE_IO, 0)) && @@ -38,7 +38,7 @@ bool ChromotingHostContext::Start() { return false; url_request_context_getter_ = new URLRequestContextGetter( - ui_message_loop_, io_thread_.message_loop(), + ui_task_runner(), io_task_runner(), static_cast<MessageLoopForIO*>(file_thread_.message_loop())); return true; } @@ -47,31 +47,31 @@ JingleThread* ChromotingHostContext::jingle_thread() { return &jingle_thread_; } -MessageLoop* ChromotingHostContext::main_message_loop() { - return main_thread_.message_loop(); +base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() { + return capture_thread_.message_loop_proxy(); } -MessageLoop* ChromotingHostContext::encode_message_loop() { - return encode_thread_.message_loop(); +base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() { + return encode_thread_.message_loop_proxy(); } -base::MessageLoopProxy* ChromotingHostContext::network_message_loop() { +base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() { return jingle_thread_.message_loop_proxy(); } -MessageLoop* ChromotingHostContext::desktop_message_loop() { - return desktop_thread_.message_loop(); +base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() { + return desktop_thread_.message_loop_proxy(); } -base::MessageLoopProxy* ChromotingHostContext::ui_message_loop() { - return ui_message_loop_; +base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() { + return ui_task_runner_; } -base::MessageLoopProxy* ChromotingHostContext::io_message_loop() { +base::SingleThreadTaskRunner* ChromotingHostContext::io_task_runner() { return io_thread_.message_loop_proxy(); } -base::MessageLoopProxy* ChromotingHostContext::file_message_loop() { +base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() { return file_thread_.message_loop_proxy(); } diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h index 7476986a..b693f1ef 100644 --- a/remoting/host/chromoting_host_context.h +++ b/remoting/host/chromoting_host_context.h @@ -8,10 +8,15 @@ #include <string> #include "base/gtest_prod_util.h" +#include "base/memory/ref_counted.h" #include "base/threading/platform_thread.h" #include "base/threading/thread.h" #include "remoting/jingle_glue/jingle_thread.h" +namespace base { +class SingleThreadTaskRunner; +} // namespace base + namespace net { class URLRequestContextGetter; } // namespace net @@ -23,7 +28,8 @@ namespace remoting { class ChromotingHostContext { public: // Create a context. - ChromotingHostContext(base::MessageLoopProxy* ui_message_loop); + ChromotingHostContext( + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner); virtual ~ChromotingHostContext(); // TODO(ajwong): Move the Start method out of this class. Then @@ -35,13 +41,45 @@ class ChromotingHostContext { virtual JingleThread* jingle_thread(); - virtual MessageLoop* main_message_loop(); - virtual MessageLoop* encode_message_loop(); - virtual base::MessageLoopProxy* network_message_loop(); - virtual MessageLoop* desktop_message_loop(); - virtual base::MessageLoopProxy* ui_message_loop(); - virtual base::MessageLoopProxy* io_message_loop(); - virtual base::MessageLoopProxy* file_message_loop(); + // Task runner for the thread that is used for the UI. In the NPAPI + // plugin this corresponds to the main plugin thread. + virtual base::SingleThreadTaskRunner* ui_task_runner(); + + // Task runner for the thread used by the ScreenRecorder to capture + // the screen. + virtual base::SingleThreadTaskRunner* capture_task_runner(); + + // Task runner for the thread used to encode video streams. + virtual base::SingleThreadTaskRunner* encode_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. + virtual base::SingleThreadTaskRunner* network_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 that is used for chromium's network + // IO, particularly all HTTP requests (for OAuth and Relay servers). + // Chromium's HTTP stack cannot be used on the network_task_runner() + // because that thread runs libjingle's message loop, while + // chromium's sockets must be used on a thread with a + // MessageLoopForIO. + // + // TODO(sergeyu): Implement socket server for libjingle that works + // on a regular chromium thread and use it for network_task_runner() + // to avoid the need for io_task_runner(). + virtual base::SingleThreadTaskRunner* io_task_runner(); + + // Task runner for the thread that is used for blocking file + // IO. This thread is used by the URLRequestContext to read proxy + // configuration and by NatConfig to read policy configs. + virtual base::SingleThreadTaskRunner* file_task_runner(); + const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter(); @@ -51,15 +89,13 @@ class ChromotingHostContext { // A thread that hosts all network operations. JingleThread jingle_thread_; - // TODO(sergeyu): The "main" thread is used just by the - // capturer. Consider renaming it. - base::Thread main_thread_; + // A thread that hosts screen capture. + base::Thread capture_thread_; // A thread that hosts all encode operations. base::Thread encode_thread_; - // A thread that hosts desktop integration (capture, input injection, etc) - // This is NOT a Chrome-style UI thread. + // A thread that hosts input injection. base::Thread desktop_thread_; // Thread for non-blocking IO operations. @@ -68,7 +104,7 @@ class ChromotingHostContext { // Thread for blocking IO operations. base::Thread file_thread_; - scoped_refptr<base::MessageLoopProxy> ui_message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; diff --git a/remoting/host/chromoting_host_context_unittest.cc b/remoting/host/chromoting_host_context_unittest.cc index b48d322..0e1a0ce 100644 --- a/remoting/host/chromoting_host_context_unittest.cc +++ b/remoting/host/chromoting_host_context_unittest.cc @@ -17,8 +17,8 @@ TEST(ChromotingHostContextTest, StartAndStop) { context.Start(); EXPECT_TRUE(context.jingle_thread()); - EXPECT_TRUE(context.main_message_loop()); - EXPECT_TRUE(context.encode_message_loop()); + EXPECT_TRUE(context.capture_task_runner()); + EXPECT_TRUE(context.encode_task_runner()); } } // namespace remoting diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index edc5ac5..699efd1 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -68,22 +68,19 @@ class ChromotingHostTest : public testing::Test { virtual void SetUp() OVERRIDE { message_loop_proxy_ = base::MessageLoopProxy::current(); - ON_CALL(context_, main_message_loop()) - .WillByDefault(Return(&message_loop_)); - ON_CALL(context_, encode_message_loop()) - .WillByDefault(Return(&message_loop_)); - ON_CALL(context_, network_message_loop()) - .WillByDefault(Return(message_loop_proxy_.get())); - ON_CALL(context_, ui_message_loop()) - .WillByDefault(Return(message_loop_proxy_.get())); - EXPECT_CALL(context_, main_message_loop()) - .Times(AnyNumber()); - EXPECT_CALL(context_, encode_message_loop()) - .Times(AnyNumber()); - EXPECT_CALL(context_, network_message_loop()) - .Times(AnyNumber()); - EXPECT_CALL(context_, ui_message_loop()) - .Times(AnyNumber()); + + EXPECT_CALL(context_, ui_task_runner()) + .Times(AnyNumber()) + .WillRepeatedly(Return(message_loop_proxy_.get())); + EXPECT_CALL(context_, capture_task_runner()) + .Times(AnyNumber()) + .WillRepeatedly(Return(message_loop_proxy_.get())); + EXPECT_CALL(context_, encode_task_runner()) + .Times(AnyNumber()) + .WillRepeatedly(Return(message_loop_proxy_.get())); + EXPECT_CALL(context_, network_task_runner()) + .Times(AnyNumber()) + .WillRepeatedly(Return(message_loop_proxy_.get())); scoped_ptr<Capturer> capturer(new CapturerFake()); event_executor_ = new MockEventExecutor(); @@ -207,22 +204,22 @@ class ChromotingHostTest : public testing::Test { desktop_environment_->capturer(), base::TimeDelta()); connection_ptr->set_host_stub(client); - context_.network_message_loop()->PostTask( + context_.network_task_runner()->PostTask( FROM_HERE, base::Bind(&ChromotingHostTest::AddClientToHost, host_, client)); if (authenticate) { - context_.network_message_loop()->PostTask( + context_.network_task_runner()->PostTask( FROM_HERE, base::Bind(&ClientSession::OnConnectionAuthenticated, base::Unretained(client), connection_ptr)); if (!reject) { - context_.network_message_loop()->PostTask( + context_.network_task_runner()->PostTask( FROM_HERE, base::Bind(&ClientSession::OnConnectionChannelsConnected, base::Unretained(client), connection_ptr)); } } else { - context_.network_message_loop()->PostTask( + context_.network_task_runner()->PostTask( FROM_HERE, base::Bind(&ClientSession::OnConnectionClosed, base::Unretained(client), connection_ptr, protocol::AUTHENTICATION_FAILED)); diff --git a/remoting/host/desktop_environment.cc b/remoting/host/desktop_environment.cc index 7eb755d..c13b8d5 100644 --- a/remoting/host/desktop_environment.cc +++ b/remoting/host/desktop_environment.cc @@ -21,8 +21,8 @@ scoped_ptr<DesktopEnvironment> DesktopEnvironment::Create( ChromotingHostContext* context) { scoped_ptr<Capturer> capturer(Capturer::Create()); scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( - context->desktop_message_loop()->message_loop_proxy(), - context->ui_message_loop(), capturer.get()); + context->desktop_task_runner(), context->ui_task_runner(), + capturer.get()); if (capturer.get() == NULL || event_executor.get() == NULL) { LOG(ERROR) << "Unable to create DesktopEnvironment"; @@ -40,8 +40,8 @@ scoped_ptr<DesktopEnvironment> DesktopEnvironment::CreateForService( ChromotingHostContext* context) { scoped_ptr<Capturer> capturer(Capturer::Create()); scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( - context->desktop_message_loop()->message_loop_proxy(), - context->ui_message_loop(), capturer.get()); + context->desktop_task_runner(), context->ui_task_runner(), + capturer.get()); if (capturer.get() == NULL || event_executor.get() == NULL) { LOG(ERROR) << "Unable to create DesktopEnvironment"; @@ -50,8 +50,8 @@ scoped_ptr<DesktopEnvironment> DesktopEnvironment::CreateForService( #if defined(OS_WIN) event_executor.reset(new SessionEventExecutorWin( - context->desktop_message_loop(), - context->file_message_loop(), + context->desktop_task_runner(), + context->file_task_runner(), event_executor.Pass())); #endif diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h index e7bebd1..f061cd2 100644 --- a/remoting/host/host_mock_objects.h +++ b/remoting/host/host_mock_objects.h @@ -89,11 +89,11 @@ class MockChromotingHostContext : public ChromotingHostContext { MOCK_METHOD0(Start, bool()); MOCK_METHOD0(Stop, void()); MOCK_METHOD0(jingle_thread, JingleThread*()); - MOCK_METHOD0(io_message_loop, base::MessageLoopProxy*()); - MOCK_METHOD0(ui_message_loop, base::MessageLoopProxy*()); - MOCK_METHOD0(main_message_loop, MessageLoop*()); - MOCK_METHOD0(encode_message_loop, MessageLoop*()); - MOCK_METHOD0(network_message_loop, base::MessageLoopProxy*()); + MOCK_METHOD0(ui_task_runner, base::SingleThreadTaskRunner*()); + MOCK_METHOD0(capture_task_runner, base::SingleThreadTaskRunner*()); + MOCK_METHOD0(encode_task_runner, base::SingleThreadTaskRunner*()); + MOCK_METHOD0(network_task_runner, base::SingleThreadTaskRunner*()); + MOCK_METHOD0(io_task_runner, base::SingleThreadTaskRunner*()); private: DISALLOW_COPY_AND_ASSIGN(MockChromotingHostContext); diff --git a/remoting/host/host_user_interface.cc b/remoting/host/host_user_interface.cc index 399a9fc..925e106 100644 --- a/remoting/host/host_user_interface.cc +++ b/remoting/host/host_user_interface.cc @@ -18,11 +18,11 @@ HostUserInterface::HostUserInterface(ChromotingHostContext* context) is_monitoring_local_inputs_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), weak_ptr_(weak_factory_.GetWeakPtr()) { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); } HostUserInterface::~HostUserInterface() { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); MonitorLocalInputs(false); ShowDisconnectWindow(false, std::string()); @@ -30,7 +30,7 @@ HostUserInterface::~HostUserInterface() { void HostUserInterface::Start(ChromotingHost* host, const base::Closure& disconnect_callback) { - DCHECK(network_message_loop()->BelongsToCurrentThread()); + DCHECK(network_task_runner()->BelongsToCurrentThread()); DCHECK(host_ == NULL); DCHECK(disconnect_callback_.is_null()); @@ -42,21 +42,21 @@ void HostUserInterface::Start(ChromotingHost* host, } void HostUserInterface::OnClientAuthenticated(const std::string& jid) { - DCHECK(network_message_loop()->BelongsToCurrentThread()); + DCHECK(network_task_runner()->BelongsToCurrentThread()); authenticated_jid_ = jid; std::string username = jid.substr(0, jid.find('/')); - ui_message_loop()->PostTask(FROM_HERE, base::Bind( + ui_task_runner()->PostTask(FROM_HERE, base::Bind( &HostUserInterface::ProcessOnClientAuthenticated, weak_ptr_, username)); } void HostUserInterface::OnClientDisconnected(const std::string& jid) { - DCHECK(network_message_loop()->BelongsToCurrentThread()); + DCHECK(network_task_runner()->BelongsToCurrentThread()); if (jid == authenticated_jid_) { - ui_message_loop()->PostTask(FROM_HERE, base::Bind( + ui_task_runner()->PostTask(FROM_HERE, base::Bind( &HostUserInterface::ProcessOnClientDisconnected, weak_ptr_)); } @@ -66,7 +66,7 @@ void HostUserInterface::OnAccessDenied(const std::string& jid) { } void HostUserInterface::OnShutdown() { - DCHECK(network_message_loop()->BelongsToCurrentThread()); + DCHECK(network_task_runner()->BelongsToCurrentThread()); // Host status observers must be removed on the network thread, so // it must happen here instead of in the destructor. @@ -75,22 +75,22 @@ void HostUserInterface::OnShutdown() { } void HostUserInterface::OnDisconnectCallback() { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); MonitorLocalInputs(false); ShowDisconnectWindow(false, std::string()); DisconnectSession(); } -base::MessageLoopProxy* HostUserInterface::network_message_loop() const { - return context_->network_message_loop(); +base::SingleThreadTaskRunner* HostUserInterface::network_task_runner() const { + return context_->network_task_runner(); } -base::MessageLoopProxy* HostUserInterface::ui_message_loop() const { - return context_->ui_message_loop(); +base::SingleThreadTaskRunner* HostUserInterface::ui_task_runner() const { + return context_->ui_task_runner(); } void HostUserInterface::DisconnectSession() const { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); DCHECK(!disconnect_callback_.is_null()); disconnect_callback_.Run(); @@ -98,14 +98,14 @@ void HostUserInterface::DisconnectSession() const { void HostUserInterface::ProcessOnClientAuthenticated( const std::string& username) { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); MonitorLocalInputs(true); ShowDisconnectWindow(true, username); } void HostUserInterface::ProcessOnClientDisconnected() { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); MonitorLocalInputs(false); ShowDisconnectWindow(false, std::string()); @@ -116,7 +116,7 @@ void HostUserInterface::StartForTest( const base::Closure& disconnect_callback, scoped_ptr<DisconnectWindow> disconnect_window, scoped_ptr<LocalInputMonitor> local_input_monitor) { - DCHECK(network_message_loop()->BelongsToCurrentThread()); + DCHECK(network_task_runner()->BelongsToCurrentThread()); DCHECK(host_ == NULL); DCHECK(disconnect_callback_.is_null()); @@ -127,7 +127,7 @@ void HostUserInterface::StartForTest( } void HostUserInterface::MonitorLocalInputs(bool enable) { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); if (enable != is_monitoring_local_inputs_) { if (enable) { @@ -141,7 +141,7 @@ void HostUserInterface::MonitorLocalInputs(bool enable) { void HostUserInterface::ShowDisconnectWindow(bool show, const std::string& username) { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); if (show) { disconnect_window_->Show( diff --git a/remoting/host/host_user_interface.h b/remoting/host/host_user_interface.h index 942cd2a..ce509b8 100644 --- a/remoting/host/host_user_interface.h +++ b/remoting/host/host_user_interface.h @@ -12,9 +12,12 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/message_loop_proxy.h" #include "remoting/host/host_status_observer.h" +namespace base { +class SingleThreadTaskRunner; +} // namespace base + namespace remoting { class ChromotingHost; @@ -44,9 +47,8 @@ class HostUserInterface : public HostStatusObserver { } ChromotingHost* get_host() const { return host_; } - // Message loop accessors. - base::MessageLoopProxy* network_message_loop() const; - base::MessageLoopProxy* ui_message_loop() const; + base::SingleThreadTaskRunner* network_task_runner() const; + base::SingleThreadTaskRunner* ui_task_runner() const; // Invokes the session disconnect callback passed to Start(). void DisconnectSession() const; diff --git a/remoting/host/it2me_host_user_interface.cc b/remoting/host/it2me_host_user_interface.cc index e5cf54e..da3888b 100644 --- a/remoting/host/it2me_host_user_interface.cc +++ b/remoting/host/it2me_host_user_interface.cc @@ -30,14 +30,14 @@ It2MeHostUserInterface::It2MeHostUserInterface(ChromotingHostContext* context) } It2MeHostUserInterface::~It2MeHostUserInterface() { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); ShowContinueWindow(false); } void It2MeHostUserInterface::Start(ChromotingHost* host, const base::Closure& disconnect_callback) { - DCHECK(network_message_loop()->BelongsToCurrentThread()); + DCHECK(network_task_runner()->BelongsToCurrentThread()); HostUserInterface::Start(host, disconnect_callback); continue_window_ = ContinueWindow::Create(); @@ -49,7 +49,7 @@ void It2MeHostUserInterface::OnClientAuthenticated(const std::string& jid) { // connections may be an attacker, so both are suspect and we have // to reject the second connection and shutdown the host. get_host()->RejectAuthenticatingClient(); - network_message_loop()->PostTask(FROM_HERE, base::Bind( + network_task_runner()->PostTask(FROM_HERE, base::Bind( &ChromotingHost::Shutdown, get_host(), base::Closure())); } else { HostUserInterface::OnClientAuthenticated(jid); @@ -58,14 +58,14 @@ void It2MeHostUserInterface::OnClientAuthenticated(const std::string& jid) { void It2MeHostUserInterface::ProcessOnClientAuthenticated( const std::string& username) { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); HostUserInterface::ProcessOnClientAuthenticated(username); StartContinueWindowTimer(true); } void It2MeHostUserInterface::ProcessOnClientDisconnected() { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); HostUserInterface::ProcessOnClientDisconnected(); ShowContinueWindow(false); @@ -85,7 +85,7 @@ void It2MeHostUserInterface::StartForTest( } void It2MeHostUserInterface::ContinueSession(bool continue_session) { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); if (continue_session) { get_host()->PauseSession(false); @@ -96,14 +96,14 @@ void It2MeHostUserInterface::ContinueSession(bool continue_session) { } void It2MeHostUserInterface::OnContinueWindowTimer() { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); get_host()->PauseSession(true); ShowContinueWindow(true); // Cancel any pending timer and post one to hide the continue window. timer_weak_factory_.InvalidateWeakPtrs(); - ui_message_loop()->PostDelayedTask( + ui_task_runner()->PostDelayedTask( FROM_HERE, base::Bind(&It2MeHostUserInterface::OnShutdownHostTimer, timer_weak_factory_.GetWeakPtr()), @@ -111,14 +111,14 @@ void It2MeHostUserInterface::OnContinueWindowTimer() { } void It2MeHostUserInterface::OnShutdownHostTimer() { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); ShowContinueWindow(false); DisconnectSession(); } void It2MeHostUserInterface::ShowContinueWindow(bool show) { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); if (show) { continue_window_->Show(get_host(), base::Bind( @@ -129,12 +129,12 @@ void It2MeHostUserInterface::ShowContinueWindow(bool show) { } void It2MeHostUserInterface::StartContinueWindowTimer(bool start) { - DCHECK(ui_message_loop()->BelongsToCurrentThread()); + DCHECK(ui_task_runner()->BelongsToCurrentThread()); // Abandon previous timer events by invalidating their weak pointer to us. timer_weak_factory_.InvalidateWeakPtrs(); if (start) { - ui_message_loop()->PostDelayedTask( + ui_task_runner()->PostDelayedTask( FROM_HERE, base::Bind(&It2MeHostUserInterface::OnContinueWindowTimer, timer_weak_factory_.GetWeakPtr()), diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc index dc6c450..ac8f9af 100644 --- a/remoting/host/plugin/host_script_object.cc +++ b/remoting/host/plugin/host_script_object.cc @@ -85,7 +85,7 @@ HostNPScriptObject::HostNPScriptObject( am_currently_logging_(false), state_(kDisconnected), np_thread_id_(base::PlatformThread::CurrentId()), - plugin_message_loop_proxy_( + plugin_task_runner_( new PluginMessageLoopProxy(plugin_thread_delegate)), failed_login_attempts_(0), disconnected_event_(true, false), @@ -101,7 +101,7 @@ HostNPScriptObject::~HostNPScriptObject() { HostLogHandler::UnregisterLoggingScriptObject(this); - plugin_message_loop_proxy_->Detach(); + plugin_task_runner_->Detach(); // Stop listening for policy updates. if (nat_policy_.get()) { @@ -135,17 +135,17 @@ HostNPScriptObject::~HostNPScriptObject() { } bool HostNPScriptObject::Init() { - DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_task_runner_->BelongsToCurrentThread()); VLOG(2) << "Init"; - host_context_.reset(new ChromotingHostContext(plugin_message_loop_proxy_)); + host_context_.reset(new ChromotingHostContext(plugin_task_runner_)); if (!host_context_->Start()) { host_context_.reset(); return false; } nat_policy_.reset( - policy_hack::NatPolicy::Create(host_context_->network_message_loop())); + policy_hack::NatPolicy::Create(host_context_->network_task_runner())); nat_policy_->StartWatching( base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, base::Unretained(this))); @@ -388,7 +388,7 @@ bool HostNPScriptObject::Enumerate(std::vector<std::string>* values) { } void HostNPScriptObject::OnAccessDenied(const std::string& jid) { - DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); ++failed_login_attempts_; if (failed_login_attempts_ == kMaxLoginAttempts) { @@ -397,7 +397,7 @@ void HostNPScriptObject::OnAccessDenied(const std::string& jid) { } void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { - DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); if (state_ == kDisconnecting) { // Ignore the new connection if we are disconnecting. @@ -413,13 +413,13 @@ void HostNPScriptObject::OnClientAuthenticated(const std::string& jid) { } void HostNPScriptObject::OnClientDisconnected(const std::string& jid) { - DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); client_username_.clear(); DisconnectInternal(); } void HostNPScriptObject::OnShutdown() { - DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); register_request_.reset(); log_to_server_.reset(); @@ -436,7 +436,7 @@ void HostNPScriptObject::OnShutdown() { bool HostNPScriptObject::Connect(const NPVariant* args, uint32_t arg_count, NPVariant* result) { - DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_task_runner_->BelongsToCurrentThread()); LOG(INFO) << "Connecting..."; @@ -478,8 +478,8 @@ bool HostNPScriptObject::Connect(const NPVariant* args, void HostNPScriptObject::ReadPolicyAndConnect(const std::string& uid, const std::string& auth_token, const std::string& auth_service) { - if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { - host_context_->network_message_loop()->PostTask( + if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { + host_context_->network_task_runner()->PostTask( FROM_HERE, base::Bind( &HostNPScriptObject::ReadPolicyAndConnect, base::Unretained(this), uid, auth_token, auth_service)); @@ -504,14 +504,14 @@ void HostNPScriptObject::FinishConnectMainThread( const std::string& uid, const std::string& auth_token, const std::string& auth_service) { - if (host_context_->main_message_loop() != MessageLoop::current()) { - host_context_->main_message_loop()->PostTask(FROM_HERE, base::Bind( + if (!host_context_->capture_task_runner()->BelongsToCurrentThread()) { + host_context_->capture_task_runner()->PostTask(FROM_HERE, base::Bind( &HostNPScriptObject::FinishConnectMainThread, base::Unretained(this), uid, auth_token, auth_service)); return; } - // DesktopEnvironment must be initialized on the main thread. + // DesktopEnvironment must be initialized on the capture thread. // // TODO(sergeyu): Fix DesktopEnvironment so that it can be created // on either the UI or the network thread so that we can avoid @@ -525,8 +525,8 @@ void HostNPScriptObject::FinishConnectNetworkThread( const std::string& uid, const std::string& auth_token, const std::string& auth_service) { - if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { - host_context_->network_message_loop()->PostTask(FROM_HERE, base::Bind( + if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { + host_context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( &HostNPScriptObject::FinishConnectNetworkThread, base::Unretained(this), uid, auth_token, auth_service)); return; @@ -595,7 +595,7 @@ void HostNPScriptObject::FinishConnectNetworkThread( bool HostNPScriptObject::Disconnect(const NPVariant* args, uint32_t arg_count, NPVariant* result) { - DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_task_runner_->BelongsToCurrentThread()); if (arg_count != 0) { SetException("disconnect: bad number of arguments"); return false; @@ -609,7 +609,7 @@ bool HostNPScriptObject::Disconnect(const NPVariant* args, bool HostNPScriptObject::Localize(const NPVariant* args, uint32_t arg_count, NPVariant* result) { - DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_task_runner_->BelongsToCurrentThread()); if (arg_count != 1) { SetException("localize: bad number of arguments"); return false; @@ -848,8 +848,8 @@ bool HostNPScriptObject::StopDaemon(const NPVariant* args, } void HostNPScriptObject::DisconnectInternal() { - if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { - host_context_->network_message_loop()->PostTask( + if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { + host_context_->network_task_runner()->PostTask( FROM_HERE, base::Bind(&HostNPScriptObject::DisconnectInternal, base::Unretained(this))); return; @@ -877,7 +877,7 @@ void HostNPScriptObject::DisconnectInternal() { // synchronously, bug SignalStrategy::Listener handlers are not // allowed to destroy SignalStrategy, so post task to call // Shutdown() later. - host_context_->network_message_loop()->PostTask( + host_context_->network_task_runner()->PostTask( FROM_HERE, base::Bind( &ChromotingHost::Shutdown, host_, base::Bind(&HostNPScriptObject::OnShutdownFinished, @@ -886,14 +886,14 @@ void HostNPScriptObject::DisconnectInternal() { } void HostNPScriptObject::OnShutdownFinished() { - DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); disconnected_event_.Signal(); } void HostNPScriptObject::OnNatPolicyUpdate(bool nat_traversal_enabled) { - if (!host_context_->network_message_loop()->BelongsToCurrentThread()) { - host_context_->network_message_loop()->PostTask( + if (!host_context_->network_task_runner()->BelongsToCurrentThread()) { + host_context_->network_task_runner()->PostTask( FROM_HERE, base::Bind(&HostNPScriptObject::OnNatPolicyUpdate, base::Unretained(this), nat_traversal_enabled)); @@ -926,7 +926,7 @@ void HostNPScriptObject::OnReceivedSupportID( bool success, const std::string& support_id, const base::TimeDelta& lifetime) { - DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); if (!success) { SetState(kError); @@ -952,7 +952,7 @@ void HostNPScriptObject::OnReceivedSupportID( } void HostNPScriptObject::SetState(State state) { - DCHECK(host_context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(host_context_->network_task_runner()->BelongsToCurrentThread()); switch (state_) { case kDisconnected: DCHECK(state == kStarting || @@ -990,8 +990,8 @@ void HostNPScriptObject::SetState(State state) { } void HostNPScriptObject::NotifyStateChanged(State state) { - if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { - plugin_message_loop_proxy_->PostTask( + if (!plugin_task_runner_->BelongsToCurrentThread()) { + plugin_task_runner_->PostTask( FROM_HERE, base::Bind(&HostNPScriptObject::NotifyStateChanged, base::Unretained(this), state)); return; @@ -1006,7 +1006,7 @@ void HostNPScriptObject::NotifyStateChanged(State state) { } } void HostNPScriptObject::PostLogDebugInfo(const std::string& message) { - if (plugin_message_loop_proxy_->BelongsToCurrentThread()) { + if (plugin_task_runner_->BelongsToCurrentThread()) { // Make sure we're not currently processing a log message. // We only need to check this if we're on the plugin thread. if (am_currently_logging_) @@ -1015,7 +1015,7 @@ void HostNPScriptObject::PostLogDebugInfo(const std::string& message) { // Always post (even if we're already on the correct thread) so that debug // log messages are shown in the correct order. - plugin_message_loop_proxy_->PostTask( + plugin_task_runner_->PostTask( FROM_HERE, base::Bind(&HostNPScriptObject::LogDebugInfo, base::Unretained(this), message)); } @@ -1025,7 +1025,7 @@ void HostNPScriptObject::SetWindow(NPWindow* np_window) { } void HostNPScriptObject::LocalizeStrings(NPObject* localize_func) { - DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_task_runner_->BelongsToCurrentThread()); UiStrings ui_strings; string16 direction; @@ -1080,8 +1080,8 @@ bool HostNPScriptObject::LocalizeString(NPObject* localize_func, } void HostNPScriptObject::UpdateWebappNatPolicy(bool nat_traversal_enabled) { - if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { - plugin_message_loop_proxy_->PostTask( + if (!plugin_task_runner_->BelongsToCurrentThread()) { + plugin_task_runner_->PostTask( FROM_HERE, base::Bind(&HostNPScriptObject::UpdateWebappNatPolicy, base::Unretained(this), nat_traversal_enabled)); return; @@ -1105,8 +1105,8 @@ void HostNPScriptObject::InvokeGenerateKeyPairCallback( const ScopedRefNPObject& callback, const std::string& private_key, const std::string& public_key) { - if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { - plugin_message_loop_proxy_->PostTask( + if (!plugin_task_runner_->BelongsToCurrentThread()) { + plugin_task_runner_->PostTask( FROM_HERE, base::Bind( &HostNPScriptObject::InvokeGenerateKeyPairCallback, base::Unretained(this), callback, private_key, public_key)); @@ -1124,8 +1124,8 @@ void HostNPScriptObject::InvokeGenerateKeyPairCallback( void HostNPScriptObject::InvokeAsyncResultCallback( const ScopedRefNPObject& callback, DaemonController::AsyncResult result) { - if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { - plugin_message_loop_proxy_->PostTask( + if (!plugin_task_runner_->BelongsToCurrentThread()) { + plugin_task_runner_->PostTask( FROM_HERE, base::Bind( &HostNPScriptObject::InvokeAsyncResultCallback, base::Unretained(this), callback, result)); @@ -1141,8 +1141,8 @@ void HostNPScriptObject::InvokeAsyncResultCallback( void HostNPScriptObject::InvokeGetDaemonConfigCallback( const ScopedRefNPObject& callback, scoped_ptr<base::DictionaryValue> config) { - if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { - plugin_message_loop_proxy_->PostTask( + if (!plugin_task_runner_->BelongsToCurrentThread()) { + plugin_task_runner_->PostTask( FROM_HERE, base::Bind( &HostNPScriptObject::InvokeGetDaemonConfigCallback, base::Unretained(this), callback, base::Passed(&config))); @@ -1162,8 +1162,8 @@ void HostNPScriptObject::InvokeGetDaemonConfigCallback( void HostNPScriptObject::InvokeGetDaemonVersionCallback( const ScopedRefNPObject& callback, const std::string& version) { - if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { - plugin_message_loop_proxy_->PostTask( + if (!plugin_task_runner_->BelongsToCurrentThread()) { + plugin_task_runner_->PostTask( FROM_HERE, base::Bind( &HostNPScriptObject::InvokeGetDaemonVersionCallback, base::Unretained(this), callback, version)); @@ -1180,8 +1180,8 @@ void HostNPScriptObject::InvokeGetUsageStatsConsentCallback( bool supported, bool allowed, bool set_by_policy) { - if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) { - plugin_message_loop_proxy_->PostTask( + if (!plugin_task_runner_->BelongsToCurrentThread()) { + plugin_task_runner_->PostTask( FROM_HERE, base::Bind( &HostNPScriptObject::InvokeGetUsageStatsConsentCallback, base::Unretained(this), callback, supported, allowed, @@ -1200,7 +1200,7 @@ void HostNPScriptObject::InvokeGetUsageStatsConsentCallback( } void HostNPScriptObject::LogDebugInfo(const std::string& message) { - DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_task_runner_->BelongsToCurrentThread()); if (log_debug_info_func_.get()) { am_currently_logging_ = true; NPVariant log_message; @@ -1217,7 +1217,7 @@ void HostNPScriptObject::LogDebugInfo(const std::string& message) { bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, const NPVariant* args, uint32_t arg_count) { - DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_task_runner_->BelongsToCurrentThread()); NPVariant np_result; bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args, arg_count, &np_result); @@ -1227,7 +1227,7 @@ bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func, } void HostNPScriptObject::SetException(const std::string& exception_string) { - DCHECK(plugin_message_loop_proxy_->BelongsToCurrentThread()); + DCHECK(plugin_task_runner_->BelongsToCurrentThread()); g_npnetscape_funcs->setexception(parent_, exception_string.c_str()); LOG(INFO) << exception_string; } diff --git a/remoting/host/plugin/host_script_object.h b/remoting/host/plugin/host_script_object.h index 9e7110e..19788cf 100644 --- a/remoting/host/plugin/host_script_object.h +++ b/remoting/host/plugin/host_script_object.h @@ -290,7 +290,7 @@ class HostNPScriptObject : public HostStatusObserver { ScopedRefNPObject on_nat_traversal_policy_changed_func_; ScopedRefNPObject on_state_changed_func_; base::PlatformThreadId np_thread_id_; - scoped_refptr<PluginMessageLoopProxy> plugin_message_loop_proxy_; + scoped_refptr<PluginMessageLoopProxy> plugin_task_runner_; scoped_ptr<ChromotingHostContext> host_context_; HostKeyPair host_key_pair_; diff --git a/remoting/host/policy_hack/nat_policy.cc b/remoting/host/policy_hack/nat_policy.cc index bccc509..77f376a 100644 --- a/remoting/host/policy_hack/nat_policy.cc +++ b/remoting/host/policy_hack/nat_policy.cc @@ -11,7 +11,7 @@ #include "base/compiler_specific.h" #include "base/location.h" #include "base/memory/weak_ptr.h" -#include "base/message_loop_proxy.h" +#include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" #include "base/time.h" #include "base/values.h" @@ -28,8 +28,8 @@ const int kFallbackReloadDelayMinutes = 15; const char NatPolicy::kNatPolicyName[] = "RemoteAccessHostFirewallTraversal"; -NatPolicy::NatPolicy(base::MessageLoopProxy* message_loop_proxy) - : message_loop_proxy_(message_loop_proxy), +NatPolicy::NatPolicy(scoped_refptr<base::SingleThreadTaskRunner> task_runner) + : task_runner_(task_runner), current_nat_enabled_state_(false), first_state_published_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { @@ -40,10 +40,10 @@ NatPolicy::~NatPolicy() { void NatPolicy::StartWatching(const NatEnabledCallback& nat_enabled_cb) { if (!OnPolicyThread()) { - message_loop_proxy_->PostTask(FROM_HERE, - base::Bind(&NatPolicy::StartWatching, - base::Unretained(this), - nat_enabled_cb)); + task_runner_->PostTask(FROM_HERE, + base::Bind(&NatPolicy::StartWatching, + base::Unretained(this), + nat_enabled_cb)); return; } @@ -53,9 +53,9 @@ void NatPolicy::StartWatching(const NatEnabledCallback& nat_enabled_cb) { void NatPolicy::StopWatching(base::WaitableEvent* done) { if (!OnPolicyThread()) { - message_loop_proxy_->PostTask(FROM_HERE, - base::Bind(&NatPolicy::StopWatching, - base::Unretained(this), done)); + task_runner_->PostTask(FROM_HERE, + base::Bind(&NatPolicy::StopWatching, + base::Unretained(this), done)); return; } @@ -74,14 +74,14 @@ void NatPolicy::ScheduleFallbackReloadTask() { void NatPolicy::ScheduleReloadTask(const base::TimeDelta& delay) { DCHECK(OnPolicyThread()); - message_loop_proxy_->PostDelayedTask( + task_runner_->PostDelayedTask( FROM_HERE, base::Bind(&NatPolicy::Reload, weak_factory_.GetWeakPtr()), delay); } bool NatPolicy::OnPolicyThread() const { - return message_loop_proxy_->BelongsToCurrentThread(); + return task_runner_->BelongsToCurrentThread(); } void NatPolicy::UpdateNatPolicy(base::DictionaryValue* new_policy) { diff --git a/remoting/host/policy_hack/nat_policy.h b/remoting/host/policy_hack/nat_policy.h index 4984d1f..93f1c41 100644 --- a/remoting/host/policy_hack/nat_policy.h +++ b/remoting/host/policy_hack/nat_policy.h @@ -10,7 +10,7 @@ namespace base { class DictionaryValue; -class MessageLoopProxy; +class SingleThreadTaskRunner; class TimeDelta; class WaitableEvent; } // namespace base @@ -26,7 +26,7 @@ class NatPolicy { // Called with the current status of whether or not NAT traversal is enabled. typedef base::Callback<void(bool)> NatEnabledCallback; - explicit NatPolicy(base::MessageLoopProxy* message_loop_proxy); + explicit NatPolicy(scoped_refptr<base::SingleThreadTaskRunner> task_runner); virtual ~NatPolicy(); // This guarantees that the |nat_enabled_cb| is called at least once with @@ -40,7 +40,8 @@ class NatPolicy { // Implemented by each platform. This message loop should be an IO message // loop. - static NatPolicy* Create(base::MessageLoopProxy* message_loop_proxy); + static NatPolicy* Create( + scoped_refptr<base::SingleThreadTaskRunner> task_runner); protected: virtual void StartWatchingInternal() = 0; @@ -62,7 +63,7 @@ class NatPolicy { static const char kNatPolicyName[]; private: - scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; NatEnabledCallback nat_enabled_cb_; bool current_nat_enabled_state_; diff --git a/remoting/host/policy_hack/nat_policy_linux.cc b/remoting/host/policy_hack/nat_policy_linux.cc index 534fdb4..184d6fc 100644 --- a/remoting/host/policy_hack/nat_policy_linux.cc +++ b/remoting/host/policy_hack/nat_policy_linux.cc @@ -22,7 +22,7 @@ #include "base/json/json_file_value_serializer.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "base/message_loop_proxy.h" +#include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" #include "base/time.h" #include "base/values.h" @@ -44,9 +44,9 @@ const int kSettleIntervalSeconds = 5; class NatPolicyLinux : public NatPolicy { public: - NatPolicyLinux(base::MessageLoopProxy* message_loop_proxy, + NatPolicyLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner, const FilePath& config_dir) - : NatPolicy(message_loop_proxy), + : NatPolicy(task_runner), config_dir_(config_dir), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { // Detach the factory because we ensure that only the policy thread ever @@ -268,9 +268,10 @@ class NatPolicyLinux : public NatPolicy { base::WeakPtrFactory<NatPolicyLinux> weak_factory_; }; -NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) { +NatPolicy* NatPolicy::Create( + scoped_refptr<base::SingleThreadTaskRunner> task_runner) { FilePath policy_dir(kPolicyDir); - return new NatPolicyLinux(message_loop_proxy, policy_dir); + return new NatPolicyLinux(task_runner, policy_dir); } } // namespace policy_hack diff --git a/remoting/host/policy_hack/nat_policy_mac.mm b/remoting/host/policy_hack/nat_policy_mac.mm index 25cf6e7..d3d2621 100644 --- a/remoting/host/policy_hack/nat_policy_mac.mm +++ b/remoting/host/policy_hack/nat_policy_mac.mm @@ -9,7 +9,7 @@ #include "base/compiler_specific.h" #include "base/mac/scoped_cftyperef.h" #include "base/memory/scoped_ptr.h" -#include "base/message_loop_proxy.h" +#include "base/single_thread_task_runner.h" #include "base/sys_string_conversions.h" #include "base/values.h" @@ -22,8 +22,8 @@ namespace policy_hack { // |kFallbackReloadDelayMinutes| which is sufficient for right now. class NatPolicyMac : public NatPolicy { public: - explicit NatPolicyMac(base::MessageLoopProxy* message_loop_proxy) - : NatPolicy(message_loop_proxy) { + explicit NatPolicyMac(scoped_refptr<base::SingleThreadTaskRunner> task_runner) + : NatPolicy(task_runner) { } virtual ~NatPolicyMac() { @@ -63,8 +63,9 @@ class NatPolicyMac : public NatPolicy { } }; -NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) { - return new NatPolicyMac(message_loop_proxy); +NatPolicy* NatPolicy::Create( + scoped_refptr<base::SingleThreadTaskRunner> task_runner) { + return new NatPolicyMac(task_runner); } } // namespace policy_hack diff --git a/remoting/host/policy_hack/nat_policy_win.cc b/remoting/host/policy_hack/nat_policy_win.cc index 1300b3b..d09d39d 100644 --- a/remoting/host/policy_hack/nat_policy_win.cc +++ b/remoting/host/policy_hack/nat_policy_win.cc @@ -42,8 +42,8 @@ class NatPolicyWin : public NatPolicy, public base::win::ObjectWatcher::Delegate { public: - explicit NatPolicyWin(base::MessageLoopProxy* message_loop_proxy) - : NatPolicy(message_loop_proxy), + explicit NatPolicyWin(scoped_refptr<base::SingleThreadTaskRunner> task_runner) + : NatPolicy(task_runner), user_policy_changed_event_(false, false), machine_policy_changed_event_(false, false), user_policy_watcher_failed_(false), @@ -177,8 +177,9 @@ class NatPolicyWin : bool machine_policy_watcher_failed_; }; -NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) { - return new NatPolicyWin(message_loop_proxy); +NatPolicy* NatPolicy::Create( + scoped_refptr<base::SingleThreadTaskRunner> task_runner) { + return new NatPolicyWin(task_runner); } } // namespace policy_hack diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index 6aa6e93..65b605b 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -146,7 +146,7 @@ class HostProcess void ConfigUpdatedDelayed() { if (LoadConfig()) { - context_->network_message_loop()->PostTask( + context_->network_task_runner()->PostTask( FROM_HERE, base::Bind(&HostProcess::CreateAuthenticatorFactory, base::Unretained(this))); @@ -158,21 +158,22 @@ class HostProcess #if defined(OS_WIN) class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { public: - ConfigChangedDelegate(base::MessageLoopProxy* message_loop, - const base::Closure& callback) - : message_loop_(message_loop), + ConfigChangedDelegate( + scoped_refptr<base::SingleThreadTaskRunner> task_runner, + const base::Closure& callback) + : task_runner_(task_runner), callback_(callback) { } void OnFilePathChanged(const FilePath& path) OVERRIDE { - message_loop_->PostTask(FROM_HERE, callback_); + task_runner_->PostTask(FROM_HERE, callback_); } void OnFilePathError(const FilePath& path) OVERRIDE { } private: - scoped_refptr<base::MessageLoopProxy> message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; base::Closure callback_; DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); @@ -215,7 +216,7 @@ class HostProcess StartWatchingNatPolicy(); #if defined(OS_MACOSX) || defined(OS_WIN) - context_->file_message_loop()->PostTask( + context_->file_task_runner()->PostTask( FROM_HERE, base::Bind(&HostProcess::ListenForConfigChanges, base::Unretained(this))); @@ -243,7 +244,7 @@ class HostProcess private: void StartWatchingNatPolicy() { nat_policy_.reset( - policy_hack::NatPolicy::Create(context_->file_message_loop())); + policy_hack::NatPolicy::Create(context_->file_task_runner())); nat_policy_->StartWatching( base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this))); } @@ -314,8 +315,8 @@ class HostProcess } void OnNatPolicyUpdate(bool nat_traversal_enabled) { - if (!context_->network_message_loop()->BelongsToCurrentThread()) { - context_->network_message_loop()->PostTask(FROM_HERE, base::Bind( + if (!context_->network_task_runner()->BelongsToCurrentThread()) { + context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( &HostProcess::OnNatPolicyUpdate, base::Unretained(this), nat_traversal_enabled)); return; @@ -336,7 +337,7 @@ class HostProcess } void StartHost() { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); DCHECK(!host_); if (!signal_strategy_.get()) { @@ -429,7 +430,7 @@ class HostProcess } void RestartHost() { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); if (restarting_ || shutting_down_) return; @@ -440,7 +441,7 @@ class HostProcess } void RestartOnHostShutdown() { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); if (shutting_down_) return; @@ -455,7 +456,7 @@ class HostProcess } void Shutdown(int exit_code) { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); if (shutting_down_) return; @@ -467,7 +468,7 @@ class HostProcess } void OnShutdownFinished() { - DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); // Destroy networking objects while we are on the network thread. host_ = NULL; diff --git a/remoting/host/screen_recorder.cc b/remoting/host/screen_recorder.cc index e7b414c..20b305a 100644 --- a/remoting/host/screen_recorder.cc +++ b/remoting/host/screen_recorder.cc @@ -32,14 +32,14 @@ namespace remoting { static const int kMaxRecordings = 2; ScreenRecorder::ScreenRecorder( - MessageLoop* capture_loop, - MessageLoop* encode_loop, - base::MessageLoopProxy* network_loop, + scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, Capturer* capturer, Encoder* encoder) - : capture_loop_(capture_loop), - encode_loop_(encode_loop), - network_loop_(network_loop), + : capture_task_runner_(capture_task_runner), + encode_task_runner_(encode_task_runner), + network_task_runner_(network_task_runner), capturer_(capturer), encoder_(encoder), network_stopped_(false), @@ -48,21 +48,21 @@ ScreenRecorder::ScreenRecorder( recordings_(0), frame_skipped_(false), sequence_number_(0) { - DCHECK(capture_loop_); - DCHECK(encode_loop_); - DCHECK(network_loop_); + DCHECK(capture_task_runner_); + DCHECK(encode_task_runner_); + DCHECK(network_task_runner_); } // Public methods -------------------------------------------------------------- void ScreenRecorder::Start() { - capture_loop_->PostTask( + capture_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::DoStart, this)); } void ScreenRecorder::Stop(const base::Closure& done_task) { - if (MessageLoop::current() != capture_loop_) { - capture_loop_->PostTask(FROM_HERE, base::Bind( + if (!capture_task_runner_->BelongsToCurrentThread()) { + capture_task_runner_->PostTask(FROM_HERE, base::Bind( &ScreenRecorder::Stop, this, done_task)); return; } @@ -72,20 +72,20 @@ void ScreenRecorder::Stop(const base::Closure& done_task) { capturer()->Stop(); capture_timer_.reset(); - network_loop_->PostTask(FROM_HERE, base::Bind( + network_task_runner_->PostTask(FROM_HERE, base::Bind( &ScreenRecorder::DoStopOnNetworkThread, this, done_task)); } void ScreenRecorder::AddConnection(ConnectionToClient* connection) { - DCHECK(network_loop_->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); connections_.push_back(connection); - capture_loop_->PostTask( + capture_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::DoInvalidateFullScreen, this)); } void ScreenRecorder::RemoveConnection(ConnectionToClient* connection) { - DCHECK(network_loop_->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); ConnectionToClientList::iterator it = std::find(connections_.begin(), connections_.end(), connection); @@ -95,14 +95,14 @@ void ScreenRecorder::RemoveConnection(ConnectionToClient* connection) { } void ScreenRecorder::RemoveAllConnections() { - DCHECK(network_loop_->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); connections_.clear(); } void ScreenRecorder::UpdateSequenceNumber(int64 sequence_number) { // Sequence number is used and written only on the capture thread. - if (MessageLoop::current() != capture_loop_) { - capture_loop_->PostTask( + if (!capture_task_runner_->BelongsToCurrentThread()) { + capture_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::UpdateSequenceNumber, this, sequence_number)); return; @@ -117,26 +117,26 @@ ScreenRecorder::~ScreenRecorder() { } Capturer* ScreenRecorder::capturer() { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); DCHECK(capturer_); return capturer_; } Encoder* ScreenRecorder::encoder() { - DCHECK_EQ(encode_loop_, MessageLoop::current()); + DCHECK(encode_task_runner_->BelongsToCurrentThread()); DCHECK(encoder_.get()); return encoder_.get(); } bool ScreenRecorder::is_recording() { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); return capture_timer_.get() != NULL; } // Capturer thread ------------------------------------------------------------- void ScreenRecorder::DoStart() { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); if (is_recording()) { NOTREACHED() << "Record session already started."; @@ -153,7 +153,7 @@ void ScreenRecorder::DoStart() { } void ScreenRecorder::StartCaptureTimer() { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); capture_timer_->Start(FROM_HERE, scheduler_.NextCaptureDelay(), @@ -162,7 +162,7 @@ void ScreenRecorder::StartCaptureTimer() { } void ScreenRecorder::DoCapture() { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); // Make sure we have at most two oustanding recordings. We can simply return // if we can't make a capture now, the next capture will be started by the // end of an encode operation. @@ -193,7 +193,7 @@ void ScreenRecorder::DoCapture() { void ScreenRecorder::CaptureDoneCallback( scoped_refptr<CaptureData> capture_data) { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); if (!is_recording()) return; @@ -213,24 +213,24 @@ void ScreenRecorder::CaptureDoneCallback( capture_data->set_client_sequence_number(sequence_number_); } - encode_loop_->PostTask( + encode_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::DoEncode, this, capture_data)); } void ScreenRecorder::CursorShapeChangedCallback( scoped_ptr<protocol::CursorShapeInfo> cursor_shape) { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); if (!is_recording()) return; - network_loop_->PostTask( + network_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::DoSendCursorShape, this, base::Passed(cursor_shape.Pass()))); } void ScreenRecorder::DoFinishOneRecording() { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); if (!is_recording()) return; @@ -247,7 +247,7 @@ void ScreenRecorder::DoFinishOneRecording() { } void ScreenRecorder::DoInvalidateFullScreen() { - DCHECK_EQ(capture_loop_, MessageLoop::current()); + DCHECK(capture_task_runner_->BelongsToCurrentThread()); capturer_->InvalidateFullScreen(); } @@ -255,7 +255,7 @@ void ScreenRecorder::DoInvalidateFullScreen() { // Network thread -------------------------------------------------------------- void ScreenRecorder::DoSendVideoPacket(scoped_ptr<VideoPacket> packet) { - DCHECK(network_loop_->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); if (network_stopped_ || connections_.empty()) return; @@ -271,17 +271,17 @@ void ScreenRecorder::DoSendVideoPacket(scoped_ptr<VideoPacket> packet) { } void ScreenRecorder::VideoFrameSentCallback() { - DCHECK(network_loop_->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); if (network_stopped_) return; - capture_loop_->PostTask( + capture_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this)); } void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { - DCHECK(network_loop_->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); // There could be tasks on the network thread when this method is being // executed. By setting the flag we'll not post anymore tasks from network @@ -291,14 +291,14 @@ void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) { // sequence. network_stopped_ = true; - encode_loop_->PostTask( + encode_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::DoStopOnEncodeThread, this, done_task)); } void ScreenRecorder::DoSendCursorShape( scoped_ptr<protocol::CursorShapeInfo> cursor_shape) { - DCHECK(network_loop_->BelongsToCurrentThread()); + DCHECK(network_task_runner_->BelongsToCurrentThread()); if (network_stopped_ || connections_.empty()) return; @@ -312,7 +312,7 @@ void ScreenRecorder::DoSendCursorShape( void ScreenRecorder::DoEncode( scoped_refptr<CaptureData> capture_data) { - DCHECK_EQ(encode_loop_, MessageLoop::current()); + DCHECK(encode_task_runner_->BelongsToCurrentThread()); if (encoder_stopped_) return; @@ -322,7 +322,7 @@ void ScreenRecorder::DoEncode( // Send an empty video packet to keep network active. scoped_ptr<VideoPacket> packet(new VideoPacket()); packet->set_flags(VideoPacket::LAST_PARTITION); - network_loop_->PostTask( + network_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, base::Passed(packet.Pass()))); return; @@ -335,19 +335,19 @@ void ScreenRecorder::DoEncode( } void ScreenRecorder::DoStopOnEncodeThread(const base::Closure& done_task) { - DCHECK_EQ(encode_loop_, MessageLoop::current()); + DCHECK(encode_task_runner_->BelongsToCurrentThread()); encoder_stopped_ = true; // When this method is being executed there are no more tasks on encode thread // for this object. We can then post a task to capture thread to finish the // stop sequence. - capture_loop_->PostTask(FROM_HERE, done_task); + capture_task_runner_->PostTask(FROM_HERE, done_task); } void ScreenRecorder::EncodedDataAvailableCallback( scoped_ptr<VideoPacket> packet) { - DCHECK_EQ(encode_loop_, MessageLoop::current()); + DCHECK(encode_task_runner_->BelongsToCurrentThread()); if (encoder_stopped_) return; @@ -361,7 +361,7 @@ void ScreenRecorder::EncodedDataAvailableCallback( scheduler_.RecordEncodeTime(encode_time); } - network_loop_->PostTask( + network_task_runner_->PostTask( FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, base::Passed(packet.Pass()))); } diff --git a/remoting/host/screen_recorder.h b/remoting/host/screen_recorder.h index 462ade7..ca539f9 100644 --- a/remoting/host/screen_recorder.h +++ b/remoting/host/screen_recorder.h @@ -11,7 +11,6 @@ #include "base/callback.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" #include "base/time.h" #include "base/timer.h" #include "remoting/base/encoder.h" @@ -20,7 +19,7 @@ #include "remoting/proto/video.pb.h" namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } // namespace base namespace remoting { @@ -79,11 +78,12 @@ class ScreenRecorder : public base::RefCountedThreadSafe<ScreenRecorder> { // Construct a ScreenRecorder. Message loops and threads are provided. // This object does not own capturer but owns encoder. - ScreenRecorder(MessageLoop* capture_loop, - MessageLoop* encode_loop, - base::MessageLoopProxy* network_loop, - Capturer* capturer, - Encoder* encoder); + ScreenRecorder( + scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, + Capturer* capturer, + Encoder* encoder); // Start recording. void Start(); @@ -156,10 +156,10 @@ class ScreenRecorder : public base::RefCountedThreadSafe<ScreenRecorder> { void EncodedDataAvailableCallback(scoped_ptr<VideoPacket> packet); void SendVideoPacket(VideoPacket* packet); - // Message loops used by this class. - MessageLoop* capture_loop_; - MessageLoop* encode_loop_; - scoped_refptr<base::MessageLoopProxy> network_loop_; + // Task runners used by this class. + scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> encode_task_runner_; + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; // Reference to the capturer. This member is always accessed on the capture // thread. diff --git a/remoting/host/screen_recorder_unittest.cc b/remoting/host/screen_recorder_unittest.cc index b7d6b3b..a99adf3 100644 --- a/remoting/host/screen_recorder_unittest.cc +++ b/remoting/host/screen_recorder_unittest.cc @@ -86,9 +86,8 @@ class ScreenRecorderTest : public testing::Test { connection_->SetEventHandler(&handler_); record_ = new ScreenRecorder( - &message_loop_, &message_loop_, - base::MessageLoopProxy::current(), - &capturer_, encoder_); + message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(), + message_loop_.message_loop_proxy(), &capturer_, encoder_); } virtual void TearDown() OVERRIDE { diff --git a/remoting/host/session_event_executor_win.cc b/remoting/host/session_event_executor_win.cc index 8168ccc..1bda463 100644 --- a/remoting/host/session_event_executor_win.cc +++ b/remoting/host/session_event_executor_win.cc @@ -9,7 +9,7 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/compiler_specific.h" -#include "base/message_loop.h" +#include "base/single_thread_task_runner.h" #include "base/win/windows_version.h" #include "ipc/ipc_channel.h" #include "ipc/ipc_channel_proxy.h" @@ -29,7 +29,7 @@ const uint32 kUsbLeftAlt = 0x0700e2; const uint32 kUsbRightAlt = 0x0700e6; const uint32 kUsbDelete = 0x07004c; -bool areCtrlAndAltPressed(const std::set<uint32>& pressed_keys) { +bool CheckCtrlAndAltArePressed(const std::set<uint32>& pressed_keys) { size_t ctrl_keys = pressed_keys.count(kUsbLeftControl) + pressed_keys.count(kUsbRightControl); size_t alt_keys = pressed_keys.count(kUsbLeftAlt) + @@ -41,7 +41,7 @@ bool areCtrlAndAltPressed(const std::set<uint32>& pressed_keys) { // Emulates Secure Attention Sequence (Ctrl+Alt+Del) by switching to // the Winlogon desktop and injecting Ctrl+Alt+Del as a hot key. // N.B. Windows XP/W2K3 only. -void emulateSecureAttentionSequence() { +void EmulateSecureAttentionSequence() { const wchar_t kWinlogonDesktopName[] = L"Winlogon"; const wchar_t kSasWindowClassName[] = L"SAS window class"; const wchar_t kSasWindowTitle[] = L"SAS window"; @@ -74,16 +74,16 @@ using protocol::MouseEvent; using protocol::KeyEvent; SessionEventExecutorWin::SessionEventExecutorWin( - MessageLoop* message_loop, - base::MessageLoopProxy* io_message_loop, + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, scoped_ptr<EventExecutor> nested_executor) : nested_executor_(nested_executor.Pass()), - message_loop_(message_loop), + task_runner_(main_task_runner), ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { - // Let weak_ptr_ be used on the message_loop_ thread. - // weak_ptr_ and weak_ptr_factory_ share a ThreadChecker, so the following - // line affects both of them. + // Let |weak_ptr_| be used on the |task_runner_| thread. + // |weak_ptr_| and |weak_ptr_factory_| share a ThreadChecker, so the + // following line affects both of them. weak_ptr_factory_.DetachFromThread(); std::string channel_name = @@ -93,21 +93,18 @@ SessionEventExecutorWin::SessionEventExecutorWin( // line. if (!channel_name.empty()) { chromoting_channel_.reset(new IPC::ChannelProxy( - channel_name, - IPC::Channel::MODE_CLIENT, - this, - io_message_loop)); + channel_name, IPC::Channel::MODE_CLIENT, this, io_task_runner)); } } SessionEventExecutorWin::~SessionEventExecutorWin() { - DCHECK(MessageLoop::current() == message_loop_); + DCHECK(task_runner_->BelongsToCurrentThread()); } void SessionEventExecutorWin::OnSessionStarted( scoped_ptr<protocol::ClipboardStub> client_clipboard) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&SessionEventExecutorWin::OnSessionStarted, weak_ptr_, base::Passed(&client_clipboard))); @@ -118,8 +115,8 @@ void SessionEventExecutorWin::OnSessionStarted( } void SessionEventExecutorWin::OnSessionFinished() { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&SessionEventExecutorWin::OnSessionFinished, weak_ptr_)); @@ -131,8 +128,8 @@ void SessionEventExecutorWin::OnSessionFinished() { void SessionEventExecutorWin::InjectClipboardEvent( const ClipboardEvent& event) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&SessionEventExecutorWin::InjectClipboardEvent, weak_ptr_, event)); @@ -143,8 +140,8 @@ void SessionEventExecutorWin::InjectClipboardEvent( } void SessionEventExecutorWin::InjectKeyEvent(const KeyEvent& event) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&SessionEventExecutorWin::InjectKeyEvent, weak_ptr_, event)); @@ -158,11 +155,11 @@ void SessionEventExecutorWin::InjectKeyEvent(const KeyEvent& event) { if (event.pressed()) { // Simulate secure attention sequence if Ctrl-Alt-Del was just pressed. if (event.usb_keycode() == kUsbDelete && - areCtrlAndAltPressed(pressed_keys_)) { + CheckCtrlAndAltArePressed(pressed_keys_)) { VLOG(3) << "Sending Secure Attention Sequence to console"; if (base::win::GetVersion() == base::win::VERSION_XP) { - emulateSecureAttentionSequence(); + EmulateSecureAttentionSequence(); } else if (chromoting_channel_.get()) { chromoting_channel_->Send(new ChromotingHostMsg_SendSasToConsole()); } @@ -179,8 +176,8 @@ void SessionEventExecutorWin::InjectKeyEvent(const KeyEvent& event) { } void SessionEventExecutorWin::InjectMouseEvent(const MouseEvent& event) { - if (MessageLoop::current() != message_loop_) { - message_loop_->PostTask( + if (!task_runner_->BelongsToCurrentThread()) { + task_runner_->PostTask( FROM_HERE, base::Bind(&SessionEventExecutorWin::InjectMouseEvent, weak_ptr_, event)); diff --git a/remoting/host/session_event_executor_win.h b/remoting/host/session_event_executor_win.h index 0778b56..4ac364e 100644 --- a/remoting/host/session_event_executor_win.h +++ b/remoting/host/session_event_executor_win.h @@ -16,10 +16,8 @@ #include "remoting/host/scoped_thread_desktop_win.h" #include "remoting/protocol/host_event_stub.h" -class MessageLoop; - namespace base { -class MessageLoopProxy; +class SingleThreadTaskRunner; } // namespace base namespace IPC { @@ -31,9 +29,10 @@ namespace remoting { class SessionEventExecutorWin : public EventExecutor, public IPC::Listener { public: - SessionEventExecutorWin(MessageLoop* message_loop, - base::MessageLoopProxy* io_message_loop, - scoped_ptr<EventExecutor> nested_executor); + SessionEventExecutorWin( + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, + scoped_ptr<EventExecutor> nested_executor); ~SessionEventExecutorWin(); // EventExecutor implementation. @@ -58,7 +57,7 @@ class SessionEventExecutorWin : public EventExecutor, // Pointer to the next event executor. scoped_ptr<EventExecutor> nested_executor_; - MessageLoop* message_loop_; + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; ScopedThreadDesktopWin desktop_; diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index de87e38..e9935d1 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -153,7 +153,7 @@ class SimpleHost : public HeartbeatSender::Listener { xmpp_auth_service_ = kChromotingTokenDefaultServiceName; } - context_.network_message_loop()->PostTask(FROM_HERE, base::Bind( + context_.network_task_runner()->PostTask(FROM_HERE, base::Bind( &SimpleHost::StartHost, base::Unretained(this))); message_loop_.MessageLoop::Run(); @@ -226,8 +226,8 @@ class SimpleHost : public HeartbeatSender::Listener { if (fake_) { scoped_ptr<Capturer> capturer(new CapturerFake()); scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( - context_.desktop_message_loop()->message_loop_proxy(), - context_.ui_message_loop(), capturer.get()); + context_.desktop_task_runner(), + context_.ui_task_runner(), capturer.get()); desktop_environment_ = DesktopEnvironment::CreateFake( &context_, capturer.Pass(), event_executor.Pass()); } else { @@ -280,7 +280,7 @@ class SimpleHost : public HeartbeatSender::Listener { } void Shutdown(int exit_code) { - DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_.network_task_runner()->BelongsToCurrentThread()); if (shutting_down_) return; @@ -292,7 +292,7 @@ class SimpleHost : public HeartbeatSender::Listener { } void OnShutdownFinished() { - DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); + DCHECK(context_.network_task_runner()->BelongsToCurrentThread()); // Destroy networking objects while we are on the network thread. host_ = NULL; diff --git a/remoting/host/url_fetcher_unittest.cc b/remoting/host/url_fetcher_unittest.cc new file mode 100644 index 0000000..3c1c3f2 --- /dev/null +++ b/remoting/host/url_fetcher_unittest.cc @@ -0,0 +1,96 @@ +// 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/url_fetcher.h" + +#include "base/message_loop.h" +#include "base/threading/thread.h" +#include "net/test/test_server.h" +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_status.h" +#include "remoting/host/url_request_context.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace remoting { + +class UrlFetcherTest : public testing::Test { + public: + UrlFetcherTest() + : test_server_( + net::TestServer::TYPE_HTTPS, + net::TestServer::kLocalhost, + FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))), + io_thread_("TestIOThread"), + file_thread_("TestFileThread") { + } + + protected: + void SetUp() OVERRIDE { + ASSERT_TRUE(io_thread_.StartWithOptions( + base::Thread::Options(MessageLoop::TYPE_IO, 0))); + ASSERT_TRUE(file_thread_.StartWithOptions( + base::Thread::Options(MessageLoop::TYPE_IO, 0))); + context_getter_ = new URLRequestContextGetter( + message_loop_.message_loop_proxy(), + io_thread_.message_loop_proxy(), + static_cast<MessageLoopForIO*>(file_thread_.message_loop())); + ASSERT_TRUE(test_server_.Start()); + } + + protected: + void OnDone(const net::URLRequestStatus& status, + int response_code, + const std::string& response) { + ASSERT_EQ(MessageLoop::current(), &message_loop_); + status_ = status; + response_code_ = response_code; + response_ = response; + message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); + } + + net::TestServer test_server_; + MessageLoopForUI message_loop_; + base::Thread io_thread_; + base::Thread file_thread_; + scoped_refptr<URLRequestContextGetter> context_getter_; + net::URLRequestStatus status_; + std::string response_; + int response_code_; +}; + +TEST_F(UrlFetcherTest, TestGet) { + UrlFetcher fetcher(test_server_.GetURL("default"), UrlFetcher::GET); + fetcher.SetRequestContext(context_getter_); + fetcher.Start(base::Bind(&UrlFetcherTest_TestGet_Test::OnDone, + base::Unretained(this))); + message_loop_.Run(); + EXPECT_EQ(net::URLRequestStatus::SUCCESS, status_.status()); + EXPECT_EQ("Default response given for path: /default", response_); + EXPECT_EQ(200, response_code_); +} + +TEST_F(UrlFetcherTest, TestPost) { + const char kTestQueryData[] = "123qwe123qwe"; + UrlFetcher fetcher(test_server_.GetURL("echo"), UrlFetcher::POST); + fetcher.SetRequestContext(context_getter_); + fetcher.SetUploadData("text/html", kTestQueryData); + fetcher.Start(base::Bind(&UrlFetcherTest_TestPost_Test::OnDone, + base::Unretained(this))); + message_loop_.Run(); + EXPECT_EQ(net::URLRequestStatus::SUCCESS, status_.status()); + EXPECT_EQ(kTestQueryData, response_); + EXPECT_EQ(200, response_code_); +} + +TEST_F(UrlFetcherTest, TestFailed) { + UrlFetcher fetcher(test_server_.GetURL("auth-basic"), UrlFetcher::GET); + fetcher.SetRequestContext(context_getter_); + fetcher.Start(base::Bind(&UrlFetcherTest_TestFailed_Test::OnDone, + base::Unretained(this))); + message_loop_.Run(); + EXPECT_EQ(net::URLRequestStatus::SUCCESS, status_.status()); + EXPECT_EQ(401, response_code_); +} + +} // namespace remoting diff --git a/remoting/host/url_request_context.cc b/remoting/host/url_request_context.cc index 3781b39..c49b3e8 100644 --- a/remoting/host/url_request_context.cc +++ b/remoting/host/url_request_context.cc @@ -42,10 +42,10 @@ class ProxyConfigServiceDirect : public net::ProxyConfigService { }; net::ProxyConfigService* CreateSystemProxyConfigService( - base::MessageLoopProxy* ui_message_loop_, + base::SingleThreadTaskRunner* ui_task_runner, base::SingleThreadTaskRunner* io_thread_task_runner, MessageLoopForIO* file_message_loop) { - DCHECK(ui_message_loop_->BelongsToCurrentThread()); + DCHECK(ui_task_runner->BelongsToCurrentThread()); #if defined(OS_WIN) return new net::ProxyConfigServiceWin(); @@ -113,12 +113,12 @@ URLRequestContext::~URLRequestContext() { } URLRequestContextGetter::URLRequestContextGetter( - base::MessageLoopProxy* ui_message_loop, - MessageLoop* io_message_loop, + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, MessageLoopForIO* file_message_loop) - : network_task_runner_(io_message_loop->message_loop_proxy()) { + : network_task_runner_(network_task_runner) { proxy_config_service_.reset(CreateSystemProxyConfigService( - ui_message_loop, network_task_runner_, file_message_loop)); + ui_task_runner, network_task_runner_, file_message_loop)); } net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { @@ -134,6 +134,7 @@ URLRequestContextGetter::GetNetworkTaskRunner() const { return network_task_runner_; } -URLRequestContextGetter::~URLRequestContextGetter() {} +URLRequestContextGetter::~URLRequestContextGetter() { +} } // namespace remoting diff --git a/remoting/host/url_request_context.h b/remoting/host/url_request_context.h index 71766b7..23d55a4 100644 --- a/remoting/host/url_request_context.h +++ b/remoting/host/url_request_context.h @@ -39,9 +39,10 @@ class URLRequestContext : public net::URLRequestContext { class URLRequestContextGetter : public net::URLRequestContextGetter { public: - URLRequestContextGetter(base::MessageLoopProxy* ui_message_loop, - MessageLoop* io_message_loop, - MessageLoopForIO* file_message_loop); + URLRequestContextGetter( + scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, + scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, + MessageLoopForIO* file_message_loop); // Overridden from net::URLRequestContextGetter: virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |