Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/renderer/web_frame_scheduler_impl.cc

Issue 2620743002: Don't throttle web views until they've been in the background for 10s (Closed)
Patch Set: Fix asan test issue Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "platform/scheduler/renderer/web_frame_scheduler_impl.h" 5 #include "platform/scheduler/renderer/web_frame_scheduler_impl.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/trace_event/blame_context.h" 8 #include "base/trace_event/blame_context.h"
9 #include "platform/scheduler/base/real_time_domain.h" 9 #include "platform/scheduler/base/real_time_domain.h"
10 #include "platform/scheduler/base/virtual_time_domain.h" 10 #include "platform/scheduler/base/virtual_time_domain.h"
(...skipping 18 matching lines...) Expand all
29 } // namespace 29 } // namespace
30 30
31 WebFrameSchedulerImpl::WebFrameSchedulerImpl( 31 WebFrameSchedulerImpl::WebFrameSchedulerImpl(
32 RendererSchedulerImpl* renderer_scheduler, 32 RendererSchedulerImpl* renderer_scheduler,
33 WebViewSchedulerImpl* parent_web_view_scheduler, 33 WebViewSchedulerImpl* parent_web_view_scheduler,
34 base::trace_event::BlameContext* blame_context) 34 base::trace_event::BlameContext* blame_context)
35 : renderer_scheduler_(renderer_scheduler), 35 : renderer_scheduler_(renderer_scheduler),
36 parent_web_view_scheduler_(parent_web_view_scheduler), 36 parent_web_view_scheduler_(parent_web_view_scheduler),
37 blame_context_(blame_context), 37 blame_context_(blame_context),
38 frame_visible_(true), 38 frame_visible_(true),
39 page_visible_(true), 39 page_throttled_(true),
40 frame_suspended_(false), 40 frame_suspended_(false),
41 cross_origin_(false) {} 41 cross_origin_(false) {}
42 42
43 WebFrameSchedulerImpl::~WebFrameSchedulerImpl() { 43 WebFrameSchedulerImpl::~WebFrameSchedulerImpl() {
44 if (loading_task_queue_) { 44 if (loading_task_queue_) {
45 loading_task_queue_->UnregisterTaskQueue(); 45 loading_task_queue_->UnregisterTaskQueue();
46 loading_task_queue_->SetBlameContext(nullptr); 46 loading_task_queue_->SetBlameContext(nullptr);
47 } 47 }
48 48
49 if (timer_task_queue_) { 49 if (timer_task_queue_) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 bool background_parser_active) { 171 bool background_parser_active) {
172 if (background_parser_active) 172 if (background_parser_active)
173 parent_web_view_scheduler_->IncrementBackgroundParserCount(); 173 parent_web_view_scheduler_->IncrementBackgroundParserCount();
174 else 174 else
175 parent_web_view_scheduler_->DecrementBackgroundParserCount(); 175 parent_web_view_scheduler_->DecrementBackgroundParserCount();
176 } 176 }
177 177
178 void WebFrameSchedulerImpl::AsValueInto( 178 void WebFrameSchedulerImpl::AsValueInto(
179 base::trace_event::TracedValue* state) const { 179 base::trace_event::TracedValue* state) const {
180 state->SetBoolean("frame_visible", frame_visible_); 180 state->SetBoolean("frame_visible", frame_visible_);
181 state->SetBoolean("page_visible", page_visible_); 181 state->SetBoolean("page_throttled", page_throttled_);
182 state->SetBoolean("cross_origin", cross_origin_); 182 state->SetBoolean("cross_origin", cross_origin_);
183 if (loading_task_queue_) { 183 if (loading_task_queue_) {
184 state->SetString("loading_task_queue", 184 state->SetString("loading_task_queue",
185 PointerToId(loading_task_queue_.get())); 185 PointerToId(loading_task_queue_.get()));
186 } 186 }
187 if (timer_task_queue_) 187 if (timer_task_queue_)
188 state->SetString("timer_task_queue", PointerToId(timer_task_queue_.get())); 188 state->SetString("timer_task_queue", PointerToId(timer_task_queue_.get()));
189 if (unthrottled_task_queue_) { 189 if (unthrottled_task_queue_) {
190 state->SetString("unthrottled_task_queue", 190 state->SetString("unthrottled_task_queue",
191 PointerToId(unthrottled_task_queue_.get())); 191 PointerToId(unthrottled_task_queue_.get()));
192 } 192 }
193 if (blame_context_) { 193 if (blame_context_) {
194 state->BeginDictionary("blame_context"); 194 state->BeginDictionary("blame_context");
195 state->SetString( 195 state->SetString(
196 "id_ref", PointerToId(reinterpret_cast<void*>(blame_context_->id()))); 196 "id_ref", PointerToId(reinterpret_cast<void*>(blame_context_->id())));
197 state->SetString("scope", blame_context_->scope()); 197 state->SetString("scope", blame_context_->scope());
198 state->EndDictionary(); 198 state->EndDictionary();
199 } 199 }
200 } 200 }
201 201
202 void WebFrameSchedulerImpl::setPageVisible(bool page_visible) { 202 void WebFrameSchedulerImpl::setPageThrottled(bool page_throttled) {
203 DCHECK(parent_web_view_scheduler_); 203 DCHECK(parent_web_view_scheduler_);
204 if (page_visible_ == page_visible) 204 if (page_throttled_ == page_throttled)
205 return; 205 return;
206 bool was_throttled = ShouldThrottleTimers(); 206 bool was_throttled = ShouldThrottleTimers();
207 page_visible_ = page_visible; 207 page_throttled_ = page_throttled;
208 UpdateTimerThrottling(was_throttled); 208 UpdateTimerThrottling(was_throttled);
209 } 209 }
210 210
211 void WebFrameSchedulerImpl::setSuspended(bool frame_suspended) { 211 void WebFrameSchedulerImpl::setSuspended(bool frame_suspended) {
212 DCHECK(parent_web_view_scheduler_); 212 DCHECK(parent_web_view_scheduler_);
213 if (frame_suspended_ == frame_suspended) 213 if (frame_suspended_ == frame_suspended)
214 return; 214 return;
215 215
216 frame_suspended_ = frame_suspended; 216 frame_suspended_ = frame_suspended;
217 if (loading_queue_enabled_voter_) 217 if (loading_queue_enabled_voter_)
218 loading_queue_enabled_voter_->SetQueueEnabled(!frame_suspended); 218 loading_queue_enabled_voter_->SetQueueEnabled(!frame_suspended);
219 if (timer_queue_enabled_voter_) 219 if (timer_queue_enabled_voter_)
220 timer_queue_enabled_voter_->SetQueueEnabled(!frame_suspended); 220 timer_queue_enabled_voter_->SetQueueEnabled(!frame_suspended);
221 } 221 }
222 222
223 void WebFrameSchedulerImpl::onFirstMeaningfulPaint() { 223 void WebFrameSchedulerImpl::onFirstMeaningfulPaint() {
224 renderer_scheduler_->OnFirstMeaningfulPaint(); 224 renderer_scheduler_->OnFirstMeaningfulPaint();
225 } 225 }
226 226
227 bool WebFrameSchedulerImpl::ShouldThrottleTimers() const { 227 bool WebFrameSchedulerImpl::ShouldThrottleTimers() const {
228 if (!page_visible_) 228 if (page_throttled_)
229 return true; 229 return true;
230 return RuntimeEnabledFeatures::timerThrottlingForHiddenFramesEnabled() && 230 return RuntimeEnabledFeatures::timerThrottlingForHiddenFramesEnabled() &&
231 !frame_visible_ && cross_origin_; 231 !frame_visible_ && cross_origin_;
232 } 232 }
233 233
234 void WebFrameSchedulerImpl::UpdateTimerThrottling(bool was_throttled) { 234 void WebFrameSchedulerImpl::UpdateTimerThrottling(bool was_throttled) {
235 bool should_throttle = ShouldThrottleTimers(); 235 bool should_throttle = ShouldThrottleTimers();
236 if (was_throttled == should_throttle || !timer_web_task_runner_) 236 if (was_throttled == should_throttle || !timer_web_task_runner_)
237 return; 237 return;
238 if (should_throttle) { 238 if (should_throttle) {
239 renderer_scheduler_->task_queue_throttler()->IncreaseThrottleRefCount( 239 renderer_scheduler_->task_queue_throttler()->IncreaseThrottleRefCount(
240 timer_task_queue_.get()); 240 timer_task_queue_.get());
241 } else { 241 } else {
242 renderer_scheduler_->task_queue_throttler()->DecreaseThrottleRefCount( 242 renderer_scheduler_->task_queue_throttler()->DecreaseThrottleRefCount(
243 timer_task_queue_.get()); 243 timer_task_queue_.get());
244 } 244 }
245 } 245 }
246 246
247 } // namespace scheduler 247 } // namespace scheduler
248 } // namespace blink 248 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698