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 <deque> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/debug/trace_event.h" |
| 13 #include "base/logging.h" |
10 #include "base/test/test_simple_task_runner.h" | 14 #include "base/test/test_simple_task_runner.h" |
| 15 #include "cc/test/test_now_source.h" |
11 | 16 |
12 namespace cc { | 17 namespace cc { |
13 | 18 |
14 // This runs pending tasks based on task's post_time + delay. | 19 // This runs pending tasks based on task's post_time + delay. |
15 // We should not execute a delayed task sooner than some of the queued tasks | 20 // We should not execute a delayed task sooner than some of the queued tasks |
16 // which don't have a delay even though it is queued early. | 21 // which don't have a delay even though it is queued early. |
17 class OrderedSimpleTaskRunner : public base::TestSimpleTaskRunner { | 22 class OrderedSimpleTaskRunner : public base::TestSimpleTaskRunner { |
18 public: | 23 public: |
19 OrderedSimpleTaskRunner(); | 24 OrderedSimpleTaskRunner(); |
| 25 OrderedSimpleTaskRunner(scoped_refptr<TestNowSource> now_src, |
| 26 bool advance_now); |
20 | 27 |
| 28 // base::TestSimpleTaskRunner implementation: |
| 29 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 30 const base::Closure& task, |
| 31 base::TimeDelta delay) OVERRIDE; |
| 32 virtual bool PostNonNestableDelayedTask( |
| 33 const tracked_objects::Location& from_here, |
| 34 const base::Closure& task, |
| 35 base::TimeDelta delay) OVERRIDE; |
21 virtual void RunPendingTasks() OVERRIDE; | 36 virtual void RunPendingTasks() OVERRIDE; |
22 | 37 |
| 38 void SetAutoAdvanceNowToPendingTasks(bool advance_now); |
| 39 base::TimeDelta DelayToNextPendingTask(); |
| 40 |
| 41 // base::debug tracing functionality |
| 42 scoped_refptr<base::debug::ConvertableToTraceFormat> AsValue() const; |
| 43 virtual void AsValueInto(base::debug::TracedValue* state) const; |
| 44 |
23 protected: | 45 protected: |
24 virtual ~OrderedSimpleTaskRunner(); | 46 virtual ~OrderedSimpleTaskRunner(); |
25 | 47 |
| 48 static void SortTasks(std::deque<base::TestPendingTask>* tasks); |
| 49 |
26 private: | 50 private: |
| 51 bool advance_now_; |
| 52 scoped_refptr<TestNowSource> now_src_; |
| 53 bool inside_run_pending_tasks_; |
| 54 |
27 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); | 55 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); |
28 }; | 56 }; |
29 | 57 |
30 } // namespace cc | 58 } // namespace cc |
31 | 59 |
32 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ | 60 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ |
OLD | NEW |