Chromium Code Reviews| 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 char kNoExperiment = -1; | |
|
dominich
2011/06/30 18:11:15
A uint8 set to static_cast<uint8>(-1) if you agree
tburkard
2011/06/30 19:45:48
Done.
| |
| 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 char 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 | 210 // 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 | 211 // supplied, if available, and stores it in alias_url. Returns whether or not |
| 204 // the operation succeeded (i.e. a valid URL was found). | 212 // the operation succeeded (i.e. a valid URL was found). |
| 205 static bool MaybeGetQueryStringBasedAliasURL(const GURL& url, | 213 static bool MaybeGetQueryStringBasedAliasURL(const GURL& url, |
| 206 GURL* alias_url); | 214 GURL* alias_url); |
| 207 | 215 |
| 216 // Extracts an experiment stored in the query parameter | |
|
cbentzel
2011/06/30 18:15:39
Can we just combine this with MaybeGetQueryStringB
tburkard
2011/06/30 19:45:48
Since it's a local check that only prerendermanage
cbentzel
2011/06/30 19:51:28
The reason to move it out is the prerender_manager
| |
| 217 // lpe= from the URL supplied, and returns it. | |
| 218 // Returns kNoExperiment if no experiment ID is found, or if the ID | |
| 219 // is not an integer in the range 0 to 9. | |
| 220 static char GetQueryStringBasedExperiment(const GURL& url); | |
| 221 | |
| 208 base::TimeDelta max_prerender_age() const; | 222 base::TimeDelta max_prerender_age() const; |
| 209 unsigned int max_elements() const; | 223 unsigned int max_elements() const; |
| 210 | 224 |
| 211 private: | 225 private: |
| 212 // Test that needs needs access to internal functions. | 226 // Test that needs needs access to internal functions. |
| 213 friend class PrerenderBrowserTest; | 227 friend class PrerenderBrowserTest; |
| 214 | 228 |
| 215 friend class base::RefCountedThreadSafe<PrerenderManager>; | 229 friend class base::RefCountedThreadSafe<PrerenderManager>; |
| 216 | 230 |
| 217 struct PrerenderContentsData; | 231 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 | 265 // objects. If |this| is deleted before the task is run, the task will |
| 252 // automatically be cancelled. | 266 // automatically be cancelled. |
| 253 void PostCleanupTask(); | 267 void PostCleanupTask(); |
| 254 | 268 |
| 255 bool IsPrerenderElementFresh(const base::Time start) const; | 269 bool IsPrerenderElementFresh(const base::Time start) const; |
| 256 void DeleteOldEntries(); | 270 void DeleteOldEntries(); |
| 257 virtual base::Time GetCurrentTime() const; | 271 virtual base::Time GetCurrentTime() const; |
| 258 virtual base::TimeTicks GetCurrentTimeTicks() const; | 272 virtual base::TimeTicks GetCurrentTimeTicks() const; |
| 259 virtual PrerenderContents* CreatePrerenderContents(const GURL& url, | 273 virtual PrerenderContents* CreatePrerenderContents(const GURL& url, |
| 260 const GURL& referrer, | 274 const GURL& referrer, |
| 261 Origin origin); | 275 Origin origin, |
| 276 char experiment_id); | |
| 262 | 277 |
| 263 // Checks if the PrerenderContents has been added to the pending delete list. | 278 // Checks if the PrerenderContents has been added to the pending delete list. |
| 264 bool IsPendingDelete(PrerenderContents* entry) const; | 279 bool IsPendingDelete(PrerenderContents* entry) const; |
| 265 | 280 |
| 266 // Deletes any PrerenderContents that have been added to the pending delete | 281 // Deletes any PrerenderContents that have been added to the pending delete |
| 267 // list. | 282 // list. |
| 268 void DeletePendingDeleteEntries(); | 283 void DeletePendingDeleteEntries(); |
| 269 | 284 |
| 270 // Finds the specified PrerenderContents and returns it, if it exists. | 285 // Finds the specified PrerenderContents and returns it, if it exists. |
| 271 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains | 286 // Returns NULL otherwise. Unlike GetEntry, the PrerenderManager maintains |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 | 330 |
| 316 // Destroys all pending prerenders using FinalStatus. Also deletes them as | 331 // Destroys all pending prerenders using FinalStatus. Also deletes them as |
| 317 // well as any swapped out TabContents queued for destruction. | 332 // well as any swapped out TabContents queued for destruction. |
| 318 // Used both on destruction, and when clearing the browing history. | 333 // Used both on destruction, and when clearing the browing history. |
| 319 void DestroyAllContents(FinalStatus final_status); | 334 void DestroyAllContents(FinalStatus final_status); |
| 320 | 335 |
| 321 // Records the time from when a page starts prerendering to when the user | 336 // 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. | 337 // navigates to it. This must be called on the UI thread. |
| 323 void RecordTimeUntilUsed(base::TimeDelta time_until_used); | 338 void RecordTimeUntilUsed(base::TimeDelta time_until_used); |
| 324 | 339 |
| 340 // Composes a histogram name based on a histogram type. | |
|
dominich
2011/06/30 18:11:15
It doesn't look like these really need to be in th
tburkard
2011/06/30 19:45:48
Can I do the cleanup in a separate CL? This CL is
| |
| 341 std::string ComposeHistogramName(std::string prefix_type, | |
| 342 std::string name) const; | |
| 343 | |
| 344 // Returns the histogram name for a given origin and experiment. | |
| 345 std::string GetHistogramName(Origin origin, char experiment_id, | |
| 346 std::string name) const; | |
| 347 // Returns the histogram name for the current window. | |
| 348 std::string GetDefaultHistogramName(std::string name) const; | |
| 349 // Returns the current experiment. | |
| 350 char GetCurrentExperimentId() const; | |
| 351 // Returns the current origin. | |
| 352 Origin GetCurrentOrigin() const; | |
| 353 // Returns whether or not there is currently an origin/experiment wash. | |
| 354 bool IsOriginExperimentWash() const; | |
| 355 | |
| 325 // Specifies whether prerendering is currently enabled for this | 356 // Specifies whether prerendering is currently enabled for this |
| 326 // manager. The value can change dynamically during the lifetime | 357 // manager. The value can change dynamically during the lifetime |
| 327 // of the PrerenderManager. | 358 // of the PrerenderManager. |
| 328 bool enabled_; | 359 bool enabled_; |
| 329 | 360 |
| 330 Profile* profile_; | 361 Profile* profile_; |
| 331 | 362 |
| 332 PrerenderTracker* prerender_tracker_; | 363 PrerenderTracker* prerender_tracker_; |
| 333 | 364 |
| 334 base::TimeDelta max_prerender_age_; | 365 base::TimeDelta max_prerender_age_; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 356 | 387 |
| 357 // Map of child/route id pairs to pending prerender data. | 388 // Map of child/route id pairs to pending prerender data. |
| 358 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > | 389 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > |
| 359 PendingPrerenderList; | 390 PendingPrerenderList; |
| 360 PendingPrerenderList pending_prerender_list_; | 391 PendingPrerenderList pending_prerender_list_; |
| 361 | 392 |
| 362 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; | 393 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; |
| 363 | 394 |
| 364 static PrerenderManagerMode mode_; | 395 static PrerenderManagerMode mode_; |
| 365 | 396 |
| 397 // An integer indicating a Prerendering Experiment being currently conducted. | |
| 398 // (The last experiment ID seen). | |
| 399 char last_experiment_id_; | |
| 400 | |
| 401 // Origin of the last prerender seen. | |
| 402 Origin last_origin_; | |
| 403 | |
| 404 // A boolean indicating that we have recently encountered a combination of | |
| 405 // different experiments and origins, making an attribution of PPLT's to | |
| 406 // experiments / origins impossible. | |
| 407 bool origin_experiment_wash_; | |
| 408 | |
| 366 // The time when we last saw a prerender request coming from a renderer. | 409 // 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 | 410 // 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. | 411 // from the point that we last saw a <link rel=prerender> tag. |
| 369 base::TimeTicks last_prerender_seen_time_; | 412 base::TimeTicks last_prerender_seen_time_; |
| 370 | 413 |
| 371 // A count of how many prerenders we do per session. Initialized to 0 then | 414 // 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. | 415 // incremented and emitted to a histogram on each successful prerender. |
| 373 static int prerenders_per_session_count_; | 416 static int prerenders_per_session_count_; |
| 374 | 417 |
| 375 // RepeatingTimer to perform periodic cleanups of pending prerendered | 418 // RepeatingTimer to perform periodic cleanups of pending prerendered |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 387 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; | 430 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; |
| 388 | 431 |
| 389 scoped_ptr<PrerenderHistory> prerender_history_; | 432 scoped_ptr<PrerenderHistory> prerender_history_; |
| 390 | 433 |
| 391 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 434 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 392 }; | 435 }; |
| 393 | 436 |
| 394 } // namespace prerender | 437 } // namespace prerender |
| 395 | 438 |
| 396 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 439 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |