| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_WIN_SCOPED_COM_INITIALIZER_H_ | 5 #ifndef BASE_WIN_SCOPED_COM_INITIALIZER_H_ |
| 6 #define BASE_WIN_SCOPED_COM_INITIALIZER_H_ | 6 #define BASE_WIN_SCOPED_COM_INITIALIZER_H_ |
| 7 | 7 |
| 8 #include <objbase.h> | 8 #include <objbase.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 | 13 |
| 14 namespace base { | 14 namespace base { |
| 15 namespace win { | 15 namespace win { |
| 16 | 16 |
| 17 // Initializes COM in the constructor (STA or MTA), and uninitializes COM in the | 17 // Initializes COM in the constructor (STA or MTA), and uninitializes COM in the |
| 18 // destructor. | 18 // destructor. |
| 19 // |
| 20 // WARNING: This should only be used once per thread, ideally scoped to a |
| 21 // similar lifetime as the thread itself. You should not be using this in |
| 22 // random utility functions that make COM calls -- instead ensure these |
| 23 // functions are running on a COM-supporting thread! |
| 19 class ScopedCOMInitializer { | 24 class ScopedCOMInitializer { |
| 20 public: | 25 public: |
| 21 // Enum value provided to initialize the thread as an MTA instead of STA. | 26 // Enum value provided to initialize the thread as an MTA instead of STA. |
| 22 enum SelectMTA { kMTA }; | 27 enum SelectMTA { kMTA }; |
| 23 | 28 |
| 24 // Constructor for STA initialization. | 29 // Constructor for STA initialization. |
| 25 ScopedCOMInitializer() { | 30 ScopedCOMInitializer() { |
| 26 Initialize(COINIT_APARTMENTTHREADED); | 31 Initialize(COINIT_APARTMENTTHREADED); |
| 27 } | 32 } |
| 28 | 33 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 DWORD thread_id_; | 70 DWORD thread_id_; |
| 66 #endif | 71 #endif |
| 67 | 72 |
| 68 DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer); | 73 DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer); |
| 69 }; | 74 }; |
| 70 | 75 |
| 71 } // namespace win | 76 } // namespace win |
| 72 } // namespace base | 77 } // namespace base |
| 73 | 78 |
| 74 #endif // BASE_WIN_SCOPED_COM_INITIALIZER_H_ | 79 #endif // BASE_WIN_SCOPED_COM_INITIALIZER_H_ |
| OLD | NEW |