OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/prerender/prerender_config.h" | 24 #include "chrome/browser/prerender/prerender_config.h" |
25 #include "chrome/browser/prerender/prerender_contents.h" | 25 #include "chrome/browser/prerender/prerender_contents.h" |
26 #include "chrome/browser/prerender/prerender_events.h" | 26 #include "chrome/browser/prerender/prerender_events.h" |
27 #include "chrome/browser/prerender/prerender_final_status.h" | 27 #include "chrome/browser/prerender/prerender_final_status.h" |
28 #include "chrome/browser/prerender/prerender_histograms.h" | 28 #include "chrome/browser/prerender/prerender_histograms.h" |
29 #include "chrome/browser/prerender/prerender_origin.h" | 29 #include "chrome/browser/prerender/prerender_origin.h" |
30 #include "chrome/browser/prerender/prerender_tracker.h" | 30 #include "chrome/browser/prerender/prerender_tracker.h" |
31 #include "components/keyed_service/core/keyed_service.h" | 31 #include "components/keyed_service/core/keyed_service.h" |
32 #include "content/public/browser/notification_observer.h" | 32 #include "content/public/browser/notification_observer.h" |
33 #include "content/public/browser/notification_registrar.h" | 33 #include "content/public/browser/notification_registrar.h" |
| 34 #include "content/public/browser/render_process_host_observer.h" |
34 #include "content/public/browser/session_storage_namespace.h" | 35 #include "content/public/browser/session_storage_namespace.h" |
35 #include "content/public/browser/web_contents_observer.h" | 36 #include "content/public/browser/web_contents_observer.h" |
36 #include "net/cookies/canonical_cookie.h" | 37 #include "net/cookies/canonical_cookie.h" |
37 #include "net/cookies/cookie_monster.h" | 38 #include "net/cookies/cookie_monster.h" |
38 #include "url/gurl.h" | 39 #include "url/gurl.h" |
39 | 40 |
40 class Profile; | 41 class Profile; |
41 class InstantSearchPrerendererTest; | 42 class InstantSearchPrerendererTest; |
42 struct ChromeCookieDetails; | 43 struct ChromeCookieDetails; |
43 | 44 |
(...skipping 23 matching lines...) Expand all Loading... |
67 class PrerenderHandle; | 68 class PrerenderHandle; |
68 class PrerenderHistory; | 69 class PrerenderHistory; |
69 class PrerenderLocalPredictor; | 70 class PrerenderLocalPredictor; |
70 | 71 |
71 // PrerenderManager is responsible for initiating and keeping prerendered | 72 // PrerenderManager is responsible for initiating and keeping prerendered |
72 // views of web pages. All methods must be called on the UI thread unless | 73 // views of web pages. All methods must be called on the UI thread unless |
73 // indicated otherwise. | 74 // indicated otherwise. |
74 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, | 75 class PrerenderManager : public base::SupportsWeakPtr<PrerenderManager>, |
75 public base::NonThreadSafe, | 76 public base::NonThreadSafe, |
76 public content::NotificationObserver, | 77 public content::NotificationObserver, |
| 78 public content::RenderProcessHostObserver, |
77 public KeyedService, | 79 public KeyedService, |
78 public MediaCaptureDevicesDispatcher::Observer { | 80 public MediaCaptureDevicesDispatcher::Observer { |
79 public: | 81 public: |
80 // NOTE: New values need to be appended, since they are used in histograms. | 82 // NOTE: New values need to be appended, since they are used in histograms. |
81 enum PrerenderManagerMode { | 83 enum PrerenderManagerMode { |
82 PRERENDER_MODE_DISABLED = 0, | 84 PRERENDER_MODE_DISABLED = 0, |
83 PRERENDER_MODE_ENABLED = 1, | 85 PRERENDER_MODE_ENABLED = 1, |
84 PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP = 2, | 86 PRERENDER_MODE_EXPERIMENT_CONTROL_GROUP = 2, |
85 PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP = 3, | 87 PRERENDER_MODE_EXPERIMENT_PRERENDER_GROUP = 3, |
86 // Obsolete: PRERENDER_MODE_EXPERIMENT_5MIN_TTL_GROUP = 4, | 88 // Obsolete: PRERENDER_MODE_EXPERIMENT_5MIN_TTL_GROUP = 4, |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 290 |
289 // MediaCaptureDevicesDispatcher::Observer | 291 // MediaCaptureDevicesDispatcher::Observer |
290 virtual void OnCreatingAudioStream(int render_process_id, | 292 virtual void OnCreatingAudioStream(int render_process_id, |
291 int render_frame_id) OVERRIDE; | 293 int render_frame_id) OVERRIDE; |
292 | 294 |
293 const Config& config() const { return config_; } | 295 const Config& config() const { return config_; } |
294 Config& mutable_config() { return config_; } | 296 Config& mutable_config() { return config_; } |
295 | 297 |
296 PrerenderTracker* prerender_tracker() { return prerender_tracker_; } | 298 PrerenderTracker* prerender_tracker() { return prerender_tracker_; } |
297 | 299 |
| 300 bool cookie_store_loaded() { return cookie_store_loaded_; } |
| 301 |
298 // Adds a condition. This is owned by the PrerenderManager. | 302 // Adds a condition. This is owned by the PrerenderManager. |
299 void AddCondition(const PrerenderCondition* condition); | 303 void AddCondition(const PrerenderCondition* condition); |
300 | 304 |
301 // Records that some visible tab navigated (or was redirected) to the | 305 // Records that some visible tab navigated (or was redirected) to the |
302 // provided URL. | 306 // provided URL. |
303 void RecordNavigation(const GURL& url); | 307 void RecordNavigation(const GURL& url); |
304 | 308 |
305 // Updates the LoggedInPredictor state to reflect that a login has likely | 309 // Updates the LoggedInPredictor state to reflect that a login has likely |
306 // on the URL provided. | 310 // on the URL provided. |
307 void RecordLikelyLoginOnURL(const GURL& url); | 311 void RecordLikelyLoginOnURL(const GURL& url); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 static void HangSessionStorageMergesForTesting(); | 357 static void HangSessionStorageMergesForTesting(); |
354 | 358 |
355 // Notification that a prerender has completed and its bytes should be | 359 // Notification that a prerender has completed and its bytes should be |
356 // recorded. | 360 // recorded. |
357 void RecordNetworkBytes(bool used, int64 prerender_bytes); | 361 void RecordNetworkBytes(bool used, int64 prerender_bytes); |
358 | 362 |
359 // Add to the running tally of bytes transferred over the network for this | 363 // Add to the running tally of bytes transferred over the network for this |
360 // profile if prerendering is currently enabled. | 364 // profile if prerendering is currently enabled. |
361 void AddProfileNetworkBytesIfEnabled(int64 bytes); | 365 void AddProfileNetworkBytesIfEnabled(int64 bytes); |
362 | 366 |
| 367 // Registers a new ProcessHost performing a prerender. Called by |
| 368 // PrerenderContents. |
| 369 void AddPrerenderProcessHost(content::RenderProcessHost* process_host); |
| 370 |
| 371 bool IsProcessPrerendering(content::RenderProcessHost* process_host); |
| 372 |
| 373 // content::RenderProcessHostObserver implementation. |
| 374 virtual void RenderProcessHostDestroyed( |
| 375 content::RenderProcessHost* host) OVERRIDE; |
| 376 |
| 377 // To be called once the cookie store for this profile has been loaded. |
| 378 void OnCookieStoreLoaded(); |
| 379 |
| 380 // For testing purposes. Issues a callback once the cookie store has been |
| 381 // loaded. |
| 382 void set_on_cookie_store_loaded_cb_for_testing(base::Closure cb) { |
| 383 on_cookie_store_loaded_cb_for_testing_ = cb; |
| 384 } |
| 385 |
363 protected: | 386 protected: |
364 class PendingSwap; | 387 class PendingSwap; |
365 class PrerenderData : public base::SupportsWeakPtr<PrerenderData> { | 388 class PrerenderData : public base::SupportsWeakPtr<PrerenderData> { |
366 public: | 389 public: |
367 struct OrderByExpiryTime; | 390 struct OrderByExpiryTime; |
368 | 391 |
369 PrerenderData(PrerenderManager* manager, | 392 PrerenderData(PrerenderManager* manager, |
370 PrerenderContents* contents, | 393 PrerenderContents* contents, |
371 base::TimeTicks expiry_time); | 394 base::TimeTicks expiry_time); |
372 | 395 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 void SetPrerenderContentsFactory( | 526 void SetPrerenderContentsFactory( |
504 PrerenderContents::Factory* prerender_contents_factory); | 527 PrerenderContents::Factory* prerender_contents_factory); |
505 | 528 |
506 // Called by a PrerenderData to signal that the launcher has navigated away | 529 // Called by a PrerenderData to signal that the launcher has navigated away |
507 // from the context that launched the prerender. A user may have clicked | 530 // from the context that launched the prerender. A user may have clicked |
508 // a link in a page containing a <link rel=prerender> element, or the user | 531 // a link in a page containing a <link rel=prerender> element, or the user |
509 // might have committed an omnibox navigation. This is used to possibly | 532 // might have committed an omnibox navigation. This is used to possibly |
510 // shorten the TTL of the prerendered page. | 533 // shorten the TTL of the prerendered page. |
511 void SourceNavigatedAway(PrerenderData* prerender_data); | 534 void SourceNavigatedAway(PrerenderData* prerender_data); |
512 | 535 |
| 536 // Gets the request context for the profile. |
| 537 // For unit tests, this will be overriden to return NULL, since it is not |
| 538 // needed. |
| 539 virtual net::URLRequestContextGetter* GetURLRequestContext(); |
| 540 |
513 private: | 541 private: |
514 friend class ::InstantSearchPrerendererTest; | 542 friend class ::InstantSearchPrerendererTest; |
515 friend class PrerenderBrowserTest; | 543 friend class PrerenderBrowserTest; |
516 friend class PrerenderContents; | 544 friend class PrerenderContents; |
517 friend class PrerenderHandle; | 545 friend class PrerenderHandle; |
518 friend class UnitTestPrerenderManager; | 546 friend class UnitTestPrerenderManager; |
519 | 547 |
520 class OnCloseWebContentsDeleter; | 548 class OnCloseWebContentsDeleter; |
521 struct NavigationRecord; | 549 struct NavigationRecord; |
522 | 550 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 | 741 |
714 CancelableRequestConsumer query_url_consumer_; | 742 CancelableRequestConsumer query_url_consumer_; |
715 | 743 |
716 // The number of bytes transferred over the network for the profile this | 744 // The number of bytes transferred over the network for the profile this |
717 // PrerenderManager is attached to. | 745 // PrerenderManager is attached to. |
718 int64 profile_network_bytes_; | 746 int64 profile_network_bytes_; |
719 | 747 |
720 // The value of profile_network_bytes_ that was last recorded. | 748 // The value of profile_network_bytes_ that was last recorded. |
721 int64 last_recorded_profile_network_bytes_; | 749 int64 last_recorded_profile_network_bytes_; |
722 | 750 |
| 751 // Set of process hosts being prerendered. |
| 752 typedef std::set<content::RenderProcessHost*> PrerenderProcessSet; |
| 753 PrerenderProcessSet prerender_process_hosts_; |
| 754 |
| 755 // Indicates whether the cookie store for this profile has fully loaded yet. |
| 756 bool cookie_store_loaded_; |
| 757 |
| 758 base::Closure on_cookie_store_loaded_cb_for_testing_; |
| 759 |
723 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 760 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
724 }; | 761 }; |
725 | 762 |
726 } // namespace prerender | 763 } // namespace prerender |
727 | 764 |
728 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 765 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
OLD | NEW |