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. |
dominich
2012/04/30 15:52:05
Or a default in the case of there being no current
gavinp
2012/04/30 23:55:39
Done.
| |
101 // Returns true if the URL was added, false if it was not. | 106 // Returns true if the URL was added, false if it was not. |
102 // If the RenderViewHost source is itself prerendering, the prerender is added | 107 // If the launching RenderView is itself prerendering, the prerender is added |
103 // as a pending prerender. | 108 // as a pending prerender. |
104 bool AddPrerenderFromLinkRelPrerender(int process_id, int route_id, | 109 bool AddPrerenderFromLinkRelPrerender( |
105 const GURL& url, | 110 int process_id, |
106 const content::Referrer& referrer); | 111 int route_id, |
112 const GURL& url, | |
113 const content::Referrer& referrer, | |
114 const gfx::Size& size, | |
115 content::SessionStorageNamespace* session_storage_namespace); | |
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 add_count_ of | |
dominich
2012/04/30 15:52:05
|active_count_|
gavinp
2012/04/30 23:55:39
Done.
| |
127 // the prerender is one, it will be canceled. Otherwise, add_count_ will be | |
dominich
2012/04/30 15:52:05
'The |active_count_| of the prerender will be decr
gavinp
2012/04/30 23:55:39
Done.
| |
128 // 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, LinkManagerAddTwiceCancelTwice); |
270 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PendingPrerenderTest); | 282 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancel); |
271 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitInWindowTest); | 283 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelThenAddAgain); |
272 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitOutsideWindowTest); | 284 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerCancelTwice); |
273 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, SourceRenderViewClosed); | 285 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerExpireThenAddAgain); |
274 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, TwoElementPrerenderTest); | 286 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, LinkManagerExpireThenCancel); |
287 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PageMatchesFragmentTest); | |
288 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, PendingPrerenderTest); | |
289 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RateLimitInWindowTest); | |
290 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, RateLimitOutsideWindowTest); | |
291 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, SourceRenderViewClosed); | |
292 FRIEND_TEST_ALL_PREFIXES(PrerenderTest, TwoElementPrerenderTest); | |
275 | 293 |
276 struct PrerenderContentsData; | 294 struct PrerenderContentsData; |
277 struct NavigationRecord; | 295 struct NavigationRecord; |
278 | 296 |
279 class OnCloseTabContentsDeleter; | 297 class OnCloseTabContentsDeleter; |
280 | 298 |
281 class MostVisitedSites; | 299 class MostVisitedSites; |
282 | 300 |
283 typedef std::list<PrerenderContentsData> PrerenderContentsDataList; | 301 typedef std::list<PrerenderContentsData> PrerenderContentsDataList; |
284 | 302 |
285 // Adds a prerender for |url| from referrer |referrer| initiated from the | 303 // Adds a prerender for |url| from referrer |referrer| initiated from the |
286 // RenderViewHost specified by |child_route_id_pair|. The |origin| specifies | 304 // child process specified by |child__id|. The |origin| specifies how the |
287 // how the prerender was added. If the |session_storage_namespace| is NULL, | 305 // prerender was added. If the |size| is empty, the size of the currently |
288 // it is discovered using the RenderViewHost specified by | 306 // active tab will be used, if available. |
dominich
2012/04/30 15:52:05
or a default if not.
gavinp
2012/04/30 23:55:39
Done.
| |
289 // |child_route_id_pair|. | |
290 bool AddPrerender( | 307 bool AddPrerender( |
291 Origin origin, | 308 Origin origin, |
292 const std::pair<int, int>& child_route_id_pair, | 309 int child_id, |
293 const GURL& url, | 310 const GURL& url, |
294 const content::Referrer& referrer, | 311 const content::Referrer& referrer, |
312 const gfx::Size& size, | |
295 content::SessionStorageNamespace* session_storage_namespace); | 313 content::SessionStorageNamespace* session_storage_namespace); |
296 | 314 |
297 // Retrieves the PrerenderContents object for the specified URL, if it | 315 // Retrieves the PrerenderContents object for the specified URL, if it |
298 // has been prerendered. The caller will then have ownership of the | 316 // has been prerendered. The caller will then have ownership of the |
299 // PrerenderContents object and is responsible for freeing it. | 317 // PrerenderContents object and is responsible for freeing it. |
300 // Returns NULL if the specified URL has not been prerendered. | 318 // Returns NULL if the specified URL has not been prerendered. |
301 PrerenderContents* GetEntry(const GURL& url); | 319 PrerenderContents* GetEntry(const GURL& url); |
302 | 320 |
303 // Identical to GetEntry, with one exception: | 321 // Identical to GetEntry, with one exception: |
304 // The WebContents specified indicates the WC in which to swap the | 322 // The WebContents specified indicates the WC in which to swap the |
(...skipping 29 matching lines...) Expand all Loading... | |
334 Origin origin, | 352 Origin origin, |
335 uint8 experiment_id); | 353 uint8 experiment_id); |
336 | 354 |
337 // Checks if the PrerenderContents has been added to the pending delete list. | 355 // Checks if the PrerenderContents has been added to the pending delete list. |
338 bool IsPendingDelete(PrerenderContents* entry) const; | 356 bool IsPendingDelete(PrerenderContents* entry) const; |
339 | 357 |
340 // Deletes any PrerenderContents that have been added to the pending delete | 358 // Deletes any PrerenderContents that have been added to the pending delete |
341 // list. | 359 // list. |
342 void DeletePendingDeleteEntries(); | 360 void DeletePendingDeleteEntries(); |
343 | 361 |
344 // Finds the specified PrerenderContents and returns it, if it exists. | 362 // Finds the specified PrerenderContentsData/PrerenderContents and returns it, |
345 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 363 // if it exists. Returns NULL otherwise. Unlike GetEntry, the |
346 // ownership of the PrerenderContents. | 364 // PrerenderManager maintains ownership of the PrerenderContents. |
365 PrerenderContentsData* FindEntryData(const GURL& url); | |
347 PrerenderContents* FindEntry(const GURL& url) const; | 366 PrerenderContents* FindEntry(const GURL& url) const; |
348 | 367 |
349 // Returns the iterator to the PrerenderContentsData entry that is being | 368 // Returns the iterator to the PrerenderContentsData entry that is being |
350 // prerendered from the given child route id pair. | 369 // prerendered from the given child route id pair. |
351 PrerenderContentsDataList::iterator | 370 PrerenderContentsDataList::iterator |
352 FindPrerenderContentsForChildRouteIdPair( | 371 FindPrerenderContentsForChildRouteIdPair( |
353 const std::pair<int, int>& child_route_id_pair); | 372 const std::pair<int, int>& child_route_id_pair); |
354 | 373 |
374 PrerenderContentsDataList::iterator | |
375 FindPrerenderContentsForURL(const GURL& url); | |
376 | |
355 bool DoesRateLimitAllowPrerender() const; | 377 bool DoesRateLimitAllowPrerender() const; |
356 | 378 |
357 // Deletes old WebContents that have been replaced by prerendered ones. This | 379 // 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, | 380 // is needed because they're replaced in a callback from the old WebContents, |
359 // so cannot immediately be deleted. | 381 // so cannot immediately be deleted. |
360 void DeleteOldTabContents(); | 382 void DeleteOldTabContents(); |
361 | 383 |
362 // Cleans up old NavigationRecord's. | 384 // Cleans up old NavigationRecord's. |
363 void CleanUpOldNavigations(); | 385 void CleanUpOldNavigations(); |
364 | 386 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 | 484 |
463 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 485 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
464 }; | 486 }; |
465 | 487 |
466 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( | 488 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( |
467 int render_process_id); | 489 int render_process_id); |
468 | 490 |
469 } // namespace prerender | 491 } // namespace prerender |
470 | 492 |
471 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 493 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |