Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: cc/test/ordered_simple_task_runner.h

Issue 1132753008: Replaced TestNowSource with SimpleTestTickClock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased again. Replaces TimeSource with TickClock in TestAlwaysFailTimeSource Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/test/simple_test_tick_clock.h"
15 #include "base/test/test_simple_task_runner.h" 16 #include "base/test/test_simple_task_runner.h"
16 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
17 #include "cc/test/test_now_source.h"
18 18
19 namespace cc { 19 namespace cc {
20 20
21 // Subclass of TestPendingTask which has a unique ID for every task, supports 21 // Subclass of TestPendingTask which has a unique ID for every task, supports
22 // being used inside a std::set and has debug tracing support. 22 // being used inside a std::set and has debug tracing support.
23 class TestOrderablePendingTask : public base::TestPendingTask { 23 class TestOrderablePendingTask : public base::TestPendingTask {
24 public: 24 public:
25 TestOrderablePendingTask(); 25 TestOrderablePendingTask();
26 TestOrderablePendingTask(const tracked_objects::Location& location, 26 TestOrderablePendingTask(const tracked_objects::Location& location,
27 const base::Closure& task, 27 const base::Closure& task,
(...skipping 14 matching lines...) Expand all
42 static size_t task_id_counter; 42 static size_t task_id_counter;
43 const size_t task_id_; 43 const size_t task_id_;
44 }; 44 };
45 45
46 // This runs pending tasks based on task's post_time + delay. 46 // This runs pending tasks based on task's post_time + delay.
47 // We should not execute a delayed task sooner than some of the queued tasks 47 // We should not execute a delayed task sooner than some of the queued tasks
48 // which don't have a delay even though it is queued early. 48 // which don't have a delay even though it is queued early.
49 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { 49 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner {
50 public: 50 public:
51 OrderedSimpleTaskRunner(); 51 OrderedSimpleTaskRunner();
52 OrderedSimpleTaskRunner(scoped_refptr<TestNowSource> now_src, 52 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now);
53 bool advance_now);
54 53
55 // base::TestSimpleTaskRunner implementation: 54 // base::TestSimpleTaskRunner implementation:
56 bool PostDelayedTask(const tracked_objects::Location& from_here, 55 bool PostDelayedTask(const tracked_objects::Location& from_here,
57 const base::Closure& task, 56 const base::Closure& task,
58 base::TimeDelta delay) override; 57 base::TimeDelta delay) override;
59 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 58 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
60 const base::Closure& task, 59 const base::Closure& task,
61 base::TimeDelta delay) override; 60 base::TimeDelta delay) override;
62 61
63 bool RunsTasksOnCurrentThread() const override; 62 bool RunsTasksOnCurrentThread() const override;
64 63
64 static const base::TimeTicks kAbsoluteMaxNow;
65
65 // Set a maximum number of tasks to run at once. Useful as a timeout to 66 // Set a maximum number of tasks to run at once. Useful as a timeout to
66 // prevent infinite task loops. 67 // prevent infinite task loops.
67 static const size_t kAbsoluteMaxTasks; 68 static const size_t kAbsoluteMaxTasks;
68 void SetRunTaskLimit(size_t max_tasks) { max_tasks_ = max_tasks; } 69 void SetRunTaskLimit(size_t max_tasks) { max_tasks_ = max_tasks; }
69 void ClearRunTaskLimit() { max_tasks_ = kAbsoluteMaxTasks; } 70 void ClearRunTaskLimit() { max_tasks_ = kAbsoluteMaxTasks; }
70 71
71 // Allow task runner to advance now when running tasks. 72 // Allow task runner to advance now when running tasks.
72 void SetAutoAdvanceNowToPendingTasks(bool advance_now) { 73 void SetAutoAdvanceNowToPendingTasks(bool advance_now) {
73 advance_now_ = advance_now; 74 advance_now_ = advance_now;
74 } 75 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 bool TaskExistedInitiallyCallback( 132 bool TaskExistedInitiallyCallback(
132 const std::set<TestOrderablePendingTask>& existing_tasks); 133 const std::set<TestOrderablePendingTask>& existing_tasks);
133 bool NowBeforeCallback(base::TimeTicks stop_at); 134 bool NowBeforeCallback(base::TimeTicks stop_at);
134 bool AdvanceNowCallback(); 135 bool AdvanceNowCallback();
135 136
136 ~OrderedSimpleTaskRunner() override; 137 ~OrderedSimpleTaskRunner() override;
137 138
138 base::ThreadChecker thread_checker_; 139 base::ThreadChecker thread_checker_;
139 140
140 bool advance_now_; 141 bool advance_now_;
141 scoped_refptr<TestNowSource> now_src_; 142 base::SimpleTestTickClock* now_src_;
Sami 2015/06/05 17:11:07 Who owns this object? One of the constructors take
Ankur Verma 2015/06/08 07:11:34 Done. Removed the ctor which allocated but never f
142 143
143 size_t max_tasks_; 144 size_t max_tasks_;
144 145
145 bool inside_run_tasks_until_; 146 bool inside_run_tasks_until_;
146 std::set<TestOrderablePendingTask> pending_tasks_; 147 std::set<TestOrderablePendingTask> pending_tasks_;
147 148
148 private: 149 private:
149 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); 150 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner);
150 }; 151 };
151 152
152 } // namespace cc 153 } // namespace cc
153 154
154 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ 155 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698