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/child/idle_helper.h" | 10 #include "components/scheduler/child/idle_helper.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 void BeginFrameNotExpectedSoon() override; | 40 void BeginFrameNotExpectedSoon() override; |
41 void DidCommitFrameToCompositor() override; | 41 void DidCommitFrameToCompositor() override; |
42 void DidHandleInputEventOnCompositorThread( | 42 void DidHandleInputEventOnCompositorThread( |
43 const blink::WebInputEvent& web_input_event, | 43 const blink::WebInputEvent& web_input_event, |
44 InputEventState event_state) override; | 44 InputEventState event_state) override; |
45 void DidHandleInputEventOnMainThread( | 45 void DidHandleInputEventOnMainThread( |
46 const blink::WebInputEvent& web_input_event) override; | 46 const blink::WebInputEvent& web_input_event) override; |
47 void DidAnimateForInputOnCompositorThread() override; | 47 void DidAnimateForInputOnCompositorThread() override; |
48 void OnRendererHidden() override; | 48 void OnRendererHidden() override; |
49 void OnRendererVisible() override; | 49 void OnRendererVisible() override; |
50 void OnRendererBackgrounded() override; | |
51 void OnRendererForegrounded() override; | |
50 void OnPageLoadStarted() override; | 52 void OnPageLoadStarted() override; |
51 bool IsHighPriorityWorkAnticipated() override; | 53 bool IsHighPriorityWorkAnticipated() override; |
52 bool ShouldYieldForHighPriorityWork() override; | 54 bool ShouldYieldForHighPriorityWork() override; |
53 bool CanExceedIdleDeadlineIfRequired() const override; | 55 bool CanExceedIdleDeadlineIfRequired() const override; |
54 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; | 56 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; |
55 void RemoveTaskObserver( | 57 void RemoveTaskObserver( |
56 base::MessageLoop::TaskObserver* task_observer) override; | 58 base::MessageLoop::TaskObserver* task_observer) override; |
57 void Shutdown() override; | 59 void Shutdown() override; |
58 void SuspendTimerQueue() override; | 60 void SuspendTimerQueue() override; |
59 void ResumeTimerQueue() override; | 61 void ResumeTimerQueue() override; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 // IdleHelper::Delegate implementation: | 100 // IdleHelper::Delegate implementation: |
99 bool CanEnterLongIdlePeriod( | 101 bool CanEnterLongIdlePeriod( |
100 base::TimeTicks now, | 102 base::TimeTicks now, |
101 base::TimeDelta* next_long_idle_period_delay_out) override; | 103 base::TimeDelta* next_long_idle_period_delay_out) override; |
102 void IsNotQuiescent() override {} | 104 void IsNotQuiescent() override {} |
103 void OnIdlePeriodStarted() override; | 105 void OnIdlePeriodStarted() override; |
104 void OnIdlePeriodEnded() override; | 106 void OnIdlePeriodEnded() override; |
105 | 107 |
106 void EndIdlePeriod(); | 108 void EndIdlePeriod(); |
107 | 109 |
110 void SuspendTimerQueueWhenBackgrounded(); | |
111 void ResumeTimerQueueWhenForegrounded(); | |
112 | |
108 // Returns the serialized scheduler state for tracing. | 113 // Returns the serialized scheduler state for tracing. |
109 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 114 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
110 base::TimeTicks optional_now) const; | 115 base::TimeTicks optional_now) const; |
111 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( | 116 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( |
112 base::TimeTicks optional_now) const; | 117 base::TimeTicks optional_now) const; |
113 static const char* PolicyToString(Policy policy); | 118 static const char* PolicyToString(Policy policy); |
114 | 119 |
115 static bool ShouldPrioritizeInputEvent( | 120 static bool ShouldPrioritizeInputEvent( |
116 const blink::WebInputEvent& web_input_event); | 121 const blink::WebInputEvent& web_input_event); |
117 | 122 |
118 // The time we should stay in a priority-escalated mode after an input event. | 123 // The time we should stay in a priority-escalated mode after an input event. |
119 static const int kPriorityEscalationAfterInputMillis = 100; | 124 static const int kPriorityEscalationAfterInputMillis = 100; |
120 | 125 |
121 // The amount of time which idle periods can continue being scheduled when the | 126 // The amount of time which idle periods can continue being scheduled when the |
122 // renderer has been hidden, before going to sleep for good. | 127 // renderer has been hidden, before going to sleep for good. |
123 static const int kEndIdleWhenHiddenDelayMillis = 10000; | 128 static const int kEndIdleWhenHiddenDelayMillis = 10000; |
124 | 129 |
125 // The amount of time for which loading tasks will be prioritized over | 130 // The amount of time for which loading tasks will be prioritized over |
126 // other tasks during the initial page load. | 131 // other tasks during the initial page load. |
127 static const int kRailsInitialLoadingPrioritizationMillis = 1000; | 132 static const int kRailsInitialLoadingPrioritizationMillis = 1000; |
128 | 133 |
129 // For the purposes of deciding whether or not it's safe to turn timers and | 134 // For the purposes of deciding whether or not it's safe to turn timers and |
130 // loading tasks on only in idle periods, we regard the system as being as | 135 // loading tasks on only in idle periods, we regard the system as being as |
131 // being "idle period" starved if there hasn't been an idle period in the last | 136 // being "idle period" starved if there hasn't been an idle period in the last |
132 // 10 seconds. This was chosen to be long enough to cover most anticipated | 137 // 10 seconds. This was chosen to be long enough to cover most anticipated |
133 // user gestures. | 138 // user gestures. |
134 static const int kIdlePeriodStarvationThresholdMillis = 10000; | 139 static const int kIdlePeriodStarvationThresholdMillis = 10000; |
135 | 140 |
141 #if defined(OS_ANDROID) | |
142 // The amount of time to wait after suspending shared timers after the | |
143 // renderer has been backgrounded. | |
144 static const int kSuspendTimersWhenBackgroundedDelayMillis = 5 * 60 * 1000; | |
Sami
2015/08/28 14:15:01
Just thinking ahead to testing this, perhaps it wo
jdduke (slow)
2015/08/31 18:36:08
Done.
| |
145 #else | |
146 static const int kSuspendTimersWhenBackgroundedDelayMillis = -1; | |
147 #endif | |
148 | |
136 // Schedules an immediate PolicyUpdate, if there isn't one already pending and | 149 // Schedules an immediate PolicyUpdate, if there isn't one already pending and |
137 // sets |policy_may_need_update_|. Note |any_thread_lock_| must be | 150 // sets |policy_may_need_update_|. Note |any_thread_lock_| must be |
138 // locked. | 151 // locked. |
139 void EnsureUrgentPolicyUpdatePostedOnMainThread( | 152 void EnsureUrgentPolicyUpdatePostedOnMainThread( |
140 const tracked_objects::Location& from_here); | 153 const tracked_objects::Location& from_here); |
141 | 154 |
142 // Update the policy if a new signal has arrived. Must be called from the main | 155 // Update the policy if a new signal has arrived. Must be called from the main |
143 // thread. | 156 // thread. |
144 void MaybeUpdatePolicy(); | 157 void MaybeUpdatePolicy(); |
145 | 158 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 IdleHelper idle_helper_; | 199 IdleHelper idle_helper_; |
187 | 200 |
188 const scoped_refptr<TaskQueue> control_task_runner_; | 201 const scoped_refptr<TaskQueue> control_task_runner_; |
189 const scoped_refptr<TaskQueue> compositor_task_runner_; | 202 const scoped_refptr<TaskQueue> compositor_task_runner_; |
190 const scoped_refptr<TaskQueue> loading_task_runner_; | 203 const scoped_refptr<TaskQueue> loading_task_runner_; |
191 const scoped_refptr<TaskQueue> timer_task_runner_; | 204 const scoped_refptr<TaskQueue> timer_task_runner_; |
192 | 205 |
193 base::Closure update_policy_closure_; | 206 base::Closure update_policy_closure_; |
194 DeadlineTaskRunner delayed_update_policy_runner_; | 207 DeadlineTaskRunner delayed_update_policy_runner_; |
195 CancelableClosureHolder end_renderer_hidden_idle_period_closure_; | 208 CancelableClosureHolder end_renderer_hidden_idle_period_closure_; |
209 CancelableClosureHolder suspend_timers_when_backgrounded_closure_; | |
196 | 210 |
197 // We have decided to improve thread safety at the cost of some boilerplate | 211 // We have decided to improve thread safety at the cost of some boilerplate |
198 // (the accessors) for the following data members. | 212 // (the accessors) for the following data members. |
199 | 213 |
200 struct MainThreadOnly { | 214 struct MainThreadOnly { |
201 MainThreadOnly(); | 215 MainThreadOnly(); |
202 ~MainThreadOnly(); | 216 ~MainThreadOnly(); |
203 | 217 |
204 TaskCostEstimator timer_task_cost_estimator_; | 218 TaskCostEstimator timer_task_cost_estimator_; |
205 cc::RollingTimeDeltaHistory short_idle_period_duration_; | 219 cc::RollingTimeDeltaHistory short_idle_period_duration_; |
206 Policy current_policy_; | 220 Policy current_policy_; |
207 base::TimeTicks current_policy_expiration_time_; | 221 base::TimeTicks current_policy_expiration_time_; |
208 base::TimeTicks estimated_next_frame_begin_; | 222 base::TimeTicks estimated_next_frame_begin_; |
209 base::TimeDelta expected_short_idle_period_duration_; | 223 base::TimeDelta expected_short_idle_period_duration_; |
210 int timer_queue_suspend_count_; // TIMER_TASK_QUEUE suspended if non-zero. | 224 int timer_queue_suspend_count_; // TIMER_TASK_QUEUE suspended if non-zero. |
211 bool renderer_hidden_; | 225 bool renderer_hidden_; |
226 bool renderer_backgrounded_; | |
227 bool timer_queue_suspended_for_backgrounded_renderer_; | |
212 bool was_shutdown_; | 228 bool was_shutdown_; |
213 }; | 229 }; |
214 | 230 |
215 struct AnyThread { | 231 struct AnyThread { |
216 AnyThread(); | 232 AnyThread(); |
217 | 233 |
218 base::TimeTicks last_input_signal_time_; | 234 base::TimeTicks last_input_signal_time_; |
219 base::TimeTicks last_idle_period_end_time_; | 235 base::TimeTicks last_idle_period_end_time_; |
220 base::TimeTicks rails_loading_priority_deadline_; | 236 base::TimeTicks rails_loading_priority_deadline_; |
221 int pending_main_thread_input_event_count_; | 237 int pending_main_thread_input_event_count_; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 | 291 |
276 PollableThreadSafeFlag policy_may_need_update_; | 292 PollableThreadSafeFlag policy_may_need_update_; |
277 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; | 293 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
278 | 294 |
279 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); | 295 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
280 }; | 296 }; |
281 | 297 |
282 } // namespace scheduler | 298 } // namespace scheduler |
283 | 299 |
284 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 300 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ |
OLD | NEW |