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

Remove IUnknownImpl

All uses have been removed in favor of Microsoft::WRL::RuntimeClass.

Fixed:1014283
TBR=gab@chromium.org
Trivial //base/BUILD.gn change.

Change-Id: Id31e464c30d59958a7ac5524217ac9b685f4b077
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863110
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706566}
parent df409599
......@@ -1074,8 +1074,6 @@ jumbo_component("base") {
"win/i18n.h",
"win/iat_patch_function.cc",
"win/iat_patch_function.h",
"win/iunknown_impl.cc",
"win/iunknown_impl.h",
"win/map.h",
"win/message_window.cc",
"win/message_window.h",
......@@ -2831,7 +2829,6 @@ test("base_unittests") {
"win/hstring_compare_unittest.cc",
"win/hstring_reference_unittest.cc",
"win/i18n_unittest.cc",
"win/iunknown_impl_unittest.cc",
"win/map_unittest.cc",
"win/message_window_unittest.cc",
"win/object_watcher_unittest.cc",
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/win/iunknown_impl.h"
namespace base {
namespace win {
IUnknownImpl::IUnknownImpl()
: ref_count_(0) {
}
IUnknownImpl::~IUnknownImpl() {
}
ULONG STDMETHODCALLTYPE IUnknownImpl::AddRef() {
ref_count_.Increment();
return 1;
}
ULONG STDMETHODCALLTYPE IUnknownImpl::Release() {
if (!ref_count_.Decrement()) {
delete this;
return 0;
}
return 1;
}
STDMETHODIMP IUnknownImpl::QueryInterface(REFIID riid, void** ppv) {
if (riid == IID_IUnknown) {
*ppv = static_cast<IUnknown*>(this);
AddRef();
return S_OK;
}
*ppv = NULL;
return E_NOINTERFACE;
}
} // namespace win
} // namespace base
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_WIN_IUNKNOWN_IMPL_H_
#define BASE_WIN_IUNKNOWN_IMPL_H_
#include <unknwn.h>
#include "base/atomic_ref_count.h"
#include "base/base_export.h"
#include "base/compiler_specific.h"
namespace base {
namespace win {
// IUnknown implementation for other classes to derive from.
class BASE_EXPORT IUnknownImpl : public IUnknown {
public:
IUnknownImpl();
ULONG STDMETHODCALLTYPE AddRef() override;
ULONG STDMETHODCALLTYPE Release() override;
// Subclasses should extend this to return any interfaces they provide.
STDMETHODIMP QueryInterface(REFIID riid, void** ppv) override;
protected:
virtual ~IUnknownImpl();
private:
AtomicRefCount ref_count_;
};
} // namespace win
} // namespace base
#endif // BASE_WIN_IUNKNOWN_IMPL_H_
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/win/iunknown_impl.h"
#include "base/win/scoped_com_initializer.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace win {
class TestIUnknownImplSubclass : public IUnknownImpl {
public:
TestIUnknownImplSubclass() {
++instance_count;
}
~TestIUnknownImplSubclass() override { --instance_count; }
static int instance_count;
};
// static
int TestIUnknownImplSubclass::instance_count = 0;
TEST(IUnknownImplTest, IUnknownImpl) {
ScopedCOMInitializer com_initializer;
EXPECT_EQ(0, TestIUnknownImplSubclass::instance_count);
IUnknown* u = new TestIUnknownImplSubclass();
EXPECT_EQ(1, TestIUnknownImplSubclass::instance_count);
EXPECT_EQ(1u, u->AddRef());
EXPECT_EQ(1u, u->AddRef());
IUnknown* other = NULL;
EXPECT_EQ(E_NOINTERFACE, u->QueryInterface(
IID_IDispatch, reinterpret_cast<void**>(&other)));
EXPECT_EQ(S_OK, u->QueryInterface(
IID_IUnknown, reinterpret_cast<void**>(&other)));
other->Release();
EXPECT_EQ(1u, u->Release());
EXPECT_EQ(0u, u->Release());
EXPECT_EQ(0, TestIUnknownImplSubclass::instance_count);
}
} // namespace win
} // namespace base
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