Index: remoting/base/auto_thread.cc |
diff --git a/remoting/base/auto_thread.cc b/remoting/base/auto_thread.cc |
index e10bf159d0271bbdd53cc9237cdfe59fa55b7dfa..b9b8f3006dfae5d075553bda444b80573d92caab 100644 |
--- a/remoting/base/auto_thread.cc |
+++ b/remoting/base/auto_thread.cc |
@@ -5,7 +5,9 @@ |
#include "remoting/base/auto_thread.h" |
#include "base/bind.h" |
+#include "base/callback.h" |
#include "base/lazy_instance.h" |
+#include "base/logging.h" |
#include "base/run_loop.h" |
#include "base/synchronization/waitable_event.h" |
#include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
@@ -99,6 +101,7 @@ AutoThread::AutoThread(const char* name) |
thread_(), |
name_(name), |
was_quit_properly_(false) { |
+ thread_checker_.DetachFromThread(); |
} |
AutoThread::AutoThread(const char* name, AutoThreadTaskRunner* joiner) |
@@ -110,6 +113,7 @@ AutoThread::AutoThread(const char* name, AutoThreadTaskRunner* joiner) |
name_(name), |
was_quit_properly_(false), |
joiner_(joiner) { |
+ thread_checker_.DetachFromThread(); |
} |
AutoThread::~AutoThread() { |
@@ -159,16 +163,10 @@ void AutoThread::SetComInitType(ComInitType com_init_type) { |
} |
#endif |
-void AutoThread::QuitThread( |
- scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
- if (!task_runner->BelongsToCurrentThread()) { |
- task_runner->PostTask(FROM_HERE, base::Bind(&AutoThread::QuitThread, |
- base::Unretained(this), |
- task_runner)); |
- return; |
- } |
+void AutoThread::QuitThread(const base::Closure& quit_when_idle_closure) { |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
- base::MessageLoop::current()->QuitWhenIdle(); |
+ quit_when_idle_closure.Run(); |
was_quit_properly_ = true; |
if (joiner_.get()) { |
@@ -183,8 +181,11 @@ void AutoThread::JoinAndDeleteThread() { |
} |
void AutoThread::ThreadMain() { |
- // The message loop for this thread. |
+ // Bind |thread_checker_| to the current thread. |
+ DCHECK(thread_checker_.CalledOnValidThread()); |
+ |
base::MessageLoop message_loop(startup_data_->loop_type); |
+ base::RunLoop run_loop; |
// Complete the initialization of our AutoThread object. |
base::PlatformThread::SetName(name_); |
@@ -192,11 +193,10 @@ void AutoThread::ThreadMain() { |
// Return an AutoThreadTaskRunner that will cleanly quit this thread when |
// no more references to it remain. |
- startup_data_->task_runner = |
- new AutoThreadTaskRunner(message_loop.task_runner(), |
- base::Bind(&AutoThread::QuitThread, |
- base::Unretained(this), |
- message_loop.task_runner())); |
+ startup_data_->task_runner = new AutoThreadTaskRunner( |
+ message_loop.task_runner(), |
+ base::Bind(&AutoThread::QuitThread, base::Unretained(this), |
+ run_loop.QuitWhenIdleClosure())); |
startup_data_->event.Signal(); |
// startup_data_ can't be touched anymore since the starting thread is now |
@@ -208,7 +208,7 @@ void AutoThread::ThreadMain() { |
CreateComInitializer(com_init_type_)); |
#endif |
- base::RunLoop().Run(); |
+ run_loop.Run(); |
// Assert that MessageLoop::QuitWhenIdle was called by AutoThread::QuitThread. |
DCHECK(was_quit_properly_); |