Chromium Code Reviews| Index: third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc |
| diff --git a/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc b/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc |
| index a5ccc87bfc7c57fbcffe72fb3dbe1e4020adb2d5..380a868e30a6df22e95cd532e41420977a39aa04 100644 |
| --- a/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc |
| +++ b/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc |
| @@ -108,6 +108,7 @@ WebViewSchedulerImpl::WebViewSchedulerImpl( |
| virtual_time_(false), |
| is_audio_playing_(false), |
| reported_background_throttling_since_navigation_(false), |
| + has_websocket_connection_(false), |
| background_time_budget_pool_(nullptr), |
| settings_(settings) { |
| renderer_scheduler->AddWebViewScheduler(this); |
| @@ -255,6 +256,19 @@ bool WebViewSchedulerImpl::IsAudioPlaying() const { |
| return is_audio_playing_; |
| } |
| +void WebViewSchedulerImpl::OnWebSocketConnectionUpdated() { |
| + bool has_websocket_connection = false; |
| + for (WebFrameSchedulerImpl* frame_scheduler : frame_schedulers_) { |
| + has_websocket_connection = |
|
alex clarke (OOO till 29th)
2017/01/24 18:15:34
nit ||= ?
altimin
2017/01/24 18:39:04
C++ does not have operator ||= :) Used |= instead.
|
| + has_websocket_connection || frame_scheduler->has_websocket_connection(); |
| + } |
| + |
| + if (has_websocket_connection_ != has_websocket_connection) { |
| + has_websocket_connection_ = has_websocket_connection; |
| + UpdateBackgroundThrottlingState(); |
| + } |
| +} |
| + |
| void WebViewSchedulerImpl::AsValueInto( |
| base::trace_event::TracedValue* state) const { |
| state->SetDouble("pending_loads", pending_loads_.size()); |
| @@ -335,10 +349,7 @@ void WebViewSchedulerImpl::EnableBackgroundThrottling() { |
| for (WebFrameSchedulerImpl* frame_scheduler : frame_schedulers_) { |
| frame_scheduler->setPageThrottled(true); |
| } |
| - if (background_time_budget_pool_) { |
| - LazyNow lazy_now(renderer_scheduler_->tick_clock()); |
| - background_time_budget_pool_->EnableThrottling(&lazy_now); |
| - } |
| + UpdateBackgroundBudgetPoolThrottlingState(); |
| } |
| void WebViewSchedulerImpl::UpdateBackgroundThrottlingState() { |
| @@ -349,15 +360,29 @@ void WebViewSchedulerImpl::UpdateBackgroundThrottlingState() { |
| for (WebFrameSchedulerImpl* frame_scheduler : frame_schedulers_) { |
| frame_scheduler->setPageThrottled(false); |
| } |
| - if (background_time_budget_pool_) { |
| - LazyNow lazy_now(renderer_scheduler_->tick_clock()); |
| - background_time_budget_pool_->DisableThrottling(&lazy_now); |
| + UpdateBackgroundBudgetPoolThrottlingState(); |
| + } else { |
| + if (has_websocket_connection_) { |
|
alex clarke (OOO till 29th)
2017/01/24 18:15:34
I'd favor this for tersness:
if (page_visible_ ||
altimin
2017/01/24 18:39:04
Personally, I don't like this option. For example,
|
| + // If websocket is active, update state immediately to stop throttling. |
| + UpdateBackgroundBudgetPoolThrottlingState(); |
| + } else { |
| + // TODO(altimin): Consider moving this logic into PumpThrottledTasks. |
| + renderer_scheduler_->ControlTaskRunner()->PostDelayedTask( |
| + FROM_HERE, delayed_background_throttling_enabler_.callback(), |
| + kBackgroundThrottlingGracePeriod); |
| } |
| + } |
| +} |
| + |
| +void WebViewSchedulerImpl::UpdateBackgroundBudgetPoolThrottlingState() { |
| + if (!background_time_budget_pool_) |
| + return; |
| + |
| + LazyNow lazy_now(renderer_scheduler_->tick_clock()); |
| + if (page_visible_ || has_websocket_connection_) { |
| + background_time_budget_pool_->DisableThrottling(&lazy_now); |
| } else { |
| - // TODO(altimin): Consider moving this logic into PumpThrottledTasks. |
| - renderer_scheduler_->ControlTaskRunner()->PostDelayedTask( |
| - FROM_HERE, delayed_background_throttling_enabler_.callback(), |
| - kBackgroundThrottlingGracePeriod); |
| + background_time_budget_pool_->EnableThrottling(&lazy_now); |
| } |
| } |