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

Unified Diff: chrome/browser/prerender/prerender_manager.h

Issue 10553029: Handle interface to prerenders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more standard code, simpler handle, no class explosion Created 8 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/prerender/prerender_manager.h
diff --git a/chrome/browser/prerender/prerender_manager.h b/chrome/browser/prerender/prerender_manager.h
index 3fa9591e9629923ea8f0ab379447502f6629ee98..7a8c121125ceafd6deda942fe3d7a44799f0110a 100644
--- a/chrome/browser/prerender/prerender_manager.h
+++ b/chrome/browser/prerender/prerender_manager.h
@@ -12,6 +12,7 @@
#include "base/gtest_prod_util.h"
#include "base/hash_tables.h"
+#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/weak_ptr.h"
@@ -55,6 +56,7 @@ struct hash<content::WebContents*> {
namespace prerender {
class PrerenderCondition;
+class PrerenderHandle;
class PrerenderHistograms;
class PrerenderHistory;
class PrerenderLocalPredictor;
@@ -107,7 +109,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// Returns true if the URL was added, false if it was not.
// If the launching RenderView is itself prerendering, the prerender is added
// as a pending prerender.
- bool AddPrerenderFromLinkRelPrerender(
+ base::WeakPtr<PrerenderHandle> AddPrerenderFromLinkRelPrerender(
int process_id,
int route_id,
const GURL& url,
@@ -119,14 +121,18 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// child or route id, or a referrer. This method uses sensible values for
// those. The |session_storage_namespace| matches the namespace of the active
// tab at the time the prerender is generated from the omnibox.
- bool AddPrerenderFromOmnibox(
+ base::WeakPtr<PrerenderHandle> AddPrerenderFromOmnibox(
dominich 2012/06/22 15:36:16 This cements it for me. I don't like an API that r
const GURL& url,
content::SessionStorageNamespace* session_storage_namespace);
- // Request cancelation of a previously added prerender. If the |active_count_|
- // of the prerender is one, it will be canceled. Otherwise, |active_count_|
- // will be decremented by one.
- void MaybeCancelPrerender(const GURL& url);
+ // Adds a prerender
+ void StartPendingPrerender(
+ scoped_ptr<PrerenderHandle> existing_prerender_handle,
dominich 2012/06/22 15:36:16 ... uses a different smart pointer to the same typ
+ int process_id,
+ const GURL& url,
+ const content::Referrer& referrer,
+ const gfx::Size& size,
+ content::SessionStorageNamespace* session_storage_namespace);
dominich 2012/06/22 15:36:16 ps - why is starting a pending prerender a public
// Destroy all prerenders for the given child route id pair and assign a final
// status to them.
@@ -137,9 +143,6 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// Cancels all active prerenders.
void CancelAllPrerenders();
- // Cancels all active prerenders with the ORIGIN_OMNIBOX origin.
- void CancelOmniboxPrerenders();
-
// If |url| matches a valid prerendered page, try to swap it into
// |web_contents| and merge browsing histories. Returns |true| if a
// prerendered page is swapped in, |false| otherwise.
@@ -186,10 +189,6 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// is prerendering a page.
bool IsWebContentsPrerendering(content::WebContents* web_contents) const;
- // Returns true if there is a prerendered page for the given URL and it has
- // finished loading. Only valid if called before MaybeUsePrerenderedPage.
- bool DidPrerenderFinishLoading(const GURL& url) const;
-
// Maintaining and querying the set of WebContents belonging to this
// PrerenderManager that are currently showing prerendered pages.
void MarkWebContentsAsPrerendered(content::WebContents* web_contents);
@@ -239,11 +238,6 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// Adds a condition. This is owned by the PrerenderManager.
void AddCondition(const PrerenderCondition* condition);
- bool IsPendingEntry(const GURL& url) const;
-
- // Returns true if |url| matches any URLs being prerendered.
- bool IsPrerendering(const GURL& url) const;
-
// Records that some visible tab navigated (or was redirected) to the
// provided URL.
void RecordNavigation(const GURL& url);
@@ -261,6 +255,8 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// tests.
void DoShutdown();
+ PrerenderContents* FindEntry(const GURL& url);
dominich 2012/06/22 15:36:16 move to protected for tests?
gavinp 2012/06/22 17:45:29 Yup.
+
private:
// Test that needs needs access to internal functions.
friend class PrerenderBrowserTest;
@@ -299,30 +295,37 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
FRIEND_TEST_ALL_PREFIXES(PrerenderTest, SourceRenderViewClosed);
FRIEND_TEST_ALL_PREFIXES(PrerenderTest, TwoElementPrerenderTest);
- struct PrerenderContentsData;
struct NavigationRecord;
class OnCloseTabContentsDeleter;
- typedef std::list<PrerenderContentsData> PrerenderContentsDataList;
+ typedef std::map<PrerenderContents*, linked_ptr<PrerenderHandle>,
+ PrerenderContents::LessThanByLoadStartTime>
+ PrerenderHandleMap;
dominich 2012/06/22 15:36:16 if the PrerenderHandle already contains the Preren
typedef base::hash_map<content::WebContents*, bool> WouldBePrerenderedMap;
// Time window for which we record old navigations, in milliseconds.
static const int kNavigationRecordWindowMs = 5000;
- // Adds a prerender for |url| from referrer |referrer| initiated from the
- // child process specified by |child_id|. The |origin| specifies how the
- // prerender was added. If the |size| is empty, then
- // PrerenderContents::StartPrerendering will instead use the size of the
- // currently active tab. If the current active tab size cannot be found, it
- // then uses a default from PrerenderConfig.
- bool AddPrerender(
+ // Adds a prerender for |url| from |referrer| initiated from the process
+ // |child_id|. The |origin| specifies how the prerender was added. If |size|
+ // is empty, then PrerenderContents::StartPrerendering will instead use the
+ // size of the currently active tab. If the current active tab size cannot be
+ // found, it then uses a default from PrerenderConfig. If |prerender_handle|
+ // is NULL, then AddPrerender will allocate a handle for the caller if
+ // successful. If |preexisting_prerender_handle| is not-NULL, the
+ // PrerenderManager will take ownership of it and associate the prerender with
+ // that handle. The return value is a WeakPtr to a PrerenderHandle. It can
+ // be NULL, if for instance Prerendering is disabled or if there was an error
+ // adding this prerender.
+ base::WeakPtr<PrerenderHandle> AddPrerender(
Origin origin,
int child_id,
const GURL& url,
const content::Referrer& referrer,
const gfx::Size& size,
- content::SessionStorageNamespace* session_storage_namespace);
+ content::SessionStorageNamespace* session_storage_namespace,
+ const scoped_ptr<PrerenderHandle> preexisting_prerender_handle);
dominich 2012/06/22 15:36:16 I don't understand why this is passed through and
// Retrieves the PrerenderContents object for the specified URL, if it
// has been prerendered. The caller will then have ownership of the
@@ -334,13 +337,14 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// The WebContents specified indicates the WC in which to swap the
// prerendering into. If the WebContents specified is the one
// to doing the prerendered itself, will return NULL.
- PrerenderContents* GetEntryButNotSpecifiedWC(const GURL& url,
- content::WebContents* wc);
+ PrerenderContents* GetEntryButNotSpecifiedWC(
+ const GURL& url,
+ content::WebContents* web_contents);
- // Starts scheduling periodic cleanups.
void StartSchedulingPeriodicCleanups();
- // Stops scheduling periodic cleanups if they're no longer needed.
- void MaybeStopSchedulingPeriodicCleanups();
+ void StopSchedulingPeriodicCleanups();
+
+ void EvictOldestPrerendersIfNecessary();
// Deletes stale and cancelled prerendered PrerenderContents, as well as
// WebContents that have been replaced by prerendered WebContents.
@@ -354,7 +358,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
void PostCleanupTask();
base::TimeDelta GetMaxAge() const;
- bool IsPrerenderElementFresh(const base::Time start) const;
+ bool IsPrerenderFresh(base::TimeTicks start) const;
void DeleteOldEntries();
virtual base::Time GetCurrentTime() const;
virtual base::TimeTicks GetCurrentTimeTicks() const;
@@ -368,20 +372,13 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
// list.
void DeletePendingDeleteEntries();
- // Finds the specified PrerenderContentsData/PrerenderContents and returns it,
- // if it exists. Returns NULL otherwise. Unlike GetEntry, the
// PrerenderManager maintains ownership of the PrerenderContents.
- PrerenderContentsData* FindEntryData(const GURL& url);
- PrerenderContents* FindEntry(const GURL& url) const;
-
- // Returns the iterator to the PrerenderContentsData entry that is being
- // prerendered from the given child route id pair.
- PrerenderContentsDataList::iterator
- FindPrerenderContentsForChildRouteIdPair(
- const std::pair<int, int>& child_route_id_pair);
+ PrerenderHandle* FindHandle(
dominich 2012/06/22 15:36:16 with all those smart pointer returns, i'm surprise
+ const GURL& url,
+ const content::SessionStorageNamespace* session_storage_namespace);
- PrerenderContentsDataList::iterator
- FindPrerenderContentsForURL(const GURL& url);
+ // PrerenderManager maintains ownership of the PrerenderContents.
+ PrerenderContents* FindContentsForChildAndRoute(int child_id, int route_id);
dominich 2012/06/22 15:36:16 If we add a new prerender for the same URL/Session
bool DoesRateLimitAllowPrerender() const;
@@ -442,8 +439,9 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
PrerenderTracker* prerender_tracker_;
- // List of prerendered elements.
- PrerenderContentsDataList prerender_list_;
+ // Map of prerendered elements. This map owns both each PrerenderHandle* and
+ // each PrerenderContents* in it.
+ PrerenderHandleMap prerender_map_;
// List of recent navigations in this profile, sorted by ascending
// navigate_time_.

Powered by Google App Engine
This is Rietveld 408576698