Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 SessionStorageNamespace* session_storage_namespace); | 114 SessionStorageNamespace* session_storage_namespace); |
| 115 | 115 |
| 116 // Destroy all prerenders for the given child route id pair and assign a final | 116 // Destroy all prerenders for the given child route id pair and assign a final |
| 117 // status to them. | 117 // status to them. |
| 118 virtual void DestroyPrerenderForRenderView(int process_id, int view_id, | 118 virtual void DestroyPrerenderForRenderView(int process_id, int view_id, |
| 119 FinalStatus final_status); | 119 FinalStatus final_status); |
| 120 | 120 |
| 121 // Cancels all active prerenders. | 121 // Cancels all active prerenders. |
| 122 void CancelAllPrerenders(); | 122 void CancelAllPrerenders(); |
| 123 | 123 |
| 124 // Cancels all active prerenders with the ORIGIN_OMNIBOX origin. | |
| 125 void CancelOmniboxPrerenders(); | |
| 126 | |
| 124 // For a given WebContents that wants to navigate to the URL supplied, | 127 // For a given WebContents that wants to navigate to the URL supplied, |
| 125 // determines whether a prerendered version of the URL can be used, | 128 // determines whether a prerendered version of the URL can be used, |
| 126 // and substitutes the prerendered RVH into the WebContents. |opener_url| is | 129 // and substitutes the prerendered RVH into the WebContents. |opener_url| is |
| 127 // set to the window.opener url that the WebContents should have set and | 130 // set to the window.opener url that the WebContents should have set and |
| 128 // will be empty if there is no opener set. Returns whether or not a | 131 // will be empty if there is no opener set. Returns whether or not a |
| 129 // prerendered RVH could be used or not. | 132 // prerendered RVH could be used or not. |
| 130 bool MaybeUsePrerenderedPage(content::WebContents* web_contents, | 133 bool MaybeUsePrerenderedPage(content::WebContents* web_contents, |
| 131 const GURL& url, | 134 const GURL& url, |
| 132 const GURL& opener_url); | 135 const GURL& opener_url); |
| 133 | 136 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 | 213 |
| 211 PrerenderTracker* prerender_tracker() { return prerender_tracker_; } | 214 PrerenderTracker* prerender_tracker() { return prerender_tracker_; } |
| 212 | 215 |
| 213 // Adds a condition. This is owned by the PrerenderManager. | 216 // Adds a condition. This is owned by the PrerenderManager. |
| 214 void AddCondition(const PrerenderCondition* condition); | 217 void AddCondition(const PrerenderCondition* condition); |
| 215 | 218 |
| 216 bool IsTopSite(const GURL& url); | 219 bool IsTopSite(const GURL& url); |
| 217 | 220 |
| 218 bool IsPendingEntry(const GURL& url) const; | 221 bool IsPendingEntry(const GURL& url) const; |
| 219 | 222 |
| 223 // Returns true if |url| matches any URLs being prerendered. | |
| 224 // TODO(dominich): This should be a const method but FindEntry is not const. | |
|
cbentzel
2012/01/25 12:14:01
Why not just make it const in this CL? You may nee
dominich
2012/01/25 23:09:23
I tried it out and it just worked, so that's done
| |
| 225 // It should be. | |
| 226 bool IsPrerendering(const GURL& url); | |
| 227 | |
| 220 protected: | 228 protected: |
| 221 void SetPrerenderContentsFactory( | 229 void SetPrerenderContentsFactory( |
| 222 PrerenderContents::Factory* prerender_contents_factory); | 230 PrerenderContents::Factory* prerender_contents_factory); |
| 223 | 231 |
| 224 // Utility method that is called from the virtual Shutdown method on this | 232 // Utility method that is called from the virtual Shutdown method on this |
| 225 // class but is called directly from the TestPrerenderManager in the unit | 233 // class but is called directly from the TestPrerenderManager in the unit |
| 226 // tests. | 234 // tests. |
| 227 void DoShutdown(); | 235 void DoShutdown(); |
| 228 | 236 |
| 229 private: | 237 private: |
| 230 // Needs access to AddPrerender. | 238 // Needs access to AddPrerender. |
| 231 friend class PrerenderContents; | 239 friend class PrerenderContents; |
| 232 | 240 |
| 233 // Test that needs needs access to internal functions. | 241 // Test that needs needs access to internal functions. |
| 234 friend class PrerenderBrowserTest; | 242 friend class PrerenderBrowserTest; |
| 235 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, AliasURLTest); | 243 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, AliasURLTest); |
| 244 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, CancelAllTest); | |
| 245 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, CancelOmniboxTest); | |
| 236 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ClearTest); | 246 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ClearTest); |
| 237 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ControlGroup); | 247 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ControlGroup); |
| 238 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropOldestRequestTest); | 248 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropOldestRequestTest); |
| 239 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropSecondRequestTest); | 249 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropSecondRequestTest); |
| 240 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExpireTest); | 250 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExpireTest); |
| 241 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FoundTest); | 251 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FoundTest); |
| 242 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesFragmentTest); | 252 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesFragmentTest); |
| 243 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesPageTest); | 253 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesPageTest); |
| 244 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PageMatchesFragmentTest); | 254 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PageMatchesFragmentTest); |
| 245 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PendingPrerenderTest); | 255 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PendingPrerenderTest); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 260 // how the prerender was added. If the |session_storage_namespace| is NULL, | 270 // how the prerender was added. If the |session_storage_namespace| is NULL, |
| 261 // it is discovered using the RenderViewHost specified by | 271 // it is discovered using the RenderViewHost specified by |
| 262 // |child_route_id_pair|. | 272 // |child_route_id_pair|. |
| 263 bool AddPrerender( | 273 bool AddPrerender( |
| 264 Origin origin, | 274 Origin origin, |
| 265 const std::pair<int, int>& child_route_id_pair, | 275 const std::pair<int, int>& child_route_id_pair, |
| 266 const GURL& url, | 276 const GURL& url, |
| 267 const content::Referrer& referrer, | 277 const content::Referrer& referrer, |
| 268 SessionStorageNamespace* session_storage_namespace); | 278 SessionStorageNamespace* session_storage_namespace); |
| 269 | 279 |
| 270 // Adds a pending preload issued by the prerendering RenderView identified by | |
| 271 // |child_route_id_pair|. If and when that prerendering RenderView is used, | |
| 272 // the specified prerender will start. | |
| 273 void AddPendingPrerender(Origin origin, | |
| 274 const std::pair<int, int>& child_route_id_pair, | |
| 275 const GURL& url, | |
| 276 const content::Referrer& referrer); | |
| 277 | |
| 278 // Retrieves the PrerenderContents object for the specified URL, if it | 280 // Retrieves the PrerenderContents object for the specified URL, if it |
| 279 // has been prerendered. The caller will then have ownership of the | 281 // has been prerendered. The caller will then have ownership of the |
| 280 // PrerenderContents object and is responsible for freeing it. | 282 // PrerenderContents object and is responsible for freeing it. |
| 281 // Returns NULL if the specified URL has not been prerendered. | 283 // Returns NULL if the specified URL has not been prerendered. |
| 282 PrerenderContents* GetEntry(const GURL& url); | 284 PrerenderContents* GetEntry(const GURL& url); |
| 283 | 285 |
| 284 // Identical to GetEntry, with one exception: | 286 // Identical to GetEntry, with one exception: |
| 285 // The WebContents specified indicates the WC in which to swap the | 287 // The WebContents specified indicates the WC in which to swap the |
| 286 // prerendering into. If the WebContents specified is the one | 288 // prerendering into. If the WebContents specified is the one |
| 287 // to doing the prerendered itself, will return NULL. | 289 // to doing the prerendered itself, will return NULL. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 327 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
| 326 // ownership of the PrerenderContents. | 328 // ownership of the PrerenderContents. |
| 327 PrerenderContents* FindEntry(const GURL& url); | 329 PrerenderContents* FindEntry(const GURL& url); |
| 328 | 330 |
| 329 // Returns the iterator to the PrerenderContentsData entry that is being | 331 // Returns the iterator to the PrerenderContentsData entry that is being |
| 330 // prerendered from the given child route id pair. | 332 // prerendered from the given child route id pair. |
| 331 std::list<PrerenderContentsData>::iterator | 333 std::list<PrerenderContentsData>::iterator |
| 332 FindPrerenderContentsForChildRouteIdPair( | 334 FindPrerenderContentsForChildRouteIdPair( |
| 333 const std::pair<int, int>& child_route_id_pair); | 335 const std::pair<int, int>& child_route_id_pair); |
| 334 | 336 |
| 335 // Returns whether the PrerenderManager is currently within the prerender | |
| 336 // window - effectively, up to 30 seconds after a prerender tag has been | |
| 337 // observed. | |
| 338 bool WithinWindow() const; | |
| 339 | |
| 340 bool DoesRateLimitAllowPrerender() const; | 337 bool DoesRateLimitAllowPrerender() const; |
| 341 | 338 |
| 342 // Deletes old TabContents that have been replaced by prerendered ones. This | 339 // Deletes old TabContents that have been replaced by prerendered ones. This |
| 343 // is needed because they're replaced in a callback from the old TabContents, | 340 // is needed because they're replaced in a callback from the old TabContents, |
| 344 // so cannot immediately be deleted. | 341 // so cannot immediately be deleted. |
| 345 void DeleteOldTabContents(); | 342 void DeleteOldTabContents(); |
| 346 | 343 |
| 347 // Cleans up old NavigationRecord's. | 344 // Cleans up old NavigationRecord's. |
| 348 void CleanUpOldNavigations(); | 345 void CleanUpOldNavigations(); |
| 349 | 346 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 | 427 |
| 431 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 428 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 432 }; | 429 }; |
| 433 | 430 |
| 434 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( | 431 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( |
| 435 int render_process_id); | 432 int render_process_id); |
| 436 | 433 |
| 437 } // namespace prerender | 434 } // namespace prerender |
| 438 | 435 |
| 439 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 436 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |