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(); |
(...skipping 14 matching lines...) Expand all Loading... | |
129 | 130 |
130 // Finds the specified PrerenderContents and returns it, if it exists. | 131 // Finds the specified PrerenderContents and returns it, if it exists. |
131 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 132 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
132 // ownership of the PrerenderContents. | 133 // ownership of the PrerenderContents. |
133 PrerenderContents* FindEntry(const GURL& url); | 134 PrerenderContents* FindEntry(const GURL& url); |
134 | 135 |
135 static bool ShouldRecordWindowedPPLT(); | 136 static bool ShouldRecordWindowedPPLT(); |
136 | 137 |
137 static void RecordPrefetchTagObservedOnUIThread(); | 138 static void RecordPrefetchTagObservedOnUIThread(); |
138 | 139 |
140 bool DoesRateLimitAllowPrerender(); | |
cbentzel
2011/03/15 18:51:03
const
dominich
2011/03/15 21:05:37
Done.
| |
141 | |
139 Profile* profile_; | 142 Profile* profile_; |
140 | 143 |
141 base::TimeDelta max_prerender_age_; | 144 base::TimeDelta max_prerender_age_; |
142 unsigned int max_elements_; | 145 unsigned int max_elements_; |
143 | 146 |
144 // List of prerendered elements. | 147 // List of prerendered elements. |
145 std::list<PrerenderContentsData> prerender_list_; | 148 std::list<PrerenderContentsData> prerender_list_; |
146 | 149 |
147 // Set of TabContents which are currently displaying a prerendered page. | 150 // Set of TabContents which are currently displaying a prerendered page. |
148 base::hash_set<TabContents*> prerendered_tc_set_; | 151 base::hash_set<TabContents*> prerendered_tc_set_; |
149 | 152 |
150 // Default maximum permitted elements to prerender. | 153 // Default maximum permitted elements to prerender. |
151 static const unsigned int kDefaultMaxPrerenderElements = 1; | 154 static const unsigned int kDefaultMaxPrerenderElements = 1; |
152 | 155 |
153 // Default maximum age a prerendered element may have, in seconds. | 156 // Default maximum age a prerendered element may have, in seconds. |
154 static const int kDefaultMaxPrerenderAgeSeconds = 20; | 157 static const int kDefaultMaxPrerenderAgeSeconds = 20; |
155 | 158 |
156 // Time window for which we will record windowed PLT's from the last | 159 // Time window for which we will record windowed PLT's from the last |
157 // observed link rel=prefetch tag. | 160 // observed link rel=prefetch tag. |
158 static const int kWindowedPPLTSeconds = 30; | 161 static const int kWindowedPPLTSeconds = 30; |
159 | 162 |
160 // Time interval at which periodic cleanups are performed. | 163 // Time interval at which periodic cleanups are performed. |
161 static const int kPeriodicCleanupIntervalMs = 1000; | 164 static const int kPeriodicCleanupIntervalMs = 1000; |
162 | 165 |
166 // Time interval before a new prerender is allowed. | |
167 static const int kMinTimeBetweenPrerendersMs = 500; | |
168 | |
163 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; | 169 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; |
164 | 170 |
165 static PrerenderManagerMode mode_; | 171 static PrerenderManagerMode mode_; |
166 | 172 |
167 // The time when we last saw a prefetch request coming from a renderer. | 173 // 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 | 174 // 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. | 175 // from the point that we last saw a <link rel=prefetch> tag. |
170 // This static variable should only be modified on the UI thread. | 176 // This static variable should only be modified on the UI thread. |
171 static base::TimeTicks last_prefetch_seen_time_; | 177 static base::TimeTicks last_prefetch_seen_time_; |
172 | 178 |
173 // RepeatingTimer to perform periodic cleanups of pending prerendered | 179 // RepeatingTimer to perform periodic cleanups of pending prerendered |
174 // pages. | 180 // pages. |
175 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 181 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
176 | 182 |
183 // Track time of last prerender to limit prerender spam. | |
184 base::TimeTicks last_prerender_start_time_; | |
185 | |
177 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 186 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
178 }; | 187 }; |
179 | 188 |
180 } // prerender | 189 } // prerender |
181 | 190 |
182 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 191 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |