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> |
| 11 #include <utility> | |
| 11 | 12 |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 18 #include "base/time.h" | 19 #include "base/time.h" |
| 19 #include "base/timer.h" | 20 #include "base/timer.h" |
| 20 #include "chrome/browser/prerender/prerender_config.h" | 21 #include "chrome/browser/prerender/prerender_config.h" |
| 21 #include "chrome/browser/prerender/prerender_contents.h" | 22 #include "chrome/browser/prerender/prerender_contents.h" |
| 22 #include "chrome/browser/prerender/prerender_final_status.h" | 23 #include "chrome/browser/prerender/prerender_final_status.h" |
| 23 #include "chrome/browser/prerender/prerender_origin.h" | 24 #include "chrome/browser/prerender/prerender_origin.h" |
| 24 #include "chrome/browser/profiles/profile_keyed_service.h" | 25 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 26 | 27 |
| 27 class Profile; | 28 class Profile; |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 class DictionaryValue; | 31 class DictionaryValue; |
| 31 } | 32 } |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 class WebContents; | 35 class WebContents; |
| 35 } | 36 } |
| 36 | 37 |
| 38 namespace gfx { | |
| 39 class Size; | |
| 40 } | |
| 41 | |
| 37 #if defined(COMPILER_GCC) | 42 #if defined(COMPILER_GCC) |
| 38 | 43 |
| 39 namespace BASE_HASH_NAMESPACE { | 44 namespace BASE_HASH_NAMESPACE { |
| 40 template <> | 45 template <> |
| 41 struct hash<content::WebContents*> { | 46 struct hash<content::WebContents*> { |
| 42 std::size_t operator()(content::WebContents* value) const { | 47 std::size_t operator()(content::WebContents* value) const { |
| 43 return reinterpret_cast<std::size_t>(value); | 48 return reinterpret_cast<std::size_t>(value); |
| 44 } | 49 } |
| 45 }; | 50 }; |
| 46 } | 51 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 PrerenderManager(Profile* profile, PrerenderTracker* prerender_tracker); | 94 PrerenderManager(Profile* profile, PrerenderTracker* prerender_tracker); |
| 90 | 95 |
| 91 virtual ~PrerenderManager(); | 96 virtual ~PrerenderManager(); |
| 92 | 97 |
| 93 // ProfileKeyedService implementation. | 98 // ProfileKeyedService implementation. |
| 94 virtual void Shutdown() OVERRIDE; | 99 virtual void Shutdown() OVERRIDE; |
| 95 | 100 |
| 96 // Entry points for adding prerenders. | 101 // Entry points for adding prerenders. |
| 97 | 102 |
| 98 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify | 103 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify |
| 99 // the RenderViewHost that the prerender request came from and are used to | 104 // the RenderView that the prerender request came from. The |size| may be |
| 100 // set the initial window size of the RenderViewHost used for prerendering. | 105 // empty, and the current tab size will be used if it is. If the current |
| 106 // active tab size cannot be found, we use a default from PrerenderConfig. | |
| 101 // Returns true if the URL was added, false if it was not. | 107 // Returns true if the URL was added, false if it was not. |
| 102 // If the RenderViewHost source is itself prerendering, the prerender is added | 108 // If the launching RenderView is itself prerendering, the prerender is added |
| 103 // as a pending prerender. | 109 // as a pending prerender. |
| 104 bool AddPrerenderFromLinkRelPrerender(int process_id, int route_id, | 110 bool AddPrerenderFromLinkRelPrerender( |
| 105 const GURL& url, | 111 int process_id, |
| 106 const content::Referrer& referrer); | 112 int route_id, |
| 113 const GURL& url, | |
| 114 const content::Referrer& referrer, | |
| 115 const gfx::Size& size, | |
| 116 content::SessionStorageNamespace* session_storage_namespace); | |
| 107 | 117 |
| 108 // Adds a prerender for |url| if valid. As the prerender request is coming | 118 // Adds a prerender for |url| if valid. As the prerender request is coming |
| 109 // from a source without a RenderViewHost (i.e., the omnibox) we don't have a | 119 // from a source without a RenderViewHost (i.e., the omnibox) we don't have a |
| 110 // child or route id, or a referrer. This method uses sensible values for | 120 // child or route id, or a referrer. This method uses sensible values for |
| 111 // those. The |session_storage_namespace| matches the namespace of the active | 121 // those. The |session_storage_namespace| matches the namespace of the active |
| 112 // tab at the time the prerender is generated from the omnibox. | 122 // tab at the time the prerender is generated from the omnibox. |
| 113 bool AddPrerenderFromOmnibox( | 123 bool AddPrerenderFromOmnibox( |
| 114 const GURL& url, | 124 const GURL& url, |
| 115 content::SessionStorageNamespace* session_storage_namespace); | 125 content::SessionStorageNamespace* session_storage_namespace); |
| 116 | 126 |
| 127 // Request cancelation of a previously added prerender. If the |active_count_| | |
| 128 // of the prerender is one, it will be canceled. Otherwise, |active_count_| | |
| 129 // will be decremented by one. | |
| 130 void MaybeCancelPrerender(const GURL& url); | |
| 131 | |
| 117 // Destroy all prerenders for the given child route id pair and assign a final | 132 // Destroy all prerenders for the given child route id pair and assign a final |
| 118 // status to them. | 133 // status to them. |
| 119 virtual void DestroyPrerenderForRenderView(int process_id, int view_id, | 134 virtual void DestroyPrerenderForRenderView(int process_id, |
| 135 int view_id, | |
| 120 FinalStatus final_status); | 136 FinalStatus final_status); |
| 121 | 137 |
| 122 // Cancels all active prerenders. | 138 // Cancels all active prerenders. |
| 123 void CancelAllPrerenders(); | 139 void CancelAllPrerenders(); |
| 124 | 140 |
| 125 // Cancels all active prerenders with the ORIGIN_OMNIBOX origin. | 141 // Cancels all active prerenders with the ORIGIN_OMNIBOX origin. |
| 126 void CancelOmniboxPrerenders(); | 142 void CancelOmniboxPrerenders(); |
| 127 | 143 |
| 128 // If |url| matches a valid prerendered page, try to swap it into | 144 // If |url| matches a valid prerendered page, try to swap it into |
| 129 // |web_contents| and merge browsing histories. Returns |true| if a | 145 // |web_contents| and merge browsing histories. Returns |true| if a |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 protected: | 256 protected: |
| 241 void SetPrerenderContentsFactory( | 257 void SetPrerenderContentsFactory( |
| 242 PrerenderContents::Factory* prerender_contents_factory); | 258 PrerenderContents::Factory* prerender_contents_factory); |
| 243 | 259 |
| 244 // Utility method that is called from the virtual Shutdown method on this | 260 // Utility method that is called from the virtual Shutdown method on this |
| 245 // class but is called directly from the TestPrerenderManager in the unit | 261 // class but is called directly from the TestPrerenderManager in the unit |
| 246 // tests. | 262 // tests. |
| 247 void DoShutdown(); | 263 void DoShutdown(); |
| 248 | 264 |
| 249 private: | 265 private: |
| 250 // Needs access to AddPrerender. | |
| 251 friend class PrerenderContents; | |
| 252 | |
| 253 // Test that needs needs access to internal functions. | 266 // Test that needs needs access to internal functions. |
| 254 friend class PrerenderBrowserTest; | 267 friend class PrerenderBrowserTest; |
| 255 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, AliasURLTest); | 268 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, AliasURLTest); |
| 256 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, CancelAllTest); | 269 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, CancelAllTest); |
| 257 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, | 270 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, |
| 258 CancelOmniboxRemovesOmniboxTest); | 271 CancelOmniboxRemovesOmniboxTest); |
| 259 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, | 272 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, |
| 260 CancelOmniboxDoesNotRemoveLinkTest); | 273 CancelOmniboxDoesNotRemoveLinkTest); |
| 261 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ClearTest); | 274 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ClearTest); |
| 262 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ControlGroup); | 275 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ControlGroup); |
| 263 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropOldestRequestTest); | 276 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, DropOldestRequestTest); |
| 264 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropSecondRequestTest); | 277 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, DropSecondRequestTest); |
| 265 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExpireTest); | 278 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ExpireTest); |
| 266 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FoundTest); | 279 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FoundTest); |
| 267 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesFragmentTest); | 280 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FragmentMatchesFragmentTest); |
| 268 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesPageTest); | 281 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FragmentMatchesPageTest); |
| 269 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PageMatchesFragmentTest); | 282 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerAddTwiceCancelTwice); |
| 270 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PendingPrerenderTest); | 283 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancel); |
| 271 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitInWindowTest); | 284 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelThenAddAgain); |
| 272 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitOutsideWindowTest); | 285 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelTwice); |
| 273 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, SourceRenderViewClosed); | 286 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerExpireThenAddAgain); |
| 274 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, TwoElementPrerenderTest); | 287 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerExpireThenCancel); |
| 288 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PageMatchesFragmentTest); | |
| 289 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PendingPrerenderTest); | |
| 290 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RateLimitInWindowTest); | |
| 291 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RateLimitOutsideWindowTest); | |
| 292 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, SourceRenderViewClosed); | |
| 293 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, TwoElementPrerenderTest); | |
| 275 | 294 |
| 276 struct PrerenderContentsData; | 295 struct PrerenderContentsData; |
| 277 struct NavigationRecord; | 296 struct NavigationRecord; |
| 278 | 297 |
| 279 class OnCloseTabContentsDeleter; | 298 class OnCloseTabContentsDeleter; |
| 280 | 299 |
| 281 class MostVisitedSites; | 300 class MostVisitedSites; |
| 282 | 301 |
| 283 typedef std::list<PrerenderContentsData> PrerenderContentsDataList; | 302 typedef std::list<PrerenderContentsData> PrerenderContentsDataList; |
| 284 | 303 |
| 285 // Adds a prerender for |url| from referrer |referrer| initiated from the | 304 // Adds a prerender for |url| from referrer |referrer| initiated from the |
| 286 // RenderViewHost specified by |child_route_id_pair|. The |origin| specifies | 305 // child process specified by |child__id|. The |origin| specifies how the |
|
mmenke
2012/05/01 16:23:21
nit: child_id.
| |
| 287 // how the prerender was added. If the |session_storage_namespace| is NULL, | 306 // prerender was added. If the |size| is empty, the size of the currently |
| 288 // it is discovered using the RenderViewHost specified by | 307 // active tab will be used, if available. If the current active tab size |
| 289 // |child_route_id_pair|. | 308 // cannot be found, we use a default from PrerenderCOnfig. |
|
mmenke
2012/05/01 16:23:21
nit: PrerenderConfig.
mmenke
2012/05/01 16:23:21
I suggest you mention that it's the PrerenderConte
gavinp
2012/05/01 18:50:22
Done.
gavinp
2012/05/01 18:50:22
Done.
| |
| 290 bool AddPrerender( | 309 bool AddPrerender( |
| 291 Origin origin, | 310 Origin origin, |
| 292 const std::pair<int, int>& child_route_id_pair, | 311 int child_id, |
| 293 const GURL& url, | 312 const GURL& url, |
| 294 const content::Referrer& referrer, | 313 const content::Referrer& referrer, |
| 314 const gfx::Size& size, | |
| 295 content::SessionStorageNamespace* session_storage_namespace); | 315 content::SessionStorageNamespace* session_storage_namespace); |
| 296 | 316 |
| 297 // Retrieves the PrerenderContents object for the specified URL, if it | 317 // Retrieves the PrerenderContents object for the specified URL, if it |
| 298 // has been prerendered. The caller will then have ownership of the | 318 // has been prerendered. The caller will then have ownership of the |
| 299 // PrerenderContents object and is responsible for freeing it. | 319 // PrerenderContents object and is responsible for freeing it. |
| 300 // Returns NULL if the specified URL has not been prerendered. | 320 // Returns NULL if the specified URL has not been prerendered. |
| 301 PrerenderContents* GetEntry(const GURL& url); | 321 PrerenderContents* GetEntry(const GURL& url); |
| 302 | 322 |
| 303 // Identical to GetEntry, with one exception: | 323 // Identical to GetEntry, with one exception: |
| 304 // The WebContents specified indicates the WC in which to swap the | 324 // The WebContents specified indicates the WC in which to swap the |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 334 Origin origin, | 354 Origin origin, |
| 335 uint8 experiment_id); | 355 uint8 experiment_id); |
| 336 | 356 |
| 337 // Checks if the PrerenderContents has been added to the pending delete list. | 357 // Checks if the PrerenderContents has been added to the pending delete list. |
| 338 bool IsPendingDelete(PrerenderContents* entry) const; | 358 bool IsPendingDelete(PrerenderContents* entry) const; |
| 339 | 359 |
| 340 // Deletes any PrerenderContents that have been added to the pending delete | 360 // Deletes any PrerenderContents that have been added to the pending delete |
| 341 // list. | 361 // list. |
| 342 void DeletePendingDeleteEntries(); | 362 void DeletePendingDeleteEntries(); |
| 343 | 363 |
| 344 // Finds the specified PrerenderContents and returns it, if it exists. | 364 // Finds the specified PrerenderContentsData/PrerenderContents and returns it, |
| 345 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 365 // if it exists. Returns NULL otherwise. Unlike GetEntry, the |
| 346 // ownership of the PrerenderContents. | 366 // PrerenderManager maintains ownership of the PrerenderContents. |
| 367 PrerenderContentsData* FindEntryData(const GURL& url); | |
| 347 PrerenderContents* FindEntry(const GURL& url) const; | 368 PrerenderContents* FindEntry(const GURL& url) const; |
| 348 | 369 |
| 349 // Returns the iterator to the PrerenderContentsData entry that is being | 370 // Returns the iterator to the PrerenderContentsData entry that is being |
| 350 // prerendered from the given child route id pair. | 371 // prerendered from the given child route id pair. |
| 351 PrerenderContentsDataList::iterator | 372 PrerenderContentsDataList::iterator |
| 352 FindPrerenderContentsForChildRouteIdPair( | 373 FindPrerenderContentsForChildRouteIdPair( |
| 353 const std::pair<int, int>& child_route_id_pair); | 374 const std::pair<int, int>& child_route_id_pair); |
| 354 | 375 |
| 376 PrerenderContentsDataList::iterator | |
| 377 FindPrerenderContentsForURL(const GURL& url); | |
| 378 | |
| 355 bool DoesRateLimitAllowPrerender() const; | 379 bool DoesRateLimitAllowPrerender() const; |
| 356 | 380 |
| 357 // Deletes old WebContents that have been replaced by prerendered ones. This | 381 // Deletes old WebContents that have been replaced by prerendered ones. This |
| 358 // is needed because they're replaced in a callback from the old WebContents, | 382 // is needed because they're replaced in a callback from the old WebContents, |
| 359 // so cannot immediately be deleted. | 383 // so cannot immediately be deleted. |
| 360 void DeleteOldTabContents(); | 384 void DeleteOldTabContents(); |
| 361 | 385 |
| 362 // Cleans up old NavigationRecord's. | 386 // Cleans up old NavigationRecord's. |
| 363 void CleanUpOldNavigations(); | 387 void CleanUpOldNavigations(); |
| 364 | 388 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 | 486 |
| 463 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 487 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 464 }; | 488 }; |
| 465 | 489 |
| 466 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( | 490 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( |
| 467 int render_process_id); | 491 int render_process_id); |
| 468 | 492 |
| 469 } // namespace prerender | 493 } // namespace prerender |
| 470 | 494 |
| 471 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 495 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |