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

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

Issue 994833003: Prevent multiple pending UpdatePolicy tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactored 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 "base/threading/thread_checker.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override; 46 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer) override;
47 void RemoveTaskObserver( 47 void RemoveTaskObserver(
48 base::MessageLoop::TaskObserver* task_observer) override; 48 base::MessageLoop::TaskObserver* task_observer) override;
49 void Shutdown() override; 49 void Shutdown() override;
50 50
51 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); 51 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source);
52 void SetWorkBatchSizeForTesting(size_t work_batch_size); 52 void SetWorkBatchSizeForTesting(size_t work_batch_size);
53 53
54 private: 54 private:
55 friend class RendererSchedulerImplTest; 55 friend class RendererSchedulerImplTest;
56 friend class MockRendererSchedulerImpl;
56 57
57 // Keep RendererSchedulerImpl::TaskQueueIdToString in sync with this enum. 58 // Keep RendererSchedulerImpl::TaskQueueIdToString in sync with this enum.
58 enum QueueId { 59 enum QueueId {
59 DEFAULT_TASK_QUEUE, 60 DEFAULT_TASK_QUEUE,
60 COMPOSITOR_TASK_QUEUE, 61 COMPOSITOR_TASK_QUEUE,
61 LOADING_TASK_QUEUE, 62 LOADING_TASK_QUEUE,
62 IDLE_TASK_QUEUE, 63 IDLE_TASK_QUEUE,
63 CONTROL_TASK_QUEUE, 64 CONTROL_TASK_QUEUE,
64 CONTROL_TASK_AFTER_WAKEUP_QUEUE, 65 CONTROL_TASK_AFTER_WAKEUP_QUEUE,
65 // Must be the last entry. 66 // Must be the last entry.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 111
111 // The time we should stay in a priority-escalated mode after an input event. 112 // The time we should stay in a priority-escalated mode after an input event.
112 static const int kPriorityEscalationAfterInputMillis = 100; 113 static const int kPriorityEscalationAfterInputMillis = 100;
113 114
114 // IdleTaskDeadlineSupplier Implementation: 115 // IdleTaskDeadlineSupplier Implementation:
115 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const; 116 void CurrentIdleTaskDeadlineCallback(base::TimeTicks* deadline_out) const;
116 117
117 // Returns the current scheduler policy. Must be called from the main thread. 118 // Returns the current scheduler policy. Must be called from the main thread.
118 Policy SchedulerPolicy() const; 119 Policy SchedulerPolicy() const;
119 120
120 // Posts a call to UpdatePolicy on the control runner to be run after |delay| 121 // Schedules an immediate PolicyUpdate, if there isn't one already pending and
121 void PostUpdatePolicyOnControlRunner(base::TimeDelta delay); 122 // sets |policy_may_need_update_|. Note |incoming_signals_lock_| must be
123 // locked.
124 void ScheduleUrgentPolicyUpdate(const tracked_objects::Location& from_here);
125
126 // Schedules a delayed PolicyUpdate, if there isn't one already pending.
127 // Note |incoming_signals_lock_| must be locked.
128 void ScheduleDelayedPolicyUpdate(const tracked_objects::Location& from_here,
129 base::TimeDelta delay);
122 130
123 // Update the policy if a new signal has arrived. Must be called from the main 131 // Update the policy if a new signal has arrived. Must be called from the main
124 // thread. 132 // thread.
125 void MaybeUpdatePolicy(); 133 void MaybeUpdatePolicy();
126 134
127 // Updates the scheduler policy. Must be called from the main thread. 135 // Locks |incoming_signals_lock_| and calls UpdatePolicyLocked.
128 void UpdatePolicy(); 136 void UpdatePolicy();
Sami 2015/03/11 16:58:25 Maybe move this next to UpdatePolicyLocked()? The
alex clarke (OOO till 29th) 2015/03/12 13:41:32 Done.
129 137
138 // Locks |incoming_signals_lock_|, clears |pending_delayed_policy_update_| and
139 // calls UpdatePolicyLocked.
140 void DelayedPolicyUpdateTask();
Sami 2015/03/11 16:58:25 nit: Name this with a verb instead a noun to match
alex clarke (OOO till 29th) 2015/03/12 13:41:31 This function is gone.
141
142 // Updates the scheduler policy. Must be called from the main thread and
143 // |incoming_signals_lock_| must be locked.
144 virtual void UpdatePolicyLocked();
145
130 // Helper for computing the new policy. |new_policy_duration| will be filled 146 // Helper for computing the new policy. |new_policy_duration| will be filled
131 // with the amount of time after which the policy should be updated again. If 147 // with the amount of time after which the policy should be updated again. If
132 // the duration is zero, a new policy update will not be scheduled. Must be 148 // the duration is zero, a new policy update will not be scheduled. Must be
133 // called with |incoming_signals_lock_| held. 149 // called with |incoming_signals_lock_| held.
134 Policy ComputeNewPolicy(base::TimeDelta* new_policy_duration); 150 Policy ComputeNewPolicy(base::TimeDelta* new_policy_duration);
135 151
136 // 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.
137 void UpdateForInputEvent(blink::WebInputEvent::Type type); 153 void UpdateForInputEvent(blink::WebInputEvent::Type type);
138 154
139 // Called when a previously queued input event was processed. 155 // Called when a previously queued input event was processed.
(...skipping 11 matching lines...) Expand all
151 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_; 167 scoped_ptr<RendererTaskQueueSelector> renderer_task_queue_selector_;
152 scoped_ptr<TaskQueueManager> task_queue_manager_; 168 scoped_ptr<TaskQueueManager> task_queue_manager_;
153 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_; 169 scoped_refptr<base::SingleThreadTaskRunner> control_task_runner_;
154 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_; 170 scoped_refptr<base::SingleThreadTaskRunner> control_task_after_wakeup_runner_;
155 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_; 171 scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
156 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 172 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
157 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_; 173 scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
158 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_; 174 scoped_refptr<SingleThreadIdleTaskRunner> idle_task_runner_;
159 175
160 base::Closure update_policy_closure_; 176 base::Closure update_policy_closure_;
177 base::Closure delayed_update_policy_closure_;
rmcilroy 2015/03/11 17:15:07 I really think this should be a CancelableClosureH
Sami 2015/03/11 17:18:47 I think a good reason for avoiding cancellable clo
161 CancelableClosureHolder end_idle_period_closure_; 178 CancelableClosureHolder end_idle_period_closure_;
162 179
163 // Don't access current_policy_ directly, instead use SchedulerPolicy(). 180 // Don't access current_policy_ directly, instead use SchedulerPolicy().
164 Policy current_policy_; 181 Policy current_policy_;
165 182
166 base::TimeTicks estimated_next_frame_begin_; 183 base::TimeTicks estimated_next_frame_begin_;
167 184
168 // The incoming_signals_lock_ mutex protects access to all variables in the 185 // The incoming_signals_lock_ mutex protects access to all variables in the
169 // (contiguous) block below. 186 // (contiguous) block below.
170 base::Lock incoming_signals_lock_; 187 base::Lock incoming_signals_lock_;
171 base::TimeTicks last_input_receipt_time_on_compositor_; 188 base::TimeTicks last_input_receipt_time_on_compositor_;
172 base::TimeTicks last_input_process_time_on_main_; 189 base::TimeTicks last_input_process_time_on_main_;
173 blink::WebInputEvent::Type last_input_type_; 190 blink::WebInputEvent::Type last_input_type_;
174 InputStreamState input_stream_state_; 191 InputStreamState input_stream_state_;
175 PollableNeedsUpdateFlag policy_may_need_update_; 192 PollableNeedsUpdateFlag policy_may_need_update_;
193 bool pending_delayed_policy_update_;
176 194
177 scoped_refptr<cc::TestNowSource> time_source_; 195 scoped_refptr<cc::TestNowSource> time_source_;
178 196
179 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_; 197 base::WeakPtr<RendererSchedulerImpl> weak_renderer_scheduler_ptr_;
180 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; 198 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_;
181 199
182 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); 200 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl);
183 }; 201 };
184 202
185 } // namespace content 203 } // namespace content
186 204
187 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_ 205 #endif // CONTENT_RENDERER_SCHEDULER_RENDERER_SCHEDULER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698