| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 #ifndef BASE_WIN_SCOPED_COM_INITIALIZER_H_ | |
| 6 #define BASE_WIN_SCOPED_COM_INITIALIZER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "build/build_config.h" | |
| 11 | |
| 12 #if defined(OS_WIN) | |
| 13 | |
| 14 #include <objbase.h> | |
| 15 | |
| 16 namespace base { | |
| 17 namespace win { | |
| 18 | |
| 19 // Initializes COM in the constructor (STA), and uninitializes COM in the | |
| 20 // destructor. | |
| 21 class ScopedCOMInitializer { | |
| 22 public: | |
| 23 ScopedCOMInitializer() : hr_(CoInitialize(NULL)) { | |
| 24 } | |
| 25 | |
| 26 ScopedCOMInitializer::~ScopedCOMInitializer() { | |
| 27 if (SUCCEEDED(hr_)) | |
| 28 CoUninitialize(); | |
| 29 } | |
| 30 | |
| 31 private: | |
| 32 HRESULT hr_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer); | |
| 35 }; | |
| 36 | |
| 37 } // namespace win | |
| 38 } // namespace base | |
| 39 | |
| 40 #else | |
| 41 | |
| 42 namespace base { | |
| 43 namespace win { | |
| 44 | |
| 45 // Do-nothing class for other platforms. | |
| 46 class ScopedCOMInitializer { | |
| 47 public: | |
| 48 ScopedCOMInitializer() {} | |
| 49 ~ScopedCOMInitializer() {} | |
| 50 | |
| 51 private: | |
| 52 DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer); | |
| 53 }; | |
| 54 | |
| 55 } // namespace win | |
| 56 } // namespace base | |
| 57 | |
| 58 #endif | |
| 59 | |
| 60 #endif // BASE_WIN_SCOPED_COM_INITIALIZER_H_ | |
| OLD | NEW |