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