| 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_view_scheduler_impl.h" | 5 #include "components/scheduler/renderer/web_view_scheduler_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "components/scheduler/base/virtual_time_domain.h" | 8 #include "components/scheduler/base/virtual_time_domain.h" |
| 9 #include "components/scheduler/child/scheduler_tqm_delegate.h" | 9 #include "components/scheduler/child/scheduler_tqm_delegate.h" |
| 10 #include "components/scheduler/renderer/auto_advancing_virtual_time_domain.h" | 10 #include "components/scheduler/renderer/auto_advancing_virtual_time_domain.h" |
| 11 #include "components/scheduler/renderer/renderer_scheduler_impl.h" | 11 #include "components/scheduler/renderer/renderer_scheduler_impl.h" |
| 12 #include "components/scheduler/renderer/web_frame_scheduler_impl.h" | 12 #include "components/scheduler/renderer/web_frame_scheduler_impl.h" |
| 13 #include "third_party/WebKit/public/platform/WebFrameScheduler.h" | 13 #include "third_party/WebKit/public/platform/WebFrameScheduler.h" |
| 14 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 14 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 15 #include "third_party/WebKit/public/web/WebFrame.h" | 15 #include "third_party/WebKit/public/web/WebFrame.h" |
| 16 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
| 17 | 17 |
| 18 namespace scheduler { | 18 namespace scheduler { |
| 19 | 19 |
| 20 WebViewSchedulerImpl::WebViewSchedulerImpl( | 20 WebViewSchedulerImpl::WebViewSchedulerImpl( |
| 21 blink::WebView* web_view, | 21 blink::WebView* web_view, |
| 22 RendererSchedulerImpl* renderer_scheduler, | 22 RendererSchedulerImpl* renderer_scheduler, |
| 23 bool disable_background_timer_throttling) | 23 bool disable_background_timer_throttling) |
| 24 : virtual_time_pump_policy_(TaskQueue::PumpPolicy::AUTO), | 24 : virtual_time_pump_policy_(TaskQueue::PumpPolicy::AUTO), |
| 25 web_view_(web_view), | 25 web_view_(web_view), |
| 26 renderer_scheduler_(renderer_scheduler), | 26 renderer_scheduler_(renderer_scheduler), |
| 27 pending_resource_load_count_(0), | |
| 28 virtual_time_policy_(VirtualTimePolicy::ADVANCE), | 27 virtual_time_policy_(VirtualTimePolicy::ADVANCE), |
| 29 page_visible_(true), | 28 page_visible_(true), |
| 30 disable_background_timer_throttling_(disable_background_timer_throttling), | 29 disable_background_timer_throttling_(disable_background_timer_throttling), |
| 31 allow_virtual_time_to_advance_(true) { | 30 allow_virtual_time_to_advance_(true) { |
| 32 renderer_scheduler->AddWebViewScheduler(this); | 31 renderer_scheduler->AddWebViewScheduler(this); |
| 33 } | 32 } |
| 34 | 33 |
| 35 WebViewSchedulerImpl::~WebViewSchedulerImpl() { | 34 WebViewSchedulerImpl::~WebViewSchedulerImpl() { |
| 36 // TODO(alexclarke): Find out why we can't rely on the web view outliving the | 35 // TODO(alexclarke): Find out why we can't rely on the web view outliving the |
| 37 // frame. | 36 // frame. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (virtual_time_domain_) { | 110 if (virtual_time_domain_) { |
| 112 virtual_time_domain_->SetCanAdvanceVirtualTime( | 111 virtual_time_domain_->SetCanAdvanceVirtualTime( |
| 113 allow_virtual_time_to_advance); | 112 allow_virtual_time_to_advance); |
| 114 } | 113 } |
| 115 } | 114 } |
| 116 | 115 |
| 117 bool WebViewSchedulerImpl::virtualTimeAllowedToAdvance() const { | 116 bool WebViewSchedulerImpl::virtualTimeAllowedToAdvance() const { |
| 118 return allow_virtual_time_to_advance_; | 117 return allow_virtual_time_to_advance_; |
| 119 } | 118 } |
| 120 | 119 |
| 121 void WebViewSchedulerImpl::incrementPendingResourceLoadCount() { | 120 void WebViewSchedulerImpl::DidStartLoading(unsigned long identifier) { |
| 122 pending_resource_load_count_++; | 121 pending_loads_.insert(identifier); |
| 123 | 122 |
| 124 if (virtual_time_policy_ != | 123 if (virtual_time_policy_ != |
| 125 VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING) { | 124 VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING) { |
| 126 return; | 125 return; |
| 127 } | 126 } |
| 128 | 127 |
| 129 if (pending_resource_load_count_ == 1) | 128 if (pending_loads_.size() == 1u) |
| 130 setAllowVirtualTimeToAdvance(false); | 129 setAllowVirtualTimeToAdvance(false); |
| 131 } | 130 } |
| 132 | 131 |
| 133 void WebViewSchedulerImpl::decrementPendingResourceLoadCount() { | 132 void WebViewSchedulerImpl::DidStopLoading(unsigned long identifier) { |
| 134 pending_resource_load_count_--; | 133 pending_loads_.erase(identifier); |
| 135 DCHECK_GE(pending_resource_load_count_, 0); | |
| 136 | 134 |
| 137 if (virtual_time_policy_ != | 135 if (virtual_time_policy_ != |
| 138 VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING) { | 136 VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING) { |
| 139 return; | 137 return; |
| 140 } | 138 } |
| 141 | 139 |
| 142 if (pending_resource_load_count_ == 0) | 140 if (pending_loads_.size() == 0) |
| 143 setAllowVirtualTimeToAdvance(true); | 141 setAllowVirtualTimeToAdvance(true); |
| 144 } | 142 } |
| 145 | 143 |
| 146 void WebViewSchedulerImpl::setVirtualTimePolicy(VirtualTimePolicy policy) { | 144 void WebViewSchedulerImpl::setVirtualTimePolicy(VirtualTimePolicy policy) { |
| 147 virtual_time_policy_ = policy; | 145 virtual_time_policy_ = policy; |
| 148 | 146 |
| 149 switch (virtual_time_policy_) { | 147 switch (virtual_time_policy_) { |
| 150 case VirtualTimePolicy::ADVANCE: | 148 case VirtualTimePolicy::ADVANCE: |
| 151 setAllowVirtualTimeToAdvance(true); | 149 setAllowVirtualTimeToAdvance(true); |
| 152 break; | 150 break; |
| 153 | 151 |
| 154 case VirtualTimePolicy::PAUSE: | 152 case VirtualTimePolicy::PAUSE: |
| 155 setAllowVirtualTimeToAdvance(false); | 153 setAllowVirtualTimeToAdvance(false); |
| 156 break; | 154 break; |
| 157 | 155 |
| 158 case VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING: | 156 case VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING: |
| 159 setAllowVirtualTimeToAdvance(pending_resource_load_count_ == 0); | 157 setAllowVirtualTimeToAdvance(pending_loads_.size() == 0); |
| 160 break; | 158 break; |
| 161 } | 159 } |
| 162 } | 160 } |
| 163 | 161 |
| 164 } // namespace scheduler | 162 } // namespace scheduler |
| OLD | NEW |