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

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

Issue 6625066: Add pending preloads indexed by routing id. Start preloading once we navigate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang fixes Created 9 years, 9 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 <vector> 11 #include <vector>
11 12
12 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
13 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
14 #include "base/time.h" 15 #include "base/time.h"
15 #include "base/timer.h" 16 #include "base/timer.h"
16 #include "chrome/browser/prerender/prerender_contents.h" 17 #include "chrome/browser/prerender/prerender_contents.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 19
19 class Profile; 20 class Profile;
(...skipping 17 matching lines...) Expand all
37 38
38 // Owned by a Profile object for the lifetime of the profile. 39 // Owned by a Profile object for the lifetime of the profile.
39 explicit PrerenderManager(Profile* profile); 40 explicit PrerenderManager(Profile* profile);
40 41
41 // Preloads the URL supplied. alias_urls indicates URLs that redirect 42 // Preloads the URL supplied. alias_urls indicates URLs that redirect
42 // to the same URL to be preloaded. Returns true if the URL was added, 43 // to the same URL to be preloaded. Returns true if the URL was added,
43 // false if it was not. 44 // false if it was not.
44 bool AddPreload(const GURL& url, const std::vector<GURL>& alias_urls, 45 bool AddPreload(const GURL& url, const std::vector<GURL>& alias_urls,
45 const GURL& referrer); 46 const GURL& referrer);
46 47
48 void AddPendingPreload(int route_id, const GURL& url,
49 const std::vector<GURL>& alias_urls,
50 const GURL& referrer);
51
47 // For a given TabContents that wants to navigate to the URL supplied, 52 // For a given TabContents that wants to navigate to the URL supplied,
48 // determines whether a preloaded version of the URL can be used, 53 // determines whether a preloaded version of the URL can be used,
49 // and substitutes the prerendered RVH into the TabContents. Returns 54 // and substitutes the prerendered RVH into the TabContents. Returns
50 // whether or not a prerendered RVH could be used or not. 55 // whether or not a prerendered RVH could be used or not.
51 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); 56 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url);
52 57
53 // Allows PrerenderContents to remove itself when prerendering should 58 // Allows PrerenderContents to remove itself when prerendering should
54 // be cancelled. 59 // be cancelled.
55 void RemoveEntry(PrerenderContents* entry); 60 void RemoveEntry(PrerenderContents* entry);
56 61
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 114
110 // Finds the specified PrerenderContents and returns it, if it exists. 115 // Finds the specified PrerenderContents and returns it, if it exists.
111 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains 116 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains
112 // ownership of the PrerenderContents. 117 // ownership of the PrerenderContents.
113 PrerenderContents* FindEntry(const GURL& url); 118 PrerenderContents* FindEntry(const GURL& url);
114 119
115 static bool ShouldRecordWindowedPPLT(); 120 static bool ShouldRecordWindowedPPLT();
116 121
117 static void RecordPrefetchTagObservedOnUIThread(); 122 static void RecordPrefetchTagObservedOnUIThread();
118 123
124 // Called when removing a preload to ensure we clean up any pending preloads
125 // that might remain in the map.
126 void RemovePendingPreload(PrerenderContents* entry);
127
119 Profile* profile_; 128 Profile* profile_;
120 129
121 base::TimeDelta max_prerender_age_; 130 base::TimeDelta max_prerender_age_;
122 unsigned int max_elements_; 131 unsigned int max_elements_;
123 132
124 // List of prerendered elements. 133 // List of prerendered elements.
125 std::list<PrerenderContentsData> prerender_list_; 134 std::list<PrerenderContentsData> prerender_list_;
126 135
136 struct PendingContentsData {
137 PendingContentsData(const GURL& url, const std::vector<GURL>& alias_urls,
138 const GURL& referrer)
139 : url_(url), alias_urls_(alias_urls), referrer_(referrer) {
140 }
141 ~PendingContentsData() {}
142 const GURL url_;
143 const std::vector<GURL> alias_urls_;
144 const GURL referrer_;
145 };
146
147 std::map<int, PendingContentsData> pending_prerender_map_;
148
127 // Default maximum permitted elements to prerender. 149 // Default maximum permitted elements to prerender.
128 static const unsigned int kDefaultMaxPrerenderElements = 1; 150 static const unsigned int kDefaultMaxPrerenderElements = 1;
129 151
130 // Default maximum age a prerendered element may have, in seconds. 152 // Default maximum age a prerendered element may have, in seconds.
131 static const int kDefaultMaxPrerenderAgeSeconds = 20; 153 static const int kDefaultMaxPrerenderAgeSeconds = 20;
132 154
133 // Time window for which we will record windowed PLT's from the last 155 // Time window for which we will record windowed PLT's from the last
134 // observed link rel=prefetch tag. 156 // observed link rel=prefetch tag.
135 static const int kWindowedPPLTSeconds = 30; 157 static const int kWindowedPPLTSeconds = 30;
136 158
(...skipping 13 matching lines...) Expand all
150 // RepeatingTimer to perform periodic cleanups of pending prerendered 172 // RepeatingTimer to perform periodic cleanups of pending prerendered
151 // pages. 173 // pages.
152 base::RepeatingTimer<PrerenderManager> repeating_timer_; 174 base::RepeatingTimer<PrerenderManager> repeating_timer_;
153 175
154 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 176 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
155 }; 177 };
156 178
157 } // prerender 179 } // prerender
158 180
159 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 181 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698