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