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

Side by Side Diff: content/renderer/scheduler/renderer_scheduler_impl.h

Issue 1025323003: Introduce a SchedulerHelper in content/child/scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added the delegate Created 5 years, 9 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 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
6 #define CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 6 #define CONTENT_RENDERER_SCHEDULER_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 "base/threading/thread_checker.h" 10 #include "content/child/scheduler/scheduler_helper.h"
11 #include "cc/test/test_now_source.h"
12 #include "content/renderer/scheduler/cancelable_closure_holder.h"
13 #include "content/renderer/scheduler/deadline_task_runner.h" 11 #include "content/renderer/scheduler/deadline_task_runner.h"
14 #include "content/renderer/scheduler/renderer_scheduler.h" 12 #include "content/renderer/scheduler/renderer_scheduler.h"
15 #include "content/renderer/scheduler/single_thread_idle_task_runner.h"
16 #include "content/renderer/scheduler/task_queue_manager.h"
17 13
18 namespace base { 14 namespace base {
19 namespace trace_event { 15 namespace trace_event {
20 class ConvertableToTraceFormat; 16 class ConvertableToTraceFormat;
21 } 17 }
22 } 18 }
23 19
24 namespace content { 20 namespace content {
25 21
26 class RendererTaskQueueSelector; 22 class CONTENT_EXPORT RendererSchedulerImpl
27 class NestableSingleThreadTaskRunner; 23 : public RendererScheduler,
28 24 public SchedulerHelper::LongIdlePeriodDelegate {
29 class CONTENT_EXPORT RendererSchedulerImpl : public RendererScheduler {
30 public: 25 public:
31 RendererSchedulerImpl( 26 RendererSchedulerImpl(
32 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner); 27 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner);
33 ~RendererSchedulerImpl() override; 28 ~RendererSchedulerImpl() override;
34 29
35 // RendererScheduler implementation: 30 // RendererScheduler implementation:
36 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override; 31 scoped_refptr<base::SingleThreadTaskRunner> DefaultTaskRunner() override;
32 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override;
37 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override; 33 scoped_refptr<base::SingleThreadTaskRunner> CompositorTaskRunner() override;
38 scoped_refptr<SingleThreadIdleTaskRunner> IdleTaskRunner() override;
39 scoped_refptr<base::SingleThreadTaskRunner> LoadingTaskRunner() override; 34 scoped_refptr<base::SingleThreadTaskRunner> LoadingTaskRunner() override;
40 void WillBeginFrame(const cc::BeginFrameArgs& args) override; 35 void WillBeginFrame(const cc::BeginFrameArgs& args) override;
41 void BeginFrameNotExpectedSoon() override; 36 void BeginFrameNotExpectedSoon() override;
42 void DidCommitFrameToCompositor() override; 37 void DidCommitFrameToCompositor() override;
43 void DidReceiveInputEventOnCompositorThread( 38 void DidReceiveInputEventOnCompositorThread(
44 const blink::WebInputEvent& web_input_event) override; 39 const blink::WebInputEvent& web_input_event) override;
45 void DidAnimateForInputOnCompositorThread() override; 40 void DidAnimateForInputOnCompositorThread() override;
46 bool CanExceedIdleDeadlineIfRequired() const override;
47 bool IsHighPriorityWorkAnticipated() override; 41 bool IsHighPriorityWorkAnticipated() override;
48 bool ShouldYieldForHighPriorityWork() override; 42 bool ShouldYieldForHighPriorityWork() override;
43 bool CanExceedIdleDeadlineIfRequired() const override;
49 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; 44 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override;
50 void RemoveTaskObserver( 45 void RemoveTaskObserver(
51 base::MessageLoop::TaskObserver* task_observer) override; 46 base::MessageLoop::TaskObserver* task_observer) override;
52 void Shutdown() override; 47 void Shutdown() override;
53 48
54 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); 49 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source);
55 void SetWorkBatchSizeForTesting(size_t work_batch_size); 50 void SetWorkBatchSizeForTesting(size_t work_batch_size);
51 void CurrentIdleTaskDeadlineCallbackForTesting(
52 base::TimeTicks* deadline_out) const;
56 53
57 private: 54 private:
58 friend class RendererSchedulerImplTest; 55 friend class RendererSchedulerImplTest;
59 friend class RendererSchedulerImplForTest; 56 friend class RendererSchedulerImplForTest;
60 57
61 // Keep RendererSchedulerImpl::TaskQueueIdToString in sync with this enum. 58 // Keep RendererSchedulerImpl::TaskQueueIdToString in sync with this enum.
62 enum QueueId { 59 enum QueueId {
63 DEFAULT_TASK_QUEUE, 60 DEFAULT_TASK_QUEUE,
64 COMPOSITOR_TASK_QUEUE, 61 COMPOSITOR_TASK_QUEUE,
65 LOADING_TASK_QUEUE, 62 LOADING_TASK_QUEUE,
(...skipping 12 matching lines...) Expand all
78 }; 75 };
79 76
80 // Keep RendererSchedulerImpl::InputStreamStateToString in sync with this 77 // Keep RendererSchedulerImpl::InputStreamStateToString in sync with this
81 // enum. 78 // enum.
82 enum class InputStreamState { 79 enum class InputStreamState {
83 INACTIVE, 80 INACTIVE,
84 ACTIVE, 81 ACTIVE,
85 ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE 82 ACTIVE_AND_AWAITING_TOUCHSTART_RESPONSE
86 }; 83 };
87 84
88 // Keep RendererSchedulerImpl::IdlePeriodStateToString in sync with this enum.
89 enum class IdlePeriodState {
90 NOT_IN_IDLE_PERIOD,
91 IN_SHORT_IDLE_PERIOD,
92 IN_LONG_IDLE_PERIOD,
93 IN_LONG_IDLE_PERIOD_WITH_MAX_DEADLINE,
94 ENDING_LONG_IDLE_PERIOD
95 };
96
97 class PollableNeedsUpdateFlag { 85 class PollableNeedsUpdateFlag {
98 public: 86 public:
99 PollableNeedsUpdateFlag(base::Lock* write_lock); 87 PollableNeedsUpdateFlag(base::Lock* write_lock);
100 ~PollableNeedsUpdateFlag(); 88 ~PollableNeedsUpdateFlag();
101 89
102 // Set the flag. May only be called if |write_lock| is held. 90 // Set the flag. May only be called if |write_lock| is held.
103 void SetWhileLocked(bool value); 91 void SetWhileLocked(bool value);
104 92
105 // Returns true iff the flag is set to true. 93 // Returns true iff the flag is set to true.
106 bool IsSet() const; 94 bool IsSet() const;
107 95
108 private: 96 private:
109 base::subtle::Atomic32 flag_; 97 base::subtle::Atomic32 flag_;
110 base::Lock* write_lock_; // Not owned. 98 base::Lock* write_lock_; // Not owned.
111 99
112 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag); 100 DISALLOW_COPY_AND_ASSIGN(PollableNeedsUpdateFlag);
113 }; 101 };
114 102
103 // LongIdlePeriodDelegate implementation:
104 bool CanEnterLongIdlePeriod(
105 base::TimeTicks now,
106 base::TimeDelta* next_long_idle_period_delay_out) override;
107
115 // Returns the serialized scheduler state for tracing. 108 // Returns the serialized scheduler state for tracing.
116 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked( 109 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValueLocked(
117 base::TimeTicks optional_now) const; 110 base::TimeTicks optional_now) const;
118 static const char* TaskQueueIdToString(QueueId queue_id); 111 static const char* TaskQueueIdToString(QueueId queue_id);
119 static const char* PolicyToString(Policy policy); 112 static const char* PolicyToString(Policy policy);
120 static const char* InputStreamStateToString(InputStreamState state); 113 static const char* InputStreamStateToString(InputStreamState state);
121 static const char* IdlePeriodStateToString(IdlePeriodState state);
122 114
123 static InputStreamState ComputeNewInputStreamState( 115 static InputStreamState ComputeNewInputStreamState(
124 InputStreamState current_state, 116 InputStreamState current_state,
125 blink::WebInputEvent::Type new_input_event, 117 blink::WebInputEvent::Type new_input_event,
126 blink::WebInputEvent::Type last_input_event); 118 blink::WebInputEvent::Type last_input_event);
127 119
128 // The time we should stay in a priority-escalated mode after an input event. 120 // The time we should stay in a priority-escalated mode after an input event.
129 static const int kPriorityEscalationAfterInputMillis = 100; 121 static const int kPriorityEscalationAfterInputMillis = 100;
130 122
131 // The maximum length of an idle period.
132 static const int kMaximumIdlePeriodMillis = 50;
133
134 // The minimum delay to wait between retrying to initiate a long idle time.
135 static const int kRetryInitiateLongIdlePeriodDelayMillis = 1;
136
137 // IdleTaskDeadlineSupplier Implementation:
138 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const;
139
140 // Returns the current scheduler policy. Must be called from the main thread. 123 // Returns the current scheduler policy. Must be called from the main thread.
141 Policy SchedulerPolicy() const; 124 Policy SchedulerPolicy() const;
142 125
143 // Schedules an immediate PolicyUpdate, if there isn't one already pending and 126 // Schedules an immediate PolicyUpdate, if there isn't one already pending and
144 // sets |policy_may_need_update_|. Note |incoming_signals_lock_| must be 127 // sets |policy_may_need_update_|. Note |incoming_signals_lock_| must be
145 // locked. 128 // locked.
146 void EnsureUrgentPolicyUpdatePostedOnMainThread( 129 void EnsureUrgentPolicyUpdatePostedOnMainThread(
147 const tracked_objects::Location& from_here); 130 const tracked_objects::Location& from_here);
148 131
149 // Update the policy if a new signal has arrived. Must be called from the main 132 // Update the policy if a new signal has arrived. Must be called from the main
(...skipping 17 matching lines...) Expand all
167 base::TimeDelta* new_policy_duration); 150 base::TimeDelta* new_policy_duration);
168 151
169 // An input event of some sort happened, the policy may need updating. 152 // An input event of some sort happened, the policy may need updating.
170 void UpdateForInputEvent(blink::WebInputEvent::Type type); 153 void UpdateForInputEvent(blink::WebInputEvent::Type type);
171 154
172 // Called when a previously queued input event was processed. 155 // Called when a previously queued input event was processed.
173 // |begin_frame_time|, if non-zero, identifies the frame time at which the 156 // |begin_frame_time|, if non-zero, identifies the frame time at which the
174 // input was processed. 157 // input was processed.
175 void DidProcessInputEvent(base::TimeTicks begin_frame_time); 158 void DidProcessInputEvent(base::TimeTicks begin_frame_time);
176 159
177 // Returns the new idle period state for the next long idle period. Fills in 160 SchedulerHelper scheduler_helper_;
Sami 2015/03/27 01:15:55 nit: Just calling this helper_ could cut down on s
alex clarke (OOO till 29th) 2015/03/27 10:55:29 Done.
178 // |next_long_idle_period_delay_out| with the next time we should try to
179 // initiate the next idle period.
180 IdlePeriodState ComputeNewLongIdlePeriodState(
181 const base::TimeTicks now,
182 base::TimeDelta* next_long_idle_period_delay_out);
183 161
184 // Initiate a long idle period.
185 void InitiateLongIdlePeriod();
186 void InitiateLongIdlePeriodAfterWakeup();
187
188 // Start and end an idle period.
189 void StartIdlePeriod(IdlePeriodState new_idle_period_state);
190 void EndIdlePeriod();
191
192 // Returns true if |state| represents being within an idle period state.
193 static bool IsInIdlePeriod(IdlePeriodState state);
194
195 base::TimeTicks Now() const;
196
197 base::ThreadChecker main_thread_checker_;
198 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_;
199 scoped_ptr<TaskQueueManager> task_queue_manager_;
200 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
201 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_;
202 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
203 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 162 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
204 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 163 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
205 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
206 164
207 base::Closure update_policy_closure_; 165 base::Closure update_policy_closure_;
208 DeadlineTaskRunner delayed_update_policy_runner_; 166 DeadlineTaskRunner delayed_update_policy_runner_;
209 CancelableClosureHolder end_idle_period_closure_;
210 CancelableClosureHolder initiate_next_long_idle_period_closure_;
211 CancelableClosureHolder initiate_next_long_idle_period_after_wakeup_closure_;
212 167
213 // Don't access current_policy_ directly, instead use SchedulerPolicy(). 168 // Don't access current_policy_ directly, instead use SchedulerPolicy().
214 Policy current_policy_; 169 Policy current_policy_;
215 IdlePeriodState idle_period_state_;
216
217 base::TimeTicks estimated_next_frame_begin_;
218 base::TimeTicks current_policy_expiration_time_; 170 base::TimeTicks current_policy_expiration_time_;
219 171
220 // The incoming_signals_lock_ mutex protects access to all variables in the 172 // The incoming_signals_lock_ mutex protects access to all variables in the
221 // (contiguous) block below. 173 // (contiguous) block below.
222 base::Lock incoming_signals_lock_; 174 base::Lock incoming_signals_lock_;
223 base::TimeTicks last_input_receipt_time_on_compositor_; 175 base::TimeTicks last_input_receipt_time_on_compositor_;
224 base::TimeTicks last_input_process_time_on_main_; 176 base::TimeTicks last_input_process_time_on_main_;
225 blink::WebInputEvent::Type last_input_type_; 177 blink::WebInputEvent::Type last_input_type_;
226 InputStreamState input_stream_state_; 178 InputStreamState input_stream_state_;
227 PollableNeedsUpdateFlag policy_may_need_update_; 179 PollableNeedsUpdateFlag policy_may_need_update_;
228 180
229 scoped_refptr<cc::TestNowSource> time_source_;
230
231 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_;
232 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; 181 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_;
233 182
234 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); 183 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl);
235 }; 184 };
236 185
237 } // namespace content 186 } // namespace content
238 187
239 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 188 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698