Chromium Code Reviews| Index: chrome/browser/prerender/prerender_manager.h |
| diff --git a/chrome/browser/prerender/prerender_manager.h b/chrome/browser/prerender/prerender_manager.h |
| index 5d357ac99087d7b15bbeea0f3e6594a3362747e4..f3adefef6fac4a5382a864327baf60c7292e45fb 100644 |
| --- a/chrome/browser/prerender/prerender_manager.h |
| +++ b/chrome/browser/prerender/prerender_manager.h |
| @@ -21,6 +21,7 @@ |
| #include "chrome/browser/prerender/prerender_config.h" |
| #include "chrome/browser/prerender/prerender_contents.h" |
| #include "chrome/browser/prerender/prerender_final_status.h" |
| +#include "chrome/browser/prerender/prerender_handle.h" |
| #include "chrome/browser/prerender/prerender_origin.h" |
| #include "chrome/browser/profiles/profile_keyed_service.h" |
| #include "googleurl/src/gurl.h" |
| @@ -107,7 +108,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( |
| + PrerenderHandle AddPrerenderFromLinkRelPrerender( |
| int process_id, |
| int route_id, |
| const GURL& url, |
| @@ -119,16 +120,11 @@ 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( |
| + PrerenderHandle AddPrerenderFromOmnibox( |
| const GURL& url, |
| content::SessionStorageNamespace* session_storage_namespace, |
| gfx::Size size); |
| - // 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); |
| - |
| // Destroy all prerenders for the given child route id pair and assign a final |
| // status to them. |
| virtual void DestroyPrerenderForRenderView(int process_id, |
| @@ -184,10 +180,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); |
| @@ -237,11 +229,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); |
| @@ -251,70 +238,60 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| PrerenderHistograms* histograms() const { return histograms_.get(); } |
| protected: |
| + friend class PrerenderContents; |
| + |
| + // Time window for which we record old navigations, in milliseconds. |
| + static const int kNavigationRecordWindowMs = 5000; |
| + |
| void SetPrerenderContentsFactory( |
| PrerenderContents::Factory* prerender_contents_factory); |
| + // Adds a prerender from a pending Prerender, called by |
| + // PrerenderContents::StartPendingPrerenders. |
| + void StartPendingPrerender( |
| + PrerenderHandleImpl* existing_prerender_handle, |
| + Origin origin, |
| + int process_id, |
| + const GURL& url, |
| + const content::Referrer& referrer, |
| + const gfx::Size& size, |
| + content::SessionStorageNamespace* session_storage_namespace); |
| + |
| // Utility method that is called from the virtual Shutdown method on this |
| // class but is called directly from the TestPrerenderManager in the unit |
| // tests. |
| void DoShutdown(); |
| + // Finds a prerender contents for the specified |url| and |
| + // |session_storage_namespace| if it is prerendering. Used only in tests. |
|
dominich
2012/06/28 00:34:32
#if UNIT_TEST?
|
| + PrerenderContents* FindEntry( |
| + const GURL& url, |
| + content::SessionStorageNamespace* session_storage_namespace); |
| + |
| + void TreatPrerenderAsUsedForTest( |
|
dominich
2012/06/28 00:34:32
This should be a member of TestPrerenderManager as
|
| + const GURL& url, |
| + content::SessionStorageNamespace* session_storage_namespace); |
| + |
| + base::TimeDelta GetMaxAge() const; |
| + |
| private: |
| - // Test that needs needs access to internal functions. |
| friend class PrerenderBrowserTest; |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, AliasURLTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, CancelAllTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, |
| - CancelOmniboxRemovesOmniboxTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, |
| - CancelOmniboxDoesNotRemoveLinkTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ClearTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ControlGroup); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, DropOldestRequestTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, DropSecondRequestTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ExpireTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FoundTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FragmentMatchesFragmentTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FragmentMatchesPageTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerAbandon); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerAddTwiceAbandonTwice); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerAddTwiceCancelTwice); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, |
| - LinkManagerAddTwiceCancelTwiceThenAbandonTwice); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancel); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelThenAbandon); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelThenAddAgain); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelTwice); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerExpireThenAddAgain); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerExpireThenCancel); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, NotSoRecentlyVisited); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PageMatchesFragmentTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PendingPrerenderTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PPLTDummy); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RateLimitInWindowTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RateLimitOutsideWindowTest); |
| - FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RecentlyVisitedPPLTDummy); |
| - 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::list<PrerenderHandleImpl*> PrerenderHandleList; |
| 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. |
| + PrerenderHandle AddPrerender( |
| Origin origin, |
| int child_id, |
| const GURL& url, |
| @@ -322,23 +299,10 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| gfx::Size size, |
| content::SessionStorageNamespace* session_storage_namespace); |
| - // Retrieves the PrerenderContents object for the specified URL, if it |
| - // has been prerendered. The caller will then have ownership of the |
| - // PrerenderContents object and is responsible for freeing it. |
| - // Returns NULL if the specified URL has not been prerendered. |
| - PrerenderContents* GetEntry(const GURL& url); |
| - |
| - // Identical to GetEntry, with one exception: |
| - // 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); |
| - |
| - // 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. |
| @@ -351,8 +315,7 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| // automatically be cancelled. |
| 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; |
| @@ -366,20 +329,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); |
| + PrerenderHandleImpl* FindHandle( |
| + const GURL& url, |
| + const content::SessionStorageNamespace* session_storage_namespace); |
| - PrerenderContentsDataList::iterator |
| - FindPrerenderContentsForURL(const GURL& url); |
| + // PrerenderManager maintains ownership of the PrerenderContents. |
| + PrerenderHandleImpl* FindHandleForChildAndRoute(int child_id, int route_id); |
| bool DoesRateLimitAllowPrerender() const; |
| @@ -440,8 +396,8 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| PrerenderTracker* prerender_tracker_; |
| - // List of prerendered elements. |
| - PrerenderContentsDataList prerender_list_; |
| + // List of all running prerenders. This list owns each PrerenderHandle in it. |
| + PrerenderHandleList prerender_list_; |
| // List of recent navigations in this profile, sorted by ascending |
| // navigate_time_. |