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