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