Refactor COM Checks to use AssertComApartmentType
BUG=
Change-Id: Ia6bba5f0f609e104ad641d45c44e909cfe60d8e5
Reviewed-on: https://chromium-review.googlesource.com/549007
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: Francois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#484779}
CrOS-Libchrome-Original-Commit: 8fbe0d4e7079dd5f485f4fc9d6f6049def20b8f2
diff --git a/base/task_scheduler/scheduler_single_thread_task_runner_manager_unittest.cc b/base/task_scheduler/scheduler_single_thread_task_runner_manager_unittest.cc
index f620683..00ac74c 100644
--- a/base/task_scheduler/scheduler_single_thread_task_runner_manager_unittest.cc
+++ b/base/task_scheduler/scheduler_single_thread_task_runner_manager_unittest.cc
@@ -23,8 +23,8 @@
#if defined(OS_WIN)
#include <windows.h>
-#include <objbase.h>
+#include "base/win/com_init_util.h"
#include "base/win/current_module.h"
#endif // defined(OS_WIN)
@@ -448,14 +448,8 @@
single_thread_task_runner_manager_->CreateCOMSTATaskRunnerWithTraits(
"A", {TaskShutdownBehavior::BLOCK_SHUTDOWN}, GetParam());
- com_task_runner->PostTask(
- FROM_HERE, BindOnce([]() {
- HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
- if (SUCCEEDED(hr)) {
- ADD_FAILURE() << "COM STA was not initialized on this thread";
- CoUninitialize();
- }
- }));
+ com_task_runner->PostTask(FROM_HERE, BindOnce(&win::AssertComApartmentType,
+ win::ComApartmentType::STA));
task_tracker_.Shutdown();
}
diff --git a/base/task_scheduler/task_scheduler_impl_unittest.cc b/base/task_scheduler/task_scheduler_impl_unittest.cc
index 9866422..b9b8d13 100644
--- a/base/task_scheduler/task_scheduler_impl_unittest.cc
+++ b/base/task_scheduler/task_scheduler_impl_unittest.cc
@@ -40,7 +40,7 @@
#endif // defined(OS_POSIX)
#if defined(OS_WIN)
-#include <objbase.h>
+#include "base/win/com_init_util.h"
#endif // defined(OS_WIN)
namespace base {
@@ -439,18 +439,12 @@
WaitableEvent task_ran(WaitableEvent::ResetPolicy::MANUAL,
WaitableEvent::InitialState::NOT_SIGNALED);
com_sta_task_runner->PostTask(
- FROM_HERE,
- Bind(
- [](scoped_refptr<TaskRunner> single_thread_task_runner,
- WaitableEvent* task_ran) {
- HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
- if (SUCCEEDED(hr)) {
- ADD_FAILURE() << "COM STA was not initialized on this thread";
- CoUninitialize();
- }
- task_ran->Signal();
- },
- com_sta_task_runner, Unretained(&task_ran)));
+ FROM_HERE, Bind(
+ [](WaitableEvent* task_ran) {
+ win::AssertComApartmentType(win::ComApartmentType::STA);
+ task_ran->Signal();
+ },
+ Unretained(&task_ran)));
task_ran.Wait();
}
#endif // defined(OS_WIN)