| 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..1443c9330b23f99686c5db9d3f2943208892f97a 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()) {
|
| @@ -37,6 +40,11 @@ WebFrameSchedulerImpl::~WebFrameSchedulerImpl() {
|
| timer_task_queue_->SetBlameContext(nullptr);
|
| }
|
|
|
| + if (default_task_queue_.get()) {
|
| + default_task_queue_->UnregisterTaskQueue();
|
| + default_task_queue_->SetBlameContext(nullptr);
|
| + }
|
| +
|
| if (parent_web_view_scheduler_)
|
| parent_web_view_scheduler_->Unregister(this);
|
| }
|
| @@ -46,8 +54,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 +95,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());
|
| }
|
| @@ -83,25 +104,28 @@ blink::WebTaskRunner* WebFrameSchedulerImpl::timerTaskRunner() {
|
| return timer_web_task_runner_.get();
|
| }
|
|
|
| +blink::WebTaskRunner* WebFrameSchedulerImpl::defaultTaskRunner() {
|
| + DCHECK(parent_web_view_scheduler_);
|
| + if (!default_web_task_runner_) {
|
| + default_task_queue_ =
|
| + renderer_scheduler_->NewDefaultTaskRunner("frame_default_tq");
|
| + default_task_queue_->SetBlameContext(blame_context_);
|
| + if (parent_web_view_scheduler_->virtual_time_domain()) {
|
| + default_task_queue_->SetTimeDomain(
|
| + parent_web_view_scheduler_->virtual_time_domain());
|
| + }
|
| + default_web_task_runner_.reset(new WebTaskRunnerImpl(default_task_queue_));
|
| + }
|
| + return default_web_task_runner_.get();
|
| +}
|
| +
|
| 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 +145,25 @@ 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();
|
| + // Don't throttle frames which are using virtual time.
|
| + if (was_throttled == should_throttle || !timer_web_task_runner_ ||
|
| + parent_web_view_scheduler_->virtual_time_domain()) {
|
| + 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
|
|
|