| 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(const GURL& url, const std::vector<GURL>& alias_urls, |
| 161 const GURL& referrer) |
| 162 : url_(url), alias_urls_(alias_urls), referrer_(referrer) { } |
| 163 ~PendingContentsData() {} |
| 164 GURL url_; |
| 165 std::vector<GURL> alias_urls_; |
| 166 GURL referrer_; |
| 167 }; |
| 168 |
| 169 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > |
| 170 PendingPrerenderList; |
| 171 PendingPrerenderList pending_prerender_list_; |
| 172 |
| 150 // Default maximum permitted elements to prerender. | 173 // Default maximum permitted elements to prerender. |
| 151 static const unsigned int kDefaultMaxPrerenderElements = 1; | 174 static const unsigned int kDefaultMaxPrerenderElements = 1; |
| 152 | 175 |
| 153 // Default maximum age a prerendered element may have, in seconds. | 176 // Default maximum age a prerendered element may have, in seconds. |
| 154 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 177 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
| 155 | 178 |
| 156 // Time window for which we will record windowed PLT's from the last | 179 // Time window for which we will record windowed PLT's from the last |
| 157 // observed link rel=prefetch tag. | 180 // observed link rel=prefetch tag. |
| 158 static const int kWindowedPPLTSeconds = 30; | 181 static const int kWindowedPPLTSeconds = 30; |
| 159 | 182 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 // RepeatingTimer to perform periodic cleanups of pending prerendered | 196 // RepeatingTimer to perform periodic cleanups of pending prerendered |
| 174 // pages. | 197 // pages. |
| 175 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 198 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
| 176 | 199 |
| 177 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 200 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 178 }; | 201 }; |
| 179 | 202 |
| 180 } // prerender | 203 } // prerender |
| 181 | 204 |
| 182 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 205 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |