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

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

Issue 2017763003: Suspend more task queues for background renderers (experimental) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 4 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 #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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 idle_time_estimator(compositor_task_runner, 112 idle_time_estimator(compositor_task_runner,
113 time_source, 113 time_source,
114 kShortIdlePeriodDurationSampleCount, 114 kShortIdlePeriodDurationSampleCount,
115 kShortIdlePeriodDurationPercentile), 115 kShortIdlePeriodDurationPercentile),
116 current_use_case(UseCase::NONE), 116 current_use_case(UseCase::NONE),
117 timer_queue_suspend_count(0), 117 timer_queue_suspend_count(0),
118 navigation_task_expected_count(0), 118 navigation_task_expected_count(0),
119 expensive_task_policy(ExpensiveTaskPolicy::RUN), 119 expensive_task_policy(ExpensiveTaskPolicy::RUN),
120 renderer_hidden(false), 120 renderer_hidden(false),
121 renderer_backgrounded(false), 121 renderer_backgrounded(false),
122 renderer_suspended(false),
122 timer_queue_suspension_when_backgrounded_enabled(false), 123 timer_queue_suspension_when_backgrounded_enabled(false),
123 timer_queue_suspended_when_backgrounded(false), 124 timer_queue_suspended_when_backgrounded(false),
124 was_shutdown(false), 125 was_shutdown(false),
125 loading_tasks_seem_expensive(false), 126 loading_tasks_seem_expensive(false),
126 timer_tasks_seem_expensive(false), 127 timer_tasks_seem_expensive(false),
127 touchstart_expected_soon(false), 128 touchstart_expected_soon(false),
128 have_seen_a_begin_main_frame(false), 129 have_seen_a_begin_main_frame(false),
129 have_reported_blocking_intervention_in_current_policy(false), 130 have_reported_blocking_intervention_in_current_policy(false),
130 have_reported_blocking_intervention_since_navigation(false), 131 have_reported_blocking_intervention_since_navigation(false),
131 has_visible_render_widget_with_touch_handler(false), 132 has_visible_render_widget_with_touch_handler(false),
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 386 }
386 387
387 void RendererSchedulerImpl::OnRendererForegrounded() { 388 void RendererSchedulerImpl::OnRendererForegrounded() {
388 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 389 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
389 "RendererSchedulerImpl::OnRendererForegrounded"); 390 "RendererSchedulerImpl::OnRendererForegrounded");
390 helper_.CheckOnValidThread(); 391 helper_.CheckOnValidThread();
391 if (helper_.IsShutdown() || !MainThreadOnly().renderer_backgrounded) 392 if (helper_.IsShutdown() || !MainThreadOnly().renderer_backgrounded)
392 return; 393 return;
393 394
394 MainThreadOnly().renderer_backgrounded = false; 395 MainThreadOnly().renderer_backgrounded = false;
396 MainThreadOnly().renderer_suspended = false;
395 suspend_timers_when_backgrounded_closure_.Cancel(); 397 suspend_timers_when_backgrounded_closure_.Cancel();
396 ResumeTimerQueueWhenForegrounded(); 398 ResumeTimerQueueWhenForegrounded();
397 } 399 }
398 400
399 void RendererSchedulerImpl::SuspendRenderer() { 401 void RendererSchedulerImpl::SuspendRenderer() {
400 helper_.CheckOnValidThread(); 402 helper_.CheckOnValidThread();
401 DCHECK(MainThreadOnly().renderer_backgrounded); 403 DCHECK(MainThreadOnly().renderer_backgrounded);
402 if (helper_.IsShutdown()) 404 if (helper_.IsShutdown())
403 return; 405 return;
404 suspend_timers_when_backgrounded_closure_.Cancel(); 406 suspend_timers_when_backgrounded_closure_.Cancel();
405 // TODO(hajimehoshi): We might need to suspend not only timer queue but also 407 // TODO(hajimehoshi): We might need to suspend not only timer queue but also
406 // e.g. loading tasks or postMessage. 408 // e.g. loading tasks or postMessage.
409 MainThreadOnly().renderer_suspended = true;
407 SuspendTimerQueueWhenBackgrounded(); 410 SuspendTimerQueueWhenBackgrounded();
408 } 411 }
409 412
410 void RendererSchedulerImpl::EndIdlePeriod() { 413 void RendererSchedulerImpl::EndIdlePeriod() {
411 if (MainThreadOnly().in_idle_period_for_testing) 414 if (MainThreadOnly().in_idle_period_for_testing)
412 return; 415 return;
413 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 416 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
414 "RendererSchedulerImpl::EndIdlePeriod"); 417 "RendererSchedulerImpl::EndIdlePeriod");
415 helper_.CheckOnValidThread(); 418 helper_.CheckOnValidThread();
416 idle_helper_.EndIdlePeriod(); 419 idle_helper_.EndIdlePeriod();
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 837 }
835 838
836 MainThreadOnly().expensive_task_policy = expensive_task_policy; 839 MainThreadOnly().expensive_task_policy = expensive_task_policy;
837 840
838 if (MainThreadOnly().timer_queue_suspend_count != 0 || 841 if (MainThreadOnly().timer_queue_suspend_count != 0 ||
839 MainThreadOnly().timer_queue_suspended_when_backgrounded) { 842 MainThreadOnly().timer_queue_suspended_when_backgrounded) {
840 new_policy.timer_queue_policy.is_enabled = false; 843 new_policy.timer_queue_policy.is_enabled = false;
841 new_policy.timer_queue_policy.time_domain_type = TimeDomainType::REAL; 844 new_policy.timer_queue_policy.time_domain_type = TimeDomainType::REAL;
842 } 845 }
843 846
847 if (MainThreadOnly().renderer_suspended) {
848 new_policy.loading_queue_policy.is_enabled = false;
849 DCHECK(!new_policy.timer_queue_policy.is_enabled);
850 }
851
844 // Tracing is done before the early out check, because it's quite possible we 852 // Tracing is done before the early out check, because it's quite possible we
845 // will otherwise miss this information in traces. 853 // will otherwise miss this information in traces.
846 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( 854 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
847 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", 855 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler",
848 this, AsValueLocked(now)); 856 this, AsValueLocked(now));
849 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "use_case", 857 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "use_case",
850 use_case); 858 use_case);
851 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), 859 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"),
852 "touchstart_expected_soon", 860 "touchstart_expected_soon",
853 MainThreadOnly().touchstart_expected_soon); 861 MainThreadOnly().touchstart_expected_soon);
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 BroadcastConsoleWarning( 1342 BroadcastConsoleWarning(
1335 "Blink deferred a task in order to make scrolling smoother. " 1343 "Blink deferred a task in order to make scrolling smoother. "
1336 "Your timer and network tasks should take less than 50ms to run " 1344 "Your timer and network tasks should take less than 50ms to run "
1337 "to avoid this. Please see " 1345 "to avoid this. Please see "
1338 "https://developers.google.com/web/tools/chrome-devtools/profile/evaluat e-performance/rail" 1346 "https://developers.google.com/web/tools/chrome-devtools/profile/evaluat e-performance/rail"
1339 " and https://crbug.com/574343#c40 for more information."); 1347 " and https://crbug.com/574343#c40 for more information.");
1340 } 1348 }
1341 } 1349 }
1342 1350
1343 } // namespace scheduler 1351 } // namespace scheduler
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698