| OLD | NEW |
| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 timer_queue_suspension_when_backgrounded_enabled(false), | 122 timer_queue_suspension_when_backgrounded_enabled(false), |
| 123 timer_queue_suspended_when_backgrounded(false), | 123 timer_queue_suspended_when_backgrounded(false), |
| 124 queue_suspended(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), |
| 132 begin_frame_not_expected_soon(false), | 133 begin_frame_not_expected_soon(false), |
| 133 expensive_task_blocking_allowed(true), | 134 expensive_task_blocking_allowed(true), |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 break; | 826 break; |
| 826 } | 827 } |
| 827 | 828 |
| 828 MainThreadOnly().expensive_task_policy = expensive_task_policy; | 829 MainThreadOnly().expensive_task_policy = expensive_task_policy; |
| 829 | 830 |
| 830 if (MainThreadOnly().timer_queue_suspend_count != 0 || | 831 if (MainThreadOnly().timer_queue_suspend_count != 0 || |
| 831 MainThreadOnly().timer_queue_suspended_when_backgrounded) { | 832 MainThreadOnly().timer_queue_suspended_when_backgrounded) { |
| 832 new_policy.timer_queue_policy.is_enabled = false; | 833 new_policy.timer_queue_policy.is_enabled = false; |
| 833 } | 834 } |
| 834 | 835 |
| 836 if (MainThreadOnly().queue_suspended) { |
| 837 new_policy.compositor_queue_policy.is_enabled = false; |
| 838 new_policy.loading_queue_policy.is_enabled = false; |
| 839 new_policy.control_queue_policy.is_enabled = false; |
| 840 } |
| 841 |
| 835 // Tracing is done before the early out check, because it's quite possible we | 842 // Tracing is done before the early out check, because it's quite possible we |
| 836 // will otherwise miss this information in traces. | 843 // will otherwise miss this information in traces. |
| 837 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( | 844 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
| 838 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", | 845 TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "RendererScheduler", |
| 839 this, AsValueLocked(now)); | 846 this, AsValueLocked(now)); |
| 840 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "use_case", | 847 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), "use_case", |
| 841 use_case); | 848 use_case); |
| 842 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), | 849 TRACE_COUNTER1(TRACE_DISABLED_BY_DEFAULT("renderer.scheduler"), |
| 843 "touchstart_expected_soon", | 850 "touchstart_expected_soon", |
| 844 MainThreadOnly().touchstart_expected_soon); | 851 MainThreadOnly().touchstart_expected_soon); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 875 MainThreadOnly().have_reported_blocking_intervention_in_current_policy = | 882 MainThreadOnly().have_reported_blocking_intervention_in_current_policy = |
| 876 false; | 883 false; |
| 877 | 884 |
| 878 // TODO(alexclarke): We shouldn't have to prioritize the default queue, but it | 885 // TODO(alexclarke): We shouldn't have to prioritize the default queue, but it |
| 879 // appears to be necessary since the order of loading tasks and IPCs (which | 886 // appears to be necessary since the order of loading tasks and IPCs (which |
| 880 // are mostly dispatched on the default queue) need to be preserved. | 887 // are mostly dispatched on the default queue) need to be preserved. |
| 881 ApplyTaskQueuePolicy(helper_.DefaultTaskRunner().get(), | 888 ApplyTaskQueuePolicy(helper_.DefaultTaskRunner().get(), |
| 882 MainThreadOnly().current_policy.default_queue_policy, | 889 MainThreadOnly().current_policy.default_queue_policy, |
| 883 new_policy.default_queue_policy); | 890 new_policy.default_queue_policy); |
| 884 | 891 |
| 885 DCHECK(compositor_task_runner_->IsQueueEnabled()); | 892 ApplyTaskQueuePolicy(helper_.ControlTaskRunner().get(), |
| 893 MainThreadOnly().current_policy.control_queue_policy, |
| 894 new_policy.control_queue_policy); |
| 895 ApplyTaskQueuePolicy(helper_.ControlAfterWakeUpTaskRunner().get(), |
| 896 MainThreadOnly().current_policy.control_queue_policy, |
| 897 new_policy.control_queue_policy); |
| 898 |
| 886 MainThreadOnly().current_policy = new_policy; | 899 MainThreadOnly().current_policy = new_policy; |
| 887 } | 900 } |
| 888 | 901 |
| 889 void RendererSchedulerImpl::ApplyTaskQueuePolicy( | 902 void RendererSchedulerImpl::ApplyTaskQueuePolicy( |
| 890 TaskQueue* task_queue, | 903 TaskQueue* task_queue, |
| 891 const TaskQueuePolicy& old_task_queue_policy, | 904 const TaskQueuePolicy& old_task_queue_policy, |
| 892 const TaskQueuePolicy& new_task_queue_policy) const { | 905 const TaskQueuePolicy& new_task_queue_policy) const { |
| 893 // The ThrottlingHelper also calls SetQueueEnabled, so we can avoid calling | 906 // The ThrottlingHelper also calls SetQueueEnabled, so we can avoid calling |
| 894 // this here. | 907 // this here. |
| 895 if (new_task_queue_policy.time_domain_type != TimeDomainType::THROTTLED) | 908 if (new_task_queue_policy.time_domain_type != TimeDomainType::THROTTLED) |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1207 base::TimeDelta::FromMilliseconds( | 1220 base::TimeDelta::FromMilliseconds( |
| 1208 kIdlePeriodStarvationThresholdMillis); | 1221 kIdlePeriodStarvationThresholdMillis); |
| 1209 } | 1222 } |
| 1210 | 1223 |
| 1211 void RendererSchedulerImpl::SuspendTimerQueueWhenBackgrounded() { | 1224 void RendererSchedulerImpl::SuspendTimerQueueWhenBackgrounded() { |
| 1212 DCHECK(MainThreadOnly().renderer_backgrounded); | 1225 DCHECK(MainThreadOnly().renderer_backgrounded); |
| 1213 if (MainThreadOnly().timer_queue_suspended_when_backgrounded) | 1226 if (MainThreadOnly().timer_queue_suspended_when_backgrounded) |
| 1214 return; | 1227 return; |
| 1215 | 1228 |
| 1216 MainThreadOnly().timer_queue_suspended_when_backgrounded = true; | 1229 MainThreadOnly().timer_queue_suspended_when_backgrounded = true; |
| 1230 MainThreadOnly().queue_suspended = true; |
| 1217 ForceUpdatePolicy(); | 1231 ForceUpdatePolicy(); |
| 1218 } | 1232 } |
| 1219 | 1233 |
| 1220 void RendererSchedulerImpl::ResumeTimerQueueWhenForegrounded() { | 1234 void RendererSchedulerImpl::ResumeTimerQueueWhenForegrounded() { |
| 1221 DCHECK(!MainThreadOnly().renderer_backgrounded); | 1235 DCHECK(!MainThreadOnly().renderer_backgrounded); |
| 1222 if (!MainThreadOnly().timer_queue_suspended_when_backgrounded) | 1236 if (!MainThreadOnly().timer_queue_suspended_when_backgrounded) |
| 1223 return; | 1237 return; |
| 1224 | 1238 |
| 1225 MainThreadOnly().timer_queue_suspended_when_backgrounded = false; | 1239 MainThreadOnly().timer_queue_suspended_when_backgrounded = false; |
| 1240 MainThreadOnly().queue_suspended = false; |
| 1226 ForceUpdatePolicy(); | 1241 ForceUpdatePolicy(); |
| 1227 } | 1242 } |
| 1228 | 1243 |
| 1229 void RendererSchedulerImpl::ResetForNavigationLocked() { | 1244 void RendererSchedulerImpl::ResetForNavigationLocked() { |
| 1230 helper_.CheckOnValidThread(); | 1245 helper_.CheckOnValidThread(); |
| 1231 any_thread_lock_.AssertAcquired(); | 1246 any_thread_lock_.AssertAcquired(); |
| 1232 AnyThread().user_model.Reset(helper_.scheduler_tqm_delegate()->NowTicks()); | 1247 AnyThread().user_model.Reset(helper_.scheduler_tqm_delegate()->NowTicks()); |
| 1233 AnyThread().have_seen_touchstart = false; | 1248 AnyThread().have_seen_touchstart = false; |
| 1234 MainThreadOnly().loading_task_cost_estimator.Clear(); | 1249 MainThreadOnly().loading_task_cost_estimator.Clear(); |
| 1235 MainThreadOnly().timer_task_cost_estimator.Clear(); | 1250 MainThreadOnly().timer_task_cost_estimator.Clear(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 BroadcastConsoleWarning( | 1332 BroadcastConsoleWarning( |
| 1318 "Blink deferred a task in order to make scrolling smoother. " | 1333 "Blink deferred a task in order to make scrolling smoother. " |
| 1319 "Your timer tasks should take less than 50ms to run to avoid this. " | 1334 "Your timer tasks should take less than 50ms to run to avoid this. " |
| 1320 "Please see " | 1335 "Please see " |
| 1321 "https://developers.google.com/web/tools/chrome-devtools/profile/evaluat
e-performance/rail" | 1336 "https://developers.google.com/web/tools/chrome-devtools/profile/evaluat
e-performance/rail" |
| 1322 " and https://crbug.com/574343#c40 for more information."); | 1337 " and https://crbug.com/574343#c40 for more information."); |
| 1323 } | 1338 } |
| 1324 } | 1339 } |
| 1325 | 1340 |
| 1326 } // namespace scheduler | 1341 } // namespace scheduler |
| OLD | NEW |