Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: chrome/browser/prerender/prerender_manager.h

Issue 10198040: New link rel=prerender api, using WebKit::WebPrerenderingPlatform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the urls_to_id_map_, and follow consequences through. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 RenderViewHost that the prerender request came from and are used to
100 // set the initial window size of the RenderViewHost used for prerendering. 105 // set the initial window size of the RenderViewHost used for prerendering.
dominich 2012/04/29 18:52:55 this comment needs to be updated.
gavinp 2012/04/30 11:43:16 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 RenderViewHost source 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
127 // the prerender is one, it will be canceled. Otherwise, add_count_ will be
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
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 // RenderViewHost specified by |child_route_id_pair|. The |origin| specifies
dominich 2012/04/29 18:52:55 update comment
gavinp 2012/04/30 11:43:16 Done.
287 // how the prerender was added. If the |session_storage_namespace| is NULL, 305 // how the prerender was added. If the |session_storage_namespace| is NULL,
288 // it is discovered using the RenderViewHost specified by 306 // it is discovered using the RenderViewHost specified by
289 // |child_route_id_pair|. 307 // |child_route_id_pair|.
290 bool AddPrerender( 308 bool AddPrerender(
291 Origin origin, 309 Origin origin,
292 const std::pair<int, int>& child_route_id_pair, 310 int child_id,
293 const GURL& url, 311 const GURL& url,
294 const content::Referrer& referrer, 312 const content::Referrer& referrer,
313 const gfx::Size& size,
295 content::SessionStorageNamespace* session_storage_namespace); 314 content::SessionStorageNamespace* session_storage_namespace);
296 315
297 // Retrieves the PrerenderContents object for the specified URL, if it 316 // Retrieves the PrerenderContents object for the specified URL, if it
298 // has been prerendered. The caller will then have ownership of the 317 // has been prerendered. The caller will then have ownership of the
299 // PrerenderContents object and is responsible for freeing it. 318 // PrerenderContents object and is responsible for freeing it.
300 // Returns NULL if the specified URL has not been prerendered. 319 // Returns NULL if the specified URL has not been prerendered.
301 PrerenderContents* GetEntry(const GURL& url); 320 PrerenderContents* GetEntry(const GURL& url);
302 321
303 // Identical to GetEntry, with one exception: 322 // Identical to GetEntry, with one exception:
304 // The WebContents specified indicates the WC in which to swap the 323 // The WebContents specified indicates the WC in which to swap the
(...skipping 29 matching lines...) Expand all
334 Origin origin, 353 Origin origin,
335 uint8 experiment_id); 354 uint8 experiment_id);
336 355
337 // Checks if the PrerenderContents has been added to the pending delete list. 356 // Checks if the PrerenderContents has been added to the pending delete list.
338 bool IsPendingDelete(PrerenderContents* entry) const; 357 bool IsPendingDelete(PrerenderContents* entry) const;
339 358
340 // Deletes any PrerenderContents that have been added to the pending delete 359 // Deletes any PrerenderContents that have been added to the pending delete
341 // list. 360 // list.
342 void DeletePendingDeleteEntries(); 361 void DeletePendingDeleteEntries();
343 362
344 // Finds the specified PrerenderContents and returns it, if it exists. 363 // Finds the specified PrerenderContentsData/PrerenderContents and returns it,
345 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains 364 // if it exists. Returns NULL otherwise. Unlike GetEntry, the
346 // ownership of the PrerenderContents. 365 // PrerenderManager maintains ownership of the PrerenderContents.
366 PrerenderContentsData* FindEntryData(const GURL& url);
347 PrerenderContents* FindEntry(const GURL& url) const; 367 PrerenderContents* FindEntry(const GURL& url) const;
348 368
349 // Returns the iterator to the PrerenderContentsData entry that is being 369 // Returns the iterator to the PrerenderContentsData entry that is being
350 // prerendered from the given child route id pair. 370 // prerendered from the given child route id pair.
351 PrerenderContentsDataList::iterator 371 PrerenderContentsDataList::iterator
352 FindPrerenderContentsForChildRouteIdPair( 372 FindPrerenderContentsForChildRouteIdPair(
353 const std::pair<int, int>& child_route_id_pair); 373 const std::pair<int, int>& child_route_id_pair);
354 374
375 PrerenderContentsDataList::iterator
376 FindPrerenderContentsForURL(const GURL& url);
dominich 2012/04/29 18:52:55 should this also take a session storage namespace
gavinp 2012/04/30 11:43:16 Yup, if we ever key prerenders on the session stor
dominich 2012/04/30 15:52:05 Or the proposed CL to add a PrerenderHandle.
377
355 bool DoesRateLimitAllowPrerender() const; 378 bool DoesRateLimitAllowPrerender() const;
356 379
357 // Deletes old WebContents that have been replaced by prerendered ones. This 380 // 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, 381 // is needed because they're replaced in a callback from the old WebContents,
359 // so cannot immediately be deleted. 382 // so cannot immediately be deleted.
360 void DeleteOldTabContents(); 383 void DeleteOldTabContents();
361 384
362 // Cleans up old NavigationRecord's. 385 // Cleans up old NavigationRecord's.
363 void CleanUpOldNavigations(); 386 void CleanUpOldNavigations();
364 387
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 485
463 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 486 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
464 }; 487 };
465 488
466 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( 489 PrerenderManager* FindPrerenderManagerUsingRenderProcessId(
467 int render_process_id); 490 int render_process_id);
468 491
469 } // namespace prerender 492 } // namespace prerender
470 493
471 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 494 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698