ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_histograms.h
blob9e08bb9b48c1a33e3485ad357283d92dd98cb640
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_local_predictor.h"
14 #include "chrome/browser/prerender/prerender_origin.h"
15 #include "url/gurl.h"
17 namespace prerender {
19 // Navigation type for histograms.
20 enum NavigationType {
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,
28 NAVIGATION_TYPE_MAX,
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 {
38 public:
39 // Owned by a PrerenderManager object for the lifetime of the
40 // PrerenderManager.
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,
49 const GURL& url);
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,
81 uint8 experiment_id,
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
92 // a prerender.
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 a prerender cookie status bitmap. Must be in the range
103 // [0, PrerenderContents::kNumCookieStatuses).
104 void RecordCookieStatus(Origin origin,
105 uint8 experiment_id,
106 int cookie_status) const;
108 // Record a prerender cookie send type. Must be in the range
109 // [0, PrerenderContents::kNumCookieSendTypes).
110 void RecordCookieSendType(Origin origin,
111 uint8 experiment_id,
112 int cookie_send_type) const;
114 void RecordPrerenderPageVisitedStatus(Origin origin,
115 uint8 experiment_id,
116 bool visited_before) const;
118 // Record the bytes in the prerender, whether it was used or not, and the
119 // total number of bytes fetched for this profile since the last call to
120 // RecordBytes.
121 void RecordNetworkBytes(Origin origin,
122 bool used,
123 int64 prerender_bytes,
124 int64 profile_bytes);
126 private:
127 base::TimeTicks GetCurrentTimeTicks() const;
129 // Returns the time elapsed since the last prerender happened.
130 base::TimeDelta GetTimeSinceLastPrerender() const;
132 // Returns whether the PrerenderManager is currently within the prerender
133 // window - effectively, up to 30 seconds after a prerender tag has been
134 // observed.
135 bool WithinWindow() const;
137 // Returns the current experiment.
138 uint8 GetCurrentExperimentId() const;
140 // Returns whether or not there is currently an origin/experiment wash.
141 bool IsOriginExperimentWash() const;
143 // An integer indicating a Prerendering Experiment being currently conducted.
144 // (The last experiment ID seen).
145 uint8 last_experiment_id_;
147 // Origin of the last prerender seen.
148 Origin last_origin_;
150 // A boolean indicating that we have recently encountered a combination of
151 // different experiments and origins, making an attribution of PPLT's to
152 // experiments / origins impossible.
153 bool origin_experiment_wash_;
155 // The time when we last saw a prerender request coming from a renderer.
156 // This is used to record perceived PLT's for a certain amount of time
157 // from the point that we last saw a <link rel=prerender> tag.
158 base::TimeTicks last_prerender_seen_time_;
160 // Indicates whether we have recorded page load events after the most
161 // recent prerender. These must be initialized to true, so that we don't
162 // start recording events before the first prerender occurs.
163 bool seen_any_pageload_;
164 bool seen_pageload_started_after_prerender_;
166 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms);
169 } // namespace prerender
171 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_