| Index: remoting/base/auto_thread.cc
|
| diff --git a/remoting/base/auto_thread.cc b/remoting/base/auto_thread.cc
|
| index 324ccc36c4289ebe8cfa44f4329f0e3dae388d90..08d2c86765c994ff44d49daf0555d69156a006ec 100644
|
| --- a/remoting/base/auto_thread.cc
|
| +++ b/remoting/base/auto_thread.cc
|
| @@ -12,12 +12,48 @@
|
| #include "base/synchronization/waitable_event.h"
|
| #include "remoting/base/auto_thread_task_runner.h"
|
|
|
| +#if defined(OS_WIN)
|
| +#include "base/win/scoped_com_initializer.h"
|
| +#endif
|
| +
|
| namespace remoting {
|
|
|
| +namespace {
|
| +
|
| +MessageLoop::Type AutoThreadToMessageLoopType(AutoThread::Type type) {
|
| + switch (type) {
|
| + case AutoThread::TYPE_DEFAULT: return MessageLoop::TYPE_DEFAULT;
|
| + case AutoThread::TYPE_IO: return MessageLoop::TYPE_IO;
|
| + case AutoThread::TYPE_UI: return MessageLoop::TYPE_UI;
|
| +#if defined(OS_WIN)
|
| + case AutoThread::TYPE_UI_COM_STA: return MessageLoop::TYPE_UI;
|
| + case AutoThread::TYPE_UI_COM_MTA: return MessageLoop::TYPE_UI;
|
| +#endif
|
| + }
|
| + NOTREACHED();
|
| + return MessageLoop::TYPE_DEFAULT;
|
| +}
|
| +
|
| +#if defined(OS_WIN)
|
| +scoped_ptr<base::win::ScopedCOMInitializer> CreateComInitializerForType(
|
| + AutoThread::Type type) {
|
| + scoped_ptr<base::win::ScopedCOMInitializer> initializer;
|
| + if (type == AutoThread::TYPE_UI_COM_STA) {
|
| + initializer.reset(new base::win::ScopedCOMInitializer());
|
| + } else if (type == AutoThread::TYPE_UI_COM_MTA) {
|
| + initializer.reset(new base::win::ScopedCOMInitializer(
|
| + base::win::ScopedCOMInitializer::kMTA));
|
| + }
|
| + return initializer.Pass();
|
| +}
|
| +#endif
|
| +
|
| +}
|
| +
|
| // Used to pass data to ThreadMain. This structure is allocated on the stack
|
| // from within StartWithType.
|
| struct AutoThread::StartupData {
|
| - MessageLoop::Type loop_type;
|
| + Type loop_type;
|
|
|
| // Used to receive the AutoThreadTaskRunner for the thread.
|
| scoped_refptr<AutoThreadTaskRunner> task_runner;
|
| @@ -25,7 +61,7 @@ struct AutoThread::StartupData {
|
| // Used to synchronize thread startup.
|
| base::WaitableEvent event;
|
|
|
| - explicit StartupData(MessageLoop::Type type)
|
| + explicit StartupData(Type type)
|
| : loop_type(type),
|
| event(false, false) {}
|
| };
|
| @@ -34,7 +70,7 @@ struct AutoThread::StartupData {
|
| scoped_refptr<AutoThreadTaskRunner> AutoThread::CreateWithType(
|
| const char* name,
|
| scoped_refptr<AutoThreadTaskRunner> joiner,
|
| - MessageLoop::Type type) {
|
| + Type type) {
|
| AutoThread* thread = new AutoThread(name, joiner);
|
| scoped_refptr<AutoThreadTaskRunner> task_runner = thread->StartWithType(type);
|
| if (task_runner.get()) {
|
| @@ -48,7 +84,7 @@ scoped_refptr<AutoThreadTaskRunner> AutoThread::CreateWithType(
|
| // static
|
| scoped_refptr<AutoThreadTaskRunner> AutoThread::Create(
|
| const char* name, scoped_refptr<AutoThreadTaskRunner> joiner) {
|
| - return CreateWithType(name, joiner, MessageLoop::TYPE_DEFAULT);
|
| + return CreateWithType(name, joiner, TYPE_DEFAULT);
|
| }
|
|
|
| AutoThread::AutoThread(const char* name)
|
| @@ -76,7 +112,7 @@ AutoThread::~AutoThread() {
|
| }
|
|
|
| scoped_refptr<AutoThreadTaskRunner>
|
| -AutoThread::StartWithType(MessageLoop::Type type) {
|
| +AutoThread::StartWithType(Type type) {
|
| DCHECK(!thread_);
|
|
|
| StartupData startup_data(type);
|
| @@ -104,7 +140,7 @@ AutoThread::StartWithType(MessageLoop::Type type) {
|
| }
|
|
|
| scoped_refptr<AutoThreadTaskRunner> AutoThread::Start() {
|
| - return StartWithType(MessageLoop::TYPE_DEFAULT);
|
| + return StartWithType(TYPE_DEFAULT);
|
| }
|
|
|
| void AutoThread::QuitThread(
|
| @@ -131,7 +167,8 @@ void AutoThread::JoinAndDeleteThread() {
|
|
|
| void AutoThread::ThreadMain() {
|
| // The message loop for this thread.
|
| - MessageLoop message_loop(startup_data_->loop_type);
|
| + MessageLoop message_loop(
|
| + AutoThreadToMessageLoopType(startup_data_->loop_type));
|
|
|
| // Complete the initialization of our AutoThread object.
|
| base::PlatformThread::SetName(name_.c_str());
|
| @@ -150,6 +187,12 @@ void AutoThread::ThreadMain() {
|
| // startup_data_ can't be touched anymore since the starting thread is now
|
| // unlocked.
|
|
|
| +#if defined(OS_WIN)
|
| + // Initialize COM on the thread, if requested.
|
| + scoped_ptr<base::win::ScopedCOMInitializer> com_initializer(
|
| + CreateComInitializerForType(startup_data_->loop_type));
|
| +#endif
|
| +
|
| message_loop.Run();
|
|
|
| // Assert that MessageLoop::Quit was called by AutoThread::QuitThread.
|
|
|