Chromium Code Reviews| Index: third_party/WebKit/Source/platform/scheduler/renderer/web_frame_scheduler_impl.cc | 
| diff --git a/third_party/WebKit/Source/platform/scheduler/renderer/web_frame_scheduler_impl.cc b/third_party/WebKit/Source/platform/scheduler/renderer/web_frame_scheduler_impl.cc | 
| index 027e3b7aff4f969f4686bc6cad611023eda2f663..eadb49b5f5ad19577e6ebadd731b91c0e28f89ca 100644 | 
| --- a/third_party/WebKit/Source/platform/scheduler/renderer/web_frame_scheduler_impl.cc | 
| +++ b/third_party/WebKit/Source/platform/scheduler/renderer/web_frame_scheduler_impl.cc | 
| @@ -28,6 +28,19 @@ std::string PointerToId(void* pointer) { | 
| } // namespace | 
| +WebFrameSchedulerImpl::ActiveConnectionHandleImpl::ActiveConnectionHandleImpl( | 
| + WebFrameSchedulerImpl* frame_scheduler) | 
| + : frame_scheduler_(frame_scheduler->AsWeakPtr()) { | 
| + frame_scheduler->didOpenActiveConnection(); | 
| +} | 
| + | 
| +WebFrameSchedulerImpl::ActiveConnectionHandleImpl:: | 
| + ~ActiveConnectionHandleImpl() { | 
| + WebFrameSchedulerImpl* frame_scheduler = frame_scheduler_.get(); | 
| + if (frame_scheduler) | 
| 
 
alex clarke (OOO till 29th)
2017/01/26 16:02:36
Nit: if (frame_scheduler_) frame_scheduler_->didCl
 
altimin
2017/02/08 15:56:54
Done.
 
 | 
| + frame_scheduler->didCloseActiveConnection(); | 
| +} | 
| + | 
| WebFrameSchedulerImpl::WebFrameSchedulerImpl( | 
| RendererSchedulerImpl* renderer_scheduler, | 
| WebViewSchedulerImpl* parent_web_view_scheduler, | 
| @@ -38,9 +51,13 @@ WebFrameSchedulerImpl::WebFrameSchedulerImpl( | 
| frame_visible_(true), | 
| page_throttled_(true), | 
| frame_suspended_(false), | 
| - cross_origin_(false) {} | 
| + cross_origin_(false), | 
| + active_connections_count_(0), | 
| + weak_factory_(this) {} | 
| WebFrameSchedulerImpl::~WebFrameSchedulerImpl() { | 
| + weak_factory_.InvalidateWeakPtrs(); | 
| + | 
| if (loading_task_queue_) { | 
| loading_task_queue_->UnregisterTaskQueue(); | 
| loading_task_queue_->SetBlameContext(nullptr); | 
| @@ -57,8 +74,12 @@ WebFrameSchedulerImpl::~WebFrameSchedulerImpl() { | 
| unthrottled_task_queue_->SetBlameContext(nullptr); | 
| } | 
| - if (parent_web_view_scheduler_) | 
| + if (parent_web_view_scheduler_) { | 
| parent_web_view_scheduler_->Unregister(this); | 
| + | 
| + if (active_connections_count_) | 
| + parent_web_view_scheduler_->OnConnectionUpdated(); | 
| + } | 
| } | 
| void WebFrameSchedulerImpl::DetachFromWebViewScheduler() { | 
| @@ -167,6 +188,19 @@ void WebFrameSchedulerImpl::didStopLoading(unsigned long identifier) { | 
| parent_web_view_scheduler_->DidStopLoading(identifier); | 
| } | 
| +void WebFrameSchedulerImpl::didOpenActiveConnection() { | 
| + ++active_connections_count_; | 
| + if (parent_web_view_scheduler_) | 
| + parent_web_view_scheduler_->OnConnectionUpdated(); | 
| +} | 
| + | 
| +void WebFrameSchedulerImpl::didCloseActiveConnection() { | 
| + DCHECK_GT(active_connections_count_, 0); | 
| + --active_connections_count_; | 
| + if (parent_web_view_scheduler_) | 
| + parent_web_view_scheduler_->OnConnectionUpdated(); | 
| +} | 
| + | 
| void WebFrameSchedulerImpl::setDocumentParsingInBackground( | 
| bool background_parser_active) { | 
| if (background_parser_active) | 
| @@ -224,6 +258,12 @@ void WebFrameSchedulerImpl::onFirstMeaningfulPaint() { | 
| renderer_scheduler_->OnFirstMeaningfulPaint(); | 
| } | 
| +std::unique_ptr<WebFrameScheduler::ActiveConnectionHandle> | 
| +WebFrameSchedulerImpl::onActiveConnectionCreated() { | 
| + return base::MakeUnique<WebFrameSchedulerImpl::ActiveConnectionHandleImpl>( | 
| + this); | 
| +} | 
| + | 
| bool WebFrameSchedulerImpl::ShouldThrottleTimers() const { | 
| if (page_throttled_) | 
| return true; | 
| @@ -244,5 +284,9 @@ void WebFrameSchedulerImpl::UpdateTimerThrottling(bool was_throttled) { | 
| } | 
| } | 
| +base::WeakPtr<WebFrameSchedulerImpl> WebFrameSchedulerImpl::AsWeakPtr() { | 
| + return weak_factory_.GetWeakPtr(); | 
| +} | 
| + | 
| } // namespace scheduler | 
| } // namespace blink |