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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ 7 8 #include <string> 9 10 #include "base/time/time.h" 11 #include "chrome/browser/prerender/prerender_contents.h" 12 #include "chrome/browser/prerender/prerender_final_status.h" 13 #include "chrome/browser/prerender/prerender_local_predictor.h" 14 #include "chrome/browser/prerender/prerender_origin.h" 15 #include "url/gurl.h" 16 17 namespace prerender { 18 19 // PrerenderHistograms is responsible for recording all prerender specific 20 // histograms for PrerenderManager. It keeps track of the type of prerender 21 // currently underway (based on the PrerenderOrigin of the most recent 22 // prerenders, and any experiments detected). 23 // PrerenderHistograms does not necessarily record all histograms related to 24 // prerendering, only the ones in the context of PrerenderManager. 25 class PrerenderHistograms { 26 public: 27 // Owned by a PrerenderManager object for the lifetime of the 28 // PrerenderManager. 29 PrerenderHistograms(); 30 31 // Records the perceived page load time for a page - effectively the time from 32 // when the user navigates to a page to when it finishes loading. The actual 33 // load may have started prior to navigation due to prerender hints. 34 void RecordPerceivedPageLoadTime(Origin origin, 35 base::TimeDelta perceived_page_load_time, 36 bool was_prerender, 37 bool was_complete_prerender, 38 const GURL& url); 39 40 // Records, in a histogram, the percentage of the page load time that had 41 // elapsed by the time it is swapped in. Values outside of [0, 1.0] are 42 // invalid and ignored. 43 void RecordPercentLoadDoneAtSwapin(Origin origin, double fraction) const; 44 45 // Records the actual pageload time of a prerender that has not been swapped 46 // in yet, but finished loading. 47 void RecordPageLoadTimeNotSwappedIn(Origin origin, 48 base::TimeDelta page_load_time, 49 const GURL& url) const; 50 51 // Records the time from when a page starts prerendering to when the user 52 // navigates to it. This must be called on the UI thread. 53 void RecordTimeUntilUsed(Origin origin, 54 base::TimeDelta time_until_used) const; 55 56 // Record a PerSessionCount data point. 57 void RecordPerSessionCount(Origin origin, int count) const; 58 59 // Record time between two prerender requests. 60 void RecordTimeBetweenPrerenderRequests(Origin origin, 61 base::TimeDelta time) const; 62 63 // Record a final status of a prerendered page in a histogram. 64 void RecordFinalStatus(Origin origin, 65 uint8 experiment_id, 66 PrerenderContents::MatchCompleteStatus mc_status, 67 FinalStatus final_status) const; 68 69 // To be called when a new prerender is added. 70 void RecordPrerender(Origin origin, const GURL& url); 71 72 // To be called when a new prerender is started. 73 void RecordPrerenderStarted(Origin origin) const; 74 75 // To be called when we know how many prerenders are running after starting 76 // a prerender. 77 void RecordConcurrency(size_t prerender_count) const; 78 79 // Called when we swap in a prerender. 80 void RecordUsedPrerender(Origin origin) const; 81 82 // Record the time since a page was recently visited. 83 void RecordTimeSinceLastRecentVisit(Origin origin, 84 base::TimeDelta time) const; 85 86 // Record a percentage of pixels of the final page already in place at 87 // swap-in. 88 void RecordFractionPixelsFinalAtSwapin(Origin origin, double fraction) const; 89 90 private: 91 base::TimeTicks GetCurrentTimeTicks() const; 92 93 // Returns the time elapsed since the last prerender happened. 94 base::TimeDelta GetTimeSinceLastPrerender() const; 95 96 // Returns whether the PrerenderManager is currently within the prerender 97 // window - effectively, up to 30 seconds after a prerender tag has been 98 // observed. 99 bool WithinWindow() const; 100 101 // Returns the current experiment. 102 uint8 GetCurrentExperimentId() const; 103 104 // Returns whether or not there is currently an origin/experiment wash. 105 bool IsOriginExperimentWash() const; 106 107 // An integer indicating a Prerendering Experiment being currently conducted. 108 // (The last experiment ID seen). 109 uint8 last_experiment_id_; 110 111 // Origin of the last prerender seen. 112 Origin last_origin_; 113 114 // A boolean indicating that we have recently encountered a combination of 115 // different experiments and origins, making an attribution of PPLT's to 116 // experiments / origins impossible. 117 bool origin_experiment_wash_; 118 119 // The time when we last saw a prerender request coming from a renderer. 120 // This is used to record perceived PLT's for a certain amount of time 121 // from the point that we last saw a <link rel=prerender> tag. 122 base::TimeTicks last_prerender_seen_time_; 123 124 // Indicates whether we have recorded page load events after the most 125 // recent prerender. These must be initialized to true, so that we don't 126 // start recording events before the first prerender occurs. 127 bool seen_any_pageload_; 128 bool seen_pageload_started_after_prerender_; 129 130 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms); 131 }; 132 133 } // namespace prerender 134 135 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_ 136