| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test_simple_task_runner.h" | 5 #include "base/test/test_simple_task_runner.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 10 | 12 |
| 11 namespace base { | 13 namespace base { |
| 12 | 14 |
| 13 TestSimpleTaskRunner::TestSimpleTaskRunner() = default; | 15 TestSimpleTaskRunner::TestSimpleTaskRunner() = default; |
| 14 | 16 |
| 15 TestSimpleTaskRunner::~TestSimpleTaskRunner() = default; | 17 TestSimpleTaskRunner::~TestSimpleTaskRunner() = default; |
| 16 | 18 |
| 17 bool TestSimpleTaskRunner::PostDelayedTask( | 19 bool TestSimpleTaskRunner::PostDelayedTask( |
| 18 const tracked_objects::Location& from_here, | 20 const tracked_objects::Location& from_here, |
| 19 const Closure& task, | 21 Closure task, |
| 20 TimeDelta delay) { | 22 TimeDelta delay) { |
| 21 AutoLock auto_lock(lock_); | 23 AutoLock auto_lock(lock_); |
| 22 pending_tasks_.push_back( | 24 pending_tasks_.push_back(TestPendingTask(from_here, std::move(task), |
| 23 TestPendingTask(from_here, task, TimeTicks(), delay, | 25 TimeTicks(), delay, |
| 24 TestPendingTask::NESTABLE)); | 26 TestPendingTask::NESTABLE)); |
| 25 return true; | 27 return true; |
| 26 } | 28 } |
| 27 | 29 |
| 28 bool TestSimpleTaskRunner::PostNonNestableDelayedTask( | 30 bool TestSimpleTaskRunner::PostNonNestableDelayedTask( |
| 29 const tracked_objects::Location& from_here, | 31 const tracked_objects::Location& from_here, |
| 30 const Closure& task, | 32 Closure task, |
| 31 TimeDelta delay) { | 33 TimeDelta delay) { |
| 32 AutoLock auto_lock(lock_); | 34 AutoLock auto_lock(lock_); |
| 33 pending_tasks_.push_back( | 35 pending_tasks_.push_back(TestPendingTask(from_here, std::move(task), |
| 34 TestPendingTask(from_here, task, TimeTicks(), delay, | 36 TimeTicks(), delay, |
| 35 TestPendingTask::NON_NESTABLE)); | 37 TestPendingTask::NON_NESTABLE)); |
| 36 return true; | 38 return true; |
| 37 } | 39 } |
| 38 | 40 |
| 39 // TODO(gab): Use SequenceToken here to differentiate between tasks running in | 41 // TODO(gab): Use SequenceToken here to differentiate between tasks running in |
| 40 // the scope of this TestSimpleTaskRunner and other task runners sharing this | 42 // the scope of this TestSimpleTaskRunner and other task runners sharing this |
| 41 // thread. http://crbug.com/631186 | 43 // thread. http://crbug.com/631186 |
| 42 bool TestSimpleTaskRunner::RunsTasksOnCurrentThread() const { | 44 bool TestSimpleTaskRunner::RunsTasksOnCurrentThread() const { |
| 43 return thread_ref_ == PlatformThread::CurrentRef(); | 45 return thread_ref_ == PlatformThread::CurrentRef(); |
| 44 } | 46 } |
| 45 | 47 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 std::move(task.task).Run(); | 97 std::move(task.task).Run(); |
| 96 } | 98 } |
| 97 | 99 |
| 98 void TestSimpleTaskRunner::RunUntilIdle() { | 100 void TestSimpleTaskRunner::RunUntilIdle() { |
| 99 while (!pending_tasks_.empty()) { | 101 while (!pending_tasks_.empty()) { |
| 100 RunPendingTasks(); | 102 RunPendingTasks(); |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 | 105 |
| 104 } // namespace base | 106 } // namespace base |
| OLD | NEW |