Chromium Code Reviews| Index: remoting/host/win/host_service.cc |
| diff --git a/remoting/host/win/host_service.cc b/remoting/host/win/host_service.cc |
| index 87088fe39b70047694f6a0a14892e7343890e105..55a4fb3189c39eaed409b75ce52dcc59daca297b 100644 |
| --- a/remoting/host/win/host_service.cc |
| +++ b/remoting/host/win/host_service.cc |
| @@ -24,6 +24,8 @@ |
| #include "base/threading/thread.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/win/wrapped_window_proc.h" |
| +#include "remoting/base/auto_message_loop.h" |
| +#include "remoting/base/auto_thread.h" |
| #include "remoting/base/breakpad.h" |
| #include "remoting/base/scoped_sc_handle_win.h" |
| #include "remoting/base/stoppable.h" |
| @@ -120,7 +122,7 @@ void HostService::RemoveWtsConsoleObserver(WtsConsoleObserver* observer) { |
| void HostService::OnChildStopped() { |
| child_.reset(NULL); |
| - main_task_runner_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| + main_task_runner_ = NULL; |
| } |
| void HostService::OnSessionChange() { |
| @@ -196,21 +198,21 @@ int HostService::Run() { |
| return (this->*run_routine_)(); |
| } |
| -void HostService::RunMessageLoop(MessageLoop* message_loop) { |
| +bool HostService::BeforeMessageLoop() { |
| // Launch the I/O thread. |
| - base::Thread io_thread(kIoThreadName); |
| + scoped_refptr<AutoThread> io_thread( |
| + new AutoThread(kIoThreadName, main_task_runner_)); |
|
Wez
2012/08/24 21:30:49
Can you instead create a normal Thread in RunMessa
alexeypa (please no reviews)
2012/08/27 21:19:40
Done.
|
| base::Thread::Options io_thread_options(MessageLoop::TYPE_IO, 0); |
| - if (!io_thread.StartWithOptions(io_thread_options)) { |
| - LOG(ERROR) << "Failed to start the I/O thread"; |
| - stopped_event_.Signal(); |
| - return; |
| + if (!io_thread->StartWithOptions(io_thread_options)) { |
| + LOG(FATAL) << "Failed to start the I/O thread"; |
| + return false; |
| } |
| #if defined(REMOTING_MULTI_PROCESS) |
| child_ = DaemonProcess::Create( |
| main_task_runner_, |
| - io_thread.message_loop_proxy(), |
| + io_thread, |
| base::Bind(&HostService::OnChildStopped, |
| base::Unretained(this))).PassAs<Stoppable>(); |
| @@ -221,12 +223,18 @@ void HostService::RunMessageLoop(MessageLoop* message_loop) { |
| base::Bind(&HostService::OnChildStopped, base::Unretained(this)), |
| this, |
| main_task_runner_, |
| - io_thread.message_loop_proxy())); |
| + io_thread)); |
| #endif // !defined(REMOTING_MULTI_PROCESS) |
| + return true; |
| +} |
| + |
| +void HostService::RunMessageLoop(MessageLoop* message_loop) { |
| // Run the service. |
| - message_loop->Run(); |
| + if (BeforeMessageLoop()) { |
| + message_loop->Run(); |
| + } |
| // Release the control handler. |
| stopped_event_.Signal(); |
| @@ -279,8 +287,9 @@ int HostService::RunAsService() { |
| int HostService::RunInConsole() { |
| MessageLoop message_loop(MessageLoop::TYPE_UI); |
| - // Allow other threads to post to our message loop. |
| - main_task_runner_ = message_loop.message_loop_proxy(); |
| + // Keep a reference to the main message loop while it is used. Once the last |
| + // reference is dropped QuitClosure() will be posted to the loop. |
| + main_task_runner_ = new AutoMessageLoop(&message_loop); |
| int result = kErrorExitCode; |
| @@ -375,11 +384,12 @@ DWORD WINAPI HostService::ServiceControlHandler(DWORD control, |
| } |
| VOID WINAPI HostService::ServiceMain(DWORD argc, WCHAR* argv[]) { |
| - MessageLoop message_loop; |
| + MessageLoop message_loop(MessageLoop::TYPE_DEFAULT); |
| - // Allow other threads to post to our message loop. |
| + // Keep a reference to the main message loop while it is used. Once the last |
| + // reference is dropped QuitClosure() will be posted to the loop. |
| HostService* self = HostService::GetInstance(); |
| - self->main_task_runner_ = message_loop.message_loop_proxy(); |
| + self->main_task_runner_ = new AutoMessageLoop(&message_loop); |
| // Register the service control handler. |
| self->service_status_handle_ = |