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

Unified Diff: base/threading/com_thread.h

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/com_thread.h
===================================================================
--- base/threading/com_thread.h (revision 0)
+++ base/threading/com_thread.h (working copy)
@@ -0,0 +1,48 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// ComThread is a Thread which, on Windows, initializes COM on the spawned
+// thread when it's created and shuts down COM just before the spawned thread is
+// destroyed. On non-Windows, ComThread is identical to Thread. This allows
+// consumers to use ComThread in cross-platform code without having to do any
+// conditional #includes or typedefs of their own.
+
+#ifndef BASE_THREADING_COM_THREAD_H_
+#define BASE_THREADING_COM_THREAD_H_
+
+#include "base/threading/thread.h"
+
+#if defined(OS_WIN)
+#include "base/memory/scoped_ptr.h"
+#include "base/win/scoped_com_initializer.h"
+#endif
+
+namespace base {
+
+class BASE_EXPORT ComThread : public Thread {
+ public:
+#if defined(OS_WIN)
+ ComThread(const char* name, bool use_mta);
+ virtual ~ComThread();
+
+ bool Start();
+
+ protected:
+ virtual void Init() OVERRIDE; // Creates com_initializer_.
+ virtual void CleanUp() OVERRIDE; // Destroys com_initializer_.
+
+ private:
+ bool use_mta_;
+ scoped_ptr<win::ScopedCOMInitializer> com_initializer_;
+#else
+ ComThread(const char* name, bool use_mta) : Thread(name) {}
+ virtual ~ComThread() {}
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(ComThread);
+};
+
+} // namespace base
+
+#endif // BASE_THREADING_COM_THREAD_H_
Property changes on: base/threading/com_thread.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property

Powered by Google App Engine
This is Rietveld 408576698