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

Unified Diff: third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc

Issue 2620743002: Don't throttle web views until they've been in the background for 10s (Closed)
Patch Set: Remove tricky to fix but redundant layout test 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc
diff --git a/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc b/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc
index e3f3a420f94167bfc56fdb324a97634ae7e19fa6..94545525fea6567f8c650f71e39cf8bc32481eba 100644
--- a/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc
+++ b/third_party/WebKit/Source/platform/scheduler/renderer/web_view_scheduler_impl.cc
@@ -30,7 +30,7 @@ constexpr base::TimeDelta kDefaultMaxBackgroundThrottlingDelay =
base::TimeDelta::FromMinutes(1);
constexpr base::TimeDelta kDefaultInitialBackgroundBudget =
base::TimeDelta::FromSeconds(1);
-constexpr base::TimeDelta kBackgroundBudgetThrottlingGracePeriod =
+constexpr base::TimeDelta kBackgroundThrottlingGracePeriod =
base::TimeDelta::FromSeconds(10);
// Values coming from WebViewSchedulerSettings are interpreted as follows:
@@ -111,8 +111,8 @@ WebViewSchedulerImpl::WebViewSchedulerImpl(
settings_(settings) {
renderer_scheduler->AddWebViewScheduler(this);
- delayed_background_budget_throttling_enabler_.Reset(
- base::Bind(&WebViewSchedulerImpl::EnableBackgroundBudgetThrottling,
+ delayed_background_throttling_enabler_.Reset(
+ base::Bind(&WebViewSchedulerImpl::EnableBackgroundThrottling,
base::Unretained(this)));
}
@@ -134,11 +134,7 @@ void WebViewSchedulerImpl::setPageVisible(bool page_visible) {
page_visible_ = page_visible;
- for (WebFrameSchedulerImpl* frame_scheduler : frame_schedulers_) {
- frame_scheduler->setPageVisible(page_visible_);
- }
-
- UpdateBackgroundBudgetThrottlingState();
+ UpdateBackgroundThrottlingState();
}
std::unique_ptr<WebFrameSchedulerImpl>
@@ -302,7 +298,7 @@ void WebViewSchedulerImpl::MaybeInitializeBackgroundTimeBudgetPool() {
"background", GetMaxBudgetLevel(settings_),
GetMaxThrottlingDelay(settings_));
- UpdateBackgroundBudgetThrottlingState();
+ UpdateBackgroundThrottlingState();
LazyNow lazy_now(renderer_scheduler_->tick_clock());
@@ -333,30 +329,32 @@ void WebViewSchedulerImpl::OnThrottlingReported(
intervention_reporter_->ReportIntervention(WebString::fromUTF8(message));
}
-void WebViewSchedulerImpl::EnableBackgroundBudgetThrottling() {
- if (!background_time_budget_pool_)
- return;
-
- LazyNow lazy_now(renderer_scheduler_->tick_clock());
-
- background_time_budget_pool_->EnableThrottling(&lazy_now);
+void WebViewSchedulerImpl::EnableBackgroundThrottling() {
+ for (WebFrameSchedulerImpl* frame_scheduler : frame_schedulers_) {
+ frame_scheduler->setPageVisible(false);
Sami 2017/01/10 14:44:22 Should we rename |setPageVisible| to |setThrottlin
alex clarke (OOO till 29th) 2017/01/11 10:54:47 You're probably right. After this patch the WebFr
+ }
+ if (background_time_budget_pool_) {
+ LazyNow lazy_now(renderer_scheduler_->tick_clock());
+ background_time_budget_pool_->EnableThrottling(&lazy_now);
+ }
}
-void WebViewSchedulerImpl::UpdateBackgroundBudgetThrottlingState() {
- if (!background_time_budget_pool_)
- return;
-
- delayed_background_budget_throttling_enabler_.Cancel();
-
- LazyNow lazy_now(renderer_scheduler_->tick_clock());
+void WebViewSchedulerImpl::UpdateBackgroundThrottlingState() {
+ delayed_background_throttling_enabler_.Cancel();
if (page_visible_) {
- background_time_budget_pool_->DisableThrottling(&lazy_now);
+ for (WebFrameSchedulerImpl* frame_scheduler : frame_schedulers_) {
+ frame_scheduler->setPageVisible(true);
+ }
+ if (background_time_budget_pool_) {
+ LazyNow lazy_now(renderer_scheduler_->tick_clock());
+ background_time_budget_pool_->DisableThrottling(&lazy_now);
+ }
} else {
// TODO(altimin): Consider moving this logic into PumpThrottledTasks.
renderer_scheduler_->ControlTaskRunner()->PostDelayedTask(
- FROM_HERE, delayed_background_budget_throttling_enabler_.callback(),
- kBackgroundBudgetThrottlingGracePeriod);
+ FROM_HERE, delayed_background_throttling_enabler_.callback(),
+ kBackgroundThrottlingGracePeriod);
}
}

Powered by Google App Engine
This is Rietveld 408576698