| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // Subclass of TestPendingTask which has a unique ID for every task, supports | 25 // Subclass of TestPendingTask which has a unique ID for every task, supports |
| 26 // being used inside a std::set and has debug tracing support. | 26 // being used inside a std::set and has debug tracing support. |
| 27 class TestOrderablePendingTask : public base::TestPendingTask { | 27 class TestOrderablePendingTask : public base::TestPendingTask { |
| 28 public: | 28 public: |
| 29 TestOrderablePendingTask(); | 29 TestOrderablePendingTask(); |
| 30 TestOrderablePendingTask(const tracked_objects::Location& location, | 30 TestOrderablePendingTask(const tracked_objects::Location& location, |
| 31 const base::Closure& task, | 31 const base::Closure& task, |
| 32 base::TimeTicks post_time, | 32 base::TimeTicks post_time, |
| 33 base::TimeDelta delay, | 33 base::TimeDelta delay, |
| 34 TestNestability nestability); | 34 TestNestability nestability); |
| 35 TestOrderablePendingTask(TestOrderablePendingTask&&); |
| 35 ~TestOrderablePendingTask(); | 36 ~TestOrderablePendingTask(); |
| 36 | 37 |
| 38 TestOrderablePendingTask& operator=(TestOrderablePendingTask&&); |
| 39 |
| 37 // operators needed by std::set and comparison | 40 // operators needed by std::set and comparison |
| 38 bool operator==(const TestOrderablePendingTask& other) const; | 41 bool operator==(const TestOrderablePendingTask& other) const; |
| 39 bool operator<(const TestOrderablePendingTask& other) const; | 42 bool operator<(const TestOrderablePendingTask& other) const; |
| 40 | 43 |
| 41 // base::trace_event tracing functionality | 44 // base::trace_event tracing functionality |
| 42 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; | 45 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; |
| 43 void AsValueInto(base::trace_event::TracedValue* state) const; | 46 void AsValueInto(base::trace_event::TracedValue* state) const; |
| 44 | 47 |
| 48 size_t task_id() const { return task_id_; } |
| 49 |
| 45 private: | 50 private: |
| 46 static size_t task_id_counter; | 51 static size_t task_id_counter; |
| 47 const size_t task_id_; | 52 size_t task_id_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(TestOrderablePendingTask); |
| 48 }; | 55 }; |
| 49 | 56 |
| 50 // This runs pending tasks based on task's post_time + delay. | 57 // This runs pending tasks based on task's post_time + delay. |
| 51 // We should not execute a delayed task sooner than some of the queued tasks | 58 // We should not execute a delayed task sooner than some of the queued tasks |
| 52 // which don't have a delay even though it is queued early. | 59 // which don't have a delay even though it is queued early. |
| 53 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { | 60 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { |
| 54 public: | 61 public: |
| 55 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now); | 62 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now); |
| 56 | 63 |
| 57 // base::TestSimpleTaskRunner implementation: | 64 // base::TestSimpleTaskRunner implementation: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 base::Callback<bool(void)> TaskExistedInitially(); | 132 base::Callback<bool(void)> TaskExistedInitially(); |
| 126 | 133 |
| 127 // Stop running tasks when NextTaskTime() >= stop_at | 134 // Stop running tasks when NextTaskTime() >= stop_at |
| 128 base::Callback<bool(void)> NowBefore(base::TimeTicks stop_at); | 135 base::Callback<bool(void)> NowBefore(base::TimeTicks stop_at); |
| 129 | 136 |
| 130 // Advance Now() to the next task to run. | 137 // Advance Now() to the next task to run. |
| 131 base::Callback<bool(void)> AdvanceNow(); | 138 base::Callback<bool(void)> AdvanceNow(); |
| 132 | 139 |
| 133 protected: | 140 protected: |
| 134 static bool TaskRunCountBelowCallback(size_t max_tasks, size_t* task_run); | 141 static bool TaskRunCountBelowCallback(size_t max_tasks, size_t* task_run); |
| 135 bool TaskExistedInitiallyCallback( | 142 bool TaskExistedInitiallyCallback(const std::set<size_t>& existing_tasks); |
| 136 const std::set<TestOrderablePendingTask>& existing_tasks); | |
| 137 bool NowBeforeCallback(base::TimeTicks stop_at); | 143 bool NowBeforeCallback(base::TimeTicks stop_at); |
| 138 bool AdvanceNowCallback(); | 144 bool AdvanceNowCallback(); |
| 139 | 145 |
| 140 ~OrderedSimpleTaskRunner() override; | 146 ~OrderedSimpleTaskRunner() override; |
| 141 | 147 |
| 142 base::ThreadChecker thread_checker_; | 148 base::ThreadChecker thread_checker_; |
| 143 | 149 |
| 144 bool advance_now_; | 150 bool advance_now_; |
| 145 // Not owned. | 151 // Not owned. |
| 146 base::SimpleTestTickClock* now_src_; | 152 base::SimpleTestTickClock* now_src_; |
| 147 | 153 |
| 148 size_t max_tasks_; | 154 size_t max_tasks_; |
| 149 | 155 |
| 150 bool inside_run_tasks_until_; | 156 bool inside_run_tasks_until_; |
| 151 std::set<TestOrderablePendingTask> pending_tasks_; | 157 std::set<TestOrderablePendingTask> pending_tasks_; |
| 152 | 158 |
| 153 private: | 159 private: |
| 154 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); | 160 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); |
| 155 }; | 161 }; |
| 156 | 162 |
| 157 } // namespace cc | 163 } // namespace cc |
| 158 | 164 |
| 159 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ | 165 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ |
| OLD | NEW |