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

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

Issue 2389683002: Modify PurgeAndSuspend to see WebContents (Closed)
Patch Set: Fixed 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
« chrome/browser/memory/tab_manager.h ('K') | « chrome/browser/memory/tab_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/memory/tab_manager.cc
diff --git a/chrome/browser/memory/tab_manager.cc b/chrome/browser/memory/tab_manager.cc
index 582b2e667099f6fa0085f6721c4b9c69a37709c8..4901cd77ccdc41c88f46d6bb59b3c71c81cc49fd 100644
--- a/chrome/browser/memory/tab_manager.cc
+++ b/chrome/browser/memory/tab_manager.cc
@@ -670,6 +670,36 @@ void TabManager::UpdateTimerCallback() {
PurgeAndSuspendBackgroundedTabs();
}
+bool TabManager::CanPurgeAndSuspendBackgroundedTab(
+ int64_t target_web_contents_id) const {
+ TabStripModel* model;
+ int idx = FindTabStripModelById(target_web_contents_id, &model);
+ if (idx == -1)
+ return false;
+
+ WebContents* web_contents = model->GetWebContentsAt(idx);
+
+ // Do not suspend tabs that are playing either playing audio or accessing the
+ // microphone or camera as it's too distruptive to the user experience.
+ if (IsMediaTab(web_contents))
chrisha 2016/10/04 21:52:41 This is the only reason I think we shouldn't suspe
tasak 2016/10/05 05:28:46 I see. Done.
+ return false;
+
+ // Do not discard a recently used tab.
Georges Khalil 2016/10/04 13:28:55 nit: s/discard/suspend.
chrisha 2016/10/04 21:52:41 I don't think this is necessary. We should feel fr
tasak 2016/10/05 05:28:46 Done.
+ if (minimum_protection_time_.InSeconds() > 0) {
+ auto delta =
+ NowTicks() - GetWebContentsData(web_contents)->LastInactiveTime();
+ if (delta < minimum_protection_time_)
+ return false;
Georges Khalil 2016/10/04 13:28:55 nit: Let's move this logic to a function, instead
+ }
+
+ // Do not purge and suspend a tab that was explicitly disallowed to.
+ // Note: reused tab discarding logic.
+ if (!IsTabAutoDiscardable(web_contents))
chrisha 2016/10/04 21:52:41 Discarding logic shouldn't affect suspending, IMO.
tasak 2016/10/05 05:28:46 I see. If needed, I will update src/chrome/common/
+ return false;
+
+ return true;
+}
+
void TabManager::PurgeAndSuspendBackgroundedTabs() {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
@@ -695,6 +725,8 @@ void TabManager::PurgeAndSuspendBackgroundedTabs() {
// timers if we want necessary and sufficient signals.
if (tab.last_active > purge_and_suspend_time_threshold)
continue;
+ if (!CanPurgeAndSuspendBackgroundedTab(tab.tab_contents_id))
+ continue;
tab.render_process_host->PurgeAndSuspend();
}
}
« chrome/browser/memory/tab_manager.h ('K') | « chrome/browser/memory/tab_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698