OLD | NEW |
---|---|
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/hash_tables.h" | 13 #include "base/hash_tables.h" |
13 #include "base/ref_counted.h" | 14 #include "base/ref_counted.h" |
14 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "base/timer.h" | 17 #include "base/timer.h" |
17 #include "chrome/browser/prerender/prerender_contents.h" | 18 #include "chrome/browser/prerender/prerender_contents.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 | 20 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 | 52 |
52 // Owned by a Profile object for the lifetime of the profile. | 53 // Owned by a Profile object for the lifetime of the profile. |
53 explicit PrerenderManager(Profile* profile); | 54 explicit PrerenderManager(Profile* profile); |
54 | 55 |
55 // Preloads the URL supplied. alias_urls indicates URLs that redirect | 56 // Preloads the URL supplied. alias_urls indicates URLs that redirect |
56 // to the same URL to be preloaded. Returns true if the URL was added, | 57 // to the same URL to be preloaded. Returns true if the URL was added, |
57 // false if it was not. | 58 // false if it was not. |
58 bool AddPreload(const GURL& url, const std::vector<GURL>& alias_urls, | 59 bool AddPreload(const GURL& url, const std::vector<GURL>& alias_urls, |
59 const GURL& referrer); | 60 const GURL& referrer); |
60 | 61 |
62 void AddPendingPreload(int child_id, int route_id, const GURL& url, | |
63 const std::vector<GURL>& alias_urls, | |
64 const GURL& referrer); | |
65 | |
61 // For a given TabContents that wants to navigate to the URL supplied, | 66 // For a given TabContents that wants to navigate to the URL supplied, |
62 // determines whether a preloaded version of the URL can be used, | 67 // determines whether a preloaded version of the URL can be used, |
63 // and substitutes the prerendered RVH into the TabContents. Returns | 68 // and substitutes the prerendered RVH into the TabContents. Returns |
64 // whether or not a prerendered RVH could be used or not. | 69 // whether or not a prerendered RVH could be used or not. |
65 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); | 70 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); |
66 | 71 |
67 // Allows PrerenderContents to remove itself when prerendering should | 72 // Allows PrerenderContents to remove itself when prerendering should |
68 // be cancelled. | 73 // be cancelled. |
69 void RemoveEntry(PrerenderContents* entry); | 74 void RemoveEntry(PrerenderContents* entry); |
70 | 75 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 | 134 |
130 // Finds the specified PrerenderContents and returns it, if it exists. | 135 // Finds the specified PrerenderContents and returns it, if it exists. |
131 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 136 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
132 // ownership of the PrerenderContents. | 137 // ownership of the PrerenderContents. |
133 PrerenderContents* FindEntry(const GURL& url); | 138 PrerenderContents* FindEntry(const GURL& url); |
134 | 139 |
135 static bool ShouldRecordWindowedPPLT(); | 140 static bool ShouldRecordWindowedPPLT(); |
136 | 141 |
137 static void RecordPrefetchTagObservedOnUIThread(); | 142 static void RecordPrefetchTagObservedOnUIThread(); |
138 | 143 |
144 // Called when removing a preload to ensure we clean up any pending preloads | |
145 // that might remain in the map. | |
146 void RemovePendingPreload(PrerenderContents* entry); | |
147 | |
139 Profile* profile_; | 148 Profile* profile_; |
140 | 149 |
141 base::TimeDelta max_prerender_age_; | 150 base::TimeDelta max_prerender_age_; |
142 unsigned int max_elements_; | 151 unsigned int max_elements_; |
143 | 152 |
144 // List of prerendered elements. | 153 // List of prerendered elements. |
145 std::list<PrerenderContentsData> prerender_list_; | 154 std::list<PrerenderContentsData> prerender_list_; |
146 | 155 |
147 // Set of TabContents which are currently displaying a prerendered page. | 156 // Set of TabContents which are currently displaying a prerendered page. |
148 base::hash_set<TabContents*> prerendered_tc_set_; | 157 base::hash_set<TabContents*> prerendered_tc_set_; |
149 | 158 |
159 struct PendingContentsData { | |
160 PendingContentsData(int child_id, int route_id, | |
161 const GURL& url, const std::vector<GURL>& alias_urls, | |
162 const GURL& referrer) | |
163 : child_id_(child_id), route_id_(route_id), | |
164 url_(url), alias_urls_(alias_urls), referrer_(referrer) { } | |
165 ~PendingContentsData() {} | |
166 int child_id_; | |
167 int route_id_; | |
168 GURL url_; | |
169 std::vector<GURL> alias_urls_; | |
170 GURL referrer_; | |
cbentzel
2011/03/14 18:06:13
It looks like default copy-constructor will work c
| |
171 }; | |
172 | |
173 typedef std::vector<PendingContentsData> PendingPrerenderList; | |
174 PendingPrerenderList pending_prerender_list_; | |
cbentzel
2011/03/14 18:06:13
Why not map of pair<child_id, route_id> to vector<
dominich
2011/03/14 19:42:34
Done.
| |
175 | |
150 // Default maximum permitted elements to prerender. | 176 // Default maximum permitted elements to prerender. |
151 static const unsigned int kDefaultMaxPrerenderElements = 1; | 177 static const unsigned int kDefaultMaxPrerenderElements = 1; |
152 | 178 |
153 // Default maximum age a prerendered element may have, in seconds. | 179 // Default maximum age a prerendered element may have, in seconds. |
154 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 180 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
155 | 181 |
156 // Time window for which we will record windowed PLT's from the last | 182 // Time window for which we will record windowed PLT's from the last |
157 // observed link rel=prefetch tag. | 183 // observed link rel=prefetch tag. |
158 static const int kWindowedPPLTSeconds = 30; | 184 static const int kWindowedPPLTSeconds = 30; |
159 | 185 |
(...skipping 13 matching lines...) Expand all Loading... | |
173 // RepeatingTimer to perform periodic cleanups of pending prerendered | 199 // RepeatingTimer to perform periodic cleanups of pending prerendered |
174 // pages. | 200 // pages. |
175 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 201 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
176 | 202 |
177 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 203 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
178 }; | 204 }; |
179 | 205 |
180 } // prerender | 206 } // prerender |
181 | 207 |
182 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 208 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |