| 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/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/test/test_pending_task.h" | 14 #include "base/test/test_pending_task_info.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 | 18 |
| 19 class TimeDelta; | 19 class TimeDelta; |
| 20 | 20 |
| 21 // TestSimpleTaskRunner is a simple TaskRunner implementation that can | 21 // TestSimpleTaskRunner is a simple TaskRunner implementation that can |
| 22 // be used for testing. It implements SingleThreadTaskRunner as that | 22 // be used for testing. It implements SingleThreadTaskRunner as that |
| 23 // interface implements SequencedTaskRunner, which in turn implements | 23 // interface implements SequencedTaskRunner, which in turn implements |
| 24 // TaskRunner, so TestSimpleTaskRunner can be passed in to a function | 24 // TaskRunner, so TestSimpleTaskRunner can be passed in to a function |
| (...skipping 19 matching lines...) Expand all Loading... |
| 44 // SingleThreadTaskRunner implementation. | 44 // SingleThreadTaskRunner implementation. |
| 45 bool PostDelayedTask(const tracked_objects::Location& from_here, | 45 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 46 const Closure& task, | 46 const Closure& task, |
| 47 TimeDelta delay) override; | 47 TimeDelta delay) override; |
| 48 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 48 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 49 const Closure& task, | 49 const Closure& task, |
| 50 TimeDelta delay) override; | 50 TimeDelta delay) override; |
| 51 | 51 |
| 52 bool RunsTasksOnCurrentThread() const override; | 52 bool RunsTasksOnCurrentThread() const override; |
| 53 | 53 |
| 54 std::deque<TestPendingTask> TakePendingTasks(); | 54 TestPendingTaskQueue TakePendingTasks(); |
| 55 size_t NumPendingTasks() const; | 55 size_t NumPendingTasks() const; |
| 56 bool HasPendingTask() const; | 56 bool HasPendingTask() const; |
| 57 base::TimeDelta NextPendingTaskDelay() const; | 57 base::TimeDelta NextPendingTaskDelay() const; |
| 58 base::TimeDelta FinalPendingTaskDelay() const; | 58 base::TimeDelta FinalPendingTaskDelay() const; |
| 59 | 59 |
| 60 // Clears the queue of pending tasks without running them. | 60 // Clears the queue of pending tasks without running them. |
| 61 void ClearPendingTasks(); | 61 void ClearPendingTasks(); |
| 62 | 62 |
| 63 // Runs each current pending task in order and clears the queue. Tasks posted | 63 // Runs each current pending task in order and clears the queue. Tasks posted |
| 64 // by the tasks that run within this call do not run within this call. Can | 64 // by the tasks that run within this call do not run within this call. Can |
| 65 // only be called on the thread that created this TestSimpleTaskRunner. | 65 // only be called on the thread that created this TestSimpleTaskRunner. |
| 66 void RunPendingTasks(); | 66 void RunPendingTasks(); |
| 67 | 67 |
| 68 // Runs pending tasks until the queue is empty. Can only be called on the | 68 // Runs pending tasks until the queue is empty. Can only be called on the |
| 69 // thread that created this TestSimpleTaskRunner. | 69 // thread that created this TestSimpleTaskRunner. |
| 70 void RunUntilIdle(); | 70 void RunUntilIdle(); |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 ~TestSimpleTaskRunner() override; | 73 ~TestSimpleTaskRunner() override; |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 // Thread on which this was instantiated. | 76 // Thread on which this was instantiated. |
| 77 const PlatformThreadRef thread_ref_ = PlatformThread::CurrentRef(); | 77 const PlatformThreadRef thread_ref_ = PlatformThread::CurrentRef(); |
| 78 | 78 |
| 79 // Synchronizes access to |pending_tasks_|. | 79 // Synchronizes access to |pending_tasks_|. |
| 80 mutable Lock lock_; | 80 mutable Lock lock_; |
| 81 | 81 |
| 82 std::deque<TestPendingTask> pending_tasks_; | 82 TestPendingTaskQueue pending_tasks_; |
| 83 | 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(TestSimpleTaskRunner); | 84 DISALLOW_COPY_AND_ASSIGN(TestSimpleTaskRunner); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 } // namespace base | 87 } // namespace base |
| 88 | 88 |
| 89 #endif // BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ | 89 #endif // BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ |
| OLD | NEW |