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

Side by Side Diff: base/test/scoped_task_environment.cc

Issue 2885783002: Add ScopedTaskEnvironment::GetMainThreadTaskRunner(). (Closed)
Patch Set: self-review Created 3 years, 7 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 | « base/test/scoped_task_environment.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/test/scoped_task_environment.h" 5 #include "base/test/scoped_task_environment.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/task_scheduler/scheduler_worker_pool_params.h" 8 #include "base/task_scheduler/scheduler_worker_pool_params.h"
9 #include "base/task_scheduler/task_scheduler.h" 9 #include "base/task_scheduler/task_scheduler.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // replaced base::~MessageLoop() behaviour better. 59 // replaced base::~MessageLoop() behaviour better.
60 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_); 60 DCHECK_EQ(TaskScheduler::GetInstance(), task_scheduler_);
61 // Without FlushForTesting(), DeleteSoon() and ReleaseSoon() tasks could be 61 // Without FlushForTesting(), DeleteSoon() and ReleaseSoon() tasks could be
62 // skipped, resulting in memory leaks. 62 // skipped, resulting in memory leaks.
63 TaskScheduler::GetInstance()->FlushForTesting(); 63 TaskScheduler::GetInstance()->FlushForTesting();
64 TaskScheduler::GetInstance()->Shutdown(); 64 TaskScheduler::GetInstance()->Shutdown();
65 TaskScheduler::GetInstance()->JoinForTesting(); 65 TaskScheduler::GetInstance()->JoinForTesting();
66 TaskScheduler::SetInstance(nullptr); 66 TaskScheduler::SetInstance(nullptr);
67 } 67 }
68 68
69 scoped_refptr<base::SingleThreadTaskRunner>
70 ScopedTaskEnvironment::GetMainThreadTaskRunner() {
71 return message_loop_.task_runner();
72 }
73
69 void ScopedTaskEnvironment::RunUntilIdle() { 74 void ScopedTaskEnvironment::RunUntilIdle() {
70 for (;;) { 75 for (;;) {
71 TaskScheduler::GetInstance()->FlushForTesting(); 76 TaskScheduler::GetInstance()->FlushForTesting();
72 77
73 TaskObserver task_observer; 78 TaskObserver task_observer;
74 MessageLoop::current()->AddTaskObserver(&task_observer); 79 MessageLoop::current()->AddTaskObserver(&task_observer);
75 RunLoop().RunUntilIdle(); 80 RunLoop().RunUntilIdle();
76 MessageLoop::current()->RemoveTaskObserver(&task_observer); 81 MessageLoop::current()->RemoveTaskObserver(&task_observer);
77 82
78 if (!task_observer.ran_task()) 83 if (!task_observer.ran_task())
79 return; 84 return;
80 } 85 }
81 } 86 }
82 87
83 } // namespace test 88 } // namespace test
84 } // namespace base 89 } // namespace base
OLDNEW
« no previous file with comments | « base/test/scoped_task_environment.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698