| 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 <vector> | 10 #include <vector> |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void MarkTabContentsAsWouldBePrerendered(TabContents* tc); | 99 void MarkTabContentsAsWouldBePrerendered(TabContents* tc); |
| 100 void MarkTabContentsAsNotPrerendered(TabContents* tc); | 100 void MarkTabContentsAsNotPrerendered(TabContents* tc); |
| 101 bool IsTabContentsPrerendered(TabContents* tc) const; | 101 bool IsTabContentsPrerendered(TabContents* tc) const; |
| 102 bool WouldTabContentsBePrerendered(TabContents* tc) const; | 102 bool WouldTabContentsBePrerendered(TabContents* tc) const; |
| 103 | 103 |
| 104 protected: | 104 protected: |
| 105 virtual ~PrerenderManager(); | 105 virtual ~PrerenderManager(); |
| 106 | 106 |
| 107 void SetPrerenderContentsFactory( | 107 void SetPrerenderContentsFactory( |
| 108 PrerenderContents::Factory* prerender_contents_factory); | 108 PrerenderContents::Factory* prerender_contents_factory); |
| 109 bool rate_limit_enabled_; |
| 109 | 110 |
| 110 private: | 111 private: |
| 111 // Test that needs needs access to internal functions. | 112 // Test that needs needs access to internal functions. |
| 112 friend class PrerenderBrowserTest; | 113 friend class PrerenderBrowserTest; |
| 113 | 114 |
| 114 friend class base::RefCounted<PrerenderManager>; | 115 friend class base::RefCounted<PrerenderManager>; |
| 115 struct PrerenderContentsData; | 116 struct PrerenderContentsData; |
| 116 | 117 |
| 117 // Starts and stops scheduling periodic cleanups, respectively. | 118 // Starts and stops scheduling periodic cleanups, respectively. |
| 118 void StartSchedulingPeriodicCleanups(); | 119 void StartSchedulingPeriodicCleanups(); |
| 119 void StopSchedulingPeriodicCleanups(); | 120 void StopSchedulingPeriodicCleanups(); |
| 120 | 121 |
| 121 // Deletes stale prerendered PrerenderContents. | 122 // Deletes stale prerendered PrerenderContents. |
| 122 // Also identifies and kills PrerenderContents that use too much | 123 // Also identifies and kills PrerenderContents that use too much |
| 123 // resources. | 124 // resources. |
| 124 void PeriodicCleanup(); | 125 void PeriodicCleanup(); |
| 125 | 126 |
| 126 bool IsPrerenderElementFresh(const base::Time start) const; | 127 bool IsPrerenderElementFresh(const base::Time start) const; |
| 127 void DeleteOldEntries(); | 128 void DeleteOldEntries(); |
| 128 virtual base::Time GetCurrentTime() const; | 129 virtual base::Time GetCurrentTime() const; |
| 130 virtual base::TimeTicks GetCurrentTimeTicks() const; |
| 129 virtual PrerenderContents* CreatePrerenderContents( | 131 virtual PrerenderContents* CreatePrerenderContents( |
| 130 const GURL& url, | 132 const GURL& url, |
| 131 const std::vector<GURL>& alias_urls, | 133 const std::vector<GURL>& alias_urls, |
| 132 const GURL& referrer); | 134 const GURL& referrer); |
| 133 | 135 |
| 134 // Finds the specified PrerenderContents and returns it, if it exists. | 136 // Finds the specified PrerenderContents and returns it, if it exists. |
| 135 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 137 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
| 136 // ownership of the PrerenderContents. | 138 // ownership of the PrerenderContents. |
| 137 PrerenderContents* FindEntry(const GURL& url); | 139 PrerenderContents* FindEntry(const GURL& url); |
| 138 | 140 |
| 139 static bool ShouldRecordWindowedPPLT(); | 141 static bool ShouldRecordWindowedPPLT(); |
| 140 | 142 |
| 141 static void RecordPrefetchTagObservedOnUIThread(); | 143 static void RecordPrefetchTagObservedOnUIThread(); |
| 142 | 144 |
| 145 bool DoesRateLimitAllowPrerender() const; |
| 146 |
| 143 Profile* profile_; | 147 Profile* profile_; |
| 144 | 148 |
| 145 base::TimeDelta max_prerender_age_; | 149 base::TimeDelta max_prerender_age_; |
| 146 unsigned int max_elements_; | 150 unsigned int max_elements_; |
| 147 | 151 |
| 148 // List of prerendered elements. | 152 // List of prerendered elements. |
| 149 std::list<PrerenderContentsData> prerender_list_; | 153 std::list<PrerenderContentsData> prerender_list_; |
| 150 | 154 |
| 151 // Set of TabContents which are currently displaying a prerendered page. | 155 // Set of TabContents which are currently displaying a prerendered page. |
| 152 base::hash_set<TabContents*> prerendered_tc_set_; | 156 base::hash_set<TabContents*> prerendered_tc_set_; |
| 153 | 157 |
| 154 // Set of TabContents which would be displaying a prerendered page | 158 // Set of TabContents which would be displaying a prerendered page |
| 155 // (for the control group). | 159 // (for the control group). |
| 156 base::hash_set<TabContents*> would_be_prerendered_tc_set_; | 160 base::hash_set<TabContents*> would_be_prerendered_tc_set_; |
| 157 | 161 |
| 158 // Default maximum permitted elements to prerender. | 162 // Default maximum permitted elements to prerender. |
| 159 static const unsigned int kDefaultMaxPrerenderElements = 1; | 163 static const unsigned int kDefaultMaxPrerenderElements = 1; |
| 160 | 164 |
| 161 // Default maximum age a prerendered element may have, in seconds. | 165 // Default maximum age a prerendered element may have, in seconds. |
| 162 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 166 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
| 163 | 167 |
| 164 // Time window for which we will record windowed PLT's from the last | 168 // Time window for which we will record windowed PLT's from the last |
| 165 // observed link rel=prefetch tag. | 169 // observed link rel=prefetch tag. |
| 166 static const int kWindowedPPLTSeconds = 30; | 170 static const int kWindowedPPLTSeconds = 30; |
| 167 | 171 |
| 168 // Time interval at which periodic cleanups are performed. | 172 // Time interval at which periodic cleanups are performed. |
| 169 static const int kPeriodicCleanupIntervalMs = 1000; | 173 static const int kPeriodicCleanupIntervalMs = 1000; |
| 170 | 174 |
| 175 // Time interval before a new prerender is allowed. |
| 176 static const int kMinTimeBetweenPrerendersMs = 500; |
| 177 |
| 171 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; | 178 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; |
| 172 | 179 |
| 173 static PrerenderManagerMode mode_; | 180 static PrerenderManagerMode mode_; |
| 174 | 181 |
| 175 // The time when we last saw a prefetch request coming from a renderer. | 182 // The time when we last saw a prefetch request coming from a renderer. |
| 176 // This is used to record perceived PLT's for a certain amount of time | 183 // This is used to record perceived PLT's for a certain amount of time |
| 177 // from the point that we last saw a <link rel=prefetch> tag. | 184 // from the point that we last saw a <link rel=prefetch> tag. |
| 178 // This static variable should only be modified on the UI thread. | 185 // This static variable should only be modified on the UI thread. |
| 179 static base::TimeTicks last_prefetch_seen_time_; | 186 static base::TimeTicks last_prefetch_seen_time_; |
| 180 | 187 |
| 181 // RepeatingTimer to perform periodic cleanups of pending prerendered | 188 // RepeatingTimer to perform periodic cleanups of pending prerendered |
| 182 // pages. | 189 // pages. |
| 183 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 190 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
| 184 | 191 |
| 192 // Track time of last prerender to limit prerender spam. |
| 193 base::TimeTicks last_prerender_start_time_; |
| 194 |
| 185 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 195 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 186 }; | 196 }; |
| 187 | 197 |
| 188 } // prerender | 198 } // prerender |
| 189 | 199 |
| 190 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 200 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |