Chromium Code Reviews| 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 #include "components/scheduler/renderer/web_frame_scheduler_impl.h" | 5 #include "components/scheduler/renderer/web_frame_scheduler_impl.h" |
| 6 | 6 |
| 7 #include "base/trace_event/blame_context.h" | 7 #include "base/trace_event/blame_context.h" |
| 8 #include "components/scheduler/base/real_time_domain.h" | 8 #include "components/scheduler/base/real_time_domain.h" |
| 9 #include "components/scheduler/base/virtual_time_domain.h" | 9 #include "components/scheduler/base/virtual_time_domain.h" |
| 10 #include "components/scheduler/child/web_task_runner_impl.h" | 10 #include "components/scheduler/child/web_task_runner_impl.h" |
| 11 #include "components/scheduler/renderer/auto_advancing_virtual_time_domain.h" | 11 #include "components/scheduler/renderer/auto_advancing_virtual_time_domain.h" |
| 12 #include "components/scheduler/renderer/renderer_scheduler_impl.h" | 12 #include "components/scheduler/renderer/renderer_scheduler_impl.h" |
| 13 #include "components/scheduler/renderer/web_view_scheduler_impl.h" | 13 #include "components/scheduler/renderer/web_view_scheduler_impl.h" |
| 14 #include "third_party/WebKit/public/platform/BlameContext.h" | 14 #include "third_party/WebKit/public/platform/BlameContext.h" |
| 15 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
| 16 | 16 |
| 17 namespace scheduler { | 17 namespace scheduler { |
| 18 | 18 |
| 19 WebFrameSchedulerImpl::WebFrameSchedulerImpl( | 19 WebFrameSchedulerImpl::WebFrameSchedulerImpl( |
| 20 RendererSchedulerImpl* renderer_scheduler, | 20 RendererSchedulerImpl* renderer_scheduler, |
| 21 WebViewSchedulerImpl* parent_web_view_scheduler, | 21 WebViewSchedulerImpl* parent_web_view_scheduler, |
| 22 base::trace_event::BlameContext* blame_context) | 22 base::trace_event::BlameContext* blame_context, |
| 23 bool allow_hidden_timer_throttling) | |
| 23 : renderer_scheduler_(renderer_scheduler), | 24 : renderer_scheduler_(renderer_scheduler), |
| 24 parent_web_view_scheduler_(parent_web_view_scheduler), | 25 parent_web_view_scheduler_(parent_web_view_scheduler), |
| 25 blame_context_(blame_context), | 26 blame_context_(blame_context), |
| 26 frame_visible_(true), | 27 frame_visible_(true), |
| 27 page_visible_(true) {} | 28 page_visible_(true), |
| 29 cross_origin_(false), | |
| 30 allow_hidden_timer_throttling_(allow_hidden_timer_throttling) {} | |
| 28 | 31 |
| 29 WebFrameSchedulerImpl::~WebFrameSchedulerImpl() { | 32 WebFrameSchedulerImpl::~WebFrameSchedulerImpl() { |
| 30 if (loading_task_queue_.get()) { | 33 if (loading_task_queue_.get()) { |
| 31 loading_task_queue_->UnregisterTaskQueue(); | 34 loading_task_queue_->UnregisterTaskQueue(); |
| 32 loading_task_queue_->SetBlameContext(nullptr); | 35 loading_task_queue_->SetBlameContext(nullptr); |
| 33 } | 36 } |
| 34 | 37 |
| 35 if (timer_task_queue_.get()) { | 38 if (timer_task_queue_.get()) { |
| 36 timer_task_queue_->UnregisterTaskQueue(); | 39 timer_task_queue_->UnregisterTaskQueue(); |
| 37 timer_task_queue_->SetBlameContext(nullptr); | 40 timer_task_queue_->SetBlameContext(nullptr); |
| 38 } | 41 } |
| 39 | 42 |
| 40 if (parent_web_view_scheduler_) | 43 if (parent_web_view_scheduler_) |
| 41 parent_web_view_scheduler_->Unregister(this); | 44 parent_web_view_scheduler_->Unregister(this); |
| 42 } | 45 } |
| 43 | 46 |
| 44 void WebFrameSchedulerImpl::DetachFromWebViewScheduler() { | 47 void WebFrameSchedulerImpl::DetachFromWebViewScheduler() { |
| 45 parent_web_view_scheduler_ = nullptr; | 48 parent_web_view_scheduler_ = nullptr; |
| 46 } | 49 } |
| 47 | 50 |
| 48 void WebFrameSchedulerImpl::setFrameVisible(bool frame_visible) { | 51 void WebFrameSchedulerImpl::setFrameVisible(bool frame_visible) { |
| 52 DCHECK(parent_web_view_scheduler_); | |
| 53 if (frame_visible_ == frame_visible) | |
| 54 return; | |
| 55 bool was_throttled = ShouldThrottleTimers(); | |
| 49 frame_visible_ = frame_visible; | 56 frame_visible_ = frame_visible; |
| 50 // TODO(alexclarke): Do something with this flag. | 57 UpdateTimerThrottling(was_throttled); |
| 58 } | |
| 59 | |
| 60 void WebFrameSchedulerImpl::setCrossOrigin(bool cross_origin) { | |
| 61 DCHECK(parent_web_view_scheduler_); | |
| 62 if (cross_origin_ == cross_origin) | |
| 63 return; | |
| 64 bool was_throttled = ShouldThrottleTimers(); | |
| 65 cross_origin_ = cross_origin; | |
| 66 UpdateTimerThrottling(was_throttled); | |
| 51 } | 67 } |
| 52 | 68 |
| 53 blink::WebTaskRunner* WebFrameSchedulerImpl::loadingTaskRunner() { | 69 blink::WebTaskRunner* WebFrameSchedulerImpl::loadingTaskRunner() { |
| 54 DCHECK(parent_web_view_scheduler_); | 70 DCHECK(parent_web_view_scheduler_); |
| 55 if (!loading_web_task_runner_) { | 71 if (!loading_web_task_runner_) { |
| 56 loading_task_queue_ = | 72 loading_task_queue_ = |
| 57 renderer_scheduler_->NewLoadingTaskRunner("frame_loading_tq"); | 73 renderer_scheduler_->NewLoadingTaskRunner("frame_loading_tq"); |
| 58 loading_task_queue_->SetBlameContext(blame_context_); | 74 loading_task_queue_->SetBlameContext(blame_context_); |
| 59 if (parent_web_view_scheduler_->virtual_time_domain()) { | 75 if (parent_web_view_scheduler_->virtual_time_domain()) { |
| 60 loading_task_queue_->SetTimeDomain( | 76 loading_task_queue_->SetTimeDomain( |
| 61 parent_web_view_scheduler_->virtual_time_domain()); | 77 parent_web_view_scheduler_->virtual_time_domain()); |
| 62 } | 78 } |
| 63 loading_web_task_runner_.reset(new WebTaskRunnerImpl(loading_task_queue_)); | 79 loading_web_task_runner_.reset(new WebTaskRunnerImpl(loading_task_queue_)); |
| 64 } | 80 } |
| 65 return loading_web_task_runner_.get(); | 81 return loading_web_task_runner_.get(); |
| 66 } | 82 } |
| 67 | 83 |
| 68 blink::WebTaskRunner* WebFrameSchedulerImpl::timerTaskRunner() { | 84 blink::WebTaskRunner* WebFrameSchedulerImpl::timerTaskRunner() { |
| 69 DCHECK(parent_web_view_scheduler_); | 85 DCHECK(parent_web_view_scheduler_); |
| 70 if (!timer_web_task_runner_) { | 86 if (!timer_web_task_runner_) { |
| 71 timer_task_queue_ = | 87 timer_task_queue_ = |
| 72 renderer_scheduler_->NewTimerTaskRunner("frame_timer_tq"); | 88 renderer_scheduler_->NewTimerTaskRunner("frame_timer_tq"); |
| 73 timer_task_queue_->SetBlameContext(blame_context_); | 89 timer_task_queue_->SetBlameContext(blame_context_); |
| 74 if (parent_web_view_scheduler_->virtual_time_domain()) { | 90 if (parent_web_view_scheduler_->virtual_time_domain()) { |
| 75 timer_task_queue_->SetTimeDomain( | 91 timer_task_queue_->SetTimeDomain( |
| 76 parent_web_view_scheduler_->virtual_time_domain()); | 92 parent_web_view_scheduler_->virtual_time_domain()); |
| 77 } else if (!page_visible_) { | 93 } else if (ShouldThrottleTimers()) { |
| 78 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( | 94 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( |
| 79 timer_task_queue_.get()); | 95 timer_task_queue_.get()); |
| 80 } | 96 } |
| 81 timer_web_task_runner_.reset(new WebTaskRunnerImpl(timer_task_queue_)); | 97 timer_web_task_runner_.reset(new WebTaskRunnerImpl(timer_task_queue_)); |
| 82 } | 98 } |
| 83 return timer_web_task_runner_.get(); | 99 return timer_web_task_runner_.get(); |
| 84 } | 100 } |
| 85 | 101 |
| 86 void WebFrameSchedulerImpl::setPageVisible(bool page_visible) { | 102 void WebFrameSchedulerImpl::setPageVisible(bool page_visible) { |
| 87 DCHECK(parent_web_view_scheduler_); | 103 DCHECK(parent_web_view_scheduler_); |
| 88 if (page_visible_ == page_visible) | 104 if (page_visible_ == page_visible) |
| 89 return; | 105 return; |
| 90 | 106 bool was_throttled = ShouldThrottleTimers(); |
| 91 page_visible_ = page_visible; | 107 page_visible_ = page_visible; |
| 92 | 108 UpdateTimerThrottling(was_throttled); |
| 93 if (!timer_web_task_runner_ || | |
| 94 parent_web_view_scheduler_->virtual_time_domain()) { | |
| 95 return; | |
| 96 } | |
| 97 | |
| 98 if (page_visible_) { | |
| 99 renderer_scheduler_->throttling_helper()->DecreaseThrottleRefCount( | |
| 100 timer_task_queue_.get()); | |
| 101 } else { | |
| 102 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( | |
| 103 timer_task_queue_.get()); | |
| 104 } | |
| 105 } | 109 } |
| 106 | 110 |
| 107 void WebFrameSchedulerImpl::OnVirtualTimeDomainChanged() { | 111 void WebFrameSchedulerImpl::OnVirtualTimeDomainChanged() { |
| 108 DCHECK(parent_web_view_scheduler_); | 112 DCHECK(parent_web_view_scheduler_); |
| 109 DCHECK(parent_web_view_scheduler_->virtual_time_domain()); | 113 DCHECK(parent_web_view_scheduler_->virtual_time_domain()); |
| 110 | 114 |
| 111 if (timer_task_queue_) { | 115 if (timer_task_queue_) { |
| 112 renderer_scheduler_->throttling_helper()->UnregisterTaskQueue( | 116 renderer_scheduler_->throttling_helper()->UnregisterTaskQueue( |
| 113 timer_task_queue_.get()); | 117 timer_task_queue_.get()); |
| 114 timer_task_queue_->SetTimeDomain( | 118 timer_task_queue_->SetTimeDomain( |
| 115 parent_web_view_scheduler_->virtual_time_domain()); | 119 parent_web_view_scheduler_->virtual_time_domain()); |
| 116 } | 120 } |
| 117 | 121 |
| 118 if (loading_task_queue_) { | 122 if (loading_task_queue_) { |
| 119 loading_task_queue_->SetTimeDomain( | 123 loading_task_queue_->SetTimeDomain( |
| 120 parent_web_view_scheduler_->virtual_time_domain()); | 124 parent_web_view_scheduler_->virtual_time_domain()); |
| 121 } | 125 } |
| 122 } | 126 } |
| 123 | 127 |
| 128 bool WebFrameSchedulerImpl::ShouldThrottleTimers() const { | |
| 129 return !page_visible_ || | |
| 130 (allow_hidden_timer_throttling_ && !frame_visible_ && cross_origin_); | |
| 131 } | |
| 132 | |
| 133 void WebFrameSchedulerImpl::UpdateTimerThrottling(bool was_throttled) { | |
| 134 bool should_throttle = ShouldThrottleTimers(); | |
| 135 if (was_throttled == should_throttle || !timer_web_task_runner_ || | |
| 136 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
| |
| 137 return; | |
| 138 } | |
| 139 if (should_throttle) { | |
| 140 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( | |
| 141 timer_task_queue_.get()); | |
| 142 } else { | |
| 143 renderer_scheduler_->throttling_helper()->DecreaseThrottleRefCount( | |
| 144 timer_task_queue_.get()); | |
| 145 } | |
| 146 } | |
| 147 | |
| 124 } // namespace scheduler | 148 } // namespace scheduler |
| OLD | NEW |