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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 217 |
215 PrerenderTracker* prerender_tracker() { return prerender_tracker_; } | 218 PrerenderTracker* prerender_tracker() { return prerender_tracker_; } |
216 | 219 |
217 // Adds a condition. This is owned by the PrerenderManager. | 220 // Adds a condition. This is owned by the PrerenderManager. |
218 void AddCondition(const PrerenderCondition* condition); | 221 void AddCondition(const PrerenderCondition* condition); |
219 | 222 |
220 bool IsTopSite(const GURL& url); | 223 bool IsTopSite(const GURL& url); |
221 | 224 |
222 bool IsPendingEntry(const GURL& url) const; | 225 bool IsPendingEntry(const GURL& url) const; |
223 | 226 |
| 227 // Returns true if |url| matches any URLs being prerendered. |
| 228 bool IsPrerendering(const GURL& url) const; |
| 229 |
224 protected: | 230 protected: |
225 void SetPrerenderContentsFactory( | 231 void SetPrerenderContentsFactory( |
226 PrerenderContents::Factory* prerender_contents_factory); | 232 PrerenderContents::Factory* prerender_contents_factory); |
227 | 233 |
228 // Utility method that is called from the virtual Shutdown method on this | 234 // Utility method that is called from the virtual Shutdown method on this |
229 // class but is called directly from the TestPrerenderManager in the unit | 235 // class but is called directly from the TestPrerenderManager in the unit |
230 // tests. | 236 // tests. |
231 void DoShutdown(); | 237 void DoShutdown(); |
232 | 238 |
233 private: | 239 private: |
234 // Needs access to AddPrerender. | 240 // Needs access to AddPrerender. |
235 friend class PrerenderContents; | 241 friend class PrerenderContents; |
236 | 242 |
237 // Test that needs needs access to internal functions. | 243 // Test that needs needs access to internal functions. |
238 friend class PrerenderBrowserTest; | 244 friend class PrerenderBrowserTest; |
239 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, AliasURLTest); | 245 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, AliasURLTest); |
| 246 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, CancelAllTest); |
| 247 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, |
| 248 CancelOmniboxRemovesOmniboxTest); |
| 249 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, |
| 250 CancelOmniboxDoesNotRemoveLinkTest); |
240 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ClearTest); | 251 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ClearTest); |
241 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ControlGroup); | 252 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ControlGroup); |
242 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropOldestRequestTest); | 253 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropOldestRequestTest); |
243 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropSecondRequestTest); | 254 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, DropSecondRequestTest); |
244 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExpireTest); | 255 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExpireTest); |
245 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FoundTest); | 256 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FoundTest); |
246 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesFragmentTest); | 257 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesFragmentTest); |
247 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesPageTest); | 258 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, FragmentMatchesPageTest); |
248 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PageMatchesFragmentTest); | 259 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PageMatchesFragmentTest); |
249 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PendingPrerenderTest); | 260 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, PendingPrerenderTest); |
250 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitInWindowTest); | 261 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitInWindowTest); |
251 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitOutsideWindowTest); | 262 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, RateLimitOutsideWindowTest); |
252 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, SourceRenderViewClosed); | 263 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, SourceRenderViewClosed); |
253 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, TwoElementPrerenderTest); | 264 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, TwoElementPrerenderTest); |
254 | 265 |
255 struct PrerenderContentsData; | 266 struct PrerenderContentsData; |
256 struct NavigationRecord; | 267 struct NavigationRecord; |
257 | 268 |
258 class OnCloseTabContentsDeleter; | 269 class OnCloseTabContentsDeleter; |
259 | 270 |
260 class MostVisitedSites; | 271 class MostVisitedSites; |
261 | 272 |
| 273 typedef std::list<PrerenderContentsData> PrerenderContentsDataList; |
| 274 |
262 // Adds a prerender for |url| from referrer |referrer| initiated from the | 275 // Adds a prerender for |url| from referrer |referrer| initiated from the |
263 // RenderViewHost specified by |child_route_id_pair|. The |origin| specifies | 276 // RenderViewHost specified by |child_route_id_pair|. The |origin| specifies |
264 // how the prerender was added. If the |session_storage_namespace| is NULL, | 277 // how the prerender was added. If the |session_storage_namespace| is NULL, |
265 // it is discovered using the RenderViewHost specified by | 278 // it is discovered using the RenderViewHost specified by |
266 // |child_route_id_pair|. | 279 // |child_route_id_pair|. |
267 bool AddPrerender( | 280 bool AddPrerender( |
268 Origin origin, | 281 Origin origin, |
269 const std::pair<int, int>& child_route_id_pair, | 282 const std::pair<int, int>& child_route_id_pair, |
270 const GURL& url, | 283 const GURL& url, |
271 const content::Referrer& referrer, | 284 const content::Referrer& referrer, |
272 SessionStorageNamespace* session_storage_namespace); | 285 SessionStorageNamespace* session_storage_namespace); |
273 | 286 |
274 // Adds a pending preload issued by the prerendering RenderView identified by | |
275 // |child_route_id_pair|. If and when that prerendering RenderView is used, | |
276 // the specified prerender will start. | |
277 void AddPendingPrerender(Origin origin, | |
278 const std::pair<int, int>& child_route_id_pair, | |
279 const GURL& url, | |
280 const content::Referrer& referrer); | |
281 | |
282 // Retrieves the PrerenderContents object for the specified URL, if it | 287 // Retrieves the PrerenderContents object for the specified URL, if it |
283 // has been prerendered. The caller will then have ownership of the | 288 // has been prerendered. The caller will then have ownership of the |
284 // PrerenderContents object and is responsible for freeing it. | 289 // PrerenderContents object and is responsible for freeing it. |
285 // Returns NULL if the specified URL has not been prerendered. | 290 // Returns NULL if the specified URL has not been prerendered. |
286 PrerenderContents* GetEntry(const GURL& url); | 291 PrerenderContents* GetEntry(const GURL& url); |
287 | 292 |
288 // Identical to GetEntry, with one exception: | 293 // Identical to GetEntry, with one exception: |
289 // The WebContents specified indicates the WC in which to swap the | 294 // The WebContents specified indicates the WC in which to swap the |
290 // prerendering into. If the WebContents specified is the one | 295 // prerendering into. If the WebContents specified is the one |
291 // to doing the prerendered itself, will return NULL. | 296 // to doing the prerendered itself, will return NULL. |
(...skipping 29 matching lines...) Expand all Loading... |
321 // Checks if the PrerenderContents has been added to the pending delete list. | 326 // Checks if the PrerenderContents has been added to the pending delete list. |
322 bool IsPendingDelete(PrerenderContents* entry) const; | 327 bool IsPendingDelete(PrerenderContents* entry) const; |
323 | 328 |
324 // Deletes any PrerenderContents that have been added to the pending delete | 329 // Deletes any PrerenderContents that have been added to the pending delete |
325 // list. | 330 // list. |
326 void DeletePendingDeleteEntries(); | 331 void DeletePendingDeleteEntries(); |
327 | 332 |
328 // Finds the specified PrerenderContents and returns it, if it exists. | 333 // Finds the specified PrerenderContents and returns it, if it exists. |
329 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 334 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
330 // ownership of the PrerenderContents. | 335 // ownership of the PrerenderContents. |
331 PrerenderContents* FindEntry(const GURL& url); | 336 PrerenderContents* FindEntry(const GURL& url) const; |
332 | 337 |
333 // Returns the iterator to the PrerenderContentsData entry that is being | 338 // Returns the iterator to the PrerenderContentsData entry that is being |
334 // prerendered from the given child route id pair. | 339 // prerendered from the given child route id pair. |
335 std::list<PrerenderContentsData>::iterator | 340 PrerenderContentsDataList::iterator |
336 FindPrerenderContentsForChildRouteIdPair( | 341 FindPrerenderContentsForChildRouteIdPair( |
337 const std::pair<int, int>& child_route_id_pair); | 342 const std::pair<int, int>& child_route_id_pair); |
338 | 343 |
339 // Returns whether the PrerenderManager is currently within the prerender | |
340 // window - effectively, up to 30 seconds after a prerender tag has been | |
341 // observed. | |
342 bool WithinWindow() const; | |
343 | |
344 bool DoesRateLimitAllowPrerender() const; | 344 bool DoesRateLimitAllowPrerender() const; |
345 | 345 |
346 // Deletes old TabContents that have been replaced by prerendered ones. This | 346 // Deletes old TabContents that have been replaced by prerendered ones. This |
347 // is needed because they're replaced in a callback from the old TabContents, | 347 // is needed because they're replaced in a callback from the old TabContents, |
348 // so cannot immediately be deleted. | 348 // so cannot immediately be deleted. |
349 void DeleteOldTabContents(); | 349 void DeleteOldTabContents(); |
350 | 350 |
351 // Cleans up old NavigationRecord's. | 351 // Cleans up old NavigationRecord's. |
352 void CleanUpOldNavigations(); | 352 void CleanUpOldNavigations(); |
353 | 353 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // manager. The value can change dynamically during the lifetime | 392 // manager. The value can change dynamically during the lifetime |
393 // of the PrerenderManager. | 393 // of the PrerenderManager. |
394 bool enabled_; | 394 bool enabled_; |
395 | 395 |
396 // The profile that owns this PrerenderManager. | 396 // The profile that owns this PrerenderManager. |
397 Profile* profile_; | 397 Profile* profile_; |
398 | 398 |
399 PrerenderTracker* prerender_tracker_; | 399 PrerenderTracker* prerender_tracker_; |
400 | 400 |
401 // List of prerendered elements. | 401 // List of prerendered elements. |
402 std::list<PrerenderContentsData> prerender_list_; | 402 PrerenderContentsDataList prerender_list_; |
403 | 403 |
404 // List of recent navigations in this profile, sorted by ascending | 404 // List of recent navigations in this profile, sorted by ascending |
405 // navigate_time_. | 405 // navigate_time_. |
406 std::list<NavigationRecord> navigations_; | 406 std::list<NavigationRecord> navigations_; |
407 | 407 |
408 // List of prerender elements to be deleted | 408 // List of prerender elements to be deleted |
409 std::list<PrerenderContents*> pending_delete_list_; | 409 std::list<PrerenderContents*> pending_delete_list_; |
410 | 410 |
411 // Set of TabContents which are currently displaying a prerendered page. | 411 // Set of TabContents which are currently displaying a prerendered page. |
412 base::hash_set<content::WebContents*> prerendered_tab_contents_set_; | 412 base::hash_set<content::WebContents*> prerendered_tab_contents_set_; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 447 |
448 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 448 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
449 }; | 449 }; |
450 | 450 |
451 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( | 451 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( |
452 int render_process_id); | 452 int render_process_id); |
453 | 453 |
454 } // namespace prerender | 454 } // namespace prerender |
455 | 455 |
456 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 456 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |