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

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 72fa655d0c0941118cd4ad190cc89a645c469eb9..2dd90e6950d23d5405b4cbbc7e1a77bd55e3f301 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,14 @@ 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 tab has finished loading. TabManager can
+ // decide which tab to load next.
+ void HasFinishedLoadingTab(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 +167,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);
@@ -205,10 +222,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.
@@ -302,6 +315,13 @@ class TabManager : public TabStripModelObserver {
// Returns true if tabs can be discarded only once.
bool CanOnlyDiscardOnce() const;
+ // Returns true if the navigation should be delay.
chrisha 2017/06/15 21:02:24 delayed*
Zhen Wang 2017/06/19 23:00:12 Done.
+ bool ShouldDelayNavigation(
+ content::NavigationHandle* navigation_handle) const;
+
+ // Resume the tab's navigation if it is pending right now.
+ void ResumeTabNavigationIfNeeded(content::WebContents* contents);
+
// Timer to periodically update the stats of the renderers.
base::RepeatingTimer update_timer_;
@@ -365,6 +385,16 @@ 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 throttled.
+ std::vector<content::NavigationHandle*> pending_navigations_;
+
+ // The tab that is currently loading. If multiple tabs are loading
+ // simultaneously, it corresponds to the lastest one. We will consider loading
+ // the next background tab when this tab has finished loading.
+ // TODO(zhenw): This is a native algorithm. It should be updated to use
nasko 2017/06/15 20:01:58 nit: Did you mean "naive" instead of "native"?
Zhen Wang 2017/06/19 23:00:12 Right. Updated to naive. Thanks for catching this!
+ // smarter ways, e.g., making sure all loading tabs have finished.
+ content::WebContents* loading_contents_;
chrisha 2017/06/15 21:02:24 We have loading states being worked on in another
Zhen Wang 2017/06/19 23:00:12 Now I have rebased this CL on the other CL and I c
chrisha 2017/06/20 18:26:54 sgtm
+
// Weak pointer factory used for posting delayed tasks.
base::WeakPtrFactory<TabManager> weak_ptr_factory_;

Powered by Google App Engine
This is Rietveld 408576698