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#include "ui/base/win/scoped_ole_initializer.h"
6
7#include "base/logging.h"
8
9namespace ui {
10
11ScopedOleInitializer::ScopedOleInitializer()
12    :
13#ifndef NDEBUG
14      // Using the windows API directly to avoid dependency on platform_thread.
15      thread_id_(GetCurrentThreadId()),
16#endif
17      hr_(OleInitialize(NULL)) {
18#ifndef NDEBUG
19  if (hr_ == S_FALSE) {
20    LOG(ERROR) << "Multiple OleInitialize() calls for thread " << thread_id_;
21  } else {
22    DCHECK_NE(OLE_E_WRONGCOMPOBJ, hr_) << "Incompatible DLLs on machine";
23    DCHECK_NE(RPC_E_CHANGED_MODE, hr_) << "Invalid COM thread model change";
24  }
25#endif
26}
27
28ScopedOleInitializer::~ScopedOleInitializer() {
29#ifndef NDEBUG
30  DCHECK_EQ(thread_id_, GetCurrentThreadId());
31#endif
32  if (SUCCEEDED(hr_))
33    OleUninitialize();
34}
35
36}  // namespace ui
37