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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 // The following static method can be called from any thread, but will result | 90 // The following static method can be called from any thread, but will result |
91 // in posting a task to the UI thread if we are not in the UI thread. | 91 // in posting a task to the UI thread if we are not in the UI thread. |
92 static void RecordPrefetchTagObserved(); | 92 static void RecordPrefetchTagObserved(); |
93 | 93 |
94 // Maintaining and querying the set of TabContents belonging to this | 94 // Maintaining and querying the set of TabContents belonging to this |
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 static void set_rate_limit_enabled(bool enable) { | |
101 rate_limit_enabled_ = enable; | |
102 } | |
103 | |
100 protected: | 104 protected: |
101 virtual ~PrerenderManager(); | 105 virtual ~PrerenderManager(); |
102 | 106 |
103 void SetPrerenderContentsFactory( | 107 void SetPrerenderContentsFactory( |
104 PrerenderContents::Factory* prerender_contents_factory); | 108 PrerenderContents::Factory* prerender_contents_factory); |
105 | 109 |
106 private: | 110 private: |
107 // Test that needs needs access to internal functions. | 111 // Test that needs needs access to internal functions. |
108 friend class PrerenderBrowserTest; | 112 friend class PrerenderBrowserTest; |
109 | 113 |
(...skipping 19 matching lines...) Expand all Loading... | |
129 | 133 |
130 // Finds the specified PrerenderContents and returns it, if it exists. | 134 // Finds the specified PrerenderContents and returns it, if it exists. |
131 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 135 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
132 // ownership of the PrerenderContents. | 136 // ownership of the PrerenderContents. |
133 PrerenderContents* FindEntry(const GURL& url); | 137 PrerenderContents* FindEntry(const GURL& url); |
134 | 138 |
135 static bool ShouldRecordWindowedPPLT(); | 139 static bool ShouldRecordWindowedPPLT(); |
136 | 140 |
137 static void RecordPrefetchTagObservedOnUIThread(); | 141 static void RecordPrefetchTagObservedOnUIThread(); |
138 | 142 |
143 static bool DoesRateLimitAllowPrerender(); | |
144 | |
139 Profile* profile_; | 145 Profile* profile_; |
140 | 146 |
141 base::TimeDelta max_prerender_age_; | 147 base::TimeDelta max_prerender_age_; |
142 unsigned int max_elements_; | 148 unsigned int max_elements_; |
143 | 149 |
144 // List of prerendered elements. | 150 // List of prerendered elements. |
145 std::list<PrerenderContentsData> prerender_list_; | 151 std::list<PrerenderContentsData> prerender_list_; |
146 | 152 |
147 // Set of TabContents which are currently displaying a prerendered page. | 153 // Set of TabContents which are currently displaying a prerendered page. |
148 base::hash_set<TabContents*> prerendered_tc_set_; | 154 base::hash_set<TabContents*> prerendered_tc_set_; |
149 | 155 |
150 // Default maximum permitted elements to prerender. | 156 // Default maximum permitted elements to prerender. |
151 static const unsigned int kDefaultMaxPrerenderElements = 1; | 157 static const unsigned int kDefaultMaxPrerenderElements = 1; |
152 | 158 |
153 // Default maximum age a prerendered element may have, in seconds. | 159 // Default maximum age a prerendered element may have, in seconds. |
154 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 160 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
155 | 161 |
156 // Time window for which we will record windowed PLT's from the last | 162 // Time window for which we will record windowed PLT's from the last |
157 // observed link rel=prefetch tag. | 163 // observed link rel=prefetch tag. |
158 static const int kWindowedPPLTSeconds = 30; | 164 static const int kWindowedPPLTSeconds = 30; |
159 | 165 |
160 // Time interval at which periodic cleanups are performed. | 166 // Time interval at which periodic cleanups are performed. |
161 static const int kPeriodicCleanupIntervalMs = 1000; | 167 static const int kPeriodicCleanupIntervalMs = 1000; |
162 | 168 |
169 // Time interval before a new prerender is allowed. | |
170 static const int kMinTimeBetweenPrerendersMs = 500; | |
tburkard
2011/03/11 22:57:40
I think we should set this to 1s.
dominich
2011/03/11 23:14:57
I originally had it at 1s but felt it was too long
| |
171 | |
163 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; | 172 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; |
164 | 173 |
165 static PrerenderManagerMode mode_; | 174 static PrerenderManagerMode mode_; |
166 | 175 |
167 // The time when we last saw a prefetch request coming from a renderer. | 176 // 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 | 177 // 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. | 178 // from the point that we last saw a <link rel=prefetch> tag. |
170 // This static variable should only be modified on the UI thread. | 179 // This static variable should only be modified on the UI thread. |
171 static base::TimeTicks last_prefetch_seen_time_; | 180 static base::TimeTicks last_prefetch_seen_time_; |
172 | 181 |
173 // RepeatingTimer to perform periodic cleanups of pending prerendered | 182 // RepeatingTimer to perform periodic cleanups of pending prerendered |
174 // pages. | 183 // pages. |
175 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 184 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
176 | 185 |
186 // Track time of last prerender to limit prerender spam. | |
187 // TODO(dominich): This could be an average rate instead of a single time | |
188 static base::TimeTicks last_prerender_start_time_; | |
189 static bool rate_limit_enabled_; | |
190 | |
177 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 191 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
178 }; | 192 }; |
179 | 193 |
180 } // prerender | 194 } // prerender |
181 | 195 |
182 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 196 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |