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