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

Unified Diff: base/test/scoped_task_scheduler.cc

Issue 2684273002: Allow ScopedTaskScheduler to be created before a class that overrides MessageLoop::current()'s task… (Closed)
Patch Set: Get rid of extra files in patch Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/test/scoped_task_scheduler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/scoped_task_scheduler.cc
diff --git a/base/test/scoped_task_scheduler.cc b/base/test/scoped_task_scheduler.cc
index 3482f06536ffc10fdb0f5e1977d80f8375046b3e..7bcd88adc0ab3c8eb95da13b6e17e982d5ebb3e5 100644
--- a/base/test/scoped_task_scheduler.cc
+++ b/base/test/scoped_task_scheduler.cc
@@ -77,10 +77,6 @@ class TestTaskScheduler : public TaskScheduler {
std::unique_ptr<MessageLoop> message_loop_owned_;
MessageLoop* message_loop_;
- // The SingleThreadTaskRunner associated with |message_loop_|.
- const scoped_refptr<SingleThreadTaskRunner> message_loop_task_runner_ =
- message_loop_->task_runner();
-
// Handles shutdown behaviors and sets up the environment to run a task.
internal::TaskTracker task_tracker_;
@@ -186,7 +182,7 @@ bool TestTaskScheduler::PostTask(std::unique_ptr<internal::Task> task,
if (!task_tracker_.WillPostTask(task.get()))
return false;
internal::Task* const task_ptr = task.get();
- return message_loop_task_runner_->PostDelayedTask(
+ return message_loop_->task_runner()->PostDelayedTask(
task_ptr->posted_from, Bind(&TestTaskScheduler::RunTask, Unretained(this),
Passed(&task), sequence_token),
task_ptr->delay);
@@ -196,6 +192,8 @@ void TestTaskScheduler::RunTask(std::unique_ptr<internal::Task> task,
const SequenceToken& sequence_token) {
// Clear the MessageLoop TaskRunner to allow TaskTracker to register its own
// Thread/SequencedTaskRunnerHandle as appropriate.
+ scoped_refptr<SingleThreadTaskRunner> saved_task_runner =
+ MessageLoop::current()->task_runner();
MessageLoop::current()->ClearTaskRunnerForTesting();
// Run the task.
@@ -204,11 +202,11 @@ void TestTaskScheduler::RunTask(std::unique_ptr<internal::Task> task,
: SequenceToken::Create());
// Restore the MessageLoop TaskRunner.
- MessageLoop::current()->SetTaskRunner(message_loop_task_runner_);
+ MessageLoop::current()->SetTaskRunner(saved_task_runner);
}
bool TestTaskScheduler::RunsTasksOnCurrentThread() const {
- return message_loop_task_runner_->RunsTasksOnCurrentThread();
+ return message_loop_->task_runner()->RunsTasksOnCurrentThread();
}
TestTaskSchedulerTaskRunner::TestTaskSchedulerTaskRunner(
« no previous file with comments | « no previous file | base/test/scoped_task_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698