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

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

Issue 2423383002: [Prerender] first contentful paint histograms. (Closed)
Patch Set: comments Created 4 years, 1 month 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|.
239 void RecordPerceivedFirstContentfulPaint(content::WebContents* web_contents,
240 base::TimeDelta time);
229 241
230 static PrerenderManagerMode GetMode(); 242 static PrerenderManagerMode GetMode();
231 static void SetMode(PrerenderManagerMode mode); 243 static void SetMode(PrerenderManagerMode mode);
232 static bool IsPrerenderingPossible(); 244 static bool IsPrerenderingPossible();
233 static bool ActuallyPrerendering(); 245 static bool ActuallyPrerendering();
234 static bool IsControlGroup(); 246 static bool IsControlGroup();
235 static bool IsNoUseGroup(); 247 static bool IsNoUseGroup();
236 static bool IsNoStatePrefetch(); 248 static bool IsNoStatePrefetch();
237 249
238 // 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
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 Profile* profile() const { return profile_; } 334 Profile* profile() const { return profile_; }
323 335
324 // 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
325 // testing. 337 // testing.
326 base::Time GetCurrentTime() const; 338 base::Time GetCurrentTime() const;
327 base::TimeTicks GetCurrentTimeTicks() const; 339 base::TimeTicks GetCurrentTimeTicks() const;
328 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock); 340 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock);
329 void SetTickClockForTesting( 341 void SetTickClockForTesting(
330 std::unique_ptr<base::SimpleTestTickClock> tick_clock); 342 std::unique_ptr<base::SimpleTestTickClock> tick_clock);
331 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
332 // Notification that a prerender has completed and its bytes should be 354 // Notification that a prerender has completed and its bytes should be
333 // recorded. 355 // recorded.
334 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); 356 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes);
335 357
336 // 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
337 // profile if prerendering is currently enabled. 359 // profile if prerendering is currently enabled.
338 void AddProfileNetworkBytesIfEnabled(int64_t bytes); 360 void AddProfileNetworkBytesIfEnabled(int64_t bytes);
339 361
340 // Registers a new ProcessHost performing a prerender. Called by 362 // Registers a new ProcessHost performing a prerender. Called by
341 // PrerenderContents. 363 // PrerenderContents.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 // The value of profile_network_bytes_ that was last recorded. 625 // The value of profile_network_bytes_ that was last recorded.
604 int64_t last_recorded_profile_network_bytes_; 626 int64_t last_recorded_profile_network_bytes_;
605 627
606 // Set of process hosts being prerendered. 628 // Set of process hosts being prerendered.
607 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; 629 using PrerenderProcessSet = std::set<content::RenderProcessHost*>;
608 PrerenderProcessSet prerender_process_hosts_; 630 PrerenderProcessSet prerender_process_hosts_;
609 631
610 std::unique_ptr<base::Clock> clock_; 632 std::unique_ptr<base::Clock> clock_;
611 std::unique_ptr<base::TickClock> tick_clock_; 633 std::unique_ptr<base::TickClock> tick_clock_;
612 634
635 bool page_load_metric_observer_disabled_;
636
637 std::vector<std::unique_ptr<PrerenderManagerObserver>> observers_;
638
613 base::WeakPtrFactory<PrerenderManager> weak_factory_; 639 base::WeakPtrFactory<PrerenderManager> weak_factory_;
614 640
615 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 641 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
616 }; 642 };
617 643
618 } // namespace prerender 644 } // namespace prerender
619 645
620 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 646 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698