| 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 <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/task.h" | 17 #include "base/task.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "base/time.h" | 19 #include "base/time.h" |
| 20 #include "base/timer.h" | 20 #include "base/timer.h" |
| 21 #include "chrome/browser/prerender/prerender_config.h" | 21 #include "chrome/browser/prerender/prerender_config.h" |
| 22 #include "chrome/browser/prerender/prerender_contents.h" | 22 #include "chrome/browser/prerender/prerender_contents.h" |
| 23 #include "chrome/browser/prerender/prerender_final_status.h" |
| 23 #include "chrome/browser/prerender/prerender_origin.h" | 24 #include "chrome/browser/prerender/prerender_origin.h" |
| 24 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 25 | 26 |
| 26 class Profile; | 27 class Profile; |
| 27 class TabContents; | 28 class TabContents; |
| 28 | 29 |
| 29 #if defined(COMPILER_GCC) | 30 #if defined(COMPILER_GCC) |
| 30 | 31 |
| 31 namespace __gnu_cxx { | 32 namespace __gnu_cxx { |
| 32 template <> | 33 template <> |
| 33 struct hash<TabContents*> { | 34 struct hash<TabContents*> { |
| 34 std::size_t operator()(TabContents* value) const { | 35 std::size_t operator()(TabContents* value) const { |
| 35 return reinterpret_cast<std::size_t>(value); | 36 return reinterpret_cast<std::size_t>(value); |
| 36 } | 37 } |
| 37 }; | 38 }; |
| 38 } | 39 } |
| 39 | 40 |
| 40 #endif | 41 #endif |
| 41 | 42 |
| 42 namespace prerender { | 43 namespace prerender { |
| 43 | 44 |
| 44 class PrerenderCondition; | 45 class PrerenderCondition; |
| 46 class PrerenderHistograms; |
| 45 class PrerenderHistory; | 47 class PrerenderHistory; |
| 46 class PrerenderTracker; | 48 class PrerenderTracker; |
| 47 | 49 |
| 48 // PrerenderManager is responsible for initiating and keeping prerendered | 50 // PrerenderManager is responsible for initiating and keeping prerendered |
| 49 // views of webpages. All methods must be called on the UI thread unless | 51 // views of webpages. All methods must be called on the UI thread unless |
| 50 // indicated otherwise. | 52 // indicated otherwise. |
| 51 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, | 53 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
| 52 public base::NonThreadSafe { | 54 public base::NonThreadSafe { |
| 53 public: | 55 public: |
| 54 // PrerenderManagerMode is used in a UMA_HISTOGRAM, so please do not | 56 // 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 | 319 |
| 318 // Returns a new Value representing the pages currently being prerendered. The | 320 // Returns a new Value representing the pages currently being prerendered. The |
| 319 // caller is responsible for delete'ing the return value. | 321 // caller is responsible for delete'ing the return value. |
| 320 base::Value* GetActivePrerendersAsValue() const; | 322 base::Value* GetActivePrerendersAsValue() const; |
| 321 | 323 |
| 322 // Destroys all pending prerenders using FinalStatus. Also deletes them as | 324 // Destroys all pending prerenders using FinalStatus. Also deletes them as |
| 323 // well as any swapped out TabContents queued for destruction. | 325 // well as any swapped out TabContents queued for destruction. |
| 324 // Used both on destruction, and when clearing the browing history. | 326 // Used both on destruction, and when clearing the browing history. |
| 325 void DestroyAllContents(FinalStatus final_status); | 327 void DestroyAllContents(FinalStatus final_status); |
| 326 | 328 |
| 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. | 329 // The configuration. |
| 348 Config config_; | 330 Config config_; |
| 349 | 331 |
| 350 // Specifies whether prerendering is currently enabled for this | 332 // Specifies whether prerendering is currently enabled for this |
| 351 // manager. The value can change dynamically during the lifetime | 333 // manager. The value can change dynamically during the lifetime |
| 352 // of the PrerenderManager. | 334 // of the PrerenderManager. |
| 353 bool enabled_; | 335 bool enabled_; |
| 354 | 336 |
| 355 // The profile that owns this PrerenderManager. | 337 // The profile that owns this PrerenderManager. |
| 356 Profile* profile_; | 338 Profile* profile_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 376 | 358 |
| 377 // Map of child/route id pairs to pending prerender data. | 359 // Map of child/route id pairs to pending prerender data. |
| 378 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > | 360 typedef std::map<std::pair<int, int>, std::vector<PendingContentsData> > |
| 379 PendingPrerenderList; | 361 PendingPrerenderList; |
| 380 PendingPrerenderList pending_prerender_list_; | 362 PendingPrerenderList pending_prerender_list_; |
| 381 | 363 |
| 382 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; | 364 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; |
| 383 | 365 |
| 384 static PrerenderManagerMode mode_; | 366 static PrerenderManagerMode mode_; |
| 385 | 367 |
| 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 | 368 // 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. | 369 // incremented and emitted to a histogram on each successful prerender. |
| 405 static int prerenders_per_session_count_; | 370 static int prerenders_per_session_count_; |
| 406 | 371 |
| 407 // RepeatingTimer to perform periodic cleanups of pending prerendered | 372 // RepeatingTimer to perform periodic cleanups of pending prerendered |
| 408 // pages. | 373 // pages. |
| 409 base::RepeatingTimer<PrerenderManager> repeating_timer_; | 374 base::RepeatingTimer<PrerenderManager> repeating_timer_; |
| 410 | 375 |
| 411 // Track time of last prerender to limit prerender spam. | 376 // Track time of last prerender to limit prerender spam. |
| 412 base::TimeTicks last_prerender_start_time_; | 377 base::TimeTicks last_prerender_start_time_; |
| 413 | 378 |
| 414 std::list<TabContentsWrapper*> old_tab_contents_list_; | 379 std::list<TabContentsWrapper*> old_tab_contents_list_; |
| 415 | 380 |
| 416 // Cancels pending tasks on deletion. | 381 // Cancels pending tasks on deletion. |
| 417 ScopedRunnableMethodFactory<PrerenderManager> runnable_method_factory_; | 382 ScopedRunnableMethodFactory<PrerenderManager> runnable_method_factory_; |
| 418 | 383 |
| 419 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; | 384 ScopedVector<OnCloseTabContentsDeleter> on_close_tab_contents_deleters_; |
| 420 | 385 |
| 421 scoped_ptr<PrerenderHistory> prerender_history_; | 386 scoped_ptr<PrerenderHistory> prerender_history_; |
| 422 | 387 |
| 423 std::list<const PrerenderCondition*> prerender_conditions_; | 388 std::list<const PrerenderCondition*> prerender_conditions_; |
| 424 | 389 |
| 390 scoped_ptr<PrerenderHistograms> histograms_; |
| 391 |
| 425 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 392 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 426 }; | 393 }; |
| 427 | 394 |
| 428 } // namespace prerender | 395 } // namespace prerender |
| 429 | 396 |
| 430 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 397 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |