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

Side by Side Diff: components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.cc

Issue 1250613002: scheduler: Remove task observer shenanigans (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a failing test. Created 5 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
« no previous file with comments | « components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tes ts.h" 5 #include "components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tes ts.h"
6 6
7 namespace scheduler { 7 namespace scheduler {
8 8
9 // static 9 // static
10 scoped_refptr<LazySchedulerMessageLoopDelegateForTests> 10 scoped_refptr<LazySchedulerMessageLoopDelegateForTests>
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 base::MessageLoop* LazySchedulerMessageLoopDelegateForTests::EnsureMessageLoop() 28 base::MessageLoop* LazySchedulerMessageLoopDelegateForTests::EnsureMessageLoop()
29 const { 29 const {
30 if (message_loop_) 30 if (message_loop_)
31 return message_loop_; 31 return message_loop_;
32 DCHECK(RunsTasksOnCurrentThread()); 32 DCHECK(RunsTasksOnCurrentThread());
33 message_loop_ = base::MessageLoop::current(); 33 message_loop_ = base::MessageLoop::current();
34 DCHECK(message_loop_); 34 DCHECK(message_loop_);
35 original_task_runner_ = message_loop_->task_runner(); 35 original_task_runner_ = message_loop_->task_runner();
36 for (auto& observer : pending_observers_) {
37 message_loop_->AddTaskObserver(observer);
38 }
39 pending_observers_.clear();
40 if (pending_task_runner_) 36 if (pending_task_runner_)
41 message_loop_->SetTaskRunner(pending_task_runner_.Pass()); 37 message_loop_->SetTaskRunner(pending_task_runner_.Pass());
42 return message_loop_; 38 return message_loop_;
43 } 39 }
44 40
45 void LazySchedulerMessageLoopDelegateForTests::SetDefaultTaskRunner( 41 void LazySchedulerMessageLoopDelegateForTests::SetDefaultTaskRunner(
46 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
47 if (!HasMessageLoop()) { 43 if (!HasMessageLoop()) {
48 pending_task_runner_ = task_runner.Pass(); 44 pending_task_runner_ = task_runner.Pass();
49 return; 45 return;
(...skipping 29 matching lines...) Expand all
79 75
80 bool LazySchedulerMessageLoopDelegateForTests::RunsTasksOnCurrentThread() 76 bool LazySchedulerMessageLoopDelegateForTests::RunsTasksOnCurrentThread()
81 const { 77 const {
82 return thread_id_ == base::PlatformThread::CurrentId(); 78 return thread_id_ == base::PlatformThread::CurrentId();
83 } 79 }
84 80
85 bool LazySchedulerMessageLoopDelegateForTests::IsNested() const { 81 bool LazySchedulerMessageLoopDelegateForTests::IsNested() const {
86 return EnsureMessageLoop()->IsNested(); 82 return EnsureMessageLoop()->IsNested();
87 } 83 }
88 84
89 void LazySchedulerMessageLoopDelegateForTests::AddTaskObserver(
90 base::MessageLoop::TaskObserver* task_observer) {
91 if (!HasMessageLoop()) {
92 pending_observers_.insert(task_observer);
93 return;
94 }
95 EnsureMessageLoop()->AddTaskObserver(task_observer);
96 }
97
98 void LazySchedulerMessageLoopDelegateForTests::RemoveTaskObserver(
99 base::MessageLoop::TaskObserver* task_observer) {
100 if (!HasMessageLoop()) {
101 pending_observers_.erase(task_observer);
102 return;
103 }
104 EnsureMessageLoop()->RemoveTaskObserver(task_observer);
105 }
106
107 } // namespace scheduler 85 } // namespace scheduler
OLDNEW
« no previous file with comments | « components/scheduler/test/lazy_scheduler_message_loop_delegate_for_tests.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698