| 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 #ifndef COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 5 #ifndef COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ |
| 6 #define COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 6 #define COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "components/scheduler/base/pollable_thread_safe_flag.h" | 10 #include "components/scheduler/base/pollable_thread_safe_flag.h" |
| 11 #include "components/scheduler/child/idle_helper.h" | 11 #include "components/scheduler/child/idle_helper.h" |
| 12 #include "components/scheduler/child/scheduler_helper.h" | 12 #include "components/scheduler/child/scheduler_helper.h" |
| 13 #include "components/scheduler/renderer/deadline_task_runner.h" | 13 #include "components/scheduler/renderer/deadline_task_runner.h" |
| 14 #include "components/scheduler/renderer/idle_time_estimator.h" |
| 14 #include "components/scheduler/renderer/renderer_scheduler.h" | 15 #include "components/scheduler/renderer/renderer_scheduler.h" |
| 15 #include "components/scheduler/renderer/task_cost_estimator.h" | 16 #include "components/scheduler/renderer/task_cost_estimator.h" |
| 16 #include "components/scheduler/renderer/user_model.h" | 17 #include "components/scheduler/renderer/user_model.h" |
| 17 #include "components/scheduler/scheduler_export.h" | 18 #include "components/scheduler/scheduler_export.h" |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 namespace trace_event { | 21 namespace trace_event { |
| 21 class ConvertableToTraceFormat; | 22 class ConvertableToTraceFormat; |
| 22 } | 23 } |
| 23 } | 24 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void ResumeTimerQueue() override; | 69 void ResumeTimerQueue() override; |
| 69 void SetTimerQueueSuspensionWhenBackgroundedEnabled(bool enabled) override; | 70 void SetTimerQueueSuspensionWhenBackgroundedEnabled(bool enabled) override; |
| 70 | 71 |
| 71 // TaskQueueManager::Observer implementation: | 72 // TaskQueueManager::Observer implementation: |
| 72 void OnUnregisterTaskQueue(const scoped_refptr<TaskQueue>& queue) override; | 73 void OnUnregisterTaskQueue(const scoped_refptr<TaskQueue>& queue) override; |
| 73 | 74 |
| 74 // Test helpers. | 75 // Test helpers. |
| 75 SchedulerHelper* GetSchedulerHelperForTesting(); | 76 SchedulerHelper* GetSchedulerHelperForTesting(); |
| 76 TaskCostEstimator* GetLoadingTaskCostEstimatorForTesting(); | 77 TaskCostEstimator* GetLoadingTaskCostEstimatorForTesting(); |
| 77 TaskCostEstimator* GetTimerTaskCostEstimatorForTesting(); | 78 TaskCostEstimator* GetTimerTaskCostEstimatorForTesting(); |
| 79 IdleTimeEstimator* GetIdleTimeEstimatorForTesting(); |
| 78 base::TimeTicks CurrentIdleTaskDeadlineForTesting() const; | 80 base::TimeTicks CurrentIdleTaskDeadlineForTesting() const; |
| 79 | 81 |
| 80 private: | 82 private: |
| 81 friend class RendererSchedulerImplTest; | 83 friend class RendererSchedulerImplTest; |
| 82 friend class RendererSchedulerImplForTest; | 84 friend class RendererSchedulerImplForTest; |
| 83 | 85 |
| 84 struct Policy { | 86 struct Policy { |
| 85 Policy(); | 87 Policy(); |
| 86 | 88 |
| 87 TaskQueue::QueuePriority compositor_queue_priority; | 89 TaskQueue::QueuePriority compositor_queue_priority; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 const blink::WebInputEvent& web_input_event); | 137 const blink::WebInputEvent& web_input_event); |
| 136 | 138 |
| 137 // The amount of time which idle periods can continue being scheduled when the | 139 // The amount of time which idle periods can continue being scheduled when the |
| 138 // renderer has been hidden, before going to sleep for good. | 140 // renderer has been hidden, before going to sleep for good. |
| 139 static const int kEndIdleWhenHiddenDelayMillis = 10000; | 141 static const int kEndIdleWhenHiddenDelayMillis = 10000; |
| 140 | 142 |
| 141 // The amount of time for which loading tasks will be prioritized over | 143 // The amount of time for which loading tasks will be prioritized over |
| 142 // other tasks during the initial page load. | 144 // other tasks during the initial page load. |
| 143 static const int kRailsInitialLoadingPrioritizationMillis = 1000; | 145 static const int kRailsInitialLoadingPrioritizationMillis = 1000; |
| 144 | 146 |
| 147 // The amount of time in milliseconds we have to respond to user input as |
| 148 // defined by RAILS. |
| 149 static const int kRailsResponseTimeMillis = 50; |
| 150 |
| 145 // For the purposes of deciding whether or not it's safe to turn timers and | 151 // For the purposes of deciding whether or not it's safe to turn timers and |
| 146 // loading tasks on only in idle periods, we regard the system as being as | 152 // loading tasks on only in idle periods, we regard the system as being as |
| 147 // being "idle period" starved if there hasn't been an idle period in the last | 153 // being "idle period" starved if there hasn't been an idle period in the last |
| 148 // 10 seconds. This was chosen to be long enough to cover most anticipated | 154 // 10 seconds. This was chosen to be long enough to cover most anticipated |
| 149 // user gestures. | 155 // user gestures. |
| 150 static const int kIdlePeriodStarvationThresholdMillis = 10000; | 156 static const int kIdlePeriodStarvationThresholdMillis = 10000; |
| 151 | 157 |
| 152 // The amount of time to wait before suspending shared timers after the | 158 // The amount of time to wait before suspending shared timers after the |
| 153 // renderer has been backgrounded. This is used only if background suspension | 159 // renderer has been backgrounded. This is used only if background suspension |
| 154 // of shared timers is enabled. | 160 // of shared timers is enabled. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 228 |
| 223 base::Closure update_policy_closure_; | 229 base::Closure update_policy_closure_; |
| 224 DeadlineTaskRunner delayed_update_policy_runner_; | 230 DeadlineTaskRunner delayed_update_policy_runner_; |
| 225 CancelableClosureHolder end_renderer_hidden_idle_period_closure_; | 231 CancelableClosureHolder end_renderer_hidden_idle_period_closure_; |
| 226 CancelableClosureHolder suspend_timers_when_backgrounded_closure_; | 232 CancelableClosureHolder suspend_timers_when_backgrounded_closure_; |
| 227 | 233 |
| 228 // We have decided to improve thread safety at the cost of some boilerplate | 234 // We have decided to improve thread safety at the cost of some boilerplate |
| 229 // (the accessors) for the following data members. | 235 // (the accessors) for the following data members. |
| 230 | 236 |
| 231 struct MainThreadOnly { | 237 struct MainThreadOnly { |
| 232 MainThreadOnly(); | 238 explicit MainThreadOnly( |
| 239 const scoped_refptr<TaskQueue>& compositor_task_runner); |
| 233 ~MainThreadOnly(); | 240 ~MainThreadOnly(); |
| 234 | 241 |
| 235 TaskCostEstimator loading_task_cost_estimator; | 242 TaskCostEstimator loading_task_cost_estimator; |
| 236 TaskCostEstimator timer_task_cost_estimator; | 243 TaskCostEstimator timer_task_cost_estimator; |
| 237 cc::RollingTimeDeltaHistory short_idle_period_duration; | 244 IdleTimeEstimator idle_time_estimator; |
| 238 UseCase current_use_case; | 245 UseCase current_use_case; |
| 239 Policy current_policy; | 246 Policy current_policy; |
| 240 base::TimeTicks current_policy_expiration_time; | 247 base::TimeTicks current_policy_expiration_time; |
| 241 base::TimeTicks estimated_next_frame_begin; | 248 base::TimeTicks estimated_next_frame_begin; |
| 242 base::TimeDelta expected_short_idle_period_duration; | 249 base::TimeDelta compositor_frame_interval; |
| 250 base::TimeDelta expected_idle_duration; |
| 243 int timer_queue_suspend_count; // TIMER_TASK_QUEUE suspended if non-zero. | 251 int timer_queue_suspend_count; // TIMER_TASK_QUEUE suspended if non-zero. |
| 244 int navigation_task_expected_count; | 252 int navigation_task_expected_count; |
| 245 bool renderer_hidden; | 253 bool renderer_hidden; |
| 246 bool renderer_backgrounded; | 254 bool renderer_backgrounded; |
| 247 bool timer_queue_suspension_when_backgrounded_enabled; | 255 bool timer_queue_suspension_when_backgrounded_enabled; |
| 248 bool timer_queue_suspended_when_backgrounded; | 256 bool timer_queue_suspended_when_backgrounded; |
| 249 bool was_shutdown; | 257 bool was_shutdown; |
| 250 bool loading_tasks_seem_expensive; | 258 bool loading_tasks_seem_expensive; |
| 251 bool timer_tasks_seem_expensive; | 259 bool timer_tasks_seem_expensive; |
| 252 bool touchstart_expected_soon; | 260 bool touchstart_expected_soon; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 322 |
| 315 PollableThreadSafeFlag policy_may_need_update_; | 323 PollableThreadSafeFlag policy_may_need_update_; |
| 316 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; | 324 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
| 317 | 325 |
| 318 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); | 326 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
| 319 }; | 327 }; |
| 320 | 328 |
| 321 } // namespace scheduler | 329 } // namespace scheduler |
| 322 | 330 |
| 323 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 331 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ |
| OLD | NEW |