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 11 matching lines...) Expand all Loading... |
22 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
23 | 23 |
24 namespace cc { | 24 namespace cc { |
25 | 25 |
26 // Subclass of TestPendingTask which has a unique ID for every task, supports | 26 // Subclass of TestPendingTask which has a unique ID for every task, supports |
27 // being used inside a std::set and has debug tracing support. | 27 // being used inside a std::set and has debug tracing support. |
28 class TestOrderablePendingTask : public base::TestPendingTask { | 28 class TestOrderablePendingTask : public base::TestPendingTask { |
29 public: | 29 public: |
30 TestOrderablePendingTask(); | 30 TestOrderablePendingTask(); |
31 TestOrderablePendingTask(const tracked_objects::Location& location, | 31 TestOrderablePendingTask(const tracked_objects::Location& location, |
32 base::Closure task, | 32 base::OnceClosure task, |
33 base::TimeTicks post_time, | 33 base::TimeTicks post_time, |
34 base::TimeDelta delay, | 34 base::TimeDelta delay, |
35 TestNestability nestability); | 35 TestNestability nestability); |
36 TestOrderablePendingTask(TestOrderablePendingTask&&); | 36 TestOrderablePendingTask(TestOrderablePendingTask&&); |
37 ~TestOrderablePendingTask(); | 37 ~TestOrderablePendingTask(); |
38 | 38 |
39 TestOrderablePendingTask& operator=(TestOrderablePendingTask&&); | 39 TestOrderablePendingTask& operator=(TestOrderablePendingTask&&); |
40 | 40 |
41 // operators needed by std::set and comparison | 41 // operators needed by std::set and comparison |
42 bool operator==(const TestOrderablePendingTask& other) const; | 42 bool operator==(const TestOrderablePendingTask& other) const; |
(...skipping 14 matching lines...) Expand all Loading... |
57 | 57 |
58 // This runs pending tasks based on task's post_time + delay. | 58 // This runs pending tasks based on task's post_time + delay. |
59 // We should not execute a delayed task sooner than some of the queued tasks | 59 // We should not execute a delayed task sooner than some of the queued tasks |
60 // which don't have a delay even though it is queued early. | 60 // which don't have a delay even though it is queued early. |
61 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { | 61 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { |
62 public: | 62 public: |
63 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now); | 63 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now); |
64 | 64 |
65 // base::TestSimpleTaskRunner implementation: | 65 // base::TestSimpleTaskRunner implementation: |
66 bool PostDelayedTask(const tracked_objects::Location& from_here, | 66 bool PostDelayedTask(const tracked_objects::Location& from_here, |
67 base::Closure task, | 67 base::OnceClosure task, |
68 base::TimeDelta delay) override; | 68 base::TimeDelta delay) override; |
69 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 69 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
70 base::Closure task, | 70 base::OnceClosure task, |
71 base::TimeDelta delay) override; | 71 base::TimeDelta delay) override; |
72 | 72 |
73 bool RunsTasksOnCurrentThread() const override; | 73 bool RunsTasksOnCurrentThread() const override; |
74 | 74 |
75 static base::TimeTicks AbsoluteMaxNow(); | 75 static base::TimeTicks AbsoluteMaxNow(); |
76 | 76 |
77 // Set a maximum number of tasks to run at once. Useful as a timeout to | 77 // Set a maximum number of tasks to run at once. Useful as a timeout to |
78 // prevent infinite task loops. | 78 // prevent infinite task loops. |
79 static const size_t kAbsoluteMaxTasks; | 79 static const size_t kAbsoluteMaxTasks; |
80 void SetRunTaskLimit(size_t max_tasks) { max_tasks_ = max_tasks; } | 80 void SetRunTaskLimit(size_t max_tasks) { max_tasks_ = max_tasks; } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 bool inside_run_tasks_until_; | 160 bool inside_run_tasks_until_; |
161 std::set<TestOrderablePendingTask> pending_tasks_; | 161 std::set<TestOrderablePendingTask> pending_tasks_; |
162 | 162 |
163 private: | 163 private: |
164 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); | 164 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); |
165 }; | 165 }; |
166 | 166 |
167 } // namespace cc | 167 } // namespace cc |
168 | 168 |
169 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ | 169 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ |
OLD | NEW |