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 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: merge 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/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
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(const std::pair<int, int>& child_route_id_pair,
63 const GURL& url,
64 const std::vector<GURL>& alias_urls,
65 const GURL& referrer);
66
61 // For a given TabContents that wants to navigate to the URL supplied, 67 // For a given TabContents that wants to navigate to the URL supplied,
62 // determines whether a preloaded version of the URL can be used, 68 // determines whether a preloaded version of the URL can be used,
63 // and substitutes the prerendered RVH into the TabContents. Returns 69 // and substitutes the prerendered RVH into the TabContents. Returns
64 // whether or not a prerendered RVH could be used or not. 70 // whether or not a prerendered RVH could be used or not.
65 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url); 71 bool MaybeUsePreloadedPage(TabContents* tc, const GURL& url);
66 72
67 // Allows PrerenderContents to remove itself when prerendering should 73 // Allows PrerenderContents to remove itself when prerendering should
68 // be cancelled. 74 // be cancelled.
69 void RemoveEntry(PrerenderContents* entry); 75 void RemoveEntry(PrerenderContents* entry);
70 76
(...skipping 24 matching lines...) Expand all
95 101
96 // Maintaining and querying the set of TabContents belonging to this 102 // Maintaining and querying the set of TabContents belonging to this
97 // PrerenderManager that are currently showing prerendered pages. 103 // PrerenderManager that are currently showing prerendered pages.
98 void MarkTabContentsAsPrerendered(TabContents* tc); 104 void MarkTabContentsAsPrerendered(TabContents* tc);
99 void MarkTabContentsAsWouldBePrerendered(TabContents* tc); 105 void MarkTabContentsAsWouldBePrerendered(TabContents* tc);
100 void MarkTabContentsAsNotPrerendered(TabContents* tc); 106 void MarkTabContentsAsNotPrerendered(TabContents* tc);
101 bool IsTabContentsPrerendered(TabContents* tc) const; 107 bool IsTabContentsPrerendered(TabContents* tc) const;
102 bool WouldTabContentsBePrerendered(TabContents* tc) const; 108 bool WouldTabContentsBePrerendered(TabContents* tc) const;
103 109
104 protected: 110 protected:
111 struct PendingContentsData;
112
105 virtual ~PrerenderManager(); 113 virtual ~PrerenderManager();
106 114
107 void SetPrerenderContentsFactory( 115 void SetPrerenderContentsFactory(
108 PrerenderContents::Factory* prerender_contents_factory); 116 PrerenderContents::Factory* prerender_contents_factory);
109 bool rate_limit_enabled_; 117 bool rate_limit_enabled_;
110 118
119 PendingContentsData* FindPendingEntry(const GURL& url);
120
111 private: 121 private:
112 // Test that needs needs access to internal functions. 122 // Test that needs needs access to internal functions.
113 friend class PrerenderBrowserTest; 123 friend class PrerenderBrowserTest;
114 124
115 friend class base::RefCounted<PrerenderManager>; 125 friend class base::RefCounted<PrerenderManager>;
116 struct PrerenderContentsData; 126 struct PrerenderContentsData;
117 127
118 // Starts and stops scheduling periodic cleanups, respectively. 128 // Starts and stops scheduling periodic cleanups, respectively.
119 void StartSchedulingPeriodicCleanups(); 129 void StartSchedulingPeriodicCleanups();
120 void StopSchedulingPeriodicCleanups(); 130 void StopSchedulingPeriodicCleanups();
(...skipping 14 matching lines...) Expand all
135 145
136 // Finds the specified PrerenderContents and returns it, if it exists. 146 // Finds the specified PrerenderContents and returns it, if it exists.
137 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains 147 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains
138 // ownership of the PrerenderContents. 148 // ownership of the PrerenderContents.
139 PrerenderContents* FindEntry(const GURL& url); 149 PrerenderContents* FindEntry(const GURL& url);
140 150
141 static bool ShouldRecordWindowedPPLT(); 151 static bool ShouldRecordWindowedPPLT();
142 152
143 static void RecordPrefetchTagObservedOnUIThread(); 153 static void RecordPrefetchTagObservedOnUIThread();
144 154
155 // Called when removing a preload to ensure we clean up any pending preloads
156 // that might remain in the map.
157 void RemovePendingPreload(PrerenderContents* entry);
158
145 bool DoesRateLimitAllowPrerender() const; 159 bool DoesRateLimitAllowPrerender() const;
146 160
147 Profile* profile_; 161 Profile* profile_;
148 162
149 base::TimeDelta max_prerender_age_; 163 base::TimeDelta max_prerender_age_;
150 unsigned int max_elements_; 164 unsigned int max_elements_;
151 165
152 // List of prerendered elements. 166 // List of prerendered elements.
153 std::list<PrerenderContentsData> prerender_list_; 167 std::list<PrerenderContentsData> prerender_list_;
154 168
155 // Set of TabContents which are currently displaying a prerendered page. 169 // Set of TabContents which are currently displaying a prerendered page.
156 base::hash_set<TabContents*> prerendered_tc_set_; 170 base::hash_set<TabContents*> prerendered_tc_set_;
157 171
158 // Set of TabContents which would be displaying a prerendered page 172 // Set of TabContents which would be displaying a prerendered page
159 // (for the control group). 173 // (for the control group).
160 base::hash_set<TabContents*> would_be_prerendered_tc_set_; 174 base::hash_set<TabContents*> would_be_prerendered_tc_set_;
161 175
176 // Map of child/route id pairs to pending prerender data.
177 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> >
178 PendingPrerenderList;
179 PendingPrerenderList pending_prerender_list_;
180
162 // Default maximum permitted elements to prerender. 181 // Default maximum permitted elements to prerender.
163 static const unsigned int kDefaultMaxPrerenderElements = 1; 182 static const unsigned int kDefaultMaxPrerenderElements = 1;
164 183
165 // Default maximum age a prerendered element may have, in seconds. 184 // Default maximum age a prerendered element may have, in seconds.
166 static const int kDefaultMaxPrerenderAgeSeconds = 20; 185 static const int kDefaultMaxPrerenderAgeSeconds = 20;
167 186
168 // Time window for which we will record windowed PLT's from the last 187 // Time window for which we will record windowed PLT's from the last
169 // observed link rel=prefetch tag. 188 // observed link rel=prefetch tag.
170 static const int kWindowedPPLTSeconds = 30; 189 static const int kWindowedPPLTSeconds = 30;
171 190
(...skipping 23 matching lines...) Expand all
195 214
196 // Track time of last prerender to limit prerender spam. 215 // Track time of last prerender to limit prerender spam.
197 base::TimeTicks last_prerender_start_time_; 216 base::TimeTicks last_prerender_start_time_;
198 217
199 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 218 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
200 }; 219 };
201 220
202 } // prerender 221 } // prerender
203 222
204 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 223 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_final_status.h ('k') | chrome/browser/prerender/prerender_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698