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

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

Issue 2423383002: [Prerender] first contentful paint histograms. (Closed)
Patch Set: comments 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 namespace prerender { 65 namespace prerender {
66 66
67 namespace test_utils { 67 namespace test_utils {
68 class PrerenderInProcessBrowserTest; 68 class PrerenderInProcessBrowserTest;
69 } 69 }
70 70
71 class PrerenderHandle; 71 class PrerenderHandle;
72 class PrerenderHistory; 72 class PrerenderHistory;
73 class PrerenderLocalPredictor; 73 class PrerenderLocalPredictor;
74 74
75 // Observer interface for PrerenderManager events.
76 class PrerenderManagerObserver {
77 public:
78 // Called from the UI thread.
79 virtual void OnFirstContentfulPaint() = 0;
80 };
81
75 // PrerenderManager is responsible for initiating and keeping prerendered 82 // PrerenderManager is responsible for initiating and keeping prerendered
76 // views of web pages. All methods must be called on the UI thread unless 83 // views of web pages. All methods must be called on the UI thread unless
77 // indicated otherwise. 84 // indicated otherwise.
78 class PrerenderManager : public content::NotificationObserver, 85 class PrerenderManager : public content::NotificationObserver,
79 public content::RenderProcessHostObserver, 86 public content::RenderProcessHostObserver,
80 public KeyedService, 87 public KeyedService,
81 public MediaCaptureDevicesDispatcher::Observer { 88 public MediaCaptureDevicesDispatcher::Observer {
82 public: 89 public:
83 // NOTE: New values need to be appended, since they are used in histograms. 90 // NOTE: New values need to be appended, since they are used in histograms.
84 enum PrerenderManagerMode { 91 enum PrerenderManagerMode {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 bool is_main_resource, 219 bool is_main_resource,
213 bool is_redirect, 220 bool is_redirect,
214 bool is_no_store); 221 bool is_no_store);
215 222
216 // Called when a NoStatePrefetch resource has been loaded. This is called only 223 // Called when a NoStatePrefetch resource has been loaded. This is called only
217 // once per resource, when all redirects have been resolved. 224 // once per resource, when all redirects have been resolved.
218 void RecordPrefetchRedirectCount(Origin origin, 225 void RecordPrefetchRedirectCount(Origin origin,
219 bool is_main_resource, 226 bool is_main_resource,
220 int redirect_count); 227 int redirect_count);
221 228
222 // Records the time to first contentful paint. 229 // Records the time to first contentful paint for loads that previously had a
223 // Must not be called for prefetch loads (which are never rendered anyway). 230 // no state prefetch load. Must not be called for prefetch loads themselves
224 // |is_no_store| must be true if the main resource has a "no-store" cache 231 // (which are never rendered anyway). |is_no_store| must be true if the main
225 // control HTTP header. 232 // resource has a "no-store" cache control HTTP header.
226 void RecordFirstContentfulPaint(const GURL& url, 233 void RecordNoStateFirstContentfulPaint(const GURL& url,
227 bool is_no_store, 234 bool is_no_store,
228 base::TimeDelta time); 235 base::TimeDelta time);
236
237 // Records the perceived first contentful paint time for a prerendered page,
238 // analogous to |RecordPerceivedPageLoadTime|. The FCP ticks is in absolute
239 // time; this has the disadvantage that the histogram will mix browser and
240 // renderer ticks, but there seems to be no way around that.
241 void RecordPerceivedFirstContentfulPaint(content::WebContents* web_contents,
242 base::TimeTicks ticks,
243 bool was_hidden);
229 244
230 static PrerenderManagerMode GetMode(); 245 static PrerenderManagerMode GetMode();
231 static void SetMode(PrerenderManagerMode mode); 246 static void SetMode(PrerenderManagerMode mode);
232 static bool IsPrerenderingPossible(); 247 static bool IsPrerenderingPossible();
233 static bool ActuallyPrerendering(); 248 static bool ActuallyPrerendering();
234 static bool IsControlGroup(); 249 static bool IsControlGroup();
235 static bool IsNoUseGroup(); 250 static bool IsNoUseGroup();
236 static bool IsNoStatePrefetch(); 251 static bool IsNoStatePrefetch();
237 252
238 // Query the list of current prerender pages to see if the given web contents 253 // Query the list of current prerender pages to see if the given web contents
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 Profile* profile() const { return profile_; } 337 Profile* profile() const { return profile_; }
323 338
324 // Return current time and ticks with ability to mock the clock out for 339 // Return current time and ticks with ability to mock the clock out for
325 // testing. 340 // testing.
326 base::Time GetCurrentTime() const; 341 base::Time GetCurrentTime() const;
327 base::TimeTicks GetCurrentTimeTicks() const; 342 base::TimeTicks GetCurrentTimeTicks() const;
328 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock); 343 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock);
329 void SetTickClockForTesting( 344 void SetTickClockForTesting(
330 std::unique_ptr<base::SimpleTestTickClock> tick_clock); 345 std::unique_ptr<base::SimpleTestTickClock> tick_clock);
331 346
347 void DisablePageLoadMetricsObserverForTesting() {
348 page_load_metric_observer_disabled_ = true;
349 }
350
351 bool PageLoadMetricsObserverDisabledForTesting() const {
352 return page_load_metric_observer_disabled_;
353 }
354
355 void AddObserver(std::unique_ptr<PrerenderManagerObserver> observer);
356
332 // Notification that a prerender has completed and its bytes should be 357 // Notification that a prerender has completed and its bytes should be
333 // recorded. 358 // recorded.
334 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); 359 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes);
335 360
336 // Add to the running tally of bytes transferred over the network for this 361 // Add to the running tally of bytes transferred over the network for this
337 // profile if prerendering is currently enabled. 362 // profile if prerendering is currently enabled.
338 void AddProfileNetworkBytesIfEnabled(int64_t bytes); 363 void AddProfileNetworkBytesIfEnabled(int64_t bytes);
339 364
340 // Registers a new ProcessHost performing a prerender. Called by 365 // Registers a new ProcessHost performing a prerender. Called by
341 // PrerenderContents. 366 // PrerenderContents.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 // The value of profile_network_bytes_ that was last recorded. 628 // The value of profile_network_bytes_ that was last recorded.
604 int64_t last_recorded_profile_network_bytes_; 629 int64_t last_recorded_profile_network_bytes_;
605 630
606 // Set of process hosts being prerendered. 631 // Set of process hosts being prerendered.
607 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; 632 using PrerenderProcessSet = std::set<content::RenderProcessHost*>;
608 PrerenderProcessSet prerender_process_hosts_; 633 PrerenderProcessSet prerender_process_hosts_;
609 634
610 std::unique_ptr<base::Clock> clock_; 635 std::unique_ptr<base::Clock> clock_;
611 std::unique_ptr<base::TickClock> tick_clock_; 636 std::unique_ptr<base::TickClock> tick_clock_;
612 637
638 bool page_load_metric_observer_disabled_;
639
640 std::vector<std::unique_ptr<PrerenderManagerObserver>> observers_;
641
613 base::WeakPtrFactory<PrerenderManager> weak_factory_; 642 base::WeakPtrFactory<PrerenderManager> weak_factory_;
614 643
615 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 644 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
616 }; 645 };
617 646
618 } // namespace prerender 647 } // namespace prerender
619 648
620 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 649 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698