| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 namespace prerender { | 59 namespace prerender { |
| 60 | 60 |
| 61 namespace test_utils { | 61 namespace test_utils { |
| 62 class PrerenderInProcessBrowserTest; | 62 class PrerenderInProcessBrowserTest; |
| 63 } | 63 } |
| 64 | 64 |
| 65 class PrerenderHandle; | 65 class PrerenderHandle; |
| 66 class PrerenderHistory; | 66 class PrerenderHistory; |
| 67 | 67 |
| 68 // Observer interface for PrerenderManager events. |
| 69 class PrerenderManagerObserver { |
| 70 public: |
| 71 virtual ~PrerenderManagerObserver(); |
| 72 |
| 73 // Called from the UI thread. |
| 74 virtual void OnFirstContentfulPaint() = 0; |
| 75 }; |
| 76 |
| 68 // PrerenderManager is responsible for initiating and keeping prerendered | 77 // PrerenderManager is responsible for initiating and keeping prerendered |
| 69 // views of web pages. All methods must be called on the UI thread unless | 78 // views of web pages. All methods must be called on the UI thread unless |
| 70 // indicated otherwise. | 79 // indicated otherwise. |
| 71 class PrerenderManager : public content::NotificationObserver, | 80 class PrerenderManager : public content::NotificationObserver, |
| 72 public content::RenderProcessHostObserver, | 81 public content::RenderProcessHostObserver, |
| 73 public KeyedService, | 82 public KeyedService, |
| 74 public MediaCaptureDevicesDispatcher::Observer { | 83 public MediaCaptureDevicesDispatcher::Observer { |
| 75 public: | 84 public: |
| 76 enum PrerenderManagerMode { | 85 enum PrerenderManagerMode { |
| 77 PRERENDER_MODE_DISABLED, | 86 PRERENDER_MODE_DISABLED, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 bool is_main_resource, | 208 bool is_main_resource, |
| 200 bool is_redirect, | 209 bool is_redirect, |
| 201 bool is_no_store); | 210 bool is_no_store); |
| 202 | 211 |
| 203 // Called when a NoStatePrefetch resource has been loaded. This is called only | 212 // Called when a NoStatePrefetch resource has been loaded. This is called only |
| 204 // once per resource, when all redirects have been resolved. | 213 // once per resource, when all redirects have been resolved. |
| 205 void RecordPrefetchRedirectCount(Origin origin, | 214 void RecordPrefetchRedirectCount(Origin origin, |
| 206 bool is_main_resource, | 215 bool is_main_resource, |
| 207 int redirect_count); | 216 int redirect_count); |
| 208 | 217 |
| 209 // Records the time to first contentful paint. | 218 // Called when a NoStatePrefetch first contentful paint has fired. |
| 210 // Must not be called for prefetch loads (which are never rendered anyway). | 219 void RecordPrefetchFirstContentfulPaint(Origin origin, |
| 211 // |is_no_store| must be true if the main resource has a "no-store" cache | 220 bool is_no_store, |
| 212 // control HTTP header. | 221 bool was_hidden, |
| 213 void RecordFirstContentfulPaint(const GURL& url, | 222 base::TimeDelta time, |
| 214 bool is_no_store, | 223 base::TimeDelta prefetch_age); |
| 215 base::TimeDelta time); | 224 |
| 225 // Records the time to first contentful paint for loads that previously had a |
| 226 // no state prefetch load. Must not be called for prefetch loads themselves |
| 227 // (which are never rendered anyway). |is_no_store| must be true if the main |
| 228 // resource has a "no-store" cache control HTTP header. |
| 229 void RecordNoStateFirstContentfulPaint(const GURL& url, |
| 230 bool is_no_store, |
| 231 bool was_hidden, |
| 232 base::TimeDelta time); |
| 233 |
| 234 // Records the perceived first contentful paint time for a prerendered page, |
| 235 // analogous to |RecordPerceivedPageLoadTime|. The FCP ticks is in absolute |
| 236 // time; this has the disadvantage that the histogram will mix browser and |
| 237 // renderer ticks, but there seems to be no way around that. |
| 238 void RecordPrerenderFirstContentfulPaint(const GURL& url, |
| 239 content::WebContents* web_contents, |
| 240 bool is_no_store, |
| 241 bool was_hidden, |
| 242 base::TimeTicks ticks); |
| 216 | 243 |
| 217 static PrerenderManagerMode GetMode(); | 244 static PrerenderManagerMode GetMode(); |
| 218 static void SetMode(PrerenderManagerMode mode); | 245 static void SetMode(PrerenderManagerMode mode); |
| 219 static bool IsPrerenderingPossible(); | 246 static bool IsPrerenderingPossible(); |
| 220 static bool IsNoStatePrefetch(Origin origin); | 247 static bool IsNoStatePrefetch(Origin origin); |
| 221 static bool IsSimpleLoadExperiment(Origin origin); | 248 static bool IsSimpleLoadExperiment(Origin origin); |
| 222 | 249 |
| 223 // Query the list of current prerender pages to see if the given web contents | 250 // Query the list of current prerender pages to see if the given web contents |
| 224 // is prerendering a page. The optional parameter |origin| is an output | 251 // is prerendering a page. The optional parameter |origin| is an output |
| 225 // parameter which, if a prerender is found, is set to the Origin of the | 252 // parameter which, if a prerender is found, is set to the Origin of the |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 Profile* profile() const { return profile_; } | 334 Profile* profile() const { return profile_; } |
| 308 | 335 |
| 309 // Return current time and ticks with ability to mock the clock out for | 336 // Return current time and ticks with ability to mock the clock out for |
| 310 // testing. | 337 // testing. |
| 311 base::Time GetCurrentTime() const; | 338 base::Time GetCurrentTime() const; |
| 312 base::TimeTicks GetCurrentTimeTicks() const; | 339 base::TimeTicks GetCurrentTimeTicks() const; |
| 313 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock); | 340 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock); |
| 314 void SetTickClockForTesting( | 341 void SetTickClockForTesting( |
| 315 std::unique_ptr<base::SimpleTestTickClock> tick_clock); | 342 std::unique_ptr<base::SimpleTestTickClock> tick_clock); |
| 316 | 343 |
| 344 void DisablePageLoadMetricsObserverForTesting() { |
| 345 page_load_metric_observer_disabled_ = true; |
| 346 } |
| 347 |
| 348 bool PageLoadMetricsObserverDisabledForTesting() const { |
| 349 return page_load_metric_observer_disabled_; |
| 350 } |
| 351 |
| 352 void AddObserver(std::unique_ptr<PrerenderManagerObserver> observer); |
| 353 |
| 317 // Notification that a prerender has completed and its bytes should be | 354 // Notification that a prerender has completed and its bytes should be |
| 318 // recorded. | 355 // recorded. |
| 319 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); | 356 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); |
| 320 | 357 |
| 321 // Add to the running tally of bytes transferred over the network for this | 358 // Add to the running tally of bytes transferred over the network for this |
| 322 // profile if prerendering is currently enabled. | 359 // profile if prerendering is currently enabled. |
| 323 void AddProfileNetworkBytesIfEnabled(int64_t bytes); | 360 void AddProfileNetworkBytesIfEnabled(int64_t bytes); |
| 324 | 361 |
| 325 // Registers a new ProcessHost performing a prerender. Called by | 362 // Registers a new ProcessHost performing a prerender. Called by |
| 326 // PrerenderContents. | 363 // PrerenderContents. |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 PrerenderDataVector::iterator FindIteratorForPrerenderContents( | 532 PrerenderDataVector::iterator FindIteratorForPrerenderContents( |
| 496 PrerenderContents* prerender_contents); | 533 PrerenderContents* prerender_contents); |
| 497 | 534 |
| 498 bool DoesRateLimitAllowPrerender(Origin origin) const; | 535 bool DoesRateLimitAllowPrerender(Origin origin) const; |
| 499 | 536 |
| 500 // Deletes old WebContents that have been replaced by prerendered ones. This | 537 // Deletes old WebContents that have been replaced by prerendered ones. This |
| 501 // is needed because they're replaced in a callback from the old WebContents, | 538 // is needed because they're replaced in a callback from the old WebContents, |
| 502 // so cannot immediately be deleted. | 539 // so cannot immediately be deleted. |
| 503 void DeleteOldWebContents(); | 540 void DeleteOldWebContents(); |
| 504 | 541 |
| 542 // Get information associated with a possible prefetch of |url|. |
| 543 void GetPrefetchInformation(const GURL& url, |
| 544 base::TimeDelta* prefetch_age, |
| 545 Origin* origin); |
| 546 |
| 505 // Cleans up old NavigationRecord's. | 547 // Cleans up old NavigationRecord's. |
| 506 void CleanUpOldNavigations(std::vector<NavigationRecord>* navigations, | 548 void CleanUpOldNavigations(std::vector<NavigationRecord>* navigations, |
| 507 base::TimeDelta max_age); | 549 base::TimeDelta max_age); |
| 508 | 550 |
| 509 // Arrange for the given WebContents to be deleted asap. Delete |deleter| as | 551 // Arrange for the given WebContents to be deleted asap. Delete |deleter| as |
| 510 // well. | 552 // well. |
| 511 void ScheduleDeleteOldWebContents(std::unique_ptr<content::WebContents> tab, | 553 void ScheduleDeleteOldWebContents(std::unique_ptr<content::WebContents> tab, |
| 512 OnCloseWebContentsDeleter* deleter); | 554 OnCloseWebContentsDeleter* deleter); |
| 513 | 555 |
| 514 // Adds to the history list. | 556 // Adds to the history list. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 // The value of profile_network_bytes_ that was last recorded. | 632 // The value of profile_network_bytes_ that was last recorded. |
| 591 int64_t last_recorded_profile_network_bytes_; | 633 int64_t last_recorded_profile_network_bytes_; |
| 592 | 634 |
| 593 // Set of process hosts being prerendered. | 635 // Set of process hosts being prerendered. |
| 594 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; | 636 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; |
| 595 PrerenderProcessSet prerender_process_hosts_; | 637 PrerenderProcessSet prerender_process_hosts_; |
| 596 | 638 |
| 597 std::unique_ptr<base::Clock> clock_; | 639 std::unique_ptr<base::Clock> clock_; |
| 598 std::unique_ptr<base::TickClock> tick_clock_; | 640 std::unique_ptr<base::TickClock> tick_clock_; |
| 599 | 641 |
| 642 bool page_load_metric_observer_disabled_; |
| 643 |
| 644 std::vector<std::unique_ptr<PrerenderManagerObserver>> observers_; |
| 645 |
| 600 base::WeakPtrFactory<PrerenderManager> weak_factory_; | 646 base::WeakPtrFactory<PrerenderManager> weak_factory_; |
| 601 | 647 |
| 602 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); | 648 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); |
| 603 }; | 649 }; |
| 604 | 650 |
| 605 } // namespace prerender | 651 } // namespace prerender |
| 606 | 652 |
| 607 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ | 653 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ |
| OLD | NEW |