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

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

Issue 2931023002: [TooManyTabs] Add TabNavigationThrottle (Closed)
Patch Set: review fix Created 3 years, 6 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/resource_coordinator/tab_manager.h
diff --git a/chrome/browser/resource_coordinator/tab_manager.h b/chrome/browser/resource_coordinator/tab_manager.h
index 4b9af621ffb4071e7c608effc8fd2ede6f6b1ec0..4c123eb2ed9980d4ac9a54deab46138e77d195e4 100644
--- a/chrome/browser/resource_coordinator/tab_manager.h
+++ b/chrome/browser/resource_coordinator/tab_manager.h
@@ -26,6 +26,7 @@
#include "chrome/browser/resource_coordinator/tab_stats.h"
#include "chrome/browser/ui/browser_tab_strip_tracker.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
+#include "content/public/browser/navigation_throttle.h"
class BrowserList;
class GURL;
@@ -36,6 +37,7 @@ class TickClock;
}
namespace content {
+class NavigationHandle;
class WebContents;
}
@@ -59,6 +61,9 @@ class TabManagerDelegate;
// kernel is forced to kill processes, it will be able to do so using the same
// algorithm as the one used here.
//
+// The TabManager also delays background tabs' navigation when needed in order
+// to improve users' experience with the foreground tab.
+//
// Note that the browser tests are only active for platforms that use
// TabManager (CrOS only for now) and need to be adjusted accordingly if
// support for new platforms is added.
@@ -146,6 +151,22 @@ class TabManager : public TabStripModelObserver {
// TODO(tasak): rename this to CanPurgeBackgroundedRenderer.
bool CanSuspendBackgroundedRenderer(int render_process_id) const;
+ // Maybe throttle a tab's navigation based on current system status.
+ content::NavigationThrottle::ThrottleCheckResult MaybeThrottleNavigation(
+ content::NavigationHandle* navigation_handle);
+
+ // Notifies TabManager that one navigation has finished. TabManager should
+ // clean up the navigation handles bookkept before.
nasko 2017/06/20 15:59:39 nit: s/navigation handles/NavigationHandle objects
Zhen Wang 2017/07/06 18:26:12 Done.
+ void OnNavigationDone(content::NavigationHandle* navigation_handle);
+
+ // Notifies TabManager that one tab has finished loading. TabManager can
+ // decide which tab to load next.
+ void OnLoadingDone(content::WebContents* contents);
+
+ // Notifies TabManager that one tab WebContents has been destroyed. TabManager
+ // needs to clean up data related to that tab.
+ void OnWebContentsDestroyed(content::WebContents* contents);
+
// Returns true if |first| is considered less desirable to be killed than
// |second|.
static bool CompareTabStats(const TabStats& first, const TabStats& second);
@@ -154,6 +175,10 @@ class TabManager : public TabStripModelObserver {
// the WebContents could be deleted if the user closed the tab.
static int64_t IdFromWebContents(content::WebContents* web_contents);
+ // Returns true if the |url| represents an internal Chrome web UI page that
+ // can be easily reloaded and hence makes a good choice to discard.
+ static bool IsInternalPage(const GURL& url);
+
private:
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, PurgeBackgroundRenderer);
FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ActivateTabResetPurgeState);
@@ -206,10 +231,6 @@ class TabManager : public TabStripModelObserver {
static void PurgeMemoryAndDiscardTab();
- // Returns true if the |url| represents an internal Chrome web UI page that
- // can be easily reloaded and hence makes a good choice to discard.
- static bool IsInternalPage(const GURL& url);
-
// Records UMA histogram statistics for a tab discard. Record statistics for
// user triggered discards via chrome://discards/ because that allows to
// manually test the system.
@@ -303,6 +324,24 @@ class TabManager : public TabStripModelObserver {
// Returns true if tabs can be discarded only once.
bool CanOnlyDiscardOnce() const;
+ // Returns true if the navigation should be delayed.
+ bool ShouldDelayNavigation(
+ content::NavigationHandle* navigation_handle) const;
+
+ // Start loading the next background tab if needed.
+ void LoadNextBackgroundTabIfNeeded();
+
+ // Resume the tab's navigation if it is pending right now.
+ void ResumeTabNavigationIfNeeded(content::WebContents* contents);
+
+ // Resume navigation.
+ void ResumeNavigation(content::NavigationHandle* navigation_handle);
+
+ // Remove the pending navigation for the provided web contents. Return the
nasko 2017/06/20 15:59:39 nit: s/web contents/WebContents/
Zhen Wang 2017/07/06 18:26:12 Done.
+ // removed navigation handle. Return nullptr if not exists.
chrisha 2017/06/20 18:26:54 if it doesn't exist.
Zhen Wang 2017/07/06 18:26:12 Done.
+ content::NavigationHandle* RemovePendingNavigationIfNeeded(
+ content::WebContents* contents);
+
// Timer to periodically update the stats of the renderers.
base::RepeatingTimer update_timer_;
@@ -366,6 +405,14 @@ class TabManager : public TabStripModelObserver {
// List of observers that will receive notifications on state changes.
base::ObserverList<TabManagerObserver> observers_;
+ // The list of navigation handles that are delayed.
+ std::vector<content::NavigationHandle*> pending_navigations_;
+
+ // The tabs that are currently loading. We will consider loading the next
+ // background tab when these tabs have finished loading or a background tab
+ // is brought to foreground.
+ std::set<content::WebContents*> loading_contents_;
+
// Weak pointer factory used for posting delayed tasks.
base::WeakPtrFactory<TabManager> weak_ptr_factory_;

Powered by Google App Engine
This is Rietveld 408576698