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

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

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 #include "components/scheduler/child/idle_helper.h" 5 #include "components/scheduler/child/idle_helper.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "base/trace_event/trace_event_argument.h" 9 #include "base/trace_event/trace_event_argument.h"
10 #include "components/scheduler/base/real_time_domain.h" 10 #include "components/scheduler/base/real_time_domain.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 // If we weren't already within an idle period then early-out. 191 // If we weren't already within an idle period then early-out.
192 if (!IsInIdlePeriod(state_.idle_period_state())) 192 if (!IsInIdlePeriod(state_.idle_period_state()))
193 return; 193 return;
194 194
195 idle_queue_->SetQueueEnabled(false); 195 idle_queue_->SetQueueEnabled(false);
196 state_.UpdateState(IdlePeriodState::NOT_IN_IDLE_PERIOD, base::TimeTicks(), 196 state_.UpdateState(IdlePeriodState::NOT_IN_IDLE_PERIOD, base::TimeTicks(),
197 base::TimeTicks()); 197 base::TimeTicks());
198 } 198 }
199 199
200 void IdleHelper::RunIdleTasksForTesting(const base::Closure& callback) {
201 IdleTaskRunner()->PostIdleTask(
202 FROM_HERE,
203 base::Bind(&IdleHelper::EndIdlePeriodForTesting,
204 weak_factory_.GetWeakPtr(),
205 callback));
206 EnableLongIdlePeriod();
207 }
208
200 void IdleHelper::WillProcessTask(const base::PendingTask& pending_task) { 209 void IdleHelper::WillProcessTask(const base::PendingTask& pending_task) {
201 } 210 }
202 211
203 void IdleHelper::DidProcessTask(const base::PendingTask& pending_task) { 212 void IdleHelper::DidProcessTask(const base::PendingTask& pending_task) {
204 helper_->CheckOnValidThread(); 213 helper_->CheckOnValidThread();
205 TRACE_EVENT0(disabled_by_default_tracing_category_, "DidProcessTask"); 214 TRACE_EVENT0(disabled_by_default_tracing_category_, "DidProcessTask");
206 if (IsInIdlePeriod(state_.idle_period_state()) && 215 if (IsInIdlePeriod(state_.idle_period_state()) &&
207 state_.idle_period_state() != 216 state_.idle_period_state() !=
208 IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED && 217 IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED &&
209 helper_->scheduler_tqm_delegate()->NowTicks() >= 218 helper_->scheduler_tqm_delegate()->NowTicks() >=
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 if (next_long_idle_period_delay == base::TimeDelta()) { 258 if (next_long_idle_period_delay == base::TimeDelta()) {
250 EnableLongIdlePeriod(); 259 EnableLongIdlePeriod();
251 } else { 260 } else {
252 helper_->ControlTaskRunner()->PostDelayedTask( 261 helper_->ControlTaskRunner()->PostDelayedTask(
253 FROM_HERE, enable_next_long_idle_period_closure_.callback(), 262 FROM_HERE, enable_next_long_idle_period_closure_.callback(),
254 next_long_idle_period_delay); 263 next_long_idle_period_delay);
255 } 264 }
256 } 265 }
257 } 266 }
258 267
268 void IdleHelper::EndIdlePeriodForTesting(
269 const base::Closure& callback,
270 base::TimeTicks time_ticks) {
271 EndIdlePeriod();
272 callback.Run();
273 }
274
259 base::TimeTicks IdleHelper::CurrentIdleTaskDeadline() const { 275 base::TimeTicks IdleHelper::CurrentIdleTaskDeadline() const {
260 helper_->CheckOnValidThread(); 276 helper_->CheckOnValidThread();
261 return state_.idle_period_deadline(); 277 return state_.idle_period_deadline();
262 } 278 }
263 279
264 void IdleHelper::OnIdleTaskPosted() { 280 void IdleHelper::OnIdleTaskPosted() {
265 TRACE_EVENT0(disabled_by_default_tracing_category_, "OnIdleTaskPosted"); 281 TRACE_EVENT0(disabled_by_default_tracing_category_, "OnIdleTaskPosted");
266 if (idle_task_runner_->RunsTasksOnCurrentThread()) { 282 if (idle_task_runner_->RunsTasksOnCurrentThread()) {
267 OnIdleTaskPostedOnMainThread(); 283 OnIdleTaskPostedOnMainThread();
268 } else { 284 } else {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 return "in_long_idle_period_with_max_deadline"; 492 return "in_long_idle_period_with_max_deadline";
477 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED: 493 case IdlePeriodState::IN_LONG_IDLE_PERIOD_PAUSED:
478 return "in_long_idle_period_paused"; 494 return "in_long_idle_period_paused";
479 default: 495 default:
480 NOTREACHED(); 496 NOTREACHED();
481 return nullptr; 497 return nullptr;
482 } 498 }
483 } 499 }
484 500
485 } // namespace scheduler 501 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698