| 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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" |
| 15 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/test/simple_test_tick_clock.h" | 19 #include "base/test/simple_test_tick_clock.h" |
| 19 #include "base/test/test_simple_task_runner.h" | 20 #include "base/test/test_simple_task_runner.h" |
| 20 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
| 21 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
| 22 | 23 |
| 23 namespace cc { | 24 namespace cc { |
| 24 | 25 |
| 25 // 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 |
| 26 // being used inside a std::set and has debug tracing support. | 27 // being used inside a std::set and has debug tracing support. |
| 27 class TestOrderablePendingTask : public base::TestPendingTask { | 28 class TestOrderablePendingTask : public base::TestPendingTask { |
| 28 public: | 29 public: |
| 29 TestOrderablePendingTask(); | 30 TestOrderablePendingTask(); |
| 30 TestOrderablePendingTask(const tracked_objects::Location& location, | 31 TestOrderablePendingTask(const tracked_objects::Location& location, |
| 31 const base::Closure& task, | 32 base::Closure task, |
| 32 base::TimeTicks post_time, | 33 base::TimeTicks post_time, |
| 33 base::TimeDelta delay, | 34 base::TimeDelta delay, |
| 34 TestNestability nestability); | 35 TestNestability nestability); |
| 35 TestOrderablePendingTask(TestOrderablePendingTask&&); | 36 TestOrderablePendingTask(TestOrderablePendingTask&&); |
| 36 ~TestOrderablePendingTask(); | 37 ~TestOrderablePendingTask(); |
| 37 | 38 |
| 38 TestOrderablePendingTask& operator=(TestOrderablePendingTask&&); | 39 TestOrderablePendingTask& operator=(TestOrderablePendingTask&&); |
| 39 | 40 |
| 40 // operators needed by std::set and comparison | 41 // operators needed by std::set and comparison |
| 41 bool operator==(const TestOrderablePendingTask& other) const; | 42 bool operator==(const TestOrderablePendingTask& other) const; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 56 | 57 |
| 57 // This runs pending tasks based on task's post_time + delay. | 58 // This runs pending tasks based on task's post_time + delay. |
| 58 // 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 |
| 59 // 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. |
| 60 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { | 61 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { |
| 61 public: | 62 public: |
| 62 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now); | 63 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now); |
| 63 | 64 |
| 64 // base::TestSimpleTaskRunner implementation: | 65 // base::TestSimpleTaskRunner implementation: |
| 65 bool PostDelayedTask(const tracked_objects::Location& from_here, | 66 bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 66 const base::Closure& task, | 67 base::Closure task, |
| 67 base::TimeDelta delay) override; | 68 base::TimeDelta delay) override; |
| 68 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, | 69 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, |
| 69 const base::Closure& task, | 70 base::Closure task, |
| 70 base::TimeDelta delay) override; | 71 base::TimeDelta delay) override; |
| 71 | 72 |
| 72 bool RunsTasksOnCurrentThread() const override; | 73 bool RunsTasksOnCurrentThread() const override; |
| 73 | 74 |
| 74 static base::TimeTicks AbsoluteMaxNow(); | 75 static base::TimeTicks AbsoluteMaxNow(); |
| 75 | 76 |
| 76 // 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 |
| 77 // prevent infinite task loops. | 78 // prevent infinite task loops. |
| 78 static const size_t kAbsoluteMaxTasks; | 79 static const size_t kAbsoluteMaxTasks; |
| 79 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... |
| 159 bool inside_run_tasks_until_; | 160 bool inside_run_tasks_until_; |
| 160 std::set<TestOrderablePendingTask> pending_tasks_; | 161 std::set<TestOrderablePendingTask> pending_tasks_; |
| 161 | 162 |
| 162 private: | 163 private: |
| 163 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); | 164 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); |
| 164 }; | 165 }; |
| 165 | 166 |
| 166 } // namespace cc | 167 } // namespace cc |
| 167 | 168 |
| 168 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ | 169 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ |
| OLD | NEW |