Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: base/task_scheduler/scheduler_worker.cc

Issue 2978253002: Disable COM Initialization on SchedulerWorkers When COM_INIT_CHECK_HOOK_ENABLED() (Closed)
Patch Set: Fixed Unused Private Field Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/task_scheduler/scheduler_worker.h" 5 #include "base/task_scheduler/scheduler_worker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/task_scheduler/task_tracker.h" 13 #include "base/task_scheduler/task_tracker.h"
14 14
15 #if defined(OS_MACOSX) 15 #if defined(OS_MACOSX)
16 #include "base/mac/scoped_nsautorelease_pool.h" 16 #include "base/mac/scoped_nsautorelease_pool.h"
17 #elif defined(OS_WIN) 17 #elif defined(OS_WIN)
18 #include "base/win/com_init_check_hook.h"
18 #include "base/win/scoped_com_initializer.h" 19 #include "base/win/scoped_com_initializer.h"
19 #endif 20 #endif
20 21
21 namespace base { 22 namespace base {
22 namespace internal { 23 namespace internal {
23 24
24 class SchedulerWorker::Thread : public PlatformThread::Delegate { 25 class SchedulerWorker::Thread : public PlatformThread::Delegate {
25 public: 26 public:
26 ~Thread() override = default; 27 ~Thread() override = default;
27 28
28 static std::unique_ptr<Thread> Create(scoped_refptr<SchedulerWorker> outer) { 29 static std::unique_ptr<Thread> Create(scoped_refptr<SchedulerWorker> outer) {
29 std::unique_ptr<Thread> thread(new Thread(std::move(outer))); 30 std::unique_ptr<Thread> thread(new Thread(std::move(outer)));
30 thread->Initialize(); 31 thread->Initialize();
31 if (thread->thread_handle_.is_null()) 32 if (thread->thread_handle_.is_null())
32 return nullptr; 33 return nullptr;
33 return thread; 34 return thread;
34 } 35 }
35 36
36 // PlatformThread::Delegate. 37 // PlatformThread::Delegate.
37 void ThreadMain() override { 38 void ThreadMain() override {
38 // Set if this thread was detached. 39 // Set if this thread was detached.
39 std::unique_ptr<Thread> detached_thread; 40 std::unique_ptr<Thread> detached_thread;
40 41
41 outer_->delegate_->OnMainEntry(outer_.get()); 42 outer_->delegate_->OnMainEntry(outer_.get());
42 43
43 // A SchedulerWorker starts out waiting for work. 44 // A SchedulerWorker starts out waiting for work.
44 outer_->delegate_->WaitForWork(&wake_up_event_); 45 outer_->delegate_->WaitForWork(&wake_up_event_);
45 46
46 #if defined(OS_WIN) 47 // When defined(COM_INIT_CHECK_HOOK_ENABLED), ignore
48 // SchedulerBackwardCompatibility::INIT_COM_STA to find incorrect uses of
49 // COM that should be running in a COM STA Task Runner.
50 #if defined(OS_WIN) && !defined(COM_INIT_CHECK_HOOK_ENABLED)
47 std::unique_ptr<win::ScopedCOMInitializer> com_initializer; 51 std::unique_ptr<win::ScopedCOMInitializer> com_initializer;
48 if (outer_->backward_compatibility_ == 52 if (outer_->backward_compatibility_ ==
49 SchedulerBackwardCompatibility::INIT_COM_STA) { 53 SchedulerBackwardCompatibility::INIT_COM_STA) {
50 com_initializer = MakeUnique<win::ScopedCOMInitializer>(); 54 com_initializer = MakeUnique<win::ScopedCOMInitializer>();
51 } 55 }
52 #endif 56 #endif
53 57
54 while (!outer_->ShouldExit()) { 58 while (!outer_->ShouldExit()) {
55 DCHECK(outer_); 59 DCHECK(outer_);
56 60
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 ThreadPriority priority_hint, 207 ThreadPriority priority_hint,
204 std::unique_ptr<Delegate> delegate, 208 std::unique_ptr<Delegate> delegate,
205 TaskTracker* task_tracker, 209 TaskTracker* task_tracker,
206 const SchedulerLock* predecessor_lock, 210 const SchedulerLock* predecessor_lock,
207 SchedulerBackwardCompatibility backward_compatibility, 211 SchedulerBackwardCompatibility backward_compatibility,
208 InitialState initial_state) 212 InitialState initial_state)
209 : thread_lock_(predecessor_lock), 213 : thread_lock_(predecessor_lock),
210 priority_hint_(priority_hint), 214 priority_hint_(priority_hint),
211 delegate_(std::move(delegate)), 215 delegate_(std::move(delegate)),
212 task_tracker_(task_tracker), 216 task_tracker_(task_tracker),
213 #if defined(OS_WIN) 217 #if defined(OS_WIN) && !defined(COM_INIT_CHECK_HOOK_ENABLED)
214 backward_compatibility_(backward_compatibility), 218 backward_compatibility_(backward_compatibility),
215 #endif 219 #endif
216 initial_state_(initial_state) { 220 initial_state_(initial_state) {
217 DCHECK(delegate_); 221 DCHECK(delegate_);
218 DCHECK(task_tracker_); 222 DCHECK(task_tracker_);
219 } 223 }
220 224
221 bool SchedulerWorker::Start() { 225 bool SchedulerWorker::Start() {
222 AutoSchedulerLock auto_lock(thread_lock_); 226 AutoSchedulerLock auto_lock(thread_lock_);
223 DCHECK(!started_); 227 DCHECK(!started_);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // The ordering of the checks is important below. This SchedulerWorker may be 332 // The ordering of the checks is important below. This SchedulerWorker may be
329 // released and outlive |task_tracker_| in unit tests. However, when the 333 // released and outlive |task_tracker_| in unit tests. However, when the
330 // SchedulerWorker is released, |should_exit_| will be set, so check that 334 // SchedulerWorker is released, |should_exit_| will be set, so check that
331 // first. 335 // first.
332 return should_exit_.IsSet() || join_called_for_testing_.IsSet() || 336 return should_exit_.IsSet() || join_called_for_testing_.IsSet() ||
333 task_tracker_->IsShutdownComplete(); 337 task_tracker_->IsShutdownComplete();
334 } 338 }
335 339
336 } // namespace internal 340 } // namespace internal
337 } // namespace base 341 } // namespace base
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker.h ('k') | base/task_scheduler/scheduler_worker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698