| 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(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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 108 |
| 103 void SetPrerenderContentsFactory( | 109 void SetPrerenderContentsFactory( |
| 104 PrerenderContents::Factory* prerender_contents_factory); | 110 PrerenderContents::Factory* prerender_contents_factory); |
| 105 | 111 |
| 106 private: | 112 private: |
| 107 // Test that needs needs access to internal functions. | 113 // Test that needs needs access to internal functions. |
| 108 friend class PrerenderBrowserTest; | 114 friend class PrerenderBrowserTest; |
| 109 | 115 |
| 110 friend class base::RefCounted<PrerenderManager>; | 116 friend class base::RefCounted<PrerenderManager>; |
| 111 struct PrerenderContentsData; | 117 struct PrerenderContentsData; |
| 118 struct PendingContentsData; |
| 112 | 119 |
| 113 // Starts and stops scheduling periodic cleanups, respectively. | 120 // Starts and stops scheduling periodic cleanups, respectively. |
| 114 void StartSchedulingPeriodicCleanups(); | 121 void StartSchedulingPeriodicCleanups(); |
| 115 void StopSchedulingPeriodicCleanups(); | 122 void StopSchedulingPeriodicCleanups(); |
| 116 | 123 |
| 117 // Deletes stale prerendered PrerenderContents. | 124 // Deletes stale prerendered PrerenderContents. |
| 118 // Also identifies and kills PrerenderContents that use too much | 125 // Also identifies and kills PrerenderContents that use too much |
| 119 // resources. | 126 // resources. |
| 120 void PeriodicCleanup(); | 127 void PeriodicCleanup(); |
| 121 | 128 |
| 122 bool IsPrerenderElementFresh(const base::Time start) const; | 129 bool IsPrerenderElementFresh(const base::Time start) const; |
| 123 void DeleteOldEntries(); | 130 void DeleteOldEntries(); |
| 124 virtual base::Time GetCurrentTime() const; | 131 virtual base::Time GetCurrentTime() const; |
| 125 virtual PrerenderContents* CreatePrerenderContents( | 132 virtual PrerenderContents* CreatePrerenderContents( |
| 126 const GURL& url, | 133 const GURL& url, |
| 127 const std::vector<GURL>& alias_urls, | 134 const std::vector<GURL>& alias_urls, |
| 128 const GURL& referrer); | 135 const GURL& referrer); |
| 129 | 136 |
| 130 // Finds the specified PrerenderContents and returns it, if it exists. | 137 // Finds the specified PrerenderContents and returns it, if it exists. |
| 131 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 138 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
| 132 // ownership of the PrerenderContents. | 139 // ownership of the PrerenderContents. |
| 133 PrerenderContents* FindEntry(const GURL& url); | 140 PrerenderContents* FindEntry(const GURL& url); |
| 141 PendingContentsData* FindPendingEntry(const GURL& url); |
| 134 | 142 |
| 135 static bool ShouldRecordWindowedPPLT(); | 143 static bool ShouldRecordWindowedPPLT(); |
| 136 | 144 |
| 137 static void RecordPrefetchTagObservedOnUIThread(); | 145 static void RecordPrefetchTagObservedOnUIThread(); |
| 138 | 146 |
| 147 // Called when removing a preload to ensure we clean up any pending preloads |
| 148 // that might remain in the map. |
| 149 void RemovePendingPreload(PrerenderContents* entry); |
| 150 |
| 139 Profile* profile_; | 151 Profile* profile_; |
| 140 | 152 |
| 141 base::TimeDelta max_prerender_age_; | 153 base::TimeDelta max_prerender_age_; |
| 142 unsigned int max_elements_; | 154 unsigned int max_elements_; |
| 143 | 155 |
| 144 // List of prerendered elements. | 156 // List of prerendered elements. |
| 145 std::list<PrerenderContentsData> prerender_list_; | 157 std::list<PrerenderContentsData> prerender_list_; |
| 146 | 158 |
| 147 // Set of TabContents which are currently displaying a prerendered page. | 159 // Set of TabContents which are currently displaying a prerendered page. |
| 148 base::hash_set<TabContents*> prerendered_tc_set_; | 160 base::hash_set<TabContents*> prerendered_tc_set_; |
| 149 | 161 |
| 162 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > |
| 163 PendingPrerenderList; |
| 164 PendingPrerenderList pending_prerender_list_; |
| 165 |
| 150 // Default maximum permitted elements to prerender. | 166 // Default maximum permitted elements to prerender. |
| 151 static const unsigned int kDefaultMaxPrerenderElements = 1; | 167 static const unsigned int kDefaultMaxPrerenderElements = 1; |
| 152 | 168 |
| 153 // Default maximum age a prerendered element may have, in seconds. | 169 // Default maximum age a prerendered element may have, in seconds. |
| 154 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 170 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
| 155 | 171 |
| 156 // Time window for which we will record windowed PLT's from the last | 172 // Time window for which we will record windowed PLT's from the last |
| 157 // observed link rel=prefetch tag. | 173 // observed link rel=prefetch tag. |
| 158 static const int kWindowedPPLTSeconds = 30; | 174 static const int kWindowedPPLTSeconds = 30; |
| 159 | 175 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 173 // RepeatingTimer to perform periodic cleanups of pending prerendered | 189 // RepeatingTimer to perform periodic cleanups of pending prerendered |
| 174 // pages. | 190 // pages. |
| 175 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 191 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
| 176 | 192 |
| 177 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 193 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 178 }; | 194 }; |
| 179 | 195 |
| 180 } // prerender | 196 } // prerender |
| 181 | 197 |
| 182 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 198 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |