Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Unified Diff: base/threading/thread.cc

Issue 11048029: Allow Thread to initialize COM for Windows consumers who need it (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/threading/thread.cc
===================================================================
--- base/threading/thread.cc (revision 162015)
+++ 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 {
@@ -60,11 +64,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 +103,7 @@
}
void Thread::Stop() {
- if (!thread_was_started())
+ if (!started_)
return;
StopSoon();
@@ -157,6 +170,14 @@
message_loop.set_thread_name(name_);
message_loop_ = &message_loop;
+#if defined(OS_WIN)
+ 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 +193,10 @@
// Let the thread do extra cleanup.
CleanUp();
+#if defined(OS_WIN)
+ com_initializer_.reset();
Ami GONE FROM CHROMIUM 2012/10/16 02:52:03 observation: this variable is only used in this fu
+#endif
+
// Assert that MessageLoop::Quit was called by ThreadQuitHelper.
DCHECK(GetThreadWasQuitProperly());

Powered by Google App Engine
This is Rietveld 408576698