Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2225)

Side by Side Diff: chrome/browser/prerender/prerender_manager.h

Issue 2423383002: [Prerender] first contentful paint histograms. (Closed)
Patch Set: Unify with nostate histograms Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Called from the UI thread.
72 virtual void OnFirstContentfulPaint() = 0;
droger 2016/11/29 15:54:39 Leak: Add a empty virtual destructor (or pure).
mattcary 2016/11/29 16:39:45 Done.
73 };
74
68 // PrerenderManager is responsible for initiating and keeping prerendered 75 // PrerenderManager is responsible for initiating and keeping prerendered
69 // views of web pages. All methods must be called on the UI thread unless 76 // views of web pages. All methods must be called on the UI thread unless
70 // indicated otherwise. 77 // indicated otherwise.
71 class PrerenderManager : public content::NotificationObserver, 78 class PrerenderManager : public content::NotificationObserver,
72 public content::RenderProcessHostObserver, 79 public content::RenderProcessHostObserver,
73 public KeyedService, 80 public KeyedService,
74 public MediaCaptureDevicesDispatcher::Observer { 81 public MediaCaptureDevicesDispatcher::Observer {
75 public: 82 public:
76 enum PrerenderManagerMode { 83 enum PrerenderManagerMode {
77 PRERENDER_MODE_DISABLED, 84 PRERENDER_MODE_DISABLED,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 bool is_main_resource, 206 bool is_main_resource,
200 bool is_redirect, 207 bool is_redirect,
201 bool is_no_store); 208 bool is_no_store);
202 209
203 // Called when a NoStatePrefetch resource has been loaded. This is called only 210 // Called when a NoStatePrefetch resource has been loaded. This is called only
204 // once per resource, when all redirects have been resolved. 211 // once per resource, when all redirects have been resolved.
205 void RecordPrefetchRedirectCount(Origin origin, 212 void RecordPrefetchRedirectCount(Origin origin,
206 bool is_main_resource, 213 bool is_main_resource,
207 int redirect_count); 214 int redirect_count);
208 215
209 // Records the time to first contentful paint. 216 // Called when a NoStatePrefetch first contentful paint has fired.
210 // Must not be called for prefetch loads (which are never rendered anyway). 217 void RecordPrefetchFirstContentfulPaint(Origin origin,
211 // |is_no_store| must be true if the main resource has a "no-store" cache 218 bool is_no_store,
212 // control HTTP header. 219 bool was_hidden,
213 void RecordFirstContentfulPaint(const GURL& url, 220 base::TimeDelta time,
214 bool is_no_store, 221 base::TimeDelta prefetch_age);
215 base::TimeDelta time); 222
223 // Records the time to first contentful paint for loads that previously had a
224 // no state prefetch load. Must not be called for prefetch loads themselves
225 // (which are never rendered anyway). |is_no_store| must be true if the main
226 // resource has a "no-store" cache control HTTP header.
227 void RecordNoStateFirstContentfulPaint(const GURL& url,
228 bool is_no_store,
229 bool was_hidden,
230 base::TimeDelta time);
231
232 // Records the perceived first contentful paint time for a prerendered page,
233 // analogous to |RecordPerceivedPageLoadTime|. The FCP ticks is in absolute
234 // time; this has the disadvantage that the histogram will mix browser and
235 // renderer ticks, but there seems to be no way around that.
236 void RecordPrerenderFirstContentfulPaint(const GURL& url,
237 content::WebContents* web_contents,
238 bool is_no_store,
239 bool was_hidden,
240 base::TimeTicks ticks);
216 241
217 static PrerenderManagerMode GetMode(); 242 static PrerenderManagerMode GetMode();
218 static void SetMode(PrerenderManagerMode mode); 243 static void SetMode(PrerenderManagerMode mode);
219 static bool IsPrerenderingPossible(); 244 static bool IsPrerenderingPossible();
220 static bool IsNoStatePrefetch(); 245 static bool IsNoStatePrefetch();
221 static bool IsSimpleLoadExperiment(); 246 static bool IsSimpleLoadExperiment();
222 247
223 // Query the list of current prerender pages to see if the given web contents 248 // 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 249 // 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 250 // 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
307 Profile* profile() const { return profile_; } 332 Profile* profile() const { return profile_; }
308 333
309 // Return current time and ticks with ability to mock the clock out for 334 // Return current time and ticks with ability to mock the clock out for
310 // testing. 335 // testing.
311 base::Time GetCurrentTime() const; 336 base::Time GetCurrentTime() const;
312 base::TimeTicks GetCurrentTimeTicks() const; 337 base::TimeTicks GetCurrentTimeTicks() const;
313 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock); 338 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock);
314 void SetTickClockForTesting( 339 void SetTickClockForTesting(
315 std::unique_ptr<base::SimpleTestTickClock> tick_clock); 340 std::unique_ptr<base::SimpleTestTickClock> tick_clock);
316 341
342 void DisablePageLoadMetricsObserverForTesting() {
343 page_load_metric_observer_disabled_ = true;
344 }
345
346 bool PageLoadMetricsObserverDisabledForTesting() const {
347 return page_load_metric_observer_disabled_;
348 }
349
350 void AddObserver(std::unique_ptr<PrerenderManagerObserver> observer);
351
317 // Notification that a prerender has completed and its bytes should be 352 // Notification that a prerender has completed and its bytes should be
318 // recorded. 353 // recorded.
319 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); 354 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes);
320 355
321 // Add to the running tally of bytes transferred over the network for this 356 // Add to the running tally of bytes transferred over the network for this
322 // profile if prerendering is currently enabled. 357 // profile if prerendering is currently enabled.
323 void AddProfileNetworkBytesIfEnabled(int64_t bytes); 358 void AddProfileNetworkBytesIfEnabled(int64_t bytes);
324 359
325 // Registers a new ProcessHost performing a prerender. Called by 360 // Registers a new ProcessHost performing a prerender. Called by
326 // PrerenderContents. 361 // PrerenderContents.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 PrerenderDataVector::iterator FindIteratorForPrerenderContents( 530 PrerenderDataVector::iterator FindIteratorForPrerenderContents(
496 PrerenderContents* prerender_contents); 531 PrerenderContents* prerender_contents);
497 532
498 bool DoesRateLimitAllowPrerender(Origin origin) const; 533 bool DoesRateLimitAllowPrerender(Origin origin) const;
499 534
500 // Deletes old WebContents that have been replaced by prerendered ones. This 535 // 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, 536 // is needed because they're replaced in a callback from the old WebContents,
502 // so cannot immediately be deleted. 537 // so cannot immediately be deleted.
503 void DeleteOldWebContents(); 538 void DeleteOldWebContents();
504 539
540 // Get infromation associated with a possible prefetch of |url|.
541 void GetPrefetchInformation(const GURL& url,
542 base::TimeDelta* prefetch_age,
543 Origin* origin);
544
505 // Cleans up old NavigationRecord's. 545 // Cleans up old NavigationRecord's.
506 void CleanUpOldNavigations(std::vector<NavigationRecord>* navigations, 546 void CleanUpOldNavigations(std::vector<NavigationRecord>* navigations,
507 base::TimeDelta max_age); 547 base::TimeDelta max_age);
508 548
509 // Arrange for the given WebContents to be deleted asap. Delete |deleter| as 549 // Arrange for the given WebContents to be deleted asap. Delete |deleter| as
510 // well. 550 // well.
511 void ScheduleDeleteOldWebContents(std::unique_ptr<content::WebContents> tab, 551 void ScheduleDeleteOldWebContents(std::unique_ptr<content::WebContents> tab,
512 OnCloseWebContentsDeleter* deleter); 552 OnCloseWebContentsDeleter* deleter);
513 553
514 // Adds to the history list. 554 // Adds to the history list.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 // The value of profile_network_bytes_ that was last recorded. 630 // The value of profile_network_bytes_ that was last recorded.
591 int64_t last_recorded_profile_network_bytes_; 631 int64_t last_recorded_profile_network_bytes_;
592 632
593 // Set of process hosts being prerendered. 633 // Set of process hosts being prerendered.
594 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; 634 using PrerenderProcessSet = std::set<content::RenderProcessHost*>;
595 PrerenderProcessSet prerender_process_hosts_; 635 PrerenderProcessSet prerender_process_hosts_;
596 636
597 std::unique_ptr<base::Clock> clock_; 637 std::unique_ptr<base::Clock> clock_;
598 std::unique_ptr<base::TickClock> tick_clock_; 638 std::unique_ptr<base::TickClock> tick_clock_;
599 639
640 bool page_load_metric_observer_disabled_;
641
642 std::vector<std::unique_ptr<PrerenderManagerObserver>> observers_;
droger 2016/11/29 15:54:40 Nit: consider using base::ObserverList. Note it h
mattcary 2016/11/29 16:39:45 Yeah, the ownership issue seemed more convenient t
droger 2016/11/29 16:46:18 I don't think there is a hard rule. ObserverList h
pasko 2016/11/29 16:51:17 I think it is good to not use the ObserverList her
mattcary 2016/11/29 16:52:19 Good point, sgtm
643
600 base::WeakPtrFactory<PrerenderManager> weak_factory_; 644 base::WeakPtrFactory<PrerenderManager> weak_factory_;
601 645
602 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 646 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
603 }; 647 };
604 648
605 } // namespace prerender 649 } // namespace prerender
606 650
607 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 651 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698