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

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: rebase again 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/task.h" 17 #include "base/task.h"
18 #include "base/threading/non_thread_safe.h" 18 #include "base/threading/non_thread_safe.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "base/timer.h" 20 #include "base/timer.h"
21 #include "chrome/browser/prerender/prerender_contents.h" 21 #include "chrome/browser/prerender/prerender_contents.h"
22 #include "chrome/browser/prerender/prerender_origin.h"
22 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
23 24
24 class Profile; 25 class Profile;
25 class TabContents; 26 class TabContents;
26 27
27 #if defined(COMPILER_GCC) 28 #if defined(COMPILER_GCC)
28 29
29 namespace __gnu_cxx { 30 namespace __gnu_cxx {
30 template <> 31 template <>
31 struct hash<TabContents*> { 32 struct hash<TabContents*> {
(...skipping 12 matching lines...) Expand all
44 45
45 // Adds either a preload or a pending preload to the PrerenderManager. 46 // Adds either a preload or a pending preload to the PrerenderManager.
46 // Must be called on the UI thread. 47 // Must be called on the UI thread.
47 void HandleTag( 48 void HandleTag(
48 const base::WeakPtr<PrerenderManager>& prerender_manager, 49 const base::WeakPtr<PrerenderManager>& prerender_manager,
49 int render_process_id, 50 int render_process_id,
50 int render_view_id, 51 int render_view_id,
51 const GURL& url, 52 const GURL& url,
52 const GURL& referrer); 53 const GURL& referrer);
53 54
54 void DestroyPreloadForRenderView( 55 void DestroyPrerenderForRenderView(
55 const base::WeakPtr<PrerenderManager>& prerender_manager_weak_ptr, 56 const base::WeakPtr<PrerenderManager>& prerender_manager_weak_ptr,
56 int child_id, 57 int child_id,
57 int route_id, 58 int route_id,
58 FinalStatus final_status); 59 FinalStatus final_status);
59 60
60 // PrerenderManager is responsible for initiating and keeping prerendered 61 // PrerenderManager is responsible for initiating and keeping prerendered
61 // views of webpages. All methods must be called on the UI thread unless 62 // views of webpages. All methods must be called on the UI thread unless
62 // indicated otherwise. 63 // indicated otherwise.
63 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, 64 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
64 public base::NonThreadSafe { 65 public base::NonThreadSafe {
(...skipping 14 matching lines...) Expand all
79 CLEAR_PRERENDER_CONTENTS = 0x1 << 0, 80 CLEAR_PRERENDER_CONTENTS = 0x1 << 0,
80 CLEAR_PRERENDER_HISTORY = 0x1 << 1, 81 CLEAR_PRERENDER_HISTORY = 0x1 << 1,
81 CLEAR_MAX = 0x1 << 2 82 CLEAR_MAX = 0x1 << 2
82 }; 83 };
83 84
84 // Owned by a Profile object for the lifetime of the profile. 85 // Owned by a Profile object for the lifetime of the profile.
85 PrerenderManager(Profile* profile, PrerenderTracker* prerender_tracker); 86 PrerenderManager(Profile* profile, PrerenderTracker* prerender_tracker);
86 87
87 virtual ~PrerenderManager(); 88 virtual ~PrerenderManager();
88 89
89 // Preloads |url| if valid. |child_route_id_pair| identifies the 90 // Starts a prerender for |url| if valid. |child_route_id_pair| identifies the
90 // RenderViewHost that the prerender request came from and is used to 91 // RenderViewHost that the prerender request came from and is used to
91 // set the initial window size of the RenderViewHost used for prerendering. 92 // set the initial window size of the RenderViewHost used for prerendering.
92 // Returns true if the URL was added, false if it was not. 93 // Returns true if the URL was added, false if it was not.
93 // If |child_route_id_pair| itself is prerendering, adds the preloads as 94 // If |child_route_id_pair| itself is prerendering, adds the preloads as
94 // a pending preload. 95 // a pending preload. |origin| enumerates the source of the prerender for
95 bool AddPreload( 96 // data-tracking purposes.
97 bool AddPrerenderFromPage(
98 Origin origin,
96 const std::pair<int, int>& child_route_id_pair, 99 const std::pair<int, int>& child_route_id_pair,
97 const GURL& url, 100 const GURL& url,
98 const GURL& referrer); 101 const GURL& referrer);
99 102
100 // Destroy all preloads for the given child route id pair and assign a final 103 // Starts a prerender for |url| if valid. As the prerender request is coming
104 // from a source without a RenderViewHost (ie, the omnibox) we don't have a
105 // child or route id, or a referrer. This method uses sensible values for
106 // those.
107 bool AddPrerender(Origin origin, const GURL& url);
108
109 // Destroy all prerenders for the given child route id pair and assign a final
101 // status to them. 110 // status to them.
102 virtual void DestroyPreloadForChildRouteIdPair( 111 virtual void DestroyPrerenderForChildRouteIdPair(
103 const std::pair<int, int>& child_route_id_pair, 112 const std::pair<int, int>& child_route_id_pair,
104 FinalStatus final_status); 113 FinalStatus final_status);
105 114
106 // For a given TabContents that wants to navigate to the URL supplied, 115 // For a given TabContents that wants to navigate to the URL supplied,
107 // determines whether a preloaded version of the URL can be used, 116 // determines whether a prerendered version of the URL can be used,
108 // and substitutes the prerendered RVH into the TabContents. Returns 117 // and substitutes the prerendered RVH into the TabContents. Returns
109 // whether or not a prerendered RVH could be used or not. 118 // whether or not a prerendered RVH could be used or not.
110 bool MaybeUsePreloadedPage(TabContents* tab_contents, 119 bool MaybeUsePrerenderedPage(TabContents* tab_contents,
111 const GURL& url, 120 const GURL& url,
112 bool has_opener_set); 121 bool has_opener_set);
113 122
114 // Moves a PrerenderContents to the pending delete list from the list of 123 // Moves a PrerenderContents to the pending delete list from the list of
115 // active prerenders when prerendering should be cancelled. 124 // active prerenders when prerendering should be cancelled.
116 void MoveEntryToPendingDelete(PrerenderContents* entry); 125 void MoveEntryToPendingDelete(PrerenderContents* entry);
117 126
118 // Checks if the PrerenderContents has been added to the pending delete list. 127 // Checks if the PrerenderContents has been added to the pending delete list.
119 bool IsPendingDelete(PrerenderContents* entry) const; 128 bool IsPendingDelete(PrerenderContents* entry) const;
120 129
121 // Retrieves the PrerenderContents object for the specified URL, if it 130 // Retrieves the PrerenderContents object for the specified URL, if it
122 // has been prerendered. The caller will then have ownership of the 131 // has been prerendered. The caller will then have ownership of the
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 friend class base::RefCountedThreadSafe<PrerenderManager>; 242 friend class base::RefCountedThreadSafe<PrerenderManager>;
234 243
235 struct PrerenderContentsData; 244 struct PrerenderContentsData;
236 struct NavigationRecord; 245 struct NavigationRecord;
237 246
238 class OnCloseTabContentsDeleter; 247 class OnCloseTabContentsDeleter;
239 248
240 // Adds a pending preload issued by the prerendering RenderView identified by 249 // Adds a pending preload issued by the prerendering RenderView identified by
241 // |child_route_id_pair|. If and when that prerendering RenderView is used, 250 // |child_route_id_pair|. If and when that prerendering RenderView is used,
242 // the specified prerender will start. 251 // the specified prerender will start.
243 void AddPendingPreload(const std::pair<int, int>& child_route_id_pair, 252 void AddPendingPrerender(Origin origin,
244 const GURL& url, 253 const std::pair<int, int>& child_route_id_pair,
245 const GURL& referrer); 254 const GURL& url,
255 const GURL& referrer);
246 256
247 // Starts scheduling periodic cleanups. 257 // Starts scheduling periodic cleanups.
248 void StartSchedulingPeriodicCleanups(); 258 void StartSchedulingPeriodicCleanups();
249 // Stops scheduling periodic cleanups if they're no longer needed. 259 // Stops scheduling periodic cleanups if they're no longer needed.
250 void MaybeStopSchedulingPeriodicCleanups(); 260 void MaybeStopSchedulingPeriodicCleanups();
251 261
252 // Deletes stale and cancelled prerendered PrerenderContents, as well as 262 // Deletes stale and cancelled prerendered PrerenderContents, as well as
253 // TabContents that have been replaced by prerendered TabContents. 263 // TabContents that have been replaced by prerendered TabContents.
254 // Also identifies and kills PrerenderContents that use too much 264 // Also identifies and kills PrerenderContents that use too much
255 // resources. 265 // resources.
256 void PeriodicCleanup(); 266 void PeriodicCleanup();
257 267
258 // Posts a task to call PeriodicCleanup. Results in quicker destruction of 268 // Posts a task to call PeriodicCleanup. Results in quicker destruction of
259 // objects. If |this| is deleted before the task is run, the task will 269 // objects. If |this| is deleted before the task is run, the task will
260 // automatically be cancelled. 270 // automatically be cancelled.
261 void PostCleanupTask(); 271 void PostCleanupTask();
262 272
263 bool IsPrerenderElementFresh(const base::Time start) const; 273 bool IsPrerenderElementFresh(const base::Time start) const;
264 void DeleteOldEntries(); 274 void DeleteOldEntries();
265 virtual base::Time GetCurrentTime() const; 275 virtual base::Time GetCurrentTime() const;
266 virtual base::TimeTicks GetCurrentTimeTicks() const; 276 virtual base::TimeTicks GetCurrentTimeTicks() const;
267 virtual PrerenderContents* CreatePrerenderContents( 277 virtual PrerenderContents* CreatePrerenderContents(const GURL& url,
268 const GURL& url, 278 const GURL& referrer,
269 const GURL& referrer); 279 Origin origin);
270 280
271 // Deletes any PrerenderContents that have been added to the pending delete 281 // Deletes any PrerenderContents that have been added to the pending delete
272 // list. 282 // list.
273 void DeletePendingDeleteEntries(); 283 void DeletePendingDeleteEntries();
274 284
275 // Finds the specified PrerenderContents and returns it, if it exists. 285 // Finds the specified PrerenderContents and returns it, if it exists.
276 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains 286 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains
277 // ownership of the PrerenderContents. 287 // ownership of the PrerenderContents.
278 PrerenderContents* FindEntry(const GURL& url); 288 PrerenderContents* FindEntry(const GURL& url);
279 289
280 // Returns the iterator to the PrerenderContentsData entry that is being 290 // Returns the iterator to the PrerenderContentsData entry that is being
281 // prerendered from the given child route id pair. 291 // prerendered from the given child route id pair.
282 std::list<PrerenderContentsData>::iterator 292 std::list<PrerenderContentsData>::iterator
283 FindPrerenderContentsForChildRouteIdPair( 293 FindPrerenderContentsForChildRouteIdPair(
284 const std::pair<int, int>& child_route_id_pair); 294 const std::pair<int, int>& child_route_id_pair);
285 295
286 // Returns whether the PrerenderManager is currently within the prerender 296 // Returns whether the PrerenderManager is currently within the prerender
287 // window - effectively, up to 30 seconds after a prerender tag has been 297 // window - effectively, up to 30 seconds after a prerender tag has been
288 // observed. 298 // observed.
289 bool WithinWindow() const; 299 bool WithinWindow() const;
290 300
291 // Called when removing a preload to ensure we clean up any pending preloads 301 // Called when removing a preload to ensure we clean up any pending preloads
292 // that might remain in the map. 302 // that might remain in the map.
293 void RemovePendingPreload(PrerenderContents* entry); 303 void RemovePendingPrerender(PrerenderContents* entry);
294 304
295 bool DoesRateLimitAllowPrerender() const; 305 bool DoesRateLimitAllowPrerender() const;
296 306
297 // Deletes old TabContents that have been replaced by prerendered ones. This 307 // Deletes old TabContents that have been replaced by prerendered ones. This
298 // is needed because they're replaced in a callback from the old TabContents, 308 // is needed because they're replaced in a callback from the old TabContents,
299 // so cannot immediately be deleted. 309 // so cannot immediately be deleted.
300 void DeleteOldTabContents(); 310 void DeleteOldTabContents();
301 311
302 // Cleans up old NavigationRecord's. 312 // Cleans up old NavigationRecord's.
303 void CleanUpOldNavigations(); 313 void CleanUpOldNavigations();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; 394 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_;
385 395
386 scoped_ptr<PrerenderHistory> prerender_history_; 396 scoped_ptr<PrerenderHistory> prerender_history_;
387 397
388 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 398 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
389 }; 399 };
390 400
391 } // namespace prerender 401 } // namespace prerender
392 402
393 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 403 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_final_status.cc ('k') | chrome/browser/prerender/prerender_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698