OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // ComThread is a Thread which, on Windows, initializes COM on the spawned |
| 6 // thread when it's created and shuts down COM just before the spawned thread is |
| 7 // destroyed. On non-Windows, ComThread is identical to Thread. This allows |
| 8 // consumers to use ComThread in cross-platform code without having to do any |
| 9 // conditional #includes or typedefs of their own. |
| 10 |
| 11 #ifndef BASE_THREADING_COM_THREAD_H_ |
| 12 #define BASE_THREADING_COM_THREAD_H_ |
| 13 |
| 14 #include "base/threading/thread.h" |
| 15 |
| 16 #if defined(OS_WIN) |
| 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/win/scoped_com_initializer.h" |
| 19 #endif |
| 20 |
| 21 namespace base { |
| 22 |
| 23 class BASE_EXPORT ComThread : public Thread { |
| 24 public: |
| 25 #if defined(OS_WIN) |
| 26 ComThread(const char* name, bool use_mta); |
| 27 virtual ~ComThread(); |
| 28 |
| 29 bool Start(); |
| 30 |
| 31 protected: |
| 32 virtual void Init() OVERRIDE; // Creates com_initializer_. |
| 33 virtual void CleanUp() OVERRIDE; // Destroys com_initializer_. |
| 34 |
| 35 private: |
| 36 bool use_mta_; |
| 37 scoped_ptr<win::ScopedCOMInitializer> com_initializer_; |
| 38 #else |
| 39 ComThread(const char* name, bool use_mta) : Thread(name) {} |
| 40 virtual ~ComThread() {} |
| 41 #endif |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(ComThread); |
| 44 }; |
| 45 |
| 46 } // namespace base |
| 47 |
| 48 #endif // BASE_THREADING_COM_THREAD_H_ |
OLD | NEW |