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

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
« no previous file with comments | « base/threading/thread.h ('k') | chrome_frame/buggy_bho_handling.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
« no previous file with comments | « base/threading/thread.h ('k') | chrome_frame/buggy_bho_handling.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698