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

Side by Side Diff: components/scheduler/renderer/renderer_scheduler_impl.cc

Issue 1832673002: Add testRunner.runIdleTasks() to force idle tasks to run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: add test 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 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 #include "components/scheduler/renderer/renderer_scheduler_impl.h" 5 #include "components/scheduler/renderer/renderer_scheduler_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/stack_trace.h" 8 #include "base/debug/stack_trace.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 11 matching lines...) Expand all
22 // The run time of loading tasks is strongly bimodal. The vast majority are 22 // The run time of loading tasks is strongly bimodal. The vast majority are
23 // very cheap, but there are usually a handful of very expensive tasks (e.g ~1 23 // very cheap, but there are usually a handful of very expensive tasks (e.g ~1
24 // second on a mobile device) so we take a very pesimistic view when estimating 24 // second on a mobile device) so we take a very pesimistic view when estimating
25 // the cost of loading tasks. 25 // the cost of loading tasks.
26 const int kLoadingTaskEstimationSampleCount = 1000; 26 const int kLoadingTaskEstimationSampleCount = 1000;
27 const double kLoadingTaskEstimationPercentile = 99; 27 const double kLoadingTaskEstimationPercentile = 99;
28 const int kTimerTaskEstimationSampleCount = 1000; 28 const int kTimerTaskEstimationSampleCount = 1000;
29 const double kTimerTaskEstimationPercentile = 99; 29 const double kTimerTaskEstimationPercentile = 99;
30 const int kShortIdlePeriodDurationSampleCount = 10; 30 const int kShortIdlePeriodDurationSampleCount = 10;
31 const double kShortIdlePeriodDurationPercentile = 50; 31 const double kShortIdlePeriodDurationPercentile = 50;
32
Sami 2016/04/06 15:52:37 Accidental change?
szager1 2016/04/06 17:55:30 Yes, reverted
32 } 33 }
33 34
34 RendererSchedulerImpl::RendererSchedulerImpl( 35 RendererSchedulerImpl::RendererSchedulerImpl(
35 scoped_refptr<SchedulerTqmDelegate> main_task_runner) 36 scoped_refptr<SchedulerTqmDelegate> main_task_runner)
36 : helper_(main_task_runner, 37 : helper_(main_task_runner,
37 "renderer.scheduler", 38 "renderer.scheduler",
38 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 39 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
39 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler.debug")), 40 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler.debug")),
40 idle_helper_(&helper_, 41 idle_helper_(&helper_,
41 this, 42 this,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 timer_queue_suspended_when_backgrounded(false), 120 timer_queue_suspended_when_backgrounded(false),
120 was_shutdown(false), 121 was_shutdown(false),
121 loading_tasks_seem_expensive(false), 122 loading_tasks_seem_expensive(false),
122 timer_tasks_seem_expensive(false), 123 timer_tasks_seem_expensive(false),
123 touchstart_expected_soon(false), 124 touchstart_expected_soon(false),
124 have_seen_a_begin_main_frame(false), 125 have_seen_a_begin_main_frame(false),
125 have_reported_blocking_intervention_in_current_policy(false), 126 have_reported_blocking_intervention_in_current_policy(false),
126 have_reported_blocking_intervention_since_navigation(false), 127 have_reported_blocking_intervention_since_navigation(false),
127 has_visible_render_widget_with_touch_handler(false), 128 has_visible_render_widget_with_touch_handler(false),
128 begin_frame_not_expected_soon(false), 129 begin_frame_not_expected_soon(false),
129 expensive_task_blocking_allowed(true) {} 130 expensive_task_blocking_allowed(true),
131 in_idle_period_for_testing(false) {}
130 132
131 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {} 133 RendererSchedulerImpl::MainThreadOnly::~MainThreadOnly() {}
132 134
133 RendererSchedulerImpl::AnyThread::AnyThread() 135 RendererSchedulerImpl::AnyThread::AnyThread()
134 : awaiting_touch_start_response(false), 136 : awaiting_touch_start_response(false),
135 in_idle_period(false), 137 in_idle_period(false),
136 begin_main_frame_on_critical_path(false), 138 begin_main_frame_on_critical_path(false),
137 last_gesture_was_compositor_driven(false), 139 last_gesture_was_compositor_driven(false),
138 have_seen_touchstart(false) {} 140 have_seen_touchstart(false) {}
139 141
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 helper_.CheckOnValidThread(); 378 helper_.CheckOnValidThread();
377 if (helper_.IsShutdown() || !MainThreadOnly().renderer_backgrounded) 379 if (helper_.IsShutdown() || !MainThreadOnly().renderer_backgrounded)
378 return; 380 return;
379 381
380 MainThreadOnly().renderer_backgrounded = false; 382 MainThreadOnly().renderer_backgrounded = false;
381 suspend_timers_when_backgrounded_closure_.Cancel(); 383 suspend_timers_when_backgrounded_closure_.Cancel();
382 ResumeTimerQueueWhenForegrounded(); 384 ResumeTimerQueueWhenForegrounded();
383 } 385 }
384 386
385 void RendererSchedulerImpl::EndIdlePeriod() { 387 void RendererSchedulerImpl::EndIdlePeriod() {
388 if (MainThreadOnly().in_idle_period_for_testing)
389 return;
386 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 390 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
387 "RendererSchedulerImpl::EndIdlePeriod"); 391 "RendererSchedulerImpl::EndIdlePeriod");
388 helper_.CheckOnValidThread(); 392 helper_.CheckOnValidThread();
389 idle_helper_.EndIdlePeriod(); 393 idle_helper_.EndIdlePeriod();
390 } 394 }
391 395
396 void RendererSchedulerImpl::EndIdlePeriodForTesting(
397 const base::Closure& callback,
398 base::TimeTicks time_remaining) {
399 MainThreadOnly().in_idle_period_for_testing = false;
400 EndIdlePeriod();
401 callback.Run();
402 }
403
392 // static 404 // static
393 bool RendererSchedulerImpl::ShouldPrioritizeInputEvent( 405 bool RendererSchedulerImpl::ShouldPrioritizeInputEvent(
394 const blink::WebInputEvent& web_input_event) { 406 const blink::WebInputEvent& web_input_event) {
395 // We regard MouseMove events with the left mouse button down as a signal 407 // We regard MouseMove events with the left mouse button down as a signal
396 // that the user is doing something requiring a smooth frame rate. 408 // that the user is doing something requiring a smooth frame rate.
397 if (web_input_event.type == blink::WebInputEvent::MouseMove && 409 if (web_input_event.type == blink::WebInputEvent::MouseMove &&
398 (web_input_event.modifiers & blink::WebInputEvent::LeftButtonDown)) { 410 (web_input_event.modifiers & blink::WebInputEvent::LeftButtonDown)) {
399 return true; 411 return true;
400 } 412 }
401 // Ignore all other mouse events because they probably don't signal user 413 // Ignore all other mouse events because they probably don't signal user
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 NOTREACHED(); 579 NOTREACHED();
568 return false; 580 return false;
569 } 581 }
570 } 582 }
571 583
572 base::TimeTicks RendererSchedulerImpl::CurrentIdleTaskDeadlineForTesting() 584 base::TimeTicks RendererSchedulerImpl::CurrentIdleTaskDeadlineForTesting()
573 const { 585 const {
574 return idle_helper_.CurrentIdleTaskDeadline(); 586 return idle_helper_.CurrentIdleTaskDeadline();
575 } 587 }
576 588
589 void RendererSchedulerImpl::RunIdleTasksForTesting(
590 const base::Closure& callback) {
591 MainThreadOnly().in_idle_period_for_testing = true;
592 IdleTaskRunner()->PostIdleTask(
593 FROM_HERE,
594 base::Bind(&RendererSchedulerImpl::EndIdlePeriodForTesting,
595 weak_factory_.GetWeakPtr(), callback));
596 idle_helper_.EnableLongIdlePeriod();
597 }
598
577 void RendererSchedulerImpl::MaybeUpdatePolicy() { 599 void RendererSchedulerImpl::MaybeUpdatePolicy() {
578 helper_.CheckOnValidThread(); 600 helper_.CheckOnValidThread();
579 if (policy_may_need_update_.IsSet()) { 601 if (policy_may_need_update_.IsSet()) {
580 UpdatePolicy(); 602 UpdatePolicy();
581 } 603 }
582 } 604 }
583 605
584 void RendererSchedulerImpl::EnsureUrgentPolicyUpdatePostedOnMainThread( 606 void RendererSchedulerImpl::EnsureUrgentPolicyUpdatePostedOnMainThread(
585 const tracked_objects::Location& from_here) { 607 const tracked_objects::Location& from_here) {
586 // TODO(scheduler-dev): Check that this method isn't called from the main 608 // TODO(scheduler-dev): Check that this method isn't called from the main
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 } 1245 }
1224 MainThreadOnly().have_reported_blocking_intervention_since_navigation = 1246 MainThreadOnly().have_reported_blocking_intervention_since_navigation =
1225 true; 1247 true;
1226 BroadcastConsoleWarning( 1248 BroadcastConsoleWarning(
1227 "Deferred long-running timer task(s) to improve scrolling smoothness. " 1249 "Deferred long-running timer task(s) to improve scrolling smoothness. "
1228 "See crbug.com/574343."); 1250 "See crbug.com/574343.");
1229 } 1251 }
1230 } 1252 }
1231 1253
1232 } // namespace scheduler 1254 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698