Unwind the URL-based experiment IDs.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_histograms.h
blob0f7bc40781bbc29ab5446c6842be19a87fd8cf1f
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_
8 #include <string>
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_origin.h"
14 #include "url/gurl.h"
16 namespace prerender {
18 // Navigation type for histograms.
19 enum NavigationType {
20 // A normal completed navigation.
21 NAVIGATION_TYPE_NORMAL,
22 // A completed navigation or swap that began as a prerender.
23 NAVIGATION_TYPE_PRERENDERED,
24 // A normal completed navigation in the control group or with a control
25 // prerender that would have been prerendered.
26 NAVIGATION_TYPE_WOULD_HAVE_BEEN_PRERENDERED,
27 NAVIGATION_TYPE_MAX,
30 // PrerenderHistograms is responsible for recording all prerender specific
31 // histograms for PrerenderManager. It keeps track of the type of prerender
32 // currently underway (based on the PrerenderOrigin of the most recent
33 // prerenders, and any experiments detected).
34 // PrerenderHistograms does not necessarily record all histograms related to
35 // prerendering, only the ones in the context of PrerenderManager.
36 class PrerenderHistograms {
37 public:
38 // Owned by a PrerenderManager object for the lifetime of the
39 // PrerenderManager.
40 PrerenderHistograms();
42 // Records the perceived page load time for a page - effectively the time from
43 // when the user navigates to a page to when it finishes loading. The actual
44 // load may have started prior to navigation due to prerender hints.
45 void RecordPerceivedPageLoadTime(Origin origin,
46 base::TimeDelta perceived_page_load_time,
47 NavigationType navigation_type,
48 const GURL& url);
50 // Records, in a histogram, the percentage of the page load time that had
51 // elapsed by the time it is swapped in. Values outside of [0, 1.0] are
52 // invalid and ignored.
53 void RecordPercentLoadDoneAtSwapin(Origin origin, double fraction) const;
55 // Records the actual pageload time of a prerender that has not been swapped
56 // in yet, but finished loading.
57 void RecordPageLoadTimeNotSwappedIn(Origin origin,
58 base::TimeDelta page_load_time,
59 const GURL& url) const;
61 // Records the time from when a page starts prerendering to when the user
62 // navigates to it. This must be called on the UI thread.
63 void RecordTimeUntilUsed(Origin origin,
64 base::TimeDelta time_until_used) const;
66 // Records the time from when a prerender is abandoned to when the user
67 // navigates to it. This must be called on the UI thread.
68 void RecordAbandonTimeUntilUsed(Origin origin,
69 base::TimeDelta time_until_used) const;
71 // Record a PerSessionCount data point.
72 void RecordPerSessionCount(Origin origin, int count) const;
74 // Record time between two prerender requests.
75 void RecordTimeBetweenPrerenderRequests(Origin origin,
76 base::TimeDelta time) const;
78 // Record a final status of a prerendered page in a histogram.
79 void RecordFinalStatus(Origin origin,
80 PrerenderContents::MatchCompleteStatus mc_status,
81 FinalStatus final_status) const;
83 // To be called when a new prerender is added.
84 void RecordPrerender(Origin origin, const GURL& url);
86 // To be called when a new prerender is started.
87 void RecordPrerenderStarted(Origin origin) const;
89 // To be called when we know how many prerenders are running after starting
90 // a prerender.
91 void RecordConcurrency(size_t prerender_count) const;
93 // Called when we swap in a prerender.
94 void RecordUsedPrerender(Origin origin) const;
96 // Record the time since a page was recently visited.
97 void RecordTimeSinceLastRecentVisit(Origin origin,
98 base::TimeDelta time) const;
100 // Record the bytes in the prerender, whether it was used or not, and the
101 // total number of bytes fetched for this profile since the last call to
102 // RecordBytes.
103 void RecordNetworkBytes(Origin origin,
104 bool used,
105 int64 prerender_bytes,
106 int64 profile_bytes);
108 private:
109 base::TimeTicks GetCurrentTimeTicks() const;
111 // Returns the time elapsed since the last prerender happened.
112 base::TimeDelta GetTimeSinceLastPrerender() const;
114 // Returns whether the PrerenderManager is currently within the prerender
115 // window - effectively, up to 30 seconds after a prerender tag has been
116 // observed.
117 bool WithinWindow() const;
119 // Returns whether or not there is currently an origin wash.
120 bool IsOriginWash() const;
122 // Origin of the last prerender seen.
123 Origin last_origin_;
125 // A boolean indicating that we have recently encountered a combination of
126 // different origins, making an attribution of PPLT's to origins impossible.
127 bool origin_wash_;
129 // The time when we last saw a prerender request coming from a renderer.
130 // This is used to record perceived PLT's for a certain amount of time
131 // from the point that we last saw a <link rel=prerender> tag.
132 base::TimeTicks last_prerender_seen_time_;
134 // Indicates whether we have recorded page load events after the most
135 // recent prerender. These must be initialized to true, so that we don't
136 // start recording events before the first prerender occurs.
137 bool seen_any_pageload_;
138 bool seen_pageload_started_after_prerender_;
140 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms);
143 } // namespace prerender
145 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_