diff options
author | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-11 20:12:41 +0000 |
---|---|---|
committer | tommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-11 20:12:41 +0000 |
commit | b09e09085f7778d06d4b9ceef1e841d950f69eaa (patch) | |
tree | 230518b9ab79cfdc129a37914fd039b9f5fa6e0b | |
parent | c184895a01fc849c49513b4d32b314a57181360b (diff) | |
download | chromium_src-b09e09085f7778d06d4b9ceef1e841d950f69eaa.zip chromium_src-b09e09085f7778d06d4b9ceef1e841d950f69eaa.tar.gz chromium_src-b09e09085f7778d06d4b9ceef1e841d950f69eaa.tar.bz2 |
Adding minimal error checking to ScopedCOMInitializer.
Review URL: http://codereview.chromium.org/17348
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7860 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/common/win_util.cc | 9 | ||||
-rw-r--r-- | chrome/common/win_util.h | 16 |
2 files changed, 19 insertions, 6 deletions
diff --git a/chrome/common/win_util.cc b/chrome/common/win_util.cc index 1c552a2..6af0db8 100644 --- a/chrome/common/win_util.cc +++ b/chrome/common/win_util.cc @@ -82,6 +82,15 @@ UINT_PTR CALLBACK SaveAsDialogHook(HWND dialog, UINT message, } // namespace +ScopedCOMInitializer::ScopedCOMInitializer() : hr_(CoInitialize(NULL)) { + DCHECK(hr_ != RPC_E_CHANGED_MODE) << "thread already initialized as MTA"; +} + +ScopedCOMInitializer::~ScopedCOMInitializer() { + if (SUCCEEDED(hr_)) + CoUninitialize(); +} + std::wstring FormatSystemTime(const SYSTEMTIME& time, const std::wstring& format) { // If the format string is empty, just use the default format. diff --git a/chrome/common/win_util.h b/chrome/common/win_util.h index 5487ef3..02a8ace 100644 --- a/chrome/common/win_util.h +++ b/chrome/common/win_util.h @@ -57,18 +57,22 @@ class CoMemReleaser { DISALLOW_COPY_AND_ASSIGN(CoMemReleaser); }; -// Initializes COM in the constructor, and uninitializes COM in the +// Initializes COM in the constructor (STA), and uninitializes COM in the // destructor. class ScopedCOMInitializer { public: - ScopedCOMInitializer() { - CoInitialize(NULL); - } + ScopedCOMInitializer(); + ~ScopedCOMInitializer(); - ~ScopedCOMInitializer() { - CoUninitialize(); + // Returns the error code from CoInitialize(NULL) + // (called in constructor) + inline HRESULT error_code() const { + return hr_; } + protected: + HRESULT hr_; + private: DISALLOW_COPY_AND_ASSIGN(ScopedCOMInitializer); }; |