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

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

Issue 2711093002: Purge once random minutes(between 30min and 60min) after backgrounded. (Closed)
Patch Set: Fixed Created 3 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/memory/tab_manager.h
diff --git a/chrome/browser/memory/tab_manager.h b/chrome/browser/memory/tab_manager.h
index c384b7e054b07fa3eb20ad6b794bd748fcaf5665..ecc23053eba1797a40a22ada94b595b556cb5f47 100644
--- a/chrome/browser/memory/tab_manager.h
+++ b/chrome/browser/memory/tab_manager.h
@@ -147,7 +147,9 @@ class TabManager : public TabStripModelObserver {
// Sets/clears the auto-discardable state of the tab.
void SetTabAutoDiscardableState(content::WebContents* contents, bool state);
- // Returns true when a given renderer can suspend when it is backgrounded.
+ // Returns true when a given renderer can be purged if the specified
+ // renderer is eligible for purging.
+ // TODO(tasak): rename this to CanPurgeBackgroundedRenderer.
bool CanSuspendBackgroundedRenderer(int render_process_id) const;
// Returns true if |first| is considered less desirable to be killed than
@@ -159,9 +161,10 @@ class TabManager : public TabStripModelObserver {
static int64_t IdFromWebContents(content::WebContents* web_contents);
private:
- FRIEND_TEST_ALL_PREFIXES(TabManagerTest,
- ActivateTabResetPurgeAndSuspendState);
- FRIEND_TEST_ALL_PREFIXES(TabManagerTest, NextPurgeAndSuspendState);
+ FRIEND_TEST_ALL_PREFIXES(TabManagerTest, PurgeBackgroundRenderer);
+ FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ActivateTabResetPurgeState);
+ FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ShouldPurgeAtDefaultTime);
+ FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DefaultTimeToPurgeInCorrectRange);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications);
@@ -176,18 +179,26 @@ class TabManager : public TabStripModelObserver {
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectVideoTabs);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ReloadDiscardedTabContextMenu);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, TabManagerBasics);
- FRIEND_TEST_ALL_PREFIXES(TabManagerWebContentsDataTest, PurgeAndSuspendState);
// The time of the first purging after a renderer is backgrounded.
// The initial value was chosen because most of users activate backgrounded
// tabs within 30 minutes. (c.f. Tabs.StateTransfer.Time_Inactive_Active)
- static constexpr base::TimeDelta kDefaultTimeToFirstPurge =
+ static constexpr base::TimeDelta kDefaultMinTimeToPurge =
base::TimeDelta::FromMinutes(30);
+ // The min/max time to purge ratio. The max time to purge is set to be
+ // min time to purge times this value.
+ const int kMinMaxTimeToPurgeRatio = 2;
+
// This is needed so WebContentsData can call OnDiscardedStateChange, and
- // can use PurgeAndSuspendState.
+ // can use PurgeState.
friend class WebContentsData;
+ // Finds TabStripModel which has a WebContents whose id is the given
+ // web_contents_id, and returns the WebContents index and the TabStripModel.
+ int FindTabStripModelById(int64_t target_web_contents_id,
+ TabStripModel** model) const;
+
// Called by WebContentsData whenever the discard state of a WebContents
// changes, so that observers can be informed.
void OnDiscardedStateChange(content::WebContents* contents,
@@ -258,38 +269,27 @@ class TabManager : public TabStripModelObserver {
// that need to be run periodically (see comment in implementation).
void UpdateTimerCallback();
- // Initially PurgeAndSuspendState is RUNNING.
- // RUNNING => SUSPENDED
- // - A tab has been backgrounded for more than purge-and-suspend-time
- // seconds.
- // SUSPENDED => RESUMED
- // - A suspended tab is still suspended (i.e. last active time < last
- // purge-and-suspend modified time), and
- // - kMaxTimeRendererAllowedToBeSuspendedBeforeResume time passes since
- // since the tab was suspended.
- // RESUMED => SUSPENDED
- // - A resumed tab is still backgrounded (i.e. last active time < last
- // purge-and-suspend modified time), and
- // - kSuspendedRendererLengthOfResumption time passes since the tab was
- // resumed.
- // SUSPENDED, RESUMED, RUNNING => RUNNING
- // - When ActiveTabChaged, the newly activated tab's state will be RUNNING.
- enum PurgeAndSuspendState {
- RUNNING,
- RESUMED,
- SUSPENDED,
- };
// Returns WebContents whose contents id matches the given tab_contents_id.
content::WebContents* GetWebContentsById(int64_t tab_contents_id) const;
- // Returns the next state of the purge and suspend.
- PurgeAndSuspendState GetNextPurgeAndSuspendState(
- content::WebContents* content,
- base::TimeTicks current_time,
- const base::TimeDelta& time_to_first_suspension) const;
-
- // Purges and suspends renderers in backgrounded tabs.
- void PurgeAndSuspendBackgroundedTabs();
+ // Returns a random time-to-purge whose min value is min_time_to_purge and max
+ // value is min_time_to_purge * kMinMaxTimeToPurgeRatio.
+ base::TimeDelta GetTimeToPurge(base::TimeDelta min_time_to_purge) const;
+
+ // Returns true if the tab specified by |content| is now eligible to have
+ // its memory purged.
+ bool ShouldPurgeNow(content::WebContents* content) const;
+
+ // Purges renderers in backgrounded tabs if the following conditions are
+ // satisfied:
+ // - the renderers are not purged yet,
+ // - the renderers are not playing media,
+ // (CanPurgeBackgroundedRenderer returns true)
+ // - the renderers are left inactive and background for time-to-purge.
+ // If renderers are purged, their internal states become 'purged'.
+ // The state is reset to be 'not purged' only when they are activated
+ // (=ActiveTabChanged is invoked).
+ void PurgeBackgroundedTabsIfNeeded();
// Does the actual discard by destroying the WebContents in |model| at |index|
// and replacing it by an empty one. Returns the new WebContents or NULL if
@@ -372,8 +372,8 @@ class TabManager : public TabStripModelObserver {
// backgrounded.
base::TimeDelta minimum_protection_time_;
- // A backgrounded renderer will be suspended when this time passes.
- base::TimeDelta time_to_first_suspension_;
+ // A backgrounded renderer will be purged when this time passes.
+ base::TimeDelta min_time_to_purge_;
#if defined(OS_CHROMEOS)
std::unique_ptr<TabManagerDelegate> delegate_;
« no previous file with comments | « no previous file | chrome/browser/memory/tab_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698