Commit a2826543 authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Convert ScopedOleInitializer To Use THREAD_CHECKER

All thread checking code in Chromium should use the modern
THREAD_CHECKER API, which automatically gets removed when
!DCHECK_IS_ON().

BUG=

Change-Id: I70d3f12915445dc14be7f03c554c32c7fc12e2b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1612377Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Auto-Submit: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660549}
parent 969e8add
......@@ -4,25 +4,19 @@
#include "ui/base/win/scoped_ole_initializer.h"
#include <ole2.h>
#include "base/logging.h"
namespace ui {
ScopedOleInitializer::ScopedOleInitializer()
:
#ifndef NDEBUG
// Using the windows API directly to avoid dependency on platform_thread.
thread_id_(GetCurrentThreadId()),
#endif
hr_(OleInitialize(NULL)) {
ScopedOleInitializer::ScopedOleInitializer() : hr_(OleInitialize(NULL)) {
DCHECK_NE(OLE_E_WRONGCOMPOBJ, hr_) << "Incompatible DLLs on machine";
DCHECK_NE(RPC_E_CHANGED_MODE, hr_) << "Invalid COM thread model change";
}
ScopedOleInitializer::~ScopedOleInitializer() {
#ifndef NDEBUG
DCHECK_EQ(thread_id_, GetCurrentThreadId());
#endif
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
if (SUCCEEDED(hr_))
OleUninitialize();
}
......
......@@ -5,9 +5,9 @@
#ifndef UI_BASE_WIN_SCOPED_OLE_INITIALIZER_H_
#define UI_BASE_WIN_SCOPED_OLE_INITIALIZER_H_
#include <ole2.h>
#include "base/macros.h"
#include "base/threading/thread_checker.h"
#include "base/win/windows_types.h"
#include "ui/base/ui_base_export.h"
namespace ui {
......@@ -18,13 +18,7 @@ class UI_BASE_EXPORT ScopedOleInitializer {
~ScopedOleInitializer();
private:
#ifndef NDEBUG
// In debug builds we use this variable to catch a potential bug where a
// ScopedOleInitializer instance is deleted on a different thread than it
// was initially created on. If that ever happens it can have bad
// consequences and the cause can be tricky to track down.
DWORD thread_id_;
#endif
THREAD_CHECKER(thread_checker_);
HRESULT hr_;
DISALLOW_COPY_AND_ASSIGN(ScopedOleInitializer);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment