Commit 8f9efe1f authored by robliao's avatar robliao Committed by Commit Bot

Disable COM Initialization on SchedulerWorkers When COM_INIT_CHECK_HOOK_ENABLED()

This change will allow for the detection of tasks running in
TaskScheduler that fail to post their task in a COM STA Task Runner
instead.

BUG=706512
TBR=gab@chromium.org
Previously Reviewed at https://chromium-review.googlesource.com/c/549223/

Review-Url: https://codereview.chromium.org/2978253002
Cr-Original-Commit-Position: refs/heads/master@{#487625}
Committed: https://chromium.googlesource.com/chromium/src/+/122a24f59d90a1b225e00b3ab6c9fd37fd365b8f
Review-Url: https://codereview.chromium.org/2978253002
Cr-Commit-Position: refs/heads/master@{#488327}
parent 025b91e3
......@@ -15,6 +15,7 @@
#if defined(OS_MACOSX)
#include "base/mac/scoped_nsautorelease_pool.h"
#elif defined(OS_WIN)
#include "base/win/com_init_check_hook.h"
#include "base/win/scoped_com_initializer.h"
#endif
......@@ -43,7 +44,10 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate {
// A SchedulerWorker starts out waiting for work.
outer_->delegate_->WaitForWork(&wake_up_event_);
#if defined(OS_WIN)
// When defined(COM_INIT_CHECK_HOOK_ENABLED), ignore
// SchedulerBackwardCompatibility::INIT_COM_STA to find incorrect uses of
// COM that should be running in a COM STA Task Runner.
#if defined(OS_WIN) && !defined(COM_INIT_CHECK_HOOK_ENABLED)
std::unique_ptr<win::ScopedCOMInitializer> com_initializer;
if (outer_->backward_compatibility_ ==
SchedulerBackwardCompatibility::INIT_COM_STA) {
......@@ -210,7 +214,7 @@ SchedulerWorker::SchedulerWorker(
priority_hint_(priority_hint),
delegate_(std::move(delegate)),
task_tracker_(task_tracker),
#if defined(OS_WIN)
#if defined(OS_WIN) && !defined(COM_INIT_CHECK_HOOK_ENABLED)
backward_compatibility_(backward_compatibility),
#endif
initial_state_(initial_state) {
......
......@@ -19,6 +19,10 @@
#include "base/time/time.h"
#include "build/build_config.h"
#if defined(OS_WIN)
#include "base/win/com_init_check_hook.h"
#endif
namespace base {
namespace internal {
......@@ -195,7 +199,7 @@ class BASE_EXPORT SchedulerWorker
const std::unique_ptr<Delegate> delegate_;
TaskTracker* const task_tracker_;
#if defined(OS_WIN)
#if defined(OS_WIN) && !defined(COM_INIT_CHECK_HOOK_ENABLED)
const SchedulerBackwardCompatibility backward_compatibility_;
#endif
......
......@@ -30,6 +30,8 @@
#if defined(OS_WIN)
#include <objbase.h>
#include "base/win/com_init_check_hook.h"
#endif
using testing::_;
......@@ -931,7 +933,13 @@ TEST(TaskSchedulerWorkerTest, BackwardCompatibilityEnabled) {
// The call to CoInitializeEx() should have returned S_FALSE to indicate that
// the COM library was already initialized on the thread.
// See SchedulerWorker::Thread::ThreadMain for why we expect two different
// results here.
#if defined(COM_INIT_CHECK_HOOK_ENABLED)
EXPECT_EQ(S_OK, delegate_raw->coinitialize_hresult());
#else
EXPECT_EQ(S_FALSE, delegate_raw->coinitialize_hresult());
#endif
worker->JoinForTesting();
}
......
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