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 <map> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 }; | 60 }; |
61 | 61 |
62 // One or more of these flags must be passed to ClearData() to specify just | 62 // One or more of these flags must be passed to ClearData() to specify just |
63 // what data to clear. See function declaration for more information. | 63 // what data to clear. See function declaration for more information. |
64 enum ClearFlags { | 64 enum ClearFlags { |
65 CLEAR_PRERENDER_CONTENTS = 0x1 << 0, | 65 CLEAR_PRERENDER_CONTENTS = 0x1 << 0, |
66 CLEAR_PRERENDER_HISTORY = 0x1 << 1, | 66 CLEAR_PRERENDER_HISTORY = 0x1 << 1, |
67 CLEAR_MAX = 0x1 << 2 | 67 CLEAR_MAX = 0x1 << 2 |
68 }; | 68 }; |
69 | 69 |
70 // ID indicating that no experiment is active. | |
71 static const uint8 kNoExperiment = 0; | |
72 | |
70 // Owned by a Profile object for the lifetime of the profile. | 73 // Owned by a Profile object for the lifetime of the profile. |
71 PrerenderManager(Profile* profile, PrerenderTracker* prerender_tracker); | 74 PrerenderManager(Profile* profile, PrerenderTracker* prerender_tracker); |
72 | 75 |
73 virtual ~PrerenderManager(); | 76 virtual ~PrerenderManager(); |
74 | 77 |
75 // Entry points for adding prerenders. | 78 // Entry points for adding prerenders. |
76 | 79 |
77 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify | 80 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify |
78 // the RenderViewHost that the prerender request came from and are used to | 81 // the RenderViewHost that the prerender request came from and are used to |
79 // set the initial window size of the RenderViewHost used for prerendering. | 82 // set the initial window size of the RenderViewHost used for prerendering. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 // cancelled and then deleted, and any TabContents queued for destruction are | 181 // cancelled and then deleted, and any TabContents queued for destruction are |
179 // destroyed as well. | 182 // destroyed as well. |
180 // | 183 // |
181 // If the CLEAR_PRERENDER_HISTORY bit is set, the prerender history is | 184 // If the CLEAR_PRERENDER_HISTORY bit is set, the prerender history is |
182 // cleared, including any entries newly created by destroying them in | 185 // cleared, including any entries newly created by destroying them in |
183 // response to the CLEAR_PRERENDER_CONTENTS flag. | 186 // response to the CLEAR_PRERENDER_CONTENTS flag. |
184 // | 187 // |
185 // Intended to be used when clearing the cache or history. | 188 // Intended to be used when clearing the cache or history. |
186 void ClearData(int clear_flags); | 189 void ClearData(int clear_flags); |
187 | 190 |
191 // Record a final status of a prerendered page in a histogram. | |
192 void RecordFinalStatus(Origin origin, | |
193 uint8 experiment_id, | |
194 FinalStatus final_status) const; | |
195 | |
188 protected: | 196 protected: |
189 // Test that needs needs access to internal functions. | 197 // Test that needs needs access to internal functions. |
190 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExpireTest); | 198 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExpireTest); |
191 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExtractURLInQueryStringTest); | 199 FRIEND_TEST_ALL_PREFIXES(PrerenderManagerTest, ExtractURLInQueryStringTest); |
192 | 200 |
193 struct PendingContentsData; | 201 struct PendingContentsData; |
194 | 202 |
195 void SetPrerenderContentsFactory( | 203 void SetPrerenderContentsFactory( |
196 PrerenderContents::Factory* prerender_contents_factory); | 204 PrerenderContents::Factory* prerender_contents_factory); |
197 | 205 |
198 bool rate_limit_enabled_; | 206 bool rate_limit_enabled_; |
199 | 207 |
200 PendingContentsData* FindPendingEntry(const GURL& url); | 208 PendingContentsData* FindPendingEntry(const GURL& url); |
201 | 209 |
202 // Extracts a urlencoded URL stored in a url= query parameter from a URL | |
203 // supplied, if available, and stores it in alias_url. Returns whether or not | |
204 // the operation succeeded (i.e. a valid URL was found). | |
205 static bool MaybeGetQueryStringBasedAliasURL(const GURL& url, | |
206 GURL* alias_url); | |
207 | |
208 base::TimeDelta max_prerender_age() const; | 210 base::TimeDelta max_prerender_age() const; |
209 unsigned int max_elements() const; | 211 unsigned int max_elements() const; |
210 | 212 |
211 private: | 213 private: |
212 // Test that needs needs access to internal functions. | 214 // Test that needs needs access to internal functions. |
213 friend class PrerenderBrowserTest; | 215 friend class PrerenderBrowserTest; |
214 | 216 |
215 friend class base::RefCountedThreadSafe<PrerenderManager>; | 217 friend class base::RefCountedThreadSafe<PrerenderManager>; |
216 | 218 |
217 struct PrerenderContentsData; | 219 struct PrerenderContentsData; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 // objects. If |this| is deleted before the task is run, the task will | 253 // objects. If |this| is deleted before the task is run, the task will |
252 // automatically be cancelled. | 254 // automatically be cancelled. |
253 void PostCleanupTask(); | 255 void PostCleanupTask(); |
254 | 256 |
255 bool IsPrerenderElementFresh(const base::Time start) const; | 257 bool IsPrerenderElementFresh(const base::Time start) const; |
256 void DeleteOldEntries(); | 258 void DeleteOldEntries(); |
257 virtual base::Time GetCurrentTime() const; | 259 virtual base::Time GetCurrentTime() const; |
258 virtual base::TimeTicks GetCurrentTimeTicks() const; | 260 virtual base::TimeTicks GetCurrentTimeTicks() const; |
259 virtual PrerenderContents* CreatePrerenderContents(const GURL& url, | 261 virtual PrerenderContents* CreatePrerenderContents(const GURL& url, |
260 const GURL& referrer, | 262 const GURL& referrer, |
261 Origin origin); | 263 Origin origin, |
264 uint8 experiment_id); | |
262 | 265 |
263 // Checks if the PrerenderContents has been added to the pending delete list. | 266 // Checks if the PrerenderContents has been added to the pending delete list. |
264 bool IsPendingDelete(PrerenderContents* entry) const; | 267 bool IsPendingDelete(PrerenderContents* entry) const; |
265 | 268 |
266 // Deletes any PrerenderContents that have been added to the pending delete | 269 // Deletes any PrerenderContents that have been added to the pending delete |
267 // list. | 270 // list. |
268 void DeletePendingDeleteEntries(); | 271 void DeletePendingDeleteEntries(); |
269 | 272 |
270 // Finds the specified PrerenderContents and returns it, if it exists. | 273 // Finds the specified PrerenderContents and returns it, if it exists. |
271 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 274 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 | 318 |
316 // Destroys all pending prerenders using FinalStatus. Also deletes them as | 319 // Destroys all pending prerenders using FinalStatus. Also deletes them as |
317 // well as any swapped out TabContents queued for destruction. | 320 // well as any swapped out TabContents queued for destruction. |
318 // Used both on destruction, and when clearing the browing history. | 321 // Used both on destruction, and when clearing the browing history. |
319 void DestroyAllContents(FinalStatus final_status); | 322 void DestroyAllContents(FinalStatus final_status); |
320 | 323 |
321 // Records the time from when a page starts prerendering to when the user | 324 // Records the time from when a page starts prerendering to when the user |
322 // navigates to it. This must be called on the UI thread. | 325 // navigates to it. This must be called on the UI thread. |
323 void RecordTimeUntilUsed(base::TimeDelta time_until_used); | 326 void RecordTimeUntilUsed(base::TimeDelta time_until_used); |
324 | 327 |
328 // Composes a histogram name based on a histogram type. | |
dominich
2011/06/30 21:44:59
Do these need to be in PrerenderManager? It seems
| |
329 std::string ComposeHistogramName(const std::string& prefix_type, | |
330 const std::string& name) const; | |
331 | |
332 // Returns the histogram name for a given origin and experiment. | |
333 std::string GetHistogramName(Origin origin, uint8 experiment_id, | |
334 const std::string& name) const; | |
335 // Returns the histogram name for the current window. | |
336 std::string GetDefaultHistogramName(const std::string& name) const; | |
337 // Returns the current experiment. | |
338 uint8 GetCurrentExperimentId() const; | |
339 // Returns the current origin. | |
340 Origin GetCurrentOrigin() const; | |
341 // Returns whether or not there is currently an origin/experiment wash. | |
342 bool IsOriginExperimentWash() const; | |
343 | |
325 // Specifies whether prerendering is currently enabled for this | 344 // Specifies whether prerendering is currently enabled for this |
326 // manager. The value can change dynamically during the lifetime | 345 // manager. The value can change dynamically during the lifetime |
327 // of the PrerenderManager. | 346 // of the PrerenderManager. |
328 bool enabled_; | 347 bool enabled_; |
329 | 348 |
330 Profile* profile_; | 349 Profile* profile_; |
331 | 350 |
332 PrerenderTracker* prerender_tracker_; | 351 PrerenderTracker* prerender_tracker_; |
333 | 352 |
334 base::TimeDelta max_prerender_age_; | 353 base::TimeDelta max_prerender_age_; |
(...skipping 21 matching lines...) Expand all Loading... | |
356 | 375 |
357 // Map of child/route id pairs to pending prerender data. | 376 // Map of child/route id pairs to pending prerender data. |
358 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > | 377 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > |
359 PendingPrerenderList; | 378 PendingPrerenderList; |
360 PendingPrerenderList pending_prerender_list_; | 379 PendingPrerenderList pending_prerender_list_; |
361 | 380 |
362 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; | 381 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; |
363 | 382 |
364 static PrerenderManagerMode mode_; | 383 static PrerenderManagerMode mode_; |
365 | 384 |
385 // An integer indicating a Prerendering Experiment being currently conducted. | |
386 // (The last experiment ID seen). | |
387 uint8 last_experiment_id_; | |
388 | |
389 // Origin of the last prerender seen. | |
390 Origin last_origin_; | |
391 | |
392 // A boolean indicating that we have recently encountered a combination of | |
393 // different experiments and origins, making an attribution of PPLT's to | |
394 // experiments / origins impossible. | |
395 bool origin_experiment_wash_; | |
396 | |
366 // The time when we last saw a prerender request coming from a renderer. | 397 // The time when we last saw a prerender request coming from a renderer. |
367 // This is used to record perceived PLT's for a certain amount of time | 398 // This is used to record perceived PLT's for a certain amount of time |
368 // from the point that we last saw a <link rel=prerender> tag. | 399 // from the point that we last saw a <link rel=prerender> tag. |
369 base::TimeTicks last_prerender_seen_time_; | 400 base::TimeTicks last_prerender_seen_time_; |
370 | 401 |
371 // A count of how many prerenders we do per session. Initialized to 0 then | 402 // A count of how many prerenders we do per session. Initialized to 0 then |
372 // incremented and emitted to a histogram on each successful prerender. | 403 // incremented and emitted to a histogram on each successful prerender. |
373 static int prerenders_per_session_count_; | 404 static int prerenders_per_session_count_; |
374 | 405 |
375 // RepeatingTimer to perform periodic cleanups of pending prerendered | 406 // RepeatingTimer to perform periodic cleanups of pending prerendered |
(...skipping 11 matching lines...) Expand all Loading... | |
387 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; | 418 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; |
388 | 419 |
389 scoped_ptr<PrerenderHistory> prerender_history_; | 420 scoped_ptr<PrerenderHistory> prerender_history_; |
390 | 421 |
391 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 422 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
392 }; | 423 }; |
393 | 424 |
394 } // namespace prerender | 425 } // namespace prerender |
395 | 426 |
396 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 427 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |