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); |
107 | 116 |
108 // Adds a prerender for |url| if valid. As the prerender request is coming | 117 // 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 | 118 // 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 | 119 // 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 | 120 // those. The |session_storage_namespace| matches the namespace of the active |
112 // tab at the time the prerender is generated from the omnibox. | 121 // tab at the time the prerender is generated from the omnibox. |
113 bool AddPrerenderFromOmnibox( | 122 bool AddPrerenderFromOmnibox( |
114 const GURL& url, | 123 const GURL& url, |
115 content::SessionStorageNamespace* session_storage_namespace); | 124 content::SessionStorageNamespace* session_storage_namespace); |
116 | 125 |
| 126 // Request cancelation of a previously added prerender. If the |active_count_| |
| 127 // of the prerender is one, it will be canceled. Otherwise, |active_count_| |
| 128 // will be decremented by one. |
| 129 void MaybeCancelPrerender(const GURL& url); |
| 130 |
117 // Destroy all prerenders for the given child route id pair and assign a final | 131 // Destroy all prerenders for the given child route id pair and assign a final |
118 // status to them. | 132 // status to them. |
119 virtual void DestroyPrerenderForRenderView(int process_id, int view_id, | 133 virtual void DestroyPrerenderForRenderView(int process_id, |
| 134 int view_id, |
120 FinalStatus final_status); | 135 FinalStatus final_status); |
121 | 136 |
122 // Cancels all active prerenders. | 137 // Cancels all active prerenders. |
123 void CancelAllPrerenders(); | 138 void CancelAllPrerenders(); |
124 | 139 |
125 // Cancels all active prerenders with the ORIGIN_OMNIBOX origin. | 140 // Cancels all active prerenders with the ORIGIN_OMNIBOX origin. |
126 void CancelOmniboxPrerenders(); | 141 void CancelOmniboxPrerenders(); |
127 | 142 |
128 // If |url| matches a valid prerendered page, try to swap it into | 143 // If |url| matches a valid prerendered page, try to swap it into |
129 // |web_contents| and merge browsing histories. Returns |true| if a | 144 // |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: | 255 protected: |
241 void SetPrerenderContentsFactory( | 256 void SetPrerenderContentsFactory( |
242 PrerenderContents::Factory* prerender_contents_factory); | 257 PrerenderContents::Factory* prerender_contents_factory); |
243 | 258 |
244 // Utility method that is called from the virtual Shutdown method on this | 259 // Utility method that is called from the virtual Shutdown method on this |
245 // class but is called directly from the TestPrerenderManager in the unit | 260 // class but is called directly from the TestPrerenderManager in the unit |
246 // tests. | 261 // tests. |
247 void DoShutdown(); | 262 void DoShutdown(); |
248 | 263 |
249 private: | 264 private: |
250 // Needs access to AddPrerender. | |
251 friend class PrerenderContents; | |
252 | |
253 // Test that needs needs access to internal functions. | 265 // Test that needs needs access to internal functions. |
254 friend class PrerenderBrowserTest; | 266 friend class PrerenderBrowserTest; |
255 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, AliasURLTest); | 267 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, AliasURLTest); |
256 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, CancelAllTest); | 268 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, CancelAllTest); |
257 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, | 269 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, |
258 CancelOmniboxRemovesOmniboxTest); | 270 CancelOmniboxRemovesOmniboxTest); |
259 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, | 271 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, |
260 CancelOmniboxDoesNotRemoveLinkTest); | 272 CancelOmniboxDoesNotRemoveLinkTest); |
261 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ClearTest); | 273 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ClearTest); |
262 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ControlGroup); | 274 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ControlGroup); |
263 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropOldestRequestTest); | 275 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, DropOldestRequestTest); |
264 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropSecondRequestTest); | 276 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, DropSecondRequestTest); |
265 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExpireTest); | 277 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, ExpireTest); |
266 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FoundTest); | 278 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FoundTest); |
267 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesFragmentTest); | 279 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FragmentMatchesFragmentTest); |
268 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesPageTest); | 280 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, FragmentMatchesPageTest); |
269 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PageMatchesFragmentTest); | 281 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerAbandon); |
270 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PendingPrerenderTest); | 282 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerAddTwiceAbandonTwice); |
271 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitInWindowTest); | 283 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerAddTwiceCancelTwice); |
272 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitOutsideWindowTest); | 284 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, |
273 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, SourceRenderViewClosed); | 285 LinkManagerAddTwiceCancelTwiceThenAbandonTwice); |
274 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, TwoElementPrerenderTest); | 286 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancel); |
| 287 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelThenAbandon); |
| 288 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelThenAddAgain); |
| 289 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelTwice); |
| 290 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerExpireThenAddAgain); |
| 291 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerExpireThenCancel); |
| 292 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PageMatchesFragmentTest); |
| 293 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PendingPrerenderTest); |
| 294 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RateLimitInWindowTest); |
| 295 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RateLimitOutsideWindowTest); |
| 296 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, SourceRenderViewClosed); |
| 297 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, TwoElementPrerenderTest); |
275 | 298 |
276 struct PrerenderContentsData; | 299 struct PrerenderContentsData; |
277 struct NavigationRecord; | 300 struct NavigationRecord; |
278 | 301 |
279 class OnCloseTabContentsDeleter; | 302 class OnCloseTabContentsDeleter; |
280 | 303 |
281 class MostVisitedSites; | 304 class MostVisitedSites; |
282 | 305 |
283 typedef std::list<PrerenderContentsData> PrerenderContentsDataList; | 306 typedef std::list<PrerenderContentsData> PrerenderContentsDataList; |
284 | 307 |
285 // Adds a prerender for |url| from referrer |referrer| initiated from the | 308 // Adds a prerender for |url| from referrer |referrer| initiated from the |
286 // RenderViewHost specified by |child_route_id_pair|. The |origin| specifies | 309 // child process specified by |child_id|. The |origin| specifies how the |
287 // how the prerender was added. If the |session_storage_namespace| is NULL, | 310 // prerender was added. If the |size| is empty, then |
288 // it is discovered using the RenderViewHost specified by | 311 // PrerenderContents::StartPrerendering will instead use the size of the |
289 // |child_route_id_pair|. | 312 // currently active tab. If the current active tab size cannot be found, it |
| 313 // then uses a default from PrerenderConfig. |
290 bool AddPrerender( | 314 bool AddPrerender( |
291 Origin origin, | 315 Origin origin, |
292 const std::pair<int, int>& child_route_id_pair, | 316 int child_id, |
293 const GURL& url, | 317 const GURL& url, |
294 const content::Referrer& referrer, | 318 const content::Referrer& referrer, |
| 319 const gfx::Size& size, |
295 content::SessionStorageNamespace* session_storage_namespace); | 320 content::SessionStorageNamespace* session_storage_namespace); |
296 | 321 |
297 // Retrieves the PrerenderContents object for the specified URL, if it | 322 // Retrieves the PrerenderContents object for the specified URL, if it |
298 // has been prerendered. The caller will then have ownership of the | 323 // has been prerendered. The caller will then have ownership of the |
299 // PrerenderContents object and is responsible for freeing it. | 324 // PrerenderContents object and is responsible for freeing it. |
300 // Returns NULL if the specified URL has not been prerendered. | 325 // Returns NULL if the specified URL has not been prerendered. |
301 PrerenderContents* GetEntry(const GURL& url); | 326 PrerenderContents* GetEntry(const GURL& url); |
302 | 327 |
303 // Identical to GetEntry, with one exception: | 328 // Identical to GetEntry, with one exception: |
304 // The WebContents specified indicates the WC in which to swap the | 329 // The WebContents specified indicates the WC in which to swap the |
(...skipping 29 matching lines...) Expand all Loading... |
334 Origin origin, | 359 Origin origin, |
335 uint8 experiment_id); | 360 uint8 experiment_id); |
336 | 361 |
337 // Checks if the PrerenderContents has been added to the pending delete list. | 362 // Checks if the PrerenderContents has been added to the pending delete list. |
338 bool IsPendingDelete(PrerenderContents* entry) const; | 363 bool IsPendingDelete(PrerenderContents* entry) const; |
339 | 364 |
340 // Deletes any PrerenderContents that have been added to the pending delete | 365 // Deletes any PrerenderContents that have been added to the pending delete |
341 // list. | 366 // list. |
342 void DeletePendingDeleteEntries(); | 367 void DeletePendingDeleteEntries(); |
343 | 368 |
344 // Finds the specified PrerenderContents and returns it, if it exists. | 369 // Finds the specified PrerenderContentsData/PrerenderContents and returns it, |
345 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 370 // if it exists. Returns NULL otherwise. Unlike GetEntry, the |
346 // ownership of the PrerenderContents. | 371 // PrerenderManager maintains ownership of the PrerenderContents. |
| 372 PrerenderContentsData* FindEntryData(const GURL& url); |
347 PrerenderContents* FindEntry(const GURL& url) const; | 373 PrerenderContents* FindEntry(const GURL& url) const; |
348 | 374 |
349 // Returns the iterator to the PrerenderContentsData entry that is being | 375 // Returns the iterator to the PrerenderContentsData entry that is being |
350 // prerendered from the given child route id pair. | 376 // prerendered from the given child route id pair. |
351 PrerenderContentsDataList::iterator | 377 PrerenderContentsDataList::iterator |
352 FindPrerenderContentsForChildRouteIdPair( | 378 FindPrerenderContentsForChildRouteIdPair( |
353 const std::pair<int, int>& child_route_id_pair); | 379 const std::pair<int, int>& child_route_id_pair); |
354 | 380 |
| 381 PrerenderContentsDataList::iterator |
| 382 FindPrerenderContentsForURL(const GURL& url); |
| 383 |
355 bool DoesRateLimitAllowPrerender() const; | 384 bool DoesRateLimitAllowPrerender() const; |
356 | 385 |
357 // Deletes old WebContents that have been replaced by prerendered ones. This | 386 // 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, | 387 // is needed because they're replaced in a callback from the old WebContents, |
359 // so cannot immediately be deleted. | 388 // so cannot immediately be deleted. |
360 void DeleteOldTabContents(); | 389 void DeleteOldTabContents(); |
361 | 390 |
362 // Cleans up old NavigationRecord's. | 391 // Cleans up old NavigationRecord's. |
363 void CleanUpOldNavigations(); | 392 void CleanUpOldNavigations(); |
364 | 393 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 491 |
463 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 492 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
464 }; | 493 }; |
465 | 494 |
466 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( | 495 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( |
467 int render_process_id); | 496 int render_process_id); |
468 | 497 |
469 } // namespace prerender | 498 } // namespace prerender |
470 | 499 |
471 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 500 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |