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.
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_
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"
19 // Navigation type for histograms.
21 // A normal completed navigation.
22 NAVIGATION_TYPE_NORMAL
,
23 // A completed navigation or swap that began as a prerender.
24 NAVIGATION_TYPE_PRERENDERED
,
25 // A normal completed navigation in the control group or with a control
26 // prerender that would have been prerendered.
27 NAVIGATION_TYPE_WOULD_HAVE_BEEN_PRERENDERED
,
31 // PrerenderHistograms is responsible for recording all prerender specific
32 // histograms for PrerenderManager. It keeps track of the type of prerender
33 // currently underway (based on the PrerenderOrigin of the most recent
34 // prerenders, and any experiments detected).
35 // PrerenderHistograms does not necessarily record all histograms related to
36 // prerendering, only the ones in the context of PrerenderManager.
37 class PrerenderHistograms
{
39 // Owned by a PrerenderManager object for the lifetime of the
41 PrerenderHistograms();
43 // Records the perceived page load time for a page - effectively the time from
44 // when the user navigates to a page to when it finishes loading. The actual
45 // load may have started prior to navigation due to prerender hints.
46 void RecordPerceivedPageLoadTime(Origin origin
,
47 base::TimeDelta perceived_page_load_time
,
48 NavigationType navigation_type
,
51 // Records, in a histogram, the percentage of the page load time that had
52 // elapsed by the time it is swapped in. Values outside of [0, 1.0] are
53 // invalid and ignored.
54 void RecordPercentLoadDoneAtSwapin(Origin origin
, double fraction
) const;
56 // Records the actual pageload time of a prerender that has not been swapped
57 // in yet, but finished loading.
58 void RecordPageLoadTimeNotSwappedIn(Origin origin
,
59 base::TimeDelta page_load_time
,
60 const GURL
& url
) const;
62 // Records the time from when a page starts prerendering to when the user
63 // navigates to it. This must be called on the UI thread.
64 void RecordTimeUntilUsed(Origin origin
,
65 base::TimeDelta time_until_used
) const;
67 // Records the time from when a prerender is abandoned to when the user
68 // navigates to it. This must be called on the UI thread.
69 void RecordAbandonTimeUntilUsed(Origin origin
,
70 base::TimeDelta time_until_used
) const;
72 // Record a PerSessionCount data point.
73 void RecordPerSessionCount(Origin origin
, int count
) const;
75 // Record time between two prerender requests.
76 void RecordTimeBetweenPrerenderRequests(Origin origin
,
77 base::TimeDelta time
) const;
79 // Record a final status of a prerendered page in a histogram.
80 void RecordFinalStatus(Origin origin
,
82 PrerenderContents::MatchCompleteStatus mc_status
,
83 FinalStatus final_status
) const;
85 // To be called when a new prerender is added.
86 void RecordPrerender(Origin origin
, const GURL
& url
);
88 // To be called when a new prerender is started.
89 void RecordPrerenderStarted(Origin origin
) const;
91 // To be called when we know how many prerenders are running after starting
93 void RecordConcurrency(size_t prerender_count
) const;
95 // Called when we swap in a prerender.
96 void RecordUsedPrerender(Origin origin
) const;
98 // Record the time since a page was recently visited.
99 void RecordTimeSinceLastRecentVisit(Origin origin
,
100 base::TimeDelta time
) const;
102 // Record the bytes in the prerender, whether it was used or not, and the
103 // total number of bytes fetched for this profile since the last call to
105 void RecordNetworkBytes(Origin origin
,
107 int64 prerender_bytes
,
108 int64 profile_bytes
);
111 base::TimeTicks
GetCurrentTimeTicks() const;
113 // Returns the time elapsed since the last prerender happened.
114 base::TimeDelta
GetTimeSinceLastPrerender() const;
116 // Returns whether the PrerenderManager is currently within the prerender
117 // window - effectively, up to 30 seconds after a prerender tag has been
119 bool WithinWindow() const;
121 // Returns the current experiment.
122 uint8
GetCurrentExperimentId() const;
124 // Returns whether or not there is currently an origin/experiment wash.
125 bool IsOriginExperimentWash() const;
127 // An integer indicating a Prerendering Experiment being currently conducted.
128 // (The last experiment ID seen).
129 uint8 last_experiment_id_
;
131 // Origin of the last prerender seen.
134 // A boolean indicating that we have recently encountered a combination of
135 // different experiments and origins, making an attribution of PPLT's to
136 // experiments / origins impossible.
137 bool origin_experiment_wash_
;
139 // The time when we last saw a prerender request coming from a renderer.
140 // This is used to record perceived PLT's for a certain amount of time
141 // from the point that we last saw a <link rel=prerender> tag.
142 base::TimeTicks last_prerender_seen_time_
;
144 // Indicates whether we have recorded page load events after the most
145 // recent prerender. These must be initialized to true, so that we don't
146 // start recording events before the first prerender occurs.
147 bool seen_any_pageload_
;
148 bool seen_pageload_started_after_prerender_
;
150 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms
);
153 } // namespace prerender
155 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_