| 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 #ifndef BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ | 5 #ifndef BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ |
| 6 #define BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ | 6 #define BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/optional.h" |
| 12 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "base/test/test_pending_task.h" | 15 #include "base/test/test_pending_task.h" |
| 15 #include "base/threading/platform_thread.h" | 16 #include "base/threading/platform_thread.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 | 19 |
| 19 class TimeDelta; | 20 class TimeDelta; |
| 20 | 21 |
| 21 // TestSimpleTaskRunner is a simple TaskRunner implementation that can | 22 // TestSimpleTaskRunner is a simple TaskRunner implementation that can |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 // SingleThreadTaskRunner implementation. | 45 // SingleThreadTaskRunner implementation. |
| 45 bool PostDelayedTask(const tracked_objects::Location& from_here, | 46 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 46 const Closure& task, | 47 const Closure& task, |
| 47 TimeDelta delay) override; | 48 TimeDelta delay) override; |
| 48 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 49 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 49 const Closure& task, | 50 const Closure& task, |
| 50 TimeDelta delay) override; | 51 TimeDelta delay) override; |
| 51 | 52 |
| 52 bool RunsTasksOnCurrentThread() const override; | 53 bool RunsTasksOnCurrentThread() const override; |
| 53 | 54 |
| 54 std::deque<TestPendingTask> GetPendingTasks() const; | 55 std::deque<TestPendingTask> TakePendingTasks(); |
| 55 size_t NumPendingTasks() const; | 56 size_t NumPendingTasks() const; |
| 56 bool HasPendingTask() const; | 57 bool HasPendingTask() const; |
| 57 base::TimeDelta NextPendingTaskDelay() const; | 58 base::TimeDelta NextPendingTaskDelay() const; |
| 59 base::TimeDelta FinalPendingTaskDelay() const; |
| 60 base::Optional<tracked_objects::Location> GetPendingTaskLocationAt( |
| 61 size_t index) const; |
| 58 | 62 |
| 59 // Clears the queue of pending tasks without running them. | 63 // Clears the queue of pending tasks without running them. |
| 60 void ClearPendingTasks(); | 64 void ClearPendingTasks(); |
| 61 | 65 |
| 62 // Runs each current pending task in order and clears the queue. Tasks posted | 66 // Runs each current pending task in order and clears the queue. Tasks posted |
| 63 // by the tasks that run within this call do not run within this call. Can | 67 // by the tasks that run within this call do not run within this call. Can |
| 64 // only be called on the thread that created this TestSimpleTaskRunner. | 68 // only be called on the thread that created this TestSimpleTaskRunner. |
| 65 void RunPendingTasks(); | 69 void RunPendingTasks(); |
| 66 | 70 |
| 67 // Runs pending tasks until the queue is empty. Can only be called on the | 71 // Runs pending tasks until the queue is empty. Can only be called on the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 79 mutable Lock lock_; | 83 mutable Lock lock_; |
| 80 | 84 |
| 81 std::deque<TestPendingTask> pending_tasks_; | 85 std::deque<TestPendingTask> pending_tasks_; |
| 82 | 86 |
| 83 DISALLOW_COPY_AND_ASSIGN(TestSimpleTaskRunner); | 87 DISALLOW_COPY_AND_ASSIGN(TestSimpleTaskRunner); |
| 84 }; | 88 }; |
| 85 | 89 |
| 86 } // namespace base | 90 } // namespace base |
| 87 | 91 |
| 88 #endif // BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ | 92 #endif // BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ |
| OLD | NEW |