| 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 <set> | 12 #include <set> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/test/simple_test_tick_clock.h" | 18 #include "base/test/simple_test_tick_clock.h" |
| 19 #include "base/test/test_simple_task_runner.h" | 19 #include "base/test/test_simple_task_runner.h" |
| 20 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
| 21 | 21 |
| 22 namespace cc { | 22 namespace cc { |
| 23 | 23 |
| 24 // Subclass of TestPendingTask which has a unique ID for every task, supports | 24 // Subclass of TestPendingTask which has a unique ID for every task, supports |
| 25 // being used inside a std::set and has debug tracing support. | 25 // being used inside a std::set and has debug tracing support. |
| 26 class TestOrderablePendingTask : public base::TestPendingTask { | 26 class TestOrderablePendingTask : public base::TestPendingTask { |
| 27 public: | 27 public: |
| 28 TestOrderablePendingTask(); | 28 TestOrderablePendingTask(); |
| 29 TestOrderablePendingTask(const tracked_objects::Location& location, | 29 TestOrderablePendingTask(const tracked_objects::Location& location, |
| 30 const base::Closure& task, | 30 const base::Closure& task, |
| 31 base::TimeTicks post_time, | 31 base::TimeTicks post_time, |
| 32 base::TimeDelta delay, | 32 base::TimeDelta delay, |
| 33 TestNestability nestability); | 33 TestNestability nestability); |
| 34 ~TestOrderablePendingTask(); | 34 ~TestOrderablePendingTask(); |
| 35 | 35 |
| 36 // operators needed by std::set and comparison | 36 // operators needed by std::set and comparison |
| 37 bool operator==(const TestOrderablePendingTask& other) const; | 37 bool operator==(const TestOrderablePendingTask& other) const; |
| 38 bool operator<(const TestOrderablePendingTask& other) const; | 38 bool operator<(const TestOrderablePendingTask& other) const; |
| 39 | 39 |
| 40 // base::trace_event tracing functionality | 40 // base::trace_event tracing functionality |
| 41 scoped_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; | 41 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; |
| 42 void AsValueInto(base::trace_event::TracedValue* state) const; | 42 void AsValueInto(base::trace_event::TracedValue* state) const; |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 static size_t task_id_counter; | 45 static size_t task_id_counter; |
| 46 const size_t task_id_; | 46 const size_t task_id_; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 // This runs pending tasks based on task's post_time + delay. | 49 // This runs pending tasks based on task's post_time + delay. |
| 50 // We should not execute a delayed task sooner than some of the queued tasks | 50 // We should not execute a delayed task sooner than some of the queued tasks |
| 51 // which don't have a delay even though it is queued early. | 51 // which don't have a delay even though it is queued early. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // Keep running tasks until no tasks are left. | 100 // Keep running tasks until no tasks are left. |
| 101 // Return code indicates tasks still exist to run which also indicates if | 101 // Return code indicates tasks still exist to run which also indicates if |
| 102 // runner reached idle. | 102 // runner reached idle. |
| 103 bool RunUntilIdle(); | 103 bool RunUntilIdle(); |
| 104 // Keep running tasks until given time period. | 104 // Keep running tasks until given time period. |
| 105 // Return code indicates tasks still exist to run. | 105 // Return code indicates tasks still exist to run. |
| 106 bool RunUntilTime(base::TimeTicks time); | 106 bool RunUntilTime(base::TimeTicks time); |
| 107 bool RunForPeriod(base::TimeDelta period); | 107 bool RunForPeriod(base::TimeDelta period); |
| 108 | 108 |
| 109 // base::trace_event tracing functionality | 109 // base::trace_event tracing functionality |
| 110 scoped_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; | 110 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; |
| 111 virtual void AsValueInto(base::trace_event::TracedValue* state) const; | 111 virtual void AsValueInto(base::trace_event::TracedValue* state) const; |
| 112 | 112 |
| 113 // Common conditions to run for, exposed publicly to allow external users to | 113 // Common conditions to run for, exposed publicly to allow external users to |
| 114 // use their own combinations. | 114 // use their own combinations. |
| 115 // ------------------------------------------------------------------------- | 115 // ------------------------------------------------------------------------- |
| 116 | 116 |
| 117 // Keep running until the given number of tasks have run. | 117 // Keep running until the given number of tasks have run. |
| 118 // You generally shouldn't use this check as it will cause your tests to fail | 118 // You generally shouldn't use this check as it will cause your tests to fail |
| 119 // when code is changed adding a new task. It is useful as a "timeout" type | 119 // when code is changed adding a new task. It is useful as a "timeout" type |
| 120 // solution. | 120 // solution. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 149 bool inside_run_tasks_until_; | 149 bool inside_run_tasks_until_; |
| 150 std::set<TestOrderablePendingTask> pending_tasks_; | 150 std::set<TestOrderablePendingTask> pending_tasks_; |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); | 153 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 } // namespace cc | 156 } // namespace cc |
| 157 | 157 |
| 158 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ | 158 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ |
| OLD | NEW |