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_RENDERER_TASK_QUEUE_THROTTL
ER_H_ | 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTL
ER_H_ |
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTL
ER_H_ | 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THROTTL
ER_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 // policy reasons. To prevent the systems from fighting, clients of | 73 // policy reasons. To prevent the systems from fighting, clients of |
74 // TaskQueueThrottler must use SetQueueEnabled rather than calling the function | 74 // TaskQueueThrottler must use SetQueueEnabled rather than calling the function |
75 // directly on the queue. | 75 // directly on the queue. |
76 // | 76 // |
77 // There may be more than one system that wishes to throttle a queue (e.g. | 77 // There may be more than one system that wishes to throttle a queue (e.g. |
78 // renderer suspension vs tab level suspension) so the TaskQueueThrottler keeps | 78 // renderer suspension vs tab level suspension) so the TaskQueueThrottler keeps |
79 // a count of the number of systems that wish a queue to be throttled. | 79 // a count of the number of systems that wish a queue to be throttled. |
80 // See IncreaseThrottleRefCount & DecreaseThrottleRefCount. | 80 // See IncreaseThrottleRefCount & DecreaseThrottleRefCount. |
81 // | 81 // |
82 // This class is main-thread only. | 82 // This class is main-thread only. |
83 class BLINK_PLATFORM_EXPORT TaskQueueThrottler : public TimeDomain::Observer, | 83 class BLINK_PLATFORM_EXPORT TaskQueueThrottler : public TaskQueue::Observer, |
84 public BudgetPoolController { | 84 public BudgetPoolController { |
85 public: | 85 public: |
86 // TODO(altimin): Do not pass tracing category as const char*, | 86 // TODO(altimin): Do not pass tracing category as const char*, |
87 // hard-code string instead. | 87 // hard-code string instead. |
88 TaskQueueThrottler(RendererSchedulerImpl* renderer_scheduler, | 88 TaskQueueThrottler(RendererSchedulerImpl* renderer_scheduler, |
89 const char* tracing_category); | 89 const char* tracing_category); |
90 | 90 |
91 ~TaskQueueThrottler() override; | 91 ~TaskQueueThrottler() override; |
92 | 92 |
93 // TimeDomain::Observer implementation: | 93 // TaskQueue::Observer implementation: |
94 void OnTimeDomainHasImmediateWork(TaskQueue*) override; | 94 void OnQueueNextWakeUpChanged(TaskQueue* queue, |
95 void OnTimeDomainHasDelayedWork(TaskQueue*) override; | 95 base::TimeTicks wake_up) override; |
96 | 96 |
97 // BudgetPoolController implementation: | 97 // BudgetPoolController implementation: |
98 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool) override; | 98 void AddQueueToBudgetPool(TaskQueue* queue, BudgetPool* budget_pool) override; |
99 void RemoveQueueFromBudgetPool(TaskQueue* queue, | 99 void RemoveQueueFromBudgetPool(TaskQueue* queue, |
100 BudgetPool* budget_pool) override; | 100 BudgetPool* budget_pool) override; |
101 void UnregisterBudgetPool(BudgetPool* budget_pool) override; | 101 void UnregisterBudgetPool(BudgetPool* budget_pool) override; |
102 void BlockQueue(base::TimeTicks now, TaskQueue* queue) override; | 102 void BlockQueue(base::TimeTicks now, TaskQueue* queue) override; |
103 void UnblockQueue(base::TimeTicks now, TaskQueue* queue) override; | 103 void UnblockQueue(base::TimeTicks now, TaskQueue* queue) override; |
104 bool IsThrottled(TaskQueue* queue) const override; | 104 bool IsThrottled(TaskQueue* queue) const override; |
105 | 105 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 base::TimeTicks GetNextAllowedRunTime(base::TimeTicks now, TaskQueue* queue); | 165 base::TimeTicks GetNextAllowedRunTime(base::TimeTicks now, TaskQueue* queue); |
166 | 166 |
167 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); | 167 void MaybeDeleteQueueMetadata(TaskQueueMap::iterator it); |
168 | 168 |
169 // Schedule a call PumpThrottledTasks at an appropriate moment for this queue. | 169 // Schedule a call PumpThrottledTasks at an appropriate moment for this queue. |
170 void SchedulePumpQueue(const tracked_objects::Location& from_here, | 170 void SchedulePumpQueue(const tracked_objects::Location& from_here, |
171 base::TimeTicks now, | 171 base::TimeTicks now, |
172 TaskQueue* queue); | 172 TaskQueue* queue); |
173 | 173 |
174 TaskQueueMap queue_details_; | 174 TaskQueueMap queue_details_; |
175 base::Callback<void(TaskQueue*)> forward_immediate_work_callback_; | 175 base::Callback<void(TaskQueue*, base::TimeTicks)> |
| 176 forward_immediate_work_callback_; |
176 scoped_refptr<TaskQueue> task_runner_; | 177 scoped_refptr<TaskQueue> task_runner_; |
177 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED | 178 RendererSchedulerImpl* renderer_scheduler_; // NOT OWNED |
178 base::TickClock* tick_clock_; // NOT OWNED | 179 base::TickClock* tick_clock_; // NOT OWNED |
179 const char* tracing_category_; // NOT OWNED | 180 const char* tracing_category_; // NOT OWNED |
180 std::unique_ptr<ThrottledTimeDomain> time_domain_; | 181 std::unique_ptr<ThrottledTimeDomain> time_domain_; |
181 | 182 |
182 CancelableClosureHolder pump_throttled_tasks_closure_; | 183 CancelableClosureHolder pump_throttled_tasks_closure_; |
183 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; | 184 base::Optional<base::TimeTicks> pending_pump_throttled_tasks_runtime_; |
184 bool allow_throttling_; | 185 bool allow_throttling_; |
185 | 186 |
186 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_; | 187 std::unordered_map<BudgetPool*, std::unique_ptr<BudgetPool>> budget_pools_; |
187 | 188 |
188 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; | 189 base::WeakPtrFactory<TaskQueueThrottler> weak_factory_; |
189 | 190 |
190 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); | 191 DISALLOW_COPY_AND_ASSIGN(TaskQueueThrottler); |
191 }; | 192 }; |
192 | 193 |
193 } // namespace scheduler | 194 } // namespace scheduler |
194 } // namespace blink | 195 } // namespace blink |
195 | 196 |
196 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO
TTLER_H_ | 197 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_RENDERER_TASK_QUEUE_THRO
TTLER_H_ |
OLD | NEW |