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

Side by Side Diff: components/scheduler/child/idle_helper.h

Issue 1832673002: Add testRunner.runIdleTasks() to force idle tasks to run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: rebase Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_SCHEDULER_CHILD_IDLE_HELPER_H_ 5 #ifndef COMPONENTS_SCHEDULER_CHILD_IDLE_HELPER_H_
6 #define COMPONENTS_SCHEDULER_CHILD_IDLE_HELPER_H_ 6 #define COMPONENTS_SCHEDULER_CHILD_IDLE_HELPER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "components/scheduler/base/cancelable_closure_holder.h" 10 #include "components/scheduler/base/cancelable_closure_holder.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 // Start an idle period with a given idle period deadline. 93 // Start an idle period with a given idle period deadline.
94 void StartIdlePeriod(IdlePeriodState new_idle_period_state, 94 void StartIdlePeriod(IdlePeriodState new_idle_period_state,
95 base::TimeTicks now, 95 base::TimeTicks now,
96 base::TimeTicks idle_period_deadline); 96 base::TimeTicks idle_period_deadline);
97 97
98 // This will end an idle period either started with StartIdlePeriod or 98 // This will end an idle period either started with StartIdlePeriod or
99 // EnableLongIdlePeriod. 99 // EnableLongIdlePeriod.
100 void EndIdlePeriod(); 100 void EndIdlePeriod();
101 101
102 // Enter a long idle period that automatically ends when all queued
103 // idle tasks have run. The callback argument will be run after the
104 // idle period ends.
105 void RunIdleTasksForTesting(const base::Closure& callback);
106
102 // Returns true if a currently running idle task could exceed its deadline 107 // Returns true if a currently running idle task could exceed its deadline
103 // without impacting user experience too much. This should only be used if 108 // without impacting user experience too much. This should only be used if
104 // there is a task which cannot be pre-empted and is likely to take longer 109 // there is a task which cannot be pre-empted and is likely to take longer
105 // than the largest expected idle task deadline. It should NOT be polled to 110 // than the largest expected idle task deadline. It should NOT be polled to
106 // check whether more work can be performed on the current idle task after 111 // check whether more work can be performed on the current idle task after
107 // its deadline has expired - post a new idle task for the continuation of the 112 // its deadline has expired - post a new idle task for the continuation of the
108 // work in this case. 113 // work in this case.
109 // Must be called from the thread this class was created on. 114 // Must be called from the thread this class was created on.
110 bool CanExceedIdleDeadlineIfRequired() const; 115 bool CanExceedIdleDeadlineIfRequired() const;
111 116
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // |next_long_idle_period_delay_out| with the next time we should try to 185 // |next_long_idle_period_delay_out| with the next time we should try to
181 // initiate the next idle period. 186 // initiate the next idle period.
182 IdlePeriodState ComputeNewLongIdlePeriodState( 187 IdlePeriodState ComputeNewLongIdlePeriodState(
183 const base::TimeTicks now, 188 const base::TimeTicks now,
184 base::TimeDelta* next_long_idle_period_delay_out); 189 base::TimeDelta* next_long_idle_period_delay_out);
185 190
186 bool ShouldWaitForQuiescence(); 191 bool ShouldWaitForQuiescence();
187 void OnIdleTaskPostedOnMainThread(); 192 void OnIdleTaskPostedOnMainThread();
188 void UpdateLongIdlePeriodStateAfterIdleTask(); 193 void UpdateLongIdlePeriodStateAfterIdleTask();
189 194
195 void EndIdlePeriodForTesting(const base::Closure& callback,
196 base::TimeTicks time_remaining);
197
190 void SetIdlePeriodState(IdlePeriodState new_state, 198 void SetIdlePeriodState(IdlePeriodState new_state,
191 base::TimeTicks new_deadline, 199 base::TimeTicks new_deadline,
192 base::TimeTicks optional_now); 200 base::TimeTicks optional_now);
193 201
194 // Returns true if |state| represents being within an idle period state. 202 // Returns true if |state| represents being within an idle period state.
195 static bool IsInIdlePeriod(IdlePeriodState state); 203 static bool IsInIdlePeriod(IdlePeriodState state);
196 // Returns true if |state| represents being within a long idle period state. 204 // Returns true if |state| represents being within a long idle period state.
197 static bool IsInLongIdlePeriod(IdlePeriodState state); 205 static bool IsInLongIdlePeriod(IdlePeriodState state);
198 206
199 SchedulerHelper* helper_; // NOT OWNED 207 SchedulerHelper* helper_; // NOT OWNED
(...skipping 12 matching lines...) Expand all
212 220
213 base::WeakPtr<IdleHelper> weak_idle_helper_ptr_; 221 base::WeakPtr<IdleHelper> weak_idle_helper_ptr_;
214 base::WeakPtrFactory<IdleHelper> weak_factory_; 222 base::WeakPtrFactory<IdleHelper> weak_factory_;
215 223
216 DISALLOW_COPY_AND_ASSIGN(IdleHelper); 224 DISALLOW_COPY_AND_ASSIGN(IdleHelper);
217 }; 225 };
218 226
219 } // namespace scheduler 227 } // namespace scheduler
220 228
221 #endif // COMPONENTS_SCHEDULER_CHILD_IDLE_HELPER_H_ 229 #endif // COMPONENTS_SCHEDULER_CHILD_IDLE_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698