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

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

Issue 6901128: Cancel prerenders that spawn post requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missed the call to erase. Created 9 years, 7 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 26 matching lines...) Expand all
37 37
38 namespace prerender { 38 namespace prerender {
39 39
40 void HandlePrefetchTagOnUIThread( 40 void HandlePrefetchTagOnUIThread(
41 const base::WeakPtr<PrerenderManager>& prerender_manager, 41 const base::WeakPtr<PrerenderManager>& prerender_manager,
42 const std::pair<int, int>& child_route_id_pair, 42 const std::pair<int, int>& child_route_id_pair,
43 const GURL& url, 43 const GURL& url,
44 const GURL& referrer, 44 const GURL& referrer,
45 bool make_pending); 45 bool make_pending);
46 46
47 void DestroyPreloadForChildRouteIdPairOnUIThread(
jam 2011/05/02 16:21:33 nit: this name seems a bit long. we usually use "
dominich 2011/05/02 16:45:55 Done and I will fix the HandlePrefetchTag above to
48 const base::WeakPtr<PrerenderManager>& prerender_manager_weak_ptr,
49 const std::pair<int, int>& child_route_id_pair,
50 FinalStatus final_status);
51
47 // PrerenderManager is responsible for initiating and keeping prerendered 52 // PrerenderManager is responsible for initiating and keeping prerendered
48 // views of webpages. All methods must be called on the UI thread unless 53 // views of webpages. All methods must be called on the UI thread unless
49 // indicated otherwise. 54 // indicated otherwise.
50 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, 55 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>,
51 public base::NonThreadSafe { 56 public base::NonThreadSafe {
52 public: 57 public:
53 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not 58 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not
54 // add in the middle. 59 // add in the middle.
55 enum PrerenderManagerMode { 60 enum PrerenderManagerMode {
56 PRERENDER_MODE_DISABLED, 61 PRERENDER_MODE_DISABLED,
(...skipping 14 matching lines...) Expand all
71 // Returns true if the URL was added, false if it was not. 76 // Returns true if the URL was added, false if it was not.
72 bool AddPreload( 77 bool AddPreload(
73 const std::pair<int, int>& child_route_id_pair, 78 const std::pair<int, int>& child_route_id_pair,
74 const GURL& url, 79 const GURL& url,
75 const GURL& referrer); 80 const GURL& referrer);
76 81
77 void AddPendingPreload(const std::pair<int, int>& child_route_id_pair, 82 void AddPendingPreload(const std::pair<int, int>& child_route_id_pair,
78 const GURL& url, 83 const GURL& url,
79 const GURL& referrer); 84 const GURL& referrer);
80 85
86 // Destroy all preloads for the given child route id pair and assign a final
87 // status to them.
88 void DestroyPreloadForChildRouteIdPair(
89 const std::pair<int, int>& child_route_id_pair,
90 FinalStatus final_status);
91
81 // For a given TabContents that wants to navigate to the URL supplied, 92 // For a given TabContents that wants to navigate to the URL supplied,
82 // determines whether a preloaded version of the URL can be used, 93 // determines whether a preloaded version of the URL can be used,
83 // and substitutes the prerendered RVH into the TabContents. Returns 94 // and substitutes the prerendered RVH into the TabContents. Returns
84 // whether or not a prerendered RVH could be used or not. 95 // whether or not a prerendered RVH could be used or not.
85 bool MaybeUsePreloadedPage(TabContents* tab_contents, const GURL& url); 96 bool MaybeUsePreloadedPage(TabContents* tab_contents, const GURL& url);
86 97
87 // Allows PrerenderContents to remove itself when prerendering should 98 // Allows PrerenderContents to remove itself when prerendering should
88 // be cancelled. 99 // be cancelled.
89 void RemoveEntry(PrerenderContents* entry); 100 void RemoveEntry(PrerenderContents* entry);
90 101
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void MarkTabContentsAsNotPrerendered(TabContents* tab_contents); 149 void MarkTabContentsAsNotPrerendered(TabContents* tab_contents);
139 bool IsTabContentsPrerendered(TabContents* tab_contents) const; 150 bool IsTabContentsPrerendered(TabContents* tab_contents) const;
140 bool WouldTabContentsBePrerendered(TabContents* tab_contents) const; 151 bool WouldTabContentsBePrerendered(TabContents* tab_contents) const;
141 152
142 // Extracts a urlencoded URL stored in a url= query parameter from a URL 153 // Extracts a urlencoded URL stored in a url= query parameter from a URL
143 // supplied, if available, and stores it in alias_url. Returns whether or not 154 // supplied, if available, and stores it in alias_url. Returns whether or not
144 // the operation succeeded (i.e. a valid URL was found). 155 // the operation succeeded (i.e. a valid URL was found).
145 static bool MaybeGetQueryStringBasedAliasURL(const GURL& url, 156 static bool MaybeGetQueryStringBasedAliasURL(const GURL& url,
146 GURL* alias_url); 157 GURL* alias_url);
147 158
159 // Returns true if the method given is invalid for prerendering.
160 static bool IsValidHttpMethod(const std::string& method);
161
148 protected: 162 protected:
149 struct PendingContentsData; 163 struct PendingContentsData;
150 164
151 void SetPrerenderContentsFactory( 165 void SetPrerenderContentsFactory(
152 PrerenderContents::Factory* prerender_contents_factory); 166 PrerenderContents::Factory* prerender_contents_factory);
153 bool rate_limit_enabled_; 167 bool rate_limit_enabled_;
154 168
155 PendingContentsData* FindPendingEntry(const GURL& url); 169 PendingContentsData* FindPendingEntry(const GURL& url);
156 170
157 private: 171 private:
(...skipping 19 matching lines...) Expand all
177 virtual base::TimeTicks GetCurrentTimeTicks() const; 191 virtual base::TimeTicks GetCurrentTimeTicks() const;
178 virtual PrerenderContents* CreatePrerenderContents( 192 virtual PrerenderContents* CreatePrerenderContents(
179 const GURL& url, 193 const GURL& url,
180 const GURL& referrer); 194 const GURL& referrer);
181 195
182 // Finds the specified PrerenderContents and returns it, if it exists. 196 // Finds the specified PrerenderContents and returns it, if it exists.
183 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains 197 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains
184 // ownership of the PrerenderContents. 198 // ownership of the PrerenderContents.
185 PrerenderContents* FindEntry(const GURL& url); 199 PrerenderContents* FindEntry(const GURL& url);
186 200
201 // Returns the iterator to the PrerenderContentsData entry that is being
202 // prerendered from the given child route id pair.
203 std::list<PrerenderContentsData>::iterator
204 FindPrerenderContentsForChildRouteIdPair(
205 const std::pair<int, int>& child_route_id_pair);
206
187 // Returns whether the PrerenderManager is currently within the prerender 207 // Returns whether the PrerenderManager is currently within the prerender
188 // window - effectively, up to 30 seconds after a prefetch tag has been 208 // window - effectively, up to 30 seconds after a prefetch tag has been
189 // observed. 209 // observed.
190 bool WithinWindow() const; 210 bool WithinWindow() const;
191 211
192 // Called when removing a preload to ensure we clean up any pending preloads 212 // Called when removing a preload to ensure we clean up any pending preloads
193 // that might remain in the map. 213 // that might remain in the map.
194 void RemovePendingPreload(PrerenderContents* entry); 214 void RemovePendingPreload(PrerenderContents* entry);
195 215
196 bool DoesRateLimitAllowPrerender() const; 216 bool DoesRateLimitAllowPrerender() const;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 262
243 // Track time of last prerender to limit prerender spam. 263 // Track time of last prerender to limit prerender spam.
244 base::TimeTicks last_prerender_start_time_; 264 base::TimeTicks last_prerender_start_time_;
245 265
246 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 266 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
247 }; 267 };
248 268
249 } // namespace prerender 269 } // namespace prerender
250 270
251 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 271 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698