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..be4df5977fcfaac1c92e3cd517036e579a00bd22 100644 |
| --- a/chrome/browser/prerender/prerender_manager.h |
| +++ b/chrome/browser/prerender/prerender_manager.h |
| @@ -7,6 +7,7 @@ |
| #pragma once |
| #include <list> |
| +#include <map> |
| #include <string> |
| #include <utility> |
| @@ -21,6 +22,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 +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. |
|
dominich
2012/07/02 20:43:03
Add comment that caller is the owner of the return
gavinp
2012/07/03 16:41:02
Done.
|
| - bool AddPrerenderFromLinkRelPrerender( |
| + PrerenderHandle* AddPrerenderFromLinkRelPrerender( |
| int process_id, |
| int route_id, |
| const GURL& url, |
| @@ -119,16 +121,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 +181,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 +230,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 +239,55 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| PrerenderHistograms* histograms() const { return histograms_.get(); } |
| protected: |
| + friend class PrerenderContents; |
| + friend class PrerenderHandle; |
| + |
| void SetPrerenderContentsFactory( |
| PrerenderContents::Factory* prerender_contents_factory); |
| + // Adds a prerender from a pending Prerender, called by |
| + // PrerenderContents::StartPendingPrerenders. |
| + void StartPendingPrerender( |
| + PrerenderHandle* existing_prerender_handle, |
| + Origin origin, |
| + int process_id, |
| + const GURL& url, |
| + const content::Referrer& referrer, |
| + const gfx::Size& size, |
| + content::SessionStorageNamespace* session_storage_namespace); |
| + |
| + void DestroyPendingPrerenderData( |
| + PrerenderHandle::PrerenderData* pending_prerender_data); |
| + |
| // 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(); |
| private: |
| - // Test that needs needs access to internal functions. |
| + friend class TestPrerenderManager; |
| 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; |
| + struct NavigationRecord; |
| + |
| + typedef PrerenderHandle::PrerenderData PrerenderData; |
|
dominich
2012/07/02 20:43:03
I'm not convinced this typedef makes the code clea
gavinp
2012/07/03 16:41:02
Done.
|
| + typedef std::map<const PrerenderData*, base::WeakPtrFactory<PrerenderData>*> |
| + PrerenderWeakPtrFactoryMap; |
| - typedef std::list<PrerenderContentsData> PrerenderContentsDataList; |
| 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| |
|
dominich
2012/07/02 20:43:03
update comment - no prerender_handle parameter.
gavinp
2012/07/03 16:41:02
Done.
|
| + // 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 +295,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. |
| @@ -352,7 +312,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; |
| @@ -366,20 +326,27 @@ 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; |
| + PrerenderHandle* CreatePrerenderHandleForPrerenderData( |
| + PrerenderData* prerender_data); |
| - // 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); |
| + void InvalidatePrerenderHandlesForPrerenderData( |
| + const PrerenderData& prerender_data); |
| - PrerenderContentsDataList::iterator |
| - FindPrerenderContentsForURL(const GURL& url); |
| + // Finds the active PrerenderData object for a running prerender matching |
| + // |url| and |session_storage_namespace|. |
| + PrerenderData* FindPrerenderData( |
| + const GURL& url, |
| + const content::SessionStorageNamespace* session_storage_namespace); |
| + |
| + // Finds the active PrerenderData object for a running prerender corresponding |
| + // to the renderer process |child_id| and the render view in |route_id|. |
| + PrerenderData* FindPrerenderDataForChildAndRoute(int child_id, |
| + int route_id); |
| + |
| + // Given the |prerender_contents|, find the iterator in active_prerender_list_ |
| + // correponding to that running prerender. |
| + std::list<PrerenderData>::iterator FindIteratorForPrerenderContents( |
| + PrerenderContents* prerender_contents); |
| bool DoesRateLimitAllowPrerender() const; |
| @@ -440,8 +407,19 @@ class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| PrerenderTracker* prerender_tracker_; |
| - // List of prerendered elements. |
| - PrerenderContentsDataList prerender_list_; |
| + // List of all running prerenders. |
| + // It is kept sorted, in increasing order by expiry time. The STL list was |
| + // chosen because it does not move items in memory (this lets handles continue |
| + // to point to their PrerenderData). |
| + std::list<PrerenderData> active_prerender_list_; |
| + |
| + // List of all pending prerenders. |
| + std::list<PrerenderData> pending_prerender_list_; |
| + |
| + // The prerenders in the above list need WeakPtrs to instantiate their |
| + // handle. Keep them here for the lifetime of each element in the list. |
| + PrerenderWeakPtrFactoryMap prerender_weak_ptr_factory_map_; |
| + |
| // List of recent navigations in this profile, sorted by ascending |
| // navigate_time_. |