Chromium Code Reviews| Index: components/scheduler/renderer/web_frame_scheduler_impl.cc |
| diff --git a/components/scheduler/renderer/web_frame_scheduler_impl.cc b/components/scheduler/renderer/web_frame_scheduler_impl.cc |
| index fba6b691b5c96ded5f4c44566bfd3f9bd137b95e..283cb9244fa0042be92e93bd8dce514fb8256ae5 100644 |
| --- a/components/scheduler/renderer/web_frame_scheduler_impl.cc |
| +++ b/components/scheduler/renderer/web_frame_scheduler_impl.cc |
| @@ -19,12 +19,15 @@ namespace scheduler { |
| WebFrameSchedulerImpl::WebFrameSchedulerImpl( |
| RendererSchedulerImpl* renderer_scheduler, |
| WebViewSchedulerImpl* parent_web_view_scheduler, |
| - base::trace_event::BlameContext* blame_context) |
| + base::trace_event::BlameContext* blame_context, |
| + bool allow_hidden_timer_throttling) |
| : renderer_scheduler_(renderer_scheduler), |
| parent_web_view_scheduler_(parent_web_view_scheduler), |
| blame_context_(blame_context), |
| frame_visible_(true), |
| - page_visible_(true) {} |
| + page_visible_(true), |
| + cross_origin_(false), |
| + allow_hidden_timer_throttling_(allow_hidden_timer_throttling) {} |
| WebFrameSchedulerImpl::~WebFrameSchedulerImpl() { |
| if (loading_task_queue_.get()) { |
| @@ -46,8 +49,21 @@ void WebFrameSchedulerImpl::DetachFromWebViewScheduler() { |
| } |
| void WebFrameSchedulerImpl::setFrameVisible(bool frame_visible) { |
| + DCHECK(parent_web_view_scheduler_); |
| + if (frame_visible_ == frame_visible) |
| + return; |
| + bool was_throttled = ShouldThrottleTimers(); |
| frame_visible_ = frame_visible; |
| - // TODO(alexclarke): Do something with this flag. |
| + UpdateTimerThrottling(was_throttled); |
| +} |
| + |
| +void WebFrameSchedulerImpl::setCrossOrigin(bool cross_origin) { |
| + DCHECK(parent_web_view_scheduler_); |
| + if (cross_origin_ == cross_origin) |
| + return; |
| + bool was_throttled = ShouldThrottleTimers(); |
| + cross_origin_ = cross_origin; |
| + UpdateTimerThrottling(was_throttled); |
| } |
| blink::WebTaskRunner* WebFrameSchedulerImpl::loadingTaskRunner() { |
| @@ -74,7 +90,7 @@ blink::WebTaskRunner* WebFrameSchedulerImpl::timerTaskRunner() { |
| if (parent_web_view_scheduler_->virtual_time_domain()) { |
| timer_task_queue_->SetTimeDomain( |
| parent_web_view_scheduler_->virtual_time_domain()); |
| - } else if (!page_visible_) { |
| + } else if (ShouldThrottleTimers()) { |
| renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( |
| timer_task_queue_.get()); |
| } |
| @@ -87,21 +103,9 @@ void WebFrameSchedulerImpl::setPageVisible(bool page_visible) { |
| DCHECK(parent_web_view_scheduler_); |
| if (page_visible_ == page_visible) |
| return; |
| - |
| + bool was_throttled = ShouldThrottleTimers(); |
| page_visible_ = page_visible; |
| - |
| - if (!timer_web_task_runner_ || |
| - parent_web_view_scheduler_->virtual_time_domain()) { |
| - return; |
| - } |
| - |
| - if (page_visible_) { |
| - renderer_scheduler_->throttling_helper()->DecreaseThrottleRefCount( |
| - timer_task_queue_.get()); |
| - } else { |
| - renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( |
| - timer_task_queue_.get()); |
| - } |
| + UpdateTimerThrottling(was_throttled); |
| } |
| void WebFrameSchedulerImpl::OnVirtualTimeDomainChanged() { |
| @@ -121,4 +125,24 @@ void WebFrameSchedulerImpl::OnVirtualTimeDomainChanged() { |
| } |
| } |
| +bool WebFrameSchedulerImpl::ShouldThrottleTimers() const { |
| + return !page_visible_ || |
| + (allow_hidden_timer_throttling_ && !frame_visible_ && cross_origin_); |
| +} |
| + |
| +void WebFrameSchedulerImpl::UpdateTimerThrottling(bool was_throttled) { |
| + bool should_throttle = ShouldThrottleTimers(); |
| + if (was_throttled == should_throttle || !timer_web_task_runner_ || |
| + parent_web_view_scheduler_->virtual_time_domain()) { |
|
alex clarke (OOO till 29th)
2016/06/28 17:11:28
This probably needs a comment explaining that we d
Sami
2016/06/28 17:22:45
Good point, done. (At some point we'll need to dec
|
| + return; |
| + } |
| + if (should_throttle) { |
| + renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( |
| + timer_task_queue_.get()); |
| + } else { |
| + renderer_scheduler_->throttling_helper()->DecreaseThrottleRefCount( |
| + timer_task_queue_.get()); |
| + } |
| +} |
| + |
| } // namespace scheduler |