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

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

Issue 2434783002: Use OnceClosure in TestPendingTask (Closed)
Patch Set: fix Created 4 years, 2 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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 14 matching lines...) Expand all
25 // Subclass of TestPendingTask which has a unique ID for every task, supports 25 // Subclass of TestPendingTask which has a unique ID for every task, supports
26 // being used inside a std::set and has debug tracing support. 26 // being used inside a std::set and has debug tracing support.
27 class TestOrderablePendingTask : public base::TestPendingTask { 27 class TestOrderablePendingTask : public base::TestPendingTask {
28 public: 28 public:
29 TestOrderablePendingTask(); 29 TestOrderablePendingTask();
30 TestOrderablePendingTask(const tracked_objects::Location& location, 30 TestOrderablePendingTask(const tracked_objects::Location& location,
31 const base::Closure& task, 31 const base::Closure& task,
32 base::TimeTicks post_time, 32 base::TimeTicks post_time,
33 base::TimeDelta delay, 33 base::TimeDelta delay,
34 TestNestability nestability); 34 TestNestability nestability);
35 TestOrderablePendingTask(TestOrderablePendingTask&&);
danakj 2016/10/20 20:07:46 add operator= too
tzik 2016/10/27 08:20:49 Done.
35 ~TestOrderablePendingTask(); 36 ~TestOrderablePendingTask();
36 37
37 // operators needed by std::set and comparison 38 // operators needed by std::set and comparison
38 bool operator==(const TestOrderablePendingTask& other) const; 39 bool operator==(const TestOrderablePendingTask& other) const;
39 bool operator<(const TestOrderablePendingTask& other) const; 40 bool operator<(const TestOrderablePendingTask& other) const;
40 41
41 // base::trace_event tracing functionality 42 // base::trace_event tracing functionality
42 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; 43 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue() const;
43 void AsValueInto(base::trace_event::TracedValue* state) const; 44 void AsValueInto(base::trace_event::TracedValue* state) const;
44 45
46 size_t task_id() const { return task_id_; }
47
45 private: 48 private:
46 static size_t task_id_counter; 49 static size_t task_id_counter;
47 const size_t task_id_; 50 const size_t task_id_;
51
52 DISALLOW_COPY_AND_ASSIGN(TestOrderablePendingTask);
48 }; 53 };
49 54
50 // This runs pending tasks based on task's post_time + delay. 55 // This runs pending tasks based on task's post_time + delay.
51 // We should not execute a delayed task sooner than some of the queued tasks 56 // We should not execute a delayed task sooner than some of the queued tasks
52 // which don't have a delay even though it is queued early. 57 // which don't have a delay even though it is queued early.
53 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner { 58 class OrderedSimpleTaskRunner : public base::SingleThreadTaskRunner {
54 public: 59 public:
55 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now); 60 OrderedSimpleTaskRunner(base::SimpleTestTickClock* now_src, bool advance_now);
56 61
57 // base::TestSimpleTaskRunner implementation: 62 // base::TestSimpleTaskRunner implementation:
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 base::Callback<bool(void)> TaskExistedInitially(); 130 base::Callback<bool(void)> TaskExistedInitially();
126 131
127 // Stop running tasks when NextTaskTime() >= stop_at 132 // Stop running tasks when NextTaskTime() >= stop_at
128 base::Callback<bool(void)> NowBefore(base::TimeTicks stop_at); 133 base::Callback<bool(void)> NowBefore(base::TimeTicks stop_at);
129 134
130 // Advance Now() to the next task to run. 135 // Advance Now() to the next task to run.
131 base::Callback<bool(void)> AdvanceNow(); 136 base::Callback<bool(void)> AdvanceNow();
132 137
133 protected: 138 protected:
134 static bool TaskRunCountBelowCallback(size_t max_tasks, size_t* task_run); 139 static bool TaskRunCountBelowCallback(size_t max_tasks, size_t* task_run);
135 bool TaskExistedInitiallyCallback( 140 bool TaskExistedInitiallyCallback(const std::set<size_t>& existing_tasks);
136 const std::set<TestOrderablePendingTask>& existing_tasks);
137 bool NowBeforeCallback(base::TimeTicks stop_at); 141 bool NowBeforeCallback(base::TimeTicks stop_at);
138 bool AdvanceNowCallback(); 142 bool AdvanceNowCallback();
139 143
140 ~OrderedSimpleTaskRunner() override; 144 ~OrderedSimpleTaskRunner() override;
141 145
142 base::ThreadChecker thread_checker_; 146 base::ThreadChecker thread_checker_;
143 147
144 bool advance_now_; 148 bool advance_now_;
145 // Not owned. 149 // Not owned.
146 base::SimpleTestTickClock* now_src_; 150 base::SimpleTestTickClock* now_src_;
147 151
148 size_t max_tasks_; 152 size_t max_tasks_;
149 153
150 bool inside_run_tasks_until_; 154 bool inside_run_tasks_until_;
151 std::set<TestOrderablePendingTask> pending_tasks_; 155 std::set<TestOrderablePendingTask> pending_tasks_;
152 156
153 private: 157 private:
154 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); 158 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner);
155 }; 159 };
156 160
157 } // namespace cc 161 } // namespace cc
158 162
159 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ 163 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698