OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "platform/scheduler/base/cancelable_closure_holder.h" | 10 #include "platform/scheduler/base/cancelable_closure_holder.h" |
11 #include "platform/scheduler/base/task_queue_selector.h" | 11 #include "platform/scheduler/base/task_queue_selector.h" |
12 #include "platform/scheduler/child/scheduler_helper.h" | 12 #include "platform/scheduler/child/scheduler_helper.h" |
13 #include "public/platform/scheduler/child/single_thread_idle_task_runner.h" | 13 #include "public/platform/scheduler/child/single_thread_idle_task_runner.h" |
14 #include "public/platform/WebCommon.h" | 14 #include "public/platform/WebCommon.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 namespace scheduler { | 17 namespace scheduler { |
18 | 18 |
19 class SchedulerHelper; | 19 class SchedulerHelper; |
20 | 20 |
21 // Common scheduler functionality for Idle tasks. | 21 // The job of the IdleHelper is to run idle tasks when the system is otherwise |
22 // idle. Idle tasks should be optional work, with no guarantee they will be run | |
23 // at all. Idle tasks are subject to three levels of throttling: | |
24 // | |
25 // 1. Both idle queues are run a BEST_EFFORT priority (i.e. only selected if | |
26 // there is noting else to do. | |
Sami
2016/08/25 15:54:13
typo: nothing
alex clarke (OOO till 29th)
2016/08/26 13:29:08
Done.
| |
27 // 2. The idle queues are only enabled during an idle period. | |
28 // 3. Idle tasks posted from within an idle task run in the next idle period. | |
29 // This is achieved by posting DisableIdleTaskQueueTask or | |
30 // DisableNonNestableIdleTaskQueueTask before enabling the queues. | |
31 // | |
32 // There are two types of idle periods: | |
33 // 1. Short idle period - typically less than 10ms run after begin main frame | |
34 // has finished, with the idle period ending at the compositor provided | |
35 // deadline. | |
36 // 2. Long idle periods - typically more than 50ms when no frames are being | |
Sami
2016/08/25 15:54:13
s/more than/up to/
alex clarke (OOO till 29th)
2016/08/26 13:29:08
Done.
| |
37 // produced. | |
38 // | |
39 // Idle tasks are supplied a deadline, and should endeavor to finished before it | |
40 // ends to avoid jank. | |
22 class BLINK_PLATFORM_EXPORT IdleHelper | 41 class BLINK_PLATFORM_EXPORT IdleHelper |
23 : public base::MessageLoop::TaskObserver, | 42 : public base::MessageLoop::TaskObserver, |
24 public SingleThreadIdleTaskRunner::Delegate { | 43 public SingleThreadIdleTaskRunner::Delegate { |
25 public: | 44 public: |
26 // Used to by scheduler implementations to customize idle behaviour. | 45 // Used to by scheduler implementations to customize idle behaviour. |
27 class BLINK_PLATFORM_EXPORT Delegate { | 46 class BLINK_PLATFORM_EXPORT Delegate { |
28 public: | 47 public: |
29 Delegate(); | 48 Delegate(); |
30 virtual ~Delegate(); | 49 virtual ~Delegate(); |
31 | 50 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 base::TimeDelta* next_long_idle_period_delay_out); | 204 base::TimeDelta* next_long_idle_period_delay_out); |
186 | 205 |
187 bool ShouldWaitForQuiescence(); | 206 bool ShouldWaitForQuiescence(); |
188 void OnIdleTaskPostedOnMainThread(); | 207 void OnIdleTaskPostedOnMainThread(); |
189 void UpdateLongIdlePeriodStateAfterIdleTask(); | 208 void UpdateLongIdlePeriodStateAfterIdleTask(); |
190 | 209 |
191 void SetIdlePeriodState(IdlePeriodState new_state, | 210 void SetIdlePeriodState(IdlePeriodState new_state, |
192 base::TimeTicks new_deadline, | 211 base::TimeTicks new_deadline, |
193 base::TimeTicks optional_now); | 212 base::TimeTicks optional_now); |
194 | 213 |
214 void DisableIdleTaskQueueTask(); | |
215 void DisableNonNestableIdleTaskQueueTask(); | |
216 | |
195 // Returns true if |state| represents being within an idle period state. | 217 // Returns true if |state| represents being within an idle period state. |
196 static bool IsInIdlePeriod(IdlePeriodState state); | 218 static bool IsInIdlePeriod(IdlePeriodState state); |
197 // Returns true if |state| represents being within a long idle period state. | 219 // Returns true if |state| represents being within a long idle period state. |
198 static bool IsInLongIdlePeriod(IdlePeriodState state); | 220 static bool IsInLongIdlePeriod(IdlePeriodState state); |
199 | 221 |
200 SchedulerHelper* helper_; // NOT OWNED | 222 SchedulerHelper* helper_; // NOT OWNED |
201 Delegate* delegate_; // NOT OWNED | 223 Delegate* delegate_; // NOT OWNED |
224 | |
225 // We want to ensure idle tasks run in the next idle period. This necessitates | |
226 // two idle queues because we do this via posting a task to disable the queue | |
227 // and non-nestable tasks execution can be deferred, meaning we end up with | |
228 // the situation where we don't want any more nestable tasks to run but the | |
229 // non-nestable ones have yet to run. | |
202 scoped_refptr<TaskQueue> idle_queue_; | 230 scoped_refptr<TaskQueue> idle_queue_; |
231 scoped_refptr<TaskQueue> non_nestable_idle_queue_; | |
203 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; | 232 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; |
204 | 233 |
205 CancelableClosureHolder enable_next_long_idle_period_closure_; | 234 CancelableClosureHolder enable_next_long_idle_period_closure_; |
206 CancelableClosureHolder on_idle_task_posted_closure_; | 235 CancelableClosureHolder on_idle_task_posted_closure_; |
236 CancelableClosureHolder disable_idle_queue_closure_; | |
237 CancelableClosureHolder disable_non_nestable_idle_queue_closure_; | |
207 | 238 |
208 State state_; | 239 State state_; |
209 | 240 |
210 base::TimeDelta required_quiescence_duration_before_long_idle_period_; | 241 base::TimeDelta required_quiescence_duration_before_long_idle_period_; |
211 | 242 |
212 const char* disabled_by_default_tracing_category_; | 243 const char* disabled_by_default_tracing_category_; |
213 | 244 |
214 base::WeakPtr<IdleHelper> weak_idle_helper_ptr_; | 245 base::WeakPtr<IdleHelper> weak_idle_helper_ptr_; |
215 base::WeakPtrFactory<IdleHelper> weak_factory_; | 246 base::WeakPtrFactory<IdleHelper> weak_factory_; |
216 | 247 |
217 DISALLOW_COPY_AND_ASSIGN(IdleHelper); | 248 DISALLOW_COPY_AND_ASSIGN(IdleHelper); |
218 }; | 249 }; |
219 | 250 |
220 } // namespace scheduler | 251 } // namespace scheduler |
221 } // namespace blink | 252 } // namespace blink |
222 | 253 |
223 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ | 254 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_CHILD_IDLE_HELPER_H_ |
OLD | NEW |