| 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/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "components/scheduler/renderer/web_view_scheduler_impl.h" | 24 #include "components/scheduler/renderer/web_view_scheduler_impl.h" |
| 25 #include "components/scheduler/scheduler_export.h" | 25 #include "components/scheduler/scheduler_export.h" |
| 26 | 26 |
| 27 namespace base { | 27 namespace base { |
| 28 namespace trace_event { | 28 namespace trace_event { |
| 29 class ConvertableToTraceFormat; | 29 class ConvertableToTraceFormat; |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 namespace scheduler { | 33 namespace scheduler { |
| 34 class AutoAdvancingVirtualTimeDomain; |
| 34 class RenderWidgetSchedulingState; | 35 class RenderWidgetSchedulingState; |
| 35 class WebViewSchedulerImpl; | 36 class WebViewSchedulerImpl; |
| 36 class ThrottlingHelper; | 37 class ThrottlingHelper; |
| 37 | 38 |
| 38 class SCHEDULER_EXPORT RendererSchedulerImpl | 39 class SCHEDULER_EXPORT RendererSchedulerImpl |
| 39 : public RendererScheduler, | 40 : public RendererScheduler, |
| 40 public IdleHelper::Delegate, | 41 public IdleHelper::Delegate, |
| 41 public SchedulerHelper::Observer, | 42 public SchedulerHelper::Observer, |
| 42 public RenderWidgetSignals::Observer, | 43 public RenderWidgetSignals::Observer, |
| 43 public TaskTimeTracker, | 44 public TaskTimeTracker, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 138 |
| 138 // QueueingTimeEstimator::Client implementation: | 139 // QueueingTimeEstimator::Client implementation: |
| 139 void OnQueueingTimeForWindowEstimated(base::TimeDelta queueing_time) override; | 140 void OnQueueingTimeForWindowEstimated(base::TimeDelta queueing_time) override; |
| 140 | 141 |
| 141 // Returns a task runner where tasks run at the highest possible priority. | 142 // Returns a task runner where tasks run at the highest possible priority. |
| 142 scoped_refptr<TaskQueue> ControlTaskRunner(); | 143 scoped_refptr<TaskQueue> ControlTaskRunner(); |
| 143 | 144 |
| 144 void RegisterTimeDomain(TimeDomain* time_domain); | 145 void RegisterTimeDomain(TimeDomain* time_domain); |
| 145 void UnregisterTimeDomain(TimeDomain* time_domain); | 146 void UnregisterTimeDomain(TimeDomain* time_domain); |
| 146 | 147 |
| 148 // Tells the scheduler that all TaskQueues should use virtual time. |
| 149 void EnableVirtualTime(); |
| 150 |
| 147 void SetExpensiveTaskBlockingAllowed(bool allowed); | 151 void SetExpensiveTaskBlockingAllowed(bool allowed); |
| 148 | 152 |
| 149 void AddWebViewScheduler(WebViewSchedulerImpl* web_view_scheduler); | 153 void AddWebViewScheduler(WebViewSchedulerImpl* web_view_scheduler); |
| 150 void RemoveWebViewScheduler(WebViewSchedulerImpl* web_view_scheduler); | 154 void RemoveWebViewScheduler(WebViewSchedulerImpl* web_view_scheduler); |
| 151 | 155 |
| 152 LongTaskTracker::LongTaskTiming GetLongTaskTiming(); | 156 LongTaskTracker::LongTaskTiming GetLongTaskTiming(); |
| 153 | 157 |
| 154 // Test helpers. | 158 // Test helpers. |
| 155 SchedulerHelper* GetSchedulerHelperForTesting(); | 159 SchedulerHelper* GetSchedulerHelperForTesting(); |
| 156 TaskCostEstimator* GetLoadingTaskCostEstimatorForTesting(); | 160 TaskCostEstimator* GetLoadingTaskCostEstimatorForTesting(); |
| 157 TaskCostEstimator* GetTimerTaskCostEstimatorForTesting(); | 161 TaskCostEstimator* GetTimerTaskCostEstimatorForTesting(); |
| 158 IdleTimeEstimator* GetIdleTimeEstimatorForTesting(); | 162 IdleTimeEstimator* GetIdleTimeEstimatorForTesting(); |
| 159 base::TimeTicks CurrentIdleTaskDeadlineForTesting() const; | 163 base::TimeTicks CurrentIdleTaskDeadlineForTesting() const; |
| 160 void RunIdleTasksForTesting(const base::Closure& callback); | 164 void RunIdleTasksForTesting(const base::Closure& callback); |
| 161 void EndIdlePeriodForTesting(const base::Closure& callback, | 165 void EndIdlePeriodForTesting(const base::Closure& callback, |
| 162 base::TimeTicks time_remaining); | 166 base::TimeTicks time_remaining); |
| 163 bool PolicyNeedsUpdateForTesting(); | 167 bool PolicyNeedsUpdateForTesting(); |
| 164 | 168 |
| 165 base::TickClock* tick_clock() const; | 169 base::TickClock* tick_clock() const; |
| 166 | 170 |
| 167 RealTimeDomain* real_time_domain() const { | 171 RealTimeDomain* real_time_domain() const { |
| 168 return helper_.real_time_domain(); | 172 return helper_.real_time_domain(); |
| 169 } | 173 } |
| 170 | 174 |
| 175 AutoAdvancingVirtualTimeDomain* GetVirtualTimeDomain(); |
| 176 |
| 171 ThrottlingHelper* throttling_helper() { return throttling_helper_.get(); } | 177 ThrottlingHelper* throttling_helper() { return throttling_helper_.get(); } |
| 172 | 178 |
| 173 private: | 179 private: |
| 174 friend class RendererSchedulerImplTest; | 180 friend class RendererSchedulerImplTest; |
| 175 friend class RendererSchedulerImplForTest; | 181 friend class RendererSchedulerImplForTest; |
| 176 friend class RenderWidgetSchedulingState; | 182 friend class RenderWidgetSchedulingState; |
| 177 | 183 |
| 178 enum class ExpensiveTaskPolicy { RUN, BLOCK, THROTTLE }; | 184 enum class ExpensiveTaskPolicy { RUN, BLOCK, THROTTLE }; |
| 179 | 185 |
| 180 enum class TimeDomainType { | 186 enum class TimeDomainType { |
| 181 REAL, | 187 REAL, |
| 182 THROTTLED, | 188 THROTTLED, |
| 189 VIRTUAL, |
| 183 }; | 190 }; |
| 184 | 191 |
| 185 struct TaskQueuePolicy { | 192 struct TaskQueuePolicy { |
| 186 TaskQueuePolicy() | 193 TaskQueuePolicy() |
| 187 : is_enabled(true), | 194 : is_enabled(true), |
| 188 priority(TaskQueue::NORMAL_PRIORITY), | 195 priority(TaskQueue::NORMAL_PRIORITY), |
| 189 time_domain_type(TimeDomainType::REAL) {} | 196 time_domain_type(TimeDomainType::REAL) {} |
| 190 | 197 |
| 191 bool is_enabled; | 198 bool is_enabled; |
| 192 TaskQueue::QueuePriority priority; | 199 TaskQueue::QueuePriority priority; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 354 |
| 348 SchedulerHelper helper_; | 355 SchedulerHelper helper_; |
| 349 IdleHelper idle_helper_; | 356 IdleHelper idle_helper_; |
| 350 std::unique_ptr<ThrottlingHelper> throttling_helper_; | 357 std::unique_ptr<ThrottlingHelper> throttling_helper_; |
| 351 RenderWidgetSignals render_widget_scheduler_signals_; | 358 RenderWidgetSignals render_widget_scheduler_signals_; |
| 352 | 359 |
| 353 const scoped_refptr<TaskQueue> control_task_runner_; | 360 const scoped_refptr<TaskQueue> control_task_runner_; |
| 354 const scoped_refptr<TaskQueue> compositor_task_runner_; | 361 const scoped_refptr<TaskQueue> compositor_task_runner_; |
| 355 std::set<scoped_refptr<TaskQueue>> loading_task_runners_; | 362 std::set<scoped_refptr<TaskQueue>> loading_task_runners_; |
| 356 std::set<scoped_refptr<TaskQueue>> timer_task_runners_; | 363 std::set<scoped_refptr<TaskQueue>> timer_task_runners_; |
| 364 std::set<scoped_refptr<TaskQueue>> unthrottled_task_runners_; |
| 357 scoped_refptr<TaskQueue> default_loading_task_runner_; | 365 scoped_refptr<TaskQueue> default_loading_task_runner_; |
| 358 scoped_refptr<TaskQueue> default_timer_task_runner_; | 366 scoped_refptr<TaskQueue> default_timer_task_runner_; |
| 359 | 367 |
| 368 // Note |virtual_time_domain_| is lazily created. |
| 369 std::unique_ptr<AutoAdvancingVirtualTimeDomain> virtual_time_domain_; |
| 370 |
| 360 base::Closure update_policy_closure_; | 371 base::Closure update_policy_closure_; |
| 361 DeadlineTaskRunner delayed_update_policy_runner_; | 372 DeadlineTaskRunner delayed_update_policy_runner_; |
| 362 CancelableClosureHolder end_renderer_hidden_idle_period_closure_; | 373 CancelableClosureHolder end_renderer_hidden_idle_period_closure_; |
| 363 CancelableClosureHolder suspend_timers_when_backgrounded_closure_; | 374 CancelableClosureHolder suspend_timers_when_backgrounded_closure_; |
| 364 | 375 |
| 365 // We have decided to improve thread safety at the cost of some boilerplate | 376 // We have decided to improve thread safety at the cost of some boilerplate |
| 366 // (the accessors) for the following data members. | 377 // (the accessors) for the following data members. |
| 367 | 378 |
| 368 struct MainThreadOnly { | 379 struct MainThreadOnly { |
| 369 MainThreadOnly(RendererSchedulerImpl* renderer_scheduler_impl, | 380 MainThreadOnly(RendererSchedulerImpl* renderer_scheduler_impl, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 394 bool loading_tasks_seem_expensive; | 405 bool loading_tasks_seem_expensive; |
| 395 bool timer_tasks_seem_expensive; | 406 bool timer_tasks_seem_expensive; |
| 396 bool touchstart_expected_soon; | 407 bool touchstart_expected_soon; |
| 397 bool have_seen_a_begin_main_frame; | 408 bool have_seen_a_begin_main_frame; |
| 398 bool have_reported_blocking_intervention_in_current_policy; | 409 bool have_reported_blocking_intervention_in_current_policy; |
| 399 bool have_reported_blocking_intervention_since_navigation; | 410 bool have_reported_blocking_intervention_since_navigation; |
| 400 bool has_visible_render_widget_with_touch_handler; | 411 bool has_visible_render_widget_with_touch_handler; |
| 401 bool begin_frame_not_expected_soon; | 412 bool begin_frame_not_expected_soon; |
| 402 bool expensive_task_blocking_allowed; | 413 bool expensive_task_blocking_allowed; |
| 403 bool in_idle_period_for_testing; | 414 bool in_idle_period_for_testing; |
| 415 bool use_virtual_time; |
| 404 std::set<WebViewSchedulerImpl*> web_view_schedulers; // Not owned. | 416 std::set<WebViewSchedulerImpl*> web_view_schedulers; // Not owned. |
| 405 RAILModeObserver* rail_mode_observer; // Not owned. | 417 RAILModeObserver* rail_mode_observer; // Not owned. |
| 406 }; | 418 }; |
| 407 | 419 |
| 408 struct AnyThread { | 420 struct AnyThread { |
| 409 AnyThread(); | 421 AnyThread(); |
| 410 ~AnyThread(); | 422 ~AnyThread(); |
| 411 | 423 |
| 412 base::TimeTicks last_idle_period_end_time; | 424 base::TimeTicks last_idle_period_end_time; |
| 413 base::TimeTicks rails_loading_priority_deadline; | 425 base::TimeTicks rails_loading_priority_deadline; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 483 |
| 472 PollableThreadSafeFlag policy_may_need_update_; | 484 PollableThreadSafeFlag policy_may_need_update_; |
| 473 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; | 485 base::WeakPtrFactory<RendererSchedulerImpl> weak_factory_; |
| 474 | 486 |
| 475 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); | 487 DISALLOW_COPY_AND_ASSIGN(RendererSchedulerImpl); |
| 476 }; | 488 }; |
| 477 | 489 |
| 478 } // namespace scheduler | 490 } // namespace scheduler |
| 479 | 491 |
| 480 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ | 492 #endif // COMPONENTS_SCHEDULER_RENDERER_RENDERER_SCHEDULER_IMPL_H_ |
| OLD | NEW |