| 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/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/test/test_pending_task.h" | 13 #include "base/test/test_pending_task.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 | 17 |
| 18 class TimeDelta; |
| 19 |
| 18 // TestSimpleTaskRunner is a simple TaskRunner implementation that can | 20 // TestSimpleTaskRunner is a simple TaskRunner implementation that can |
| 19 // be used for testing. It implements SingleThreadTaskRunner as that | 21 // be used for testing. It implements SingleThreadTaskRunner as that |
| 20 // interface implements SequencedTaskRunner, which in turn implements | 22 // interface implements SequencedTaskRunner, which in turn implements |
| 21 // TaskRunner, so TestSimpleTaskRunner can be passed in to a function | 23 // TaskRunner, so TestSimpleTaskRunner can be passed in to a function |
| 22 // that accepts any *TaskRunner object. | 24 // that accepts any *TaskRunner object. |
| 23 // | 25 // |
| 24 // TestSimpleTaskRunner has the following properties which make it simple: | 26 // TestSimpleTaskRunner has the following properties which make it simple: |
| 25 // | 27 // |
| 26 // - It is non-thread safe; all member functions must be called on | 28 // - It is non-thread safe; all member functions must be called on |
| 27 // the same thread. | 29 // the same thread. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 49 const Closure& task, | 51 const Closure& task, |
| 50 TimeDelta delay) OVERRIDE; | 52 TimeDelta delay) OVERRIDE; |
| 51 virtual bool PostNonNestableDelayedTask( | 53 virtual bool PostNonNestableDelayedTask( |
| 52 const tracked_objects::Location& from_here, | 54 const tracked_objects::Location& from_here, |
| 53 const Closure& task, | 55 const Closure& task, |
| 54 TimeDelta delay) OVERRIDE; | 56 TimeDelta delay) OVERRIDE; |
| 55 | 57 |
| 56 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | 58 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
| 57 | 59 |
| 58 const std::deque<TestPendingTask>& GetPendingTasks() const; | 60 const std::deque<TestPendingTask>& GetPendingTasks() const; |
| 61 bool HasPendingTask() const; |
| 62 base::TimeDelta NextPendingTaskDelay() const; |
| 59 | 63 |
| 60 // Clears the queue of pending tasks without running them. | 64 // Clears the queue of pending tasks without running them. |
| 61 void ClearPendingTasks(); | 65 void ClearPendingTasks(); |
| 62 | 66 |
| 63 // Runs each current pending task in order and clears the queue. | 67 // Runs each current pending task in order and clears the queue. |
| 64 // Any tasks posted by the tasks are not run. | 68 // Any tasks posted by the tasks are not run. |
| 65 void RunPendingTasks(); | 69 void RunPendingTasks(); |
| 66 | 70 |
| 67 // Runs pending tasks until the queue is empty. | 71 // Runs pending tasks until the queue is empty. |
| 68 void RunUntilIdle(); | 72 void RunUntilIdle(); |
| 69 | 73 |
| 70 protected: | 74 protected: |
| 71 virtual ~TestSimpleTaskRunner(); | 75 virtual ~TestSimpleTaskRunner(); |
| 72 | 76 |
| 73 private: | 77 private: |
| 74 ThreadChecker thread_checker_; | 78 ThreadChecker thread_checker_; |
| 75 std::deque<TestPendingTask> pending_tasks_; | 79 std::deque<TestPendingTask> pending_tasks_; |
| 76 | 80 |
| 77 DISALLOW_COPY_AND_ASSIGN(TestSimpleTaskRunner); | 81 DISALLOW_COPY_AND_ASSIGN(TestSimpleTaskRunner); |
| 78 }; | 82 }; |
| 79 | 83 |
| 80 } // namespace base | 84 } // namespace base |
| 81 | 85 |
| 82 #endif // BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ | 86 #endif // BASE_TEST_TEST_SIMPLE_TASK_RUNNER_H_ |
| OLD | NEW |