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_events.h"
13 #include "chrome/browser/prerender/prerender_final_status.h"
14 #include "chrome/browser/prerender/prerender_local_predictor.h"
15 #include "chrome/browser/prerender/prerender_origin.h"
20 // Navigation type for histograms.
22 // A normal completed navigation.
23 NAVIGATION_TYPE_NORMAL
,
24 // A completed navigation or swap that began as a prerender.
25 NAVIGATION_TYPE_PRERENDERED
,
26 // A normal completed navigation in the control group or with a control
27 // prerender that would have been prerendered.
28 NAVIGATION_TYPE_WOULD_HAVE_BEEN_PRERENDERED
,
32 // PrerenderHistograms is responsible for recording all prerender specific
33 // histograms for PrerenderManager. It keeps track of the type of prerender
34 // currently underway (based on the PrerenderOrigin of the most recent
35 // prerenders, and any experiments detected).
36 // PrerenderHistograms does not necessarily record all histograms related to
37 // prerendering, only the ones in the context of PrerenderManager.
38 class PrerenderHistograms
{
40 // Owned by a PrerenderManager object for the lifetime of the
42 PrerenderHistograms();
44 // Records the perceived page load time for a page - effectively the time from
45 // when the user navigates to a page to when it finishes loading. The actual
46 // load may have started prior to navigation due to prerender hints.
47 void RecordPerceivedPageLoadTime(Origin origin
,
48 base::TimeDelta perceived_page_load_time
,
49 NavigationType navigation_type
,
52 // Records, in a histogram, the percentage of the page load time that had
53 // elapsed by the time it is swapped in. Values outside of [0, 1.0] are
54 // invalid and ignored.
55 void RecordPercentLoadDoneAtSwapin(Origin origin
, double fraction
) const;
57 // Records the actual pageload time of a prerender that has not been swapped
58 // in yet, but finished loading.
59 void RecordPageLoadTimeNotSwappedIn(Origin origin
,
60 base::TimeDelta page_load_time
,
61 const GURL
& url
) const;
63 // Records the time from when a page starts prerendering to when the user
64 // navigates to it. This must be called on the UI thread.
65 void RecordTimeUntilUsed(Origin origin
,
66 base::TimeDelta time_until_used
) const;
68 // Record a PerSessionCount data point.
69 void RecordPerSessionCount(Origin origin
, int count
) const;
71 // Record time between two prerender requests.
72 void RecordTimeBetweenPrerenderRequests(Origin origin
,
73 base::TimeDelta time
) const;
75 // Record a final status of a prerendered page in a histogram.
76 void RecordFinalStatus(Origin origin
,
78 PrerenderContents::MatchCompleteStatus mc_status
,
79 FinalStatus final_status
) const;
81 // To be called when a new prerender is added.
82 void RecordPrerender(Origin origin
, const GURL
& url
);
84 // To be called when a new prerender is started.
85 void RecordPrerenderStarted(Origin origin
) const;
87 // To be called when we know how many prerenders are running after starting
89 void RecordConcurrency(size_t prerender_count
) const;
91 // Called when we swap in a prerender.
92 void RecordUsedPrerender(Origin origin
) const;
94 // Record the time since a page was recently visited.
95 void RecordTimeSinceLastRecentVisit(Origin origin
,
96 base::TimeDelta time
) const;
98 // Records a prerender event.
99 void RecordEvent(Origin origin
, uint8 experiment_id
, PrerenderEvent event
)
102 // Record a prerender cookie status bitmap. Must be in the range
103 // [0, PrerenderContents::kNumCookieStatuses).
104 void RecordCookieStatus(Origin origin
,
106 int cookie_status
) const;
108 void RecordPrerenderPageVisitedStatus(Origin origin
,
110 bool visited_before
) const;
112 // Record the bytes in the prerender, whether it was used or not, and the
113 // total number of bytes fetched for this profile since the last call to
115 void RecordNetworkBytes(bool used
,
116 int64 prerender_bytes
,
117 int64 profile_bytes
);
120 base::TimeTicks
GetCurrentTimeTicks() const;
122 // Returns the time elapsed since the last prerender happened.
123 base::TimeDelta
GetTimeSinceLastPrerender() const;
125 // Returns whether the PrerenderManager is currently within the prerender
126 // window - effectively, up to 30 seconds after a prerender tag has been
128 bool WithinWindow() const;
130 // Returns the current experiment.
131 uint8
GetCurrentExperimentId() const;
133 // Returns whether or not there is currently an origin/experiment wash.
134 bool IsOriginExperimentWash() const;
136 // An integer indicating a Prerendering Experiment being currently conducted.
137 // (The last experiment ID seen).
138 uint8 last_experiment_id_
;
140 // Origin of the last prerender seen.
143 // A boolean indicating that we have recently encountered a combination of
144 // different experiments and origins, making an attribution of PPLT's to
145 // experiments / origins impossible.
146 bool origin_experiment_wash_
;
148 // The time when we last saw a prerender request coming from a renderer.
149 // This is used to record perceived PLT's for a certain amount of time
150 // from the point that we last saw a <link rel=prerender> tag.
151 base::TimeTicks last_prerender_seen_time_
;
153 // Indicates whether we have recorded page load events after the most
154 // recent prerender. These must be initialized to true, so that we don't
155 // start recording events before the first prerender occurs.
156 bool seen_any_pageload_
;
157 bool seen_pageload_started_after_prerender_
;
159 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms
);
162 } // namespace prerender
164 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_