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

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

Issue 7210020: Added prerendering to omnibox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename update_instant_ and refactor conditionals. Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <map> 10 #include <map>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // Adds either a preload or a pending preload to the PrerenderManager. 44 // Adds either a preload or a pending preload to the PrerenderManager.
45 // Must be called on the UI thread. 45 // Must be called on the UI thread.
46 void HandleTag( 46 void HandleTag(
47 const base::WeakPtr<PrerenderManager>& prerender_manager, 47 const base::WeakPtr<PrerenderManager>& prerender_manager,
48 int render_process_id, 48 int render_process_id,
49 int render_view_id, 49 int render_view_id,
50 const GURL& url, 50 const GURL& url,
51 const GURL& referrer); 51 const GURL& referrer);
52 52
53 void DestroyPreloadForRenderView( 53 void DestroyPrerenderForRenderView(
54 const base::WeakPtr<PrerenderManager>& prerender_manager_weak_ptr, 54 const base::WeakPtr<PrerenderManager>& prerender_manager_weak_ptr,
55 int child_id, 55 int child_id,
56 int route_id, 56 int route_id,
57 FinalStatus final_status); 57 FinalStatus final_status);
58 58
59 // PrerenderManager is responsible for initiating and keeping prerendered 59 // PrerenderManager is responsible for initiating and keeping prerendered
60 // views of webpages. All methods must be called on the UI thread unless 60 // views of webpages. All methods must be called on the UI thread unless
61 // indicated otherwise. 61 // indicated otherwise.
62 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, 62 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
63 public base::NonThreadSafe { 63 public base::NonThreadSafe {
64 public: 64 public:
65 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not 65 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not
66 // add in the middle. 66 // add in the middle.
67 enum PrerenderManagerMode { 67 enum PrerenderManagerMode {
68 PRERENDER_MODE_DISABLED, 68 PRERENDER_MODE_DISABLED,
69 PRERENDER_MODE_ENABLED, 69 PRERENDER_MODE_ENABLED,
70 PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP, 70 PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP,
71 PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP, 71 PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP,
72 PRERENDER_MODE_MAX 72 PRERENDER_MODE_MAX
73 }; 73 };
74 74
75 // Owned by a Profile object for the lifetime of the profile. 75 // Owned by a Profile object for the lifetime of the profile.
76 PrerenderManager(Profile* profile, PrerenderTracker* prerender_tracker); 76 PrerenderManager(Profile* profile, PrerenderTracker* prerender_tracker);
77 77
78 virtual ~PrerenderManager(); 78 virtual ~PrerenderManager();
79 79
80 // Preloads |url| if valid. |child_route_id_pair| identifies the 80 // Starts a prerender for |url| if valid. |child_route_id_pair| identifies the
81 // RenderViewHost that the prerender request came from and is used to 81 // RenderViewHost that the prerender request came from and is used to
82 // set the initial window size of the RenderViewHost used for prerendering. 82 // set the initial window size of the RenderViewHost used for prerendering.
83 // Returns true if the URL was added, false if it was not. 83 // Returns true if the URL was added, false if it was not.
84 // If |child_route_id_pair| itself is prerendering, adds the preloads as 84 // If |child_route_id_pair| itself is prerendering, adds the preloads as
85 // a pending preload. 85 // a pending preload.
86 bool AddPreload( 86 bool AddPrerender(
87 const std::pair<int, int>& child_route_id_pair, 87 const std::pair<int, int>& child_route_id_pair,
88 const GURL& url, 88 const GURL& url,
89 const GURL& referrer); 89 const GURL& referrer);
90 90
91 // Destroy all preloads for the given child route id pair and assign a final 91 // Starts a prerender for |url| if valid. As the prerender request is coming
92 // from a source without a RenderViewHost (ie, the omnibox) we don't have a
93 // child or route id, or a referrer. This method uses sensible values for
94 // those.
95 bool AddPrerenderWithNoTag(const GURL& url);
96
97 // Destroy all prerenders for the given child route id pair and assign a final
92 // status to them. 98 // status to them.
93 virtual void DestroyPreloadForChildRouteIdPair( 99 virtual void DestroyPrerenderForChildRouteIdPair(
94 const std::pair<int, int>& child_route_id_pair, 100 const std::pair<int, int>& child_route_id_pair,
95 FinalStatus final_status); 101 FinalStatus final_status);
96 102
97 // For a given TabContents that wants to navigate to the URL supplied, 103 // For a given TabContents that wants to navigate to the URL supplied,
98 // determines whether a preloaded version of the URL can be used, 104 // determines whether a prerendered version of the URL can be used,
99 // and substitutes the prerendered RVH into the TabContents. Returns 105 // and substitutes the prerendered RVH into the TabContents. Returns
100 // whether or not a prerendered RVH could be used or not. 106 // whether or not a prerendered RVH could be used or not.
101 bool MaybeUsePreloadedPage(TabContents* tab_contents, 107 bool MaybeUsePrerenderedPage(TabContents* tab_contents,
102 const GURL& url, 108 const GURL& url,
103 bool has_opener_set); 109 bool has_opener_set);
104 110
105 // Moves a PrerenderContents to the pending delete list from the list of 111 // Moves a PrerenderContents to the pending delete list from the list of
106 // active prerenders when prerendering should be cancelled. 112 // active prerenders when prerendering should be cancelled.
107 void MoveEntryToPendingDelete(PrerenderContents* entry); 113 void MoveEntryToPendingDelete(PrerenderContents* entry);
108 114
109 // Checks if the PrerenderContents has been added to the pending delete list. 115 // Checks if the PrerenderContents has been added to the pending delete list.
110 bool IsPendingDelete(PrerenderContents* entry) const; 116 bool IsPendingDelete(PrerenderContents* entry) const;
111 117
112 // Retrieves the PrerenderContents object for the specified URL, if it 118 // Retrieves the PrerenderContents object for the specified URL, if it
113 // has been prerendered. The caller will then have ownership of the 119 // has been prerendered. The caller will then have ownership of the
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 friend class base::RefCountedThreadSafe<PrerenderManager>; 211 friend class base::RefCountedThreadSafe<PrerenderManager>;
206 212
207 struct PrerenderContentsData; 213 struct PrerenderContentsData;
208 struct NavigationRecord; 214 struct NavigationRecord;
209 215
210 class OnCloseTabContentsDeleter; 216 class OnCloseTabContentsDeleter;
211 217
212 // Adds a pending preload issued by the prerendering RenderView identified by 218 // Adds a pending preload issued by the prerendering RenderView identified by
213 // |child_route_id_pair|. If and when that prerendering RenderView is used, 219 // |child_route_id_pair|. If and when that prerendering RenderView is used,
214 // the specified prerender will start. 220 // the specified prerender will start.
215 void AddPendingPreload(const std::pair<int, int>& child_route_id_pair, 221 void AddPendingPrerender(const std::pair<int, int>& child_route_id_pair,
216 const GURL& url, 222 const GURL& url,
217 const GURL& referrer); 223 const GURL& referrer);
218 224
219 // Starts scheduling periodic cleanups. 225 // Starts scheduling periodic cleanups.
220 void StartSchedulingPeriodicCleanups(); 226 void StartSchedulingPeriodicCleanups();
221 // Stops scheduling periodic cleanups if they're no longer needed. 227 // Stops scheduling periodic cleanups if they're no longer needed.
222 void MaybeStopSchedulingPeriodicCleanups(); 228 void MaybeStopSchedulingPeriodicCleanups();
223 229
224 // Deletes stale and cancelled prerendered PrerenderContents, as well as 230 // Deletes stale and cancelled prerendered PrerenderContents, as well as
225 // TabContents that have been replaced by prerendered TabContents. 231 // TabContents that have been replaced by prerendered TabContents.
226 // Also identifies and kills PrerenderContents that use too much 232 // Also identifies and kills PrerenderContents that use too much
227 // resources. 233 // resources.
(...skipping 27 matching lines...) Expand all
255 FindPrerenderContentsForChildRouteIdPair( 261 FindPrerenderContentsForChildRouteIdPair(
256 const std::pair<int, int>& child_route_id_pair); 262 const std::pair<int, int>& child_route_id_pair);
257 263
258 // Returns whether the PrerenderManager is currently within the prerender 264 // Returns whether the PrerenderManager is currently within the prerender
259 // window - effectively, up to 30 seconds after a prerender tag has been 265 // window - effectively, up to 30 seconds after a prerender tag has been
260 // observed. 266 // observed.
261 bool WithinWindow() const; 267 bool WithinWindow() const;
262 268
263 // Called when removing a preload to ensure we clean up any pending preloads 269 // Called when removing a preload to ensure we clean up any pending preloads
264 // that might remain in the map. 270 // that might remain in the map.
265 void RemovePendingPreload(PrerenderContents* entry); 271 void RemovePendingPrerender(PrerenderContents* entry);
266 272
267 bool DoesRateLimitAllowPrerender() const; 273 bool DoesRateLimitAllowPrerender() const;
268 274
269 // Deletes old TabContents that have been replaced by prerendered ones. This 275 // Deletes old TabContents that have been replaced by prerendered ones. This
270 // is needed because they're replaced in a callback from the old TabContents, 276 // is needed because they're replaced in a callback from the old TabContents,
271 // so cannot immediately be deleted. 277 // so cannot immediately be deleted.
272 void DeleteOldTabContents(); 278 void DeleteOldTabContents();
273 279
274 // Cleans up old NavigationRecord's. 280 // Cleans up old NavigationRecord's.
275 void CleanUpOldNavigations(); 281 void CleanUpOldNavigations();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ScopedRunnableMethodFactory<PrerenderManager> runnable_method_factory_; 348 ScopedRunnableMethodFactory<PrerenderManager> runnable_method_factory_;
343 349
344 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; 350 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_;
345 351
346 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 352 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
347 }; 353 };
348 354
349 } // namespace prerender 355 } // namespace prerender
350 356
351 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 357 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698