| 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 <map> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 std::size_t operator()(TabContents* value) const { | 30 std::size_t operator()(TabContents* value) const { |
| 31 return reinterpret_cast<std::size_t>(value); | 31 return reinterpret_cast<std::size_t>(value); |
| 32 } | 32 } |
| 33 }; | 33 }; |
| 34 } | 34 } |
| 35 | 35 |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 namespace prerender { | 38 namespace prerender { |
| 39 | 39 |
| 40 void HandlePrefetchTagOnUIThread( | 40 // Adds either a preload or a pending preload to the PrerenderManager. |
| 41 // Must be called on the UI thread. |
| 42 void HandlePrefetchTag( |
| 41 const base::WeakPtr<PrerenderManager>& prerender_manager, | 43 const base::WeakPtr<PrerenderManager>& prerender_manager, |
| 42 const std::pair<int, int>& child_route_id_pair, | 44 int render_process_id, |
| 45 int render_view_id, |
| 43 const GURL& url, | 46 const GURL& url, |
| 44 const GURL& referrer, | 47 const GURL& referrer, |
| 45 bool make_pending); | 48 bool make_pending); |
| 46 | 49 |
| 50 // Given a renderer process id and view id, this will destroy any preloads and |
| 51 // pending preloads than are using or originated in the given render view. |
| 52 // Must be called on the UI thread. |
| 53 void DestroyPreloadForRenderView( |
| 54 const base::WeakPtr<PrerenderManager>& prerender_manager_weak_ptr, |
| 55 int render_process_id, |
| 56 int render_view_id, |
| 57 FinalStatus final_status); |
| 58 |
| 47 // PrerenderManager is responsible for initiating and keeping prerendered | 59 // PrerenderManager is responsible for initiating and keeping prerendered |
| 48 // views of webpages. All methods must be called on the UI thread unless | 60 // views of webpages. All methods must be called on the UI thread unless |
| 49 // indicated otherwise. | 61 // indicated otherwise. |
| 50 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, | 62 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| 51 public base::NonThreadSafe { | 63 public base::NonThreadSafe { |
| 52 public: | 64 public: |
| 53 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not | 65 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not |
| 54 // add in the middle. | 66 // add in the middle. |
| 55 enum PrerenderManagerMode { | 67 enum PrerenderManagerMode { |
| 56 PRERENDER_MODE_DISABLED, | 68 PRERENDER_MODE_DISABLED, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 // Returns true if the URL was added, false if it was not. | 83 // Returns true if the URL was added, false if it was not. |
| 72 bool AddPreload( | 84 bool AddPreload( |
| 73 const std::pair<int, int>& child_route_id_pair, | 85 const std::pair<int, int>& child_route_id_pair, |
| 74 const GURL& url, | 86 const GURL& url, |
| 75 const GURL& referrer); | 87 const GURL& referrer); |
| 76 | 88 |
| 77 void AddPendingPreload(const std::pair<int, int>& child_route_id_pair, | 89 void AddPendingPreload(const std::pair<int, int>& child_route_id_pair, |
| 78 const GURL& url, | 90 const GURL& url, |
| 79 const GURL& referrer); | 91 const GURL& referrer); |
| 80 | 92 |
| 93 // Destroy all preloads for the given child route id pair and assign a final |
| 94 // status to them. |
| 95 void DestroyPreloadForChildRouteIdPair( |
| 96 const std::pair<int, int>& child_route_id_pair, |
| 97 FinalStatus final_status); |
| 98 |
| 81 // For a given TabContents that wants to navigate to the URL supplied, | 99 // For a given TabContents that wants to navigate to the URL supplied, |
| 82 // determines whether a preloaded version of the URL can be used, | 100 // determines whether a preloaded version of the URL can be used, |
| 83 // and substitutes the prerendered RVH into the TabContents. Returns | 101 // and substitutes the prerendered RVH into the TabContents. Returns |
| 84 // whether or not a prerendered RVH could be used or not. | 102 // whether or not a prerendered RVH could be used or not. |
| 85 bool MaybeUsePreloadedPage(TabContents* tab_contents, const GURL& url); | 103 bool MaybeUsePreloadedPage(TabContents* tab_contents, const GURL& url); |
| 86 bool MaybeUsePreloadedPageOld(TabContents* tab_contents, const GURL& url); | 104 bool MaybeUsePreloadedPageOld(TabContents* tab_contents, const GURL& url); |
| 87 | 105 |
| 88 // Allows PrerenderContents to remove itself when prerendering should | 106 // Allows PrerenderContents to remove itself when prerendering should |
| 89 // be cancelled. | 107 // be cancelled. |
| 90 void RemoveEntry(PrerenderContents* entry); | 108 void RemoveEntry(PrerenderContents* entry); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 void MarkTabContentsAsNotPrerendered(TabContents* tab_contents); | 164 void MarkTabContentsAsNotPrerendered(TabContents* tab_contents); |
| 147 bool IsTabContentsPrerendered(TabContents* tab_contents) const; | 165 bool IsTabContentsPrerendered(TabContents* tab_contents) const; |
| 148 bool WouldTabContentsBePrerendered(TabContents* tab_contents) const; | 166 bool WouldTabContentsBePrerendered(TabContents* tab_contents) const; |
| 149 | 167 |
| 150 // Extracts a urlencoded URL stored in a url= query parameter from a URL | 168 // Extracts a urlencoded URL stored in a url= query parameter from a URL |
| 151 // supplied, if available, and stores it in alias_url. Returns whether or not | 169 // supplied, if available, and stores it in alias_url. Returns whether or not |
| 152 // the operation succeeded (i.e. a valid URL was found). | 170 // the operation succeeded (i.e. a valid URL was found). |
| 153 static bool MaybeGetQueryStringBasedAliasURL(const GURL& url, | 171 static bool MaybeGetQueryStringBasedAliasURL(const GURL& url, |
| 154 GURL* alias_url); | 172 GURL* alias_url); |
| 155 | 173 |
| 174 // Returns true if the method given is invalid for prerendering. |
| 175 static bool IsValidHttpMethod(const std::string& method); |
| 176 |
| 156 protected: | 177 protected: |
| 157 struct PendingContentsData; | 178 struct PendingContentsData; |
| 158 | 179 |
| 159 void SetPrerenderContentsFactory( | 180 void SetPrerenderContentsFactory( |
| 160 PrerenderContents::Factory* prerender_contents_factory); | 181 PrerenderContents::Factory* prerender_contents_factory); |
| 161 bool rate_limit_enabled_; | 182 bool rate_limit_enabled_; |
| 162 | 183 |
| 163 PendingContentsData* FindPendingEntry(const GURL& url); | 184 PendingContentsData* FindPendingEntry(const GURL& url); |
| 164 | 185 |
| 165 private: | 186 private: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 185 virtual base::TimeTicks GetCurrentTimeTicks() const; | 206 virtual base::TimeTicks GetCurrentTimeTicks() const; |
| 186 virtual PrerenderContents* CreatePrerenderContents( | 207 virtual PrerenderContents* CreatePrerenderContents( |
| 187 const GURL& url, | 208 const GURL& url, |
| 188 const GURL& referrer); | 209 const GURL& referrer); |
| 189 | 210 |
| 190 // Finds the specified PrerenderContents and returns it, if it exists. | 211 // Finds the specified PrerenderContents and returns it, if it exists. |
| 191 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 212 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
| 192 // ownership of the PrerenderContents. | 213 // ownership of the PrerenderContents. |
| 193 PrerenderContents* FindEntry(const GURL& url); | 214 PrerenderContents* FindEntry(const GURL& url); |
| 194 | 215 |
| 216 // Returns the iterator to the PrerenderContentsData entry that is being |
| 217 // prerendered from the given child route id pair. |
| 218 std::list<PrerenderContentsData>::iterator |
| 219 FindPrerenderContentsForChildRouteIdPair( |
| 220 const std::pair<int, int>& child_route_id_pair); |
| 221 |
| 195 // Returns whether the PrerenderManager is currently within the prerender | 222 // Returns whether the PrerenderManager is currently within the prerender |
| 196 // window - effectively, up to 30 seconds after a prefetch tag has been | 223 // window - effectively, up to 30 seconds after a prefetch tag has been |
| 197 // observed. | 224 // observed. |
| 198 bool WithinWindow() const; | 225 bool WithinWindow() const; |
| 199 | 226 |
| 200 // Called when removing a preload to ensure we clean up any pending preloads | 227 // Called when removing a preload to ensure we clean up any pending preloads |
| 201 // that might remain in the map. | 228 // that might remain in the map. |
| 202 void RemovePendingPreload(PrerenderContents* entry); | 229 void RemovePendingPreload(PrerenderContents* entry); |
| 203 | 230 |
| 204 bool DoesRateLimitAllowPrerender() const; | 231 bool DoesRateLimitAllowPrerender() const; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 277 |
| 251 // Track time of last prerender to limit prerender spam. | 278 // Track time of last prerender to limit prerender spam. |
| 252 base::TimeTicks last_prerender_start_time_; | 279 base::TimeTicks last_prerender_start_time_; |
| 253 | 280 |
| 254 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 281 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 255 }; | 282 }; |
| 256 | 283 |
| 257 } // namespace prerender | 284 } // namespace prerender |
| 258 | 285 |
| 259 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 286 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |