| 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_frame_scheduler_impl.h" | 5 #include "components/scheduler/renderer/web_frame_scheduler_impl.h" |
| 6 | 6 |
| 7 #include "base/trace_event/blame_context.h" | 7 #include "base/trace_event/blame_context.h" |
| 8 #include "components/scheduler/base/real_time_domain.h" | 8 #include "components/scheduler/base/real_time_domain.h" |
| 9 #include "components/scheduler/base/virtual_time_domain.h" | 9 #include "components/scheduler/base/virtual_time_domain.h" |
| 10 #include "components/scheduler/child/web_task_runner_impl.h" | 10 #include "components/scheduler/child/web_task_runner_impl.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 frame_visible_ = frame_visible; | 54 frame_visible_ = frame_visible; |
| 55 // TODO(alexclarke): Do something with this flag. | 55 // TODO(alexclarke): Do something with this flag. |
| 56 } | 56 } |
| 57 | 57 |
| 58 blink::WebTaskRunner* WebFrameSchedulerImpl::loadingTaskRunner() { | 58 blink::WebTaskRunner* WebFrameSchedulerImpl::loadingTaskRunner() { |
| 59 DCHECK(parent_web_view_scheduler_); | 59 DCHECK(parent_web_view_scheduler_); |
| 60 if (!loading_web_task_runner_) { | 60 if (!loading_web_task_runner_) { |
| 61 loading_task_queue_ = | 61 loading_task_queue_ = |
| 62 renderer_scheduler_->NewLoadingTaskRunner("frame_loading_tq"); | 62 renderer_scheduler_->NewLoadingTaskRunner("frame_loading_tq"); |
| 63 loading_task_queue_->SetBlameContext(blame_context_); | 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_)); | 64 loading_web_task_runner_.reset(new WebTaskRunnerImpl(loading_task_queue_)); |
| 69 } | 65 } |
| 70 return loading_web_task_runner_.get(); | 66 return loading_web_task_runner_.get(); |
| 71 } | 67 } |
| 72 | 68 |
| 73 blink::WebTaskRunner* WebFrameSchedulerImpl::timerTaskRunner() { | 69 blink::WebTaskRunner* WebFrameSchedulerImpl::timerTaskRunner() { |
| 74 DCHECK(parent_web_view_scheduler_); | 70 DCHECK(parent_web_view_scheduler_); |
| 75 if (!timer_web_task_runner_) { | 71 if (!timer_web_task_runner_) { |
| 76 timer_task_queue_ = | 72 timer_task_queue_ = |
| 77 renderer_scheduler_->NewTimerTaskRunner("frame_timer_tq"); | 73 renderer_scheduler_->NewTimerTaskRunner("frame_timer_tq"); |
| 78 timer_task_queue_->SetBlameContext(blame_context_); | 74 timer_task_queue_->SetBlameContext(blame_context_); |
| 79 if (parent_web_view_scheduler_->virtual_time_domain()) { | 75 if (!page_visible_) { |
| 80 timer_task_queue_->SetTimeDomain( | |
| 81 parent_web_view_scheduler_->virtual_time_domain()); | |
| 82 } else if (!page_visible_) { | |
| 83 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( | 76 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( |
| 84 timer_task_queue_.get()); | 77 timer_task_queue_.get()); |
| 85 } | 78 } |
| 86 timer_web_task_runner_.reset(new WebTaskRunnerImpl(timer_task_queue_)); | 79 timer_web_task_runner_.reset(new WebTaskRunnerImpl(timer_task_queue_)); |
| 87 } | 80 } |
| 88 return timer_web_task_runner_.get(); | 81 return timer_web_task_runner_.get(); |
| 89 } | 82 } |
| 90 | 83 |
| 91 blink::WebTaskRunner* WebFrameSchedulerImpl::unthrottledTaskRunner() { | 84 blink::WebTaskRunner* WebFrameSchedulerImpl::unthrottledTaskRunner() { |
| 92 DCHECK(parent_web_view_scheduler_); | 85 DCHECK(parent_web_view_scheduler_); |
| 93 if (!unthrottled_web_task_runner_) { | 86 if (!unthrottled_web_task_runner_) { |
| 94 unthrottled_task_queue_ = | 87 unthrottled_task_queue_ = |
| 95 renderer_scheduler_->NewUnthrottledTaskRunner("frame_unthrottled_tq"); | 88 renderer_scheduler_->NewUnthrottledTaskRunner("frame_unthrottled_tq"); |
| 96 unthrottled_task_queue_->SetBlameContext(blame_context_); | 89 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( | 90 unthrottled_web_task_runner_.reset( |
| 102 new WebTaskRunnerImpl(unthrottled_task_queue_)); | 91 new WebTaskRunnerImpl(unthrottled_task_queue_)); |
| 103 } | 92 } |
| 104 return unthrottled_web_task_runner_.get(); | 93 return unthrottled_web_task_runner_.get(); |
| 105 } | 94 } |
| 106 | 95 |
| 107 blink::WebViewScheduler* WebFrameSchedulerImpl::webViewScheduler() { | 96 blink::WebViewScheduler* WebFrameSchedulerImpl::webViewScheduler() { |
| 108 return parent_web_view_scheduler_; | 97 return parent_web_view_scheduler_; |
| 109 } | 98 } |
| 110 | 99 |
| 111 void WebFrameSchedulerImpl::didStartLoading(unsigned long identifier) { | 100 void WebFrameSchedulerImpl::didStartLoading(unsigned long identifier) { |
| 112 if (parent_web_view_scheduler_) | 101 if (parent_web_view_scheduler_) |
| 113 parent_web_view_scheduler_->DidStartLoading(identifier); | 102 parent_web_view_scheduler_->DidStartLoading(identifier); |
| 114 } | 103 } |
| 115 | 104 |
| 116 void WebFrameSchedulerImpl::didStopLoading(unsigned long identifier) { | 105 void WebFrameSchedulerImpl::didStopLoading(unsigned long identifier) { |
| 117 if (parent_web_view_scheduler_) | 106 if (parent_web_view_scheduler_) |
| 118 parent_web_view_scheduler_->DidStopLoading(identifier); | 107 parent_web_view_scheduler_->DidStopLoading(identifier); |
| 119 } | 108 } |
| 120 | 109 |
| 121 void WebFrameSchedulerImpl::setPageVisible(bool page_visible) { | 110 void WebFrameSchedulerImpl::setPageVisible(bool page_visible) { |
| 122 DCHECK(parent_web_view_scheduler_); | 111 DCHECK(parent_web_view_scheduler_); |
| 123 if (page_visible_ == page_visible) | 112 if (page_visible_ == page_visible) |
| 124 return; | 113 return; |
| 125 | 114 |
| 126 page_visible_ = page_visible; | 115 page_visible_ = page_visible; |
| 127 | 116 |
| 128 if (!timer_web_task_runner_ || | 117 if (!timer_web_task_runner_) |
| 129 parent_web_view_scheduler_->virtual_time_domain()) { | |
| 130 return; | 118 return; |
| 131 } | |
| 132 | 119 |
| 133 if (page_visible_) { | 120 if (page_visible_) { |
| 134 renderer_scheduler_->throttling_helper()->DecreaseThrottleRefCount( | 121 renderer_scheduler_->throttling_helper()->DecreaseThrottleRefCount( |
| 135 timer_task_queue_.get()); | 122 timer_task_queue_.get()); |
| 136 } else { | 123 } else { |
| 137 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( | 124 renderer_scheduler_->throttling_helper()->IncreaseThrottleRefCount( |
| 138 timer_task_queue_.get()); | 125 timer_task_queue_.get()); |
| 139 } | 126 } |
| 140 } | 127 } |
| 141 | 128 |
| 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 | 129 } // namespace scheduler |
| OLD | NEW |