Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/test/scoped_mock_time_message_loop_task_runner.h" | |
| 6 | |
| 7 #include <deque> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/message_loop/message_loop.h" | |
| 11 #include "base/run_loop.h" | |
| 12 #include "base/test/test_pending_task.h" | |
| 13 #include "base/threading/thread_task_runner_handle.h" | |
| 14 #include "base/time/time.h" | |
| 15 | |
| 16 namespace base { | |
| 17 | |
| 18 ScopedMockTimeMessageLoopTaskRunner::ScopedMockTimeMessageLoopTaskRunner() | |
| 19 : task_runner_(new TestMockTimeTaskRunner), | |
| 20 previous_task_runner_(ThreadTaskRunnerHandle::Get()) { | |
| 21 DCHECK(MessageLoop::current()); | |
| 22 RunLoop().RunUntilIdle(); | |
|
danakj
2016/11/18 21:27:21
Can you leave a comment explaining this?
bruthig
2016/11/18 22:53:28
Done.
| |
| 23 MessageLoop::current()->SetTaskRunner(task_runner_); | |
| 24 } | |
| 25 | |
| 26 ScopedMockTimeMessageLoopTaskRunner::~ScopedMockTimeMessageLoopTaskRunner() { | |
| 27 DCHECK(previous_task_runner_->RunsTasksOnCurrentThread()); | |
| 28 DCHECK_EQ(task_runner_, ThreadTaskRunnerHandle::Get()); | |
| 29 for (const auto& pending_task : task_runner_->TakePendingTasks()) { | |
| 30 previous_task_runner_->PostDelayedTask( | |
| 31 pending_task.location, pending_task.task, | |
| 32 pending_task.GetTimeToRun() - task_runner_->NowTicks()); | |
| 33 } | |
| 34 MessageLoop::current()->SetTaskRunner(std::move(previous_task_runner_)); | |
| 35 } | |
| 36 | |
| 37 } // namespace base | |
| OLD | NEW |