Index: base/threading/thread.cc |
=================================================================== |
--- base/threading/thread.cc (revision 163371) |
+++ base/threading/thread.cc (working copy) |
@@ -11,6 +11,10 @@ |
#include "base/threading/thread_restrictions.h" |
#include "base/synchronization/waitable_event.h" |
+#if defined(OS_WIN) |
+#include "base/win/scoped_com_initializer.h" |
+#endif |
+ |
namespace base { |
namespace { |
@@ -45,7 +49,11 @@ |
}; |
Thread::Thread(const char* name) |
- : started_(false), |
+ : |
+#if defined(OS_WIN) |
+ com_status_(NONE), |
+#endif |
+ started_(false), |
stopping_(false), |
running_(false), |
startup_data_(NULL), |
@@ -60,11 +68,20 @@ |
} |
bool Thread::Start() { |
- return StartWithOptions(Options()); |
+ Options options; |
+#if defined(OS_WIN) |
+ if (com_status_ == STA) |
+ options.message_loop_type = MessageLoop::TYPE_UI; |
+#endif |
+ return StartWithOptions(options); |
} |
bool Thread::StartWithOptions(const Options& options) { |
DCHECK(!message_loop_); |
+#if defined(OS_WIN) |
+ DCHECK((com_status_ != STA) || |
+ (options.message_loop_type == MessageLoop::TYPE_UI)); |
+#endif |
SetThreadWasQuitProperly(false); |
@@ -90,7 +107,7 @@ |
} |
void Thread::Stop() { |
- if (!thread_was_started()) |
+ if (!started_) |
return; |
StopSoon(); |
@@ -157,6 +174,15 @@ |
message_loop.set_thread_name(name_); |
message_loop_ = &message_loop; |
+#if defined(OS_WIN) |
+ scoped_ptr<win::ScopedCOMInitializer> com_initializer; |
+ if (com_status_ != NONE) { |
+ com_initializer.reset((com_status_ == STA) ? |
+ new win::ScopedCOMInitializer() : |
+ new win::ScopedCOMInitializer(win::ScopedCOMInitializer::kMTA)); |
+ } |
+#endif |
+ |
// Let the thread do extra initialization. |
// Let's do this before signaling we are started. |
Init(); |
@@ -172,6 +198,10 @@ |
// Let the thread do extra cleanup. |
CleanUp(); |
+#if defined(OS_WIN) |
+ com_initializer.reset(); |
+#endif |
+ |
// Assert that MessageLoop::Quit was called by ThreadQuitHelper. |
DCHECK(GetThreadWasQuitProperly()); |