| 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> |
| 11 #include <string> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/hash_tables.h" | 14 #include "base/hash_tables.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 16 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 17 #include "base/task.h" | 18 #include "base/task.h" |
| 18 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
| 19 #include "base/time.h" | 20 #include "base/time.h" |
| 20 #include "base/timer.h" | 21 #include "base/timer.h" |
| 21 #include "chrome/browser/prerender/prerender_config.h" | 22 #include "chrome/browser/prerender/prerender_config.h" |
| 22 #include "chrome/browser/prerender/prerender_contents.h" | 23 #include "chrome/browser/prerender/prerender_contents.h" |
| 24 #include "chrome/browser/prerender/prerender_final_status.h" |
| 23 #include "chrome/browser/prerender/prerender_origin.h" | 25 #include "chrome/browser/prerender/prerender_origin.h" |
| 24 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 25 | 27 |
| 26 class Profile; | 28 class Profile; |
| 27 class TabContents; | 29 class TabContents; |
| 28 | 30 |
| 29 #if defined(COMPILER_GCC) | 31 #if defined(COMPILER_GCC) |
| 30 | 32 |
| 31 namespace __gnu_cxx { | 33 namespace __gnu_cxx { |
| 32 template <> | 34 template <> |
| 33 struct hash<TabContents*> { | 35 struct hash<TabContents*> { |
| 34 std::size_t operator()(TabContents* value) const { | 36 std::size_t operator()(TabContents* value) const { |
| 35 return reinterpret_cast<std::size_t>(value); | 37 return reinterpret_cast<std::size_t>(value); |
| 36 } | 38 } |
| 37 }; | 39 }; |
| 38 } | 40 } |
| 39 | 41 |
| 40 #endif | 42 #endif |
| 41 | 43 |
| 42 namespace prerender { | 44 namespace prerender { |
| 43 | 45 |
| 44 class PrerenderCondition; | 46 class PrerenderCondition; |
| 47 class PrerenderHistograms; |
| 45 class PrerenderHistory; | 48 class PrerenderHistory; |
| 46 class PrerenderTracker; | 49 class PrerenderTracker; |
| 47 | 50 |
| 48 // PrerenderManager is responsible for initiating and keeping prerendered | 51 // PrerenderManager is responsible for initiating and keeping prerendered |
| 49 // views of webpages. All methods must be called on the UI thread unless | 52 // views of webpages. All methods must be called on the UI thread unless |
| 50 // indicated otherwise. | 53 // indicated otherwise. |
| 51 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, | 54 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| 52 public base::NonThreadSafe { | 55 public base::NonThreadSafe { |
| 53 public: | 56 public: |
| 54 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not | 57 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 320 |
| 318 // Returns a new Value representing the pages currently being prerendered. The | 321 // Returns a new Value representing the pages currently being prerendered. The |
| 319 // caller is responsible for delete'ing the return value. | 322 // caller is responsible for delete'ing the return value. |
| 320 base::Value* GetActivePrerendersAsValue() const; | 323 base::Value* GetActivePrerendersAsValue() const; |
| 321 | 324 |
| 322 // Destroys all pending prerenders using FinalStatus. Also deletes them as | 325 // Destroys all pending prerenders using FinalStatus. Also deletes them as |
| 323 // well as any swapped out TabContents queued for destruction. | 326 // well as any swapped out TabContents queued for destruction. |
| 324 // Used both on destruction, and when clearing the browing history. | 327 // Used both on destruction, and when clearing the browing history. |
| 325 void DestroyAllContents(FinalStatus final_status); | 328 void DestroyAllContents(FinalStatus final_status); |
| 326 | 329 |
| 327 // Records the time from when a page starts prerendering to when the user | |
| 328 // navigates to it. This must be called on the UI thread. | |
| 329 void RecordTimeUntilUsed(base::TimeDelta time_until_used); | |
| 330 | |
| 331 // Composes a histogram name based on a histogram type. | |
| 332 std::string ComposeHistogramName(const std::string& prefix_type, | |
| 333 const std::string& name) const; | |
| 334 | |
| 335 // Returns the histogram name for a given origin and experiment. | |
| 336 std::string GetHistogramName(Origin origin, uint8 experiment_id, | |
| 337 const std::string& name) const; | |
| 338 // Returns the histogram name for the current window. | |
| 339 std::string GetDefaultHistogramName(const std::string& name) const; | |
| 340 // Returns the current experiment. | |
| 341 uint8 GetCurrentExperimentId() const; | |
| 342 // Returns the current origin. | |
| 343 Origin GetCurrentOrigin() const; | |
| 344 // Returns whether or not there is currently an origin/experiment wash. | |
| 345 bool IsOriginExperimentWash() const; | |
| 346 | |
| 347 // The configuration. | 330 // The configuration. |
| 348 Config config_; | 331 Config config_; |
| 349 | 332 |
| 350 // Specifies whether prerendering is currently enabled for this | 333 // Specifies whether prerendering is currently enabled for this |
| 351 // manager. The value can change dynamically during the lifetime | 334 // manager. The value can change dynamically during the lifetime |
| 352 // of the PrerenderManager. | 335 // of the PrerenderManager. |
| 353 bool enabled_; | 336 bool enabled_; |
| 354 | 337 |
| 355 // The profile that owns this PrerenderManager. | 338 // The profile that owns this PrerenderManager. |
| 356 Profile* profile_; | 339 Profile* profile_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 376 | 359 |
| 377 // Map of child/route id pairs to pending prerender data. | 360 // Map of child/route id pairs to pending prerender data. |
| 378 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > | 361 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > |
| 379 PendingPrerenderList; | 362 PendingPrerenderList; |
| 380 PendingPrerenderList pending_prerender_list_; | 363 PendingPrerenderList pending_prerender_list_; |
| 381 | 364 |
| 382 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; | 365 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; |
| 383 | 366 |
| 384 static PrerenderManagerMode mode_; | 367 static PrerenderManagerMode mode_; |
| 385 | 368 |
| 386 // An integer indicating a Prerendering Experiment being currently conducted. | |
| 387 // (The last experiment ID seen). | |
| 388 uint8 last_experiment_id_; | |
| 389 | |
| 390 // Origin of the last prerender seen. | |
| 391 Origin last_origin_; | |
| 392 | |
| 393 // A boolean indicating that we have recently encountered a combination of | |
| 394 // different experiments and origins, making an attribution of PPLT's to | |
| 395 // experiments / origins impossible. | |
| 396 bool origin_experiment_wash_; | |
| 397 | |
| 398 // The time when we last saw a prerender request coming from a renderer. | |
| 399 // This is used to record perceived PLT's for a certain amount of time | |
| 400 // from the point that we last saw a <link rel=prerender> tag. | |
| 401 base::TimeTicks last_prerender_seen_time_; | |
| 402 | |
| 403 // A count of how many prerenders we do per session. Initialized to 0 then | 369 // A count of how many prerenders we do per session. Initialized to 0 then |
| 404 // incremented and emitted to a histogram on each successful prerender. | 370 // incremented and emitted to a histogram on each successful prerender. |
| 405 static int prerenders_per_session_count_; | 371 static int prerenders_per_session_count_; |
| 406 | 372 |
| 407 // RepeatingTimer to perform periodic cleanups of pending prerendered | 373 // RepeatingTimer to perform periodic cleanups of pending prerendered |
| 408 // pages. | 374 // pages. |
| 409 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 375 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
| 410 | 376 |
| 411 // Track time of last prerender to limit prerender spam. | 377 // Track time of last prerender to limit prerender spam. |
| 412 base::TimeTicks last_prerender_start_time_; | 378 base::TimeTicks last_prerender_start_time_; |
| 413 | 379 |
| 414 std::list<TabContentsWrapper*> old_tab_contents_list_; | 380 std::list<TabContentsWrapper*> old_tab_contents_list_; |
| 415 | 381 |
| 416 // Cancels pending tasks on deletion. | 382 // Cancels pending tasks on deletion. |
| 417 ScopedRunnableMethodFactory<PrerenderManager> runnable_method_factory_; | 383 ScopedRunnableMethodFactory<PrerenderManager> runnable_method_factory_; |
| 418 | 384 |
| 419 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; | 385 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; |
| 420 | 386 |
| 421 scoped_ptr<PrerenderHistory> prerender_history_; | 387 scoped_ptr<PrerenderHistory> prerender_history_; |
| 422 | 388 |
| 423 std::list<const PrerenderCondition*> prerender_conditions_; | 389 std::list<const PrerenderCondition*> prerender_conditions_; |
| 424 | 390 |
| 391 scoped_ptr<PrerenderHistograms> histograms_; |
| 392 |
| 425 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 393 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 426 }; | 394 }; |
| 427 | 395 |
| 428 } // namespace prerender | 396 } // namespace prerender |
| 429 | 397 |
| 430 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 398 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |