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

Unified Diff: chrome/browser/memory/tab_manager.cc

Issue 2387603003: Resume a backgrounded renderer that was purged and suspended (Closed)
Patch Set: Rebaselined Created 4 years, 2 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: chrome/browser/memory/tab_manager.cc
diff --git a/chrome/browser/memory/tab_manager.cc b/chrome/browser/memory/tab_manager.cc
index e761e81a7c43a1d31ef1ebd15c33c984e6faa98b..76adc41e147cd427faac4ff4227e22cd3c603292 100644
--- a/chrome/browser/memory/tab_manager.cc
+++ b/chrome/browser/memory/tab_manager.cc
@@ -84,6 +84,16 @@ const int kRecentTabDiscardIntervalSeconds = 60;
// machine was suspended and correct the timing statistics.
const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4;
+// If a backgrounded renderer is kept backgrounded for this time after
+// being suspended, resume the renderer to avoid breaking web.
+constexpr base::TimeDelta kSuspendResumedRendererTime =
+ base::TimeDelta::FromSeconds(10);
+
+// After resuming and running a backgrounded renderer for this period,
+// the renderer is purged and suspended again.
+constexpr base::TimeDelta kResumeSuspendedRendererTime =
+ base::TimeDelta::FromSeconds(120);
Avi (use Gerrit) 2016/10/18 06:15:37 These comments seem to be opposite what you say in
tasak 2016/10/18 10:38:42 Yeah, my comment was completely wrong. Thank you.
+
// The time during which a tab is protected from discarding after it stops being
// audible.
const int kAudioProtectionTimeSeconds = 60;
@@ -700,8 +710,9 @@ void TabManager::PurgeAndSuspendBackgroundedTabs() {
}
if (purge_and_suspend_time <= 0)
return;
+ base::TimeTicks current_time = NowTicks();
auto purge_and_suspend_time_threshold =
- NowTicks() - base::TimeDelta::FromSeconds(purge_and_suspend_time);
+ current_time - base::TimeDelta::FromSeconds(purge_and_suspend_time);
auto tab_stats = GetUnsortedTabStats();
for (auto& tab : tab_stats) {
if (!tab.render_process_host->IsProcessBackgrounded())
@@ -714,7 +725,25 @@ void TabManager::PurgeAndSuspendBackgroundedTabs() {
continue;
if (!CanSuspendBackgroundedRenderer(tab.child_process_host_id))
continue;
- tab.render_process_host->PurgeAndSuspend();
+
+ auto last_purged_and_suspended_time =
+ tab.render_process_host->GetLastPurgedAndSuspendedTime();
+ auto last_resumed_time =
+ tab.render_process_host->GetLastResumedInBackgroundTime();
+
+ if (last_purged_and_suspended_time < tab.last_active ||
+ (last_resumed_time > last_purged_and_suspended_time &&
+ last_purged_and_suspended_time > tab.last_active &&
+ ((current_time - last_resumed_time) > kSuspendResumedRendererTime))) {
Avi (use Gerrit) 2016/10/18 06:15:36 Holy moly. I just spent twenty minutes pondering t
tasak 2016/10/18 10:38:42 Yeah... the code was dirty... So I add "purge-and
+ tab.render_process_host->PurgeAndSuspend();
+ if (!task_runner_.get())
+ task_runner_ = base::ThreadTaskRunnerHandle::Get();
+ } else {
+ auto delta = current_time - last_purged_and_suspended_time;
+ if (last_resumed_time < last_purged_and_suspended_time &&
+ delta > kResumeSuspendedRendererTime)
+ tab.render_process_host->Resume();
+ }
}
}
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.h » ('j') | content/public/browser/render_process_host.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698