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

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

Issue 2423383002: [Prerender] first contentful paint histograms. (Closed)
Patch Set: cleanup 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 }; 96 };
97 97
98 // One or more of these flags must be passed to ClearData() to specify just 98 // One or more of these flags must be passed to ClearData() to specify just
99 // what data to clear. See function declaration for more information. 99 // what data to clear. See function declaration for more information.
100 enum ClearFlags { 100 enum ClearFlags {
101 CLEAR_PRERENDER_CONTENTS = 0x1 << 0, 101 CLEAR_PRERENDER_CONTENTS = 0x1 << 0,
102 CLEAR_PRERENDER_HISTORY = 0x1 << 1, 102 CLEAR_PRERENDER_HISTORY = 0x1 << 1,
103 CLEAR_MAX = 0x1 << 2 103 CLEAR_MAX = 0x1 << 2
104 }; 104 };
105 105
106 // Observer interface for PrerenderManager events.
107 class Observer {
pasko 2016/11/17 19:52:16 A toplevel class PrerenderManagerObserver is prefe
mattcary 2016/11/18 09:21:11 Done. I was copying what PrerenderContents was do
108 public:
109 virtual void OnFirstContentfulPaint() = 0;
pasko 2016/11/17 19:52:16 should have a comment saying on which thread all t
mattcary 2016/11/18 09:21:11 Done.
110 };
111
106 // Owned by a Profile object for the lifetime of the profile. 112 // Owned by a Profile object for the lifetime of the profile.
107 explicit PrerenderManager(Profile* profile); 113 explicit PrerenderManager(Profile* profile);
108 ~PrerenderManager() override; 114 ~PrerenderManager() override;
109 115
110 // From KeyedService: 116 // From KeyedService:
111 void Shutdown() override; 117 void Shutdown() override;
112 118
113 // Entry points for adding prerenders. 119 // Entry points for adding prerenders.
114 120
115 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify 121 // Adds a prerender for |url| if valid. |process_id| and |route_id| identify
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 bool is_main_resource, 218 bool is_main_resource,
213 bool is_redirect, 219 bool is_redirect,
214 bool is_no_store); 220 bool is_no_store);
215 221
216 // Called when a NoStatePrefetch resource has been loaded. This is called only 222 // Called when a NoStatePrefetch resource has been loaded. This is called only
217 // once per resource, when all redirects have been resolved. 223 // once per resource, when all redirects have been resolved.
218 void RecordPrefetchRedirectCount(Origin origin, 224 void RecordPrefetchRedirectCount(Origin origin,
219 bool is_main_resource, 225 bool is_main_resource,
220 int redirect_count); 226 int redirect_count);
221 227
222 // Records the time to first contentful paint. 228 // Records the time to first contentful paint for no state prefetch loads.
pasko 2016/11/17 19:52:16 is it rather for loads that were recently prefetch
mattcary 2016/11/18 09:21:11 Done.
223 // Must not be called for prefetch loads (which are never rendered anyway). 229 // Must not be called for prefetch loads (which are never rendered anyway).
224 // |is_no_store| must be true if the main resource has a "no-store" cache 230 // |is_no_store| must be true if the main resource has a "no-store" cache
225 // control HTTP header. 231 // control HTTP header.
226 void RecordFirstContentfulPaint(const GURL& url, 232 void RecordNoStateFirstContentfulPaint(const GURL& url,
227 bool is_no_store, 233 bool is_no_store,
228 base::TimeDelta time); 234 base::TimeDelta time);
235
236 // Records the perceived first contentful paint time for a prerendered page,
237 // analogous to |RecordPerceivedPageLoadTime|.
238 void RecordPerceivedFirstContentfulPaint(content::WebContents* web_contents,
239 base::TimeDelta time);
229 240
230 static PrerenderManagerMode GetMode(); 241 static PrerenderManagerMode GetMode();
231 static void SetMode(PrerenderManagerMode mode); 242 static void SetMode(PrerenderManagerMode mode);
232 static bool IsPrerenderingPossible(); 243 static bool IsPrerenderingPossible();
233 static bool ActuallyPrerendering(); 244 static bool ActuallyPrerendering();
234 static bool IsControlGroup(); 245 static bool IsControlGroup();
235 static bool IsNoUseGroup(); 246 static bool IsNoUseGroup();
236 static bool IsNoStatePrefetch(); 247 static bool IsNoStatePrefetch();
237 248
238 // Query the list of current prerender pages to see if the given web contents 249 // 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_; } 333 Profile* profile() const { return profile_; }
323 334
324 // Return current time and ticks with ability to mock the clock out for 335 // Return current time and ticks with ability to mock the clock out for
325 // testing. 336 // testing.
326 base::Time GetCurrentTime() const; 337 base::Time GetCurrentTime() const;
327 base::TimeTicks GetCurrentTimeTicks() const; 338 base::TimeTicks GetCurrentTimeTicks() const;
328 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock); 339 void SetClockForTesting(std::unique_ptr<base::SimpleTestClock> clock);
329 void SetTickClockForTesting( 340 void SetTickClockForTesting(
330 std::unique_ptr<base::SimpleTestTickClock> tick_clock); 341 std::unique_ptr<base::SimpleTestTickClock> tick_clock);
331 342
343 void DisablePageLoadMetricsObserverForTesting() {
pasko 2016/11/17 19:52:16 I see a few tests calling this, does something bre
mattcary 2016/11/18 09:21:11 Yes, if it's not disabled there will be a race bet
Bryan McQuade 2016/11/18 14:52:37 You do get a bit less complete test coverage this
mattcary 2016/11/18 15:14:13 We already have logging of the histogram counts el
344 page_load_metric_observer_disabled_ = true;
345 }
346
347 bool PageLoadMetricsObserverDisabledForTesting() const {
348 return page_load_metric_observer_disabled_;
349 }
350
351 void AddObserver(std::unique_ptr<Observer> observer);
352
332 // Notification that a prerender has completed and its bytes should be 353 // Notification that a prerender has completed and its bytes should be
333 // recorded. 354 // recorded.
334 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes); 355 void RecordNetworkBytes(Origin origin, bool used, int64_t prerender_bytes);
335 356
336 // Add to the running tally of bytes transferred over the network for this 357 // Add to the running tally of bytes transferred over the network for this
337 // profile if prerendering is currently enabled. 358 // profile if prerendering is currently enabled.
338 void AddProfileNetworkBytesIfEnabled(int64_t bytes); 359 void AddProfileNetworkBytesIfEnabled(int64_t bytes);
339 360
340 // Registers a new ProcessHost performing a prerender. Called by 361 // Registers a new ProcessHost performing a prerender. Called by
341 // PrerenderContents. 362 // PrerenderContents.
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 // The value of profile_network_bytes_ that was last recorded. 624 // The value of profile_network_bytes_ that was last recorded.
604 int64_t last_recorded_profile_network_bytes_; 625 int64_t last_recorded_profile_network_bytes_;
605 626
606 // Set of process hosts being prerendered. 627 // Set of process hosts being prerendered.
607 using PrerenderProcessSet = std::set<content::RenderProcessHost*>; 628 using PrerenderProcessSet = std::set<content::RenderProcessHost*>;
608 PrerenderProcessSet prerender_process_hosts_; 629 PrerenderProcessSet prerender_process_hosts_;
609 630
610 std::unique_ptr<base::Clock> clock_; 631 std::unique_ptr<base::Clock> clock_;
611 std::unique_ptr<base::TickClock> tick_clock_; 632 std::unique_ptr<base::TickClock> tick_clock_;
612 633
634 bool page_load_metric_observer_disabled_;
635
636 std::vector<std::unique_ptr<Observer>> observers_;
637
613 base::WeakPtrFactory<PrerenderManager> weak_factory_; 638 base::WeakPtrFactory<PrerenderManager> weak_factory_;
614 639
615 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 640 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
616 }; 641 };
617 642
618 } // namespace prerender 643 } // namespace prerender
619 644
620 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 645 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698