| 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 if (parent_web_view_scheduler_->virtual_time_domain()) { | |
| 65 loading_task_queue_->SetTimeDomain( | |
| 66 parent_web_view_scheduler_->virtual_time_domain()); | |
| 67 } | |
| 68 loading_web_task_runner_.reset(new WebTaskRunnerImpl(loading_task_queue_)); | |
| 69 } | |
| 70 return loading_web_task_runner_.get(); | |
| 71 } | |
| 72 | |
| 73 blink::WebTaskRunner* WebFrameSchedulerImpl::timerTaskRunner() { | |
| 74 DCHECK(parent_web_view_scheduler_); | |
| 75 if (!timer_web_task_runner_) { | |
| 76 timer_task_queue_ = | |
| 77 renderer_scheduler_->NewTimerTaskRunner("frame_timer_tq"); | |
| 78 timer_task_queue_->SetBlameContext(blame_context_); | |
| 79 if (parent_web_view_scheduler_->virtual_time_domain()) { | |
| 80 timer_task_queue_->SetTimeDomain( | |
| 81 parent_web_view_scheduler_->virtual_time_domain()); | |
| 82 } else if (!page_visible_) { | |
| 83 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( | |
| 84 timer_task_queue_.get()); | |
| 85 } | |
| 86 timer_web_task_runner_.reset(new WebTaskRunnerImpl(timer_task_queue_)); | |
| 87 } | |
| 88 return timer_web_task_runner_.get(); | |
| 89 } | |
| 90 | |
| 91 blink::WebTaskRunner* WebFrameSchedulerImpl::unthrottledTaskRunner() { | |
| 92 DCHECK(parent_web_view_scheduler_); | |
| 93 if (!unthrottled_web_task_runner_) { | |
| 94 unthrottled_task_queue_ = | |
| 95 renderer_scheduler_->NewUnthrottledTaskRunner("frame_unthrottled_tq"); | |
| 96 unthrottled_task_queue_->SetBlameContext(blame_context_); | |
| 97 if (parent_web_view_scheduler_->virtual_time_domain()) { | |
| 98 unthrottled_task_queue_->SetTimeDomain( | |
| 99 parent_web_view_scheduler_->virtual_time_domain()); | |
| 100 } | |
| 101 unthrottled_web_task_runner_.reset( | |
| 102 new WebTaskRunnerImpl(unthrottled_task_queue_)); | |
| 103 } | |
| 104 return unthrottled_web_task_runner_.get(); | |
| 105 } | |
| 106 | |
| 107 blink::WebViewScheduler* WebFrameSchedulerImpl::webViewScheduler() { | |
| 108 return parent_web_view_scheduler_; | |
| 109 } | |
| 110 | |
| 111 void WebFrameSchedulerImpl::didStartLoading(unsigned long identifier) { | |
| 112 if (parent_web_view_scheduler_) | |
| 113 parent_web_view_scheduler_->DidStartLoading(identifier); | |
| 114 } | |
| 115 | |
| 116 void WebFrameSchedulerImpl::didStopLoading(unsigned long identifier) { | |
| 117 if (parent_web_view_scheduler_) | |
| 118 parent_web_view_scheduler_->DidStopLoading(identifier); | |
| 119 } | |
| 120 | |
| 121 void WebFrameSchedulerImpl::setPageVisible(bool page_visible) { | |
| 122 DCHECK(parent_web_view_scheduler_); | |
| 123 if (page_visible_ == page_visible) | |
| 124 return; | |
| 125 | |
| 126 page_visible_ = page_visible; | |
| 127 | |
| 128 if (!timer_web_task_runner_ || | |
| 129 parent_web_view_scheduler_->virtual_time_domain()) { | |
| 130 return; | |
| 131 } | |
| 132 | |
| 133 if (page_visible_) { | |
| 134 renderer_scheduler_->throttling_helper()->DecreaseThrottleRefCount( | |
| 135 timer_task_queue_.get()); | |
| 136 } else { | |
| 137 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( | |
| 138 timer_task_queue_.get()); | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 void WebFrameSchedulerImpl::OnVirtualTimeDomainChanged() { | |
| 143 DCHECK(parent_web_view_scheduler_); | |
| 144 DCHECK(parent_web_view_scheduler_->virtual_time_domain()); | |
| 145 | |
| 146 if (timer_task_queue_) { | |
| 147 renderer_scheduler_->throttling_helper()->UnregisterTaskQueue( | |
| 148 timer_task_queue_.get()); | |
| 149 timer_task_queue_->SetTimeDomain( | |
| 150 parent_web_view_scheduler_->virtual_time_domain()); | |
| 151 } | |
| 152 | |
| 153 if (loading_task_queue_) { | |
| 154 loading_task_queue_->SetTimeDomain( | |
| 155 parent_web_view_scheduler_->virtual_time_domain()); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 } // namespace scheduler | |
| OLD | NEW |