OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ | 5 #ifndef CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ |
6 #define CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ | 6 #define CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // This runs pending tasks based on task's post_time + delay. | 46 // This runs pending tasks based on task's post_time + delay. |
47 // We should not execute a delayed task sooner than some of the queued tasks | 47 // We should not execute a delayed task sooner than some of the queued tasks |
48 // which don't have a delay even though it is queued early. | 48 // which don't have a delay even though it is queued early. |
49 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { | 49 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { |
50 public: | 50 public: |
51 OrderedSimpleTaskRunner(); | 51 OrderedSimpleTaskRunner(); |
52 OrderedSimpleTaskRunner(scoped_refptr<TestNowSource> now_src, | 52 OrderedSimpleTaskRunner(scoped_refptr<TestNowSource> now_src, |
53 bool advance_now); | 53 bool advance_now); |
54 | 54 |
55 // base::TestSimpleTaskRunner implementation: | 55 // base::TestSimpleTaskRunner implementation: |
56 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 56 bool PostDelayedTask(const tracked_objects::Location& from_here, |
57 const base::Closure& task, | 57 const base::Closure& task, |
58 base::TimeDelta delay) override; | 58 base::TimeDelta delay) override; |
59 virtual bool PostNonNestableDelayedTask( | 59 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
60 const tracked_objects::Location& from_here, | 60 const base::Closure& task, |
61 const base::Closure& task, | 61 base::TimeDelta delay) override; |
62 base::TimeDelta delay) override; | |
63 | 62 |
64 virtual bool RunsTasksOnCurrentThread() const override; | 63 bool RunsTasksOnCurrentThread() const override; |
65 | 64 |
66 // Set a maximum number of tasks to run at once. Useful as a timeout to | 65 // Set a maximum number of tasks to run at once. Useful as a timeout to |
67 // prevent infinite task loops. | 66 // prevent infinite task loops. |
68 static const size_t kAbsoluteMaxTasks; | 67 static const size_t kAbsoluteMaxTasks; |
69 void SetRunTaskLimit(size_t max_tasks) { max_tasks_ = max_tasks; } | 68 void SetRunTaskLimit(size_t max_tasks) { max_tasks_ = max_tasks; } |
70 void ClearRunTaskLimit() { max_tasks_ = kAbsoluteMaxTasks; } | 69 void ClearRunTaskLimit() { max_tasks_ = kAbsoluteMaxTasks; } |
71 | 70 |
72 // Allow task runner to advance now when running tasks. | 71 // Allow task runner to advance now when running tasks. |
73 void SetAutoAdvanceNowToPendingTasks(bool advance_now) { | 72 void SetAutoAdvanceNowToPendingTasks(bool advance_now) { |
74 advance_now_ = advance_now; | 73 advance_now_ = advance_now; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // Advance Now() to the next task to run. | 125 // Advance Now() to the next task to run. |
127 base::Callback<bool(void)> AdvanceNow(); | 126 base::Callback<bool(void)> AdvanceNow(); |
128 | 127 |
129 protected: | 128 protected: |
130 static bool TaskRunCountBelowCallback(size_t max_tasks, size_t* task_run); | 129 static bool TaskRunCountBelowCallback(size_t max_tasks, size_t* task_run); |
131 bool TaskExistedInitiallyCallback( | 130 bool TaskExistedInitiallyCallback( |
132 const std::set<TestOrderablePendingTask>& existing_tasks); | 131 const std::set<TestOrderablePendingTask>& existing_tasks); |
133 bool NowBeforeCallback(base::TimeTicks stop_at); | 132 bool NowBeforeCallback(base::TimeTicks stop_at); |
134 bool AdvanceNowCallback(); | 133 bool AdvanceNowCallback(); |
135 | 134 |
136 virtual ~OrderedSimpleTaskRunner(); | 135 ~OrderedSimpleTaskRunner() override; |
137 | 136 |
138 base::ThreadChecker thread_checker_; | 137 base::ThreadChecker thread_checker_; |
139 | 138 |
140 bool advance_now_; | 139 bool advance_now_; |
141 scoped_refptr<TestNowSource> now_src_; | 140 scoped_refptr<TestNowSource> now_src_; |
142 | 141 |
143 size_t max_tasks_; | 142 size_t max_tasks_; |
144 | 143 |
145 bool inside_run_tasks_until_; | 144 bool inside_run_tasks_until_; |
146 std::set<TestOrderablePendingTask> pending_tasks_; | 145 std::set<TestOrderablePendingTask> pending_tasks_; |
147 | 146 |
148 private: | 147 private: |
149 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); | 148 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); |
150 }; | 149 }; |
151 | 150 |
152 } // namespace cc | 151 } // namespace cc |
153 | 152 |
154 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ | 153 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ |
OLD | NEW |