Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_histograms.h
blob889cdbd106a33199649cfbb27cd7f1eb12c59bb0
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 void RecordPrerenderPageVisitedStatus(Origin origin,
103 uint8 experiment_id,
104 bool visited_before) const;
106 // Record the bytes in the prerender, whether it was used or not, and the
107 // total number of bytes fetched for this profile since the last call to
108 // RecordBytes.
109 void RecordNetworkBytes(Origin origin,
110 bool used,
111 int64 prerender_bytes,
112 int64 profile_bytes);
114 private:
115 base::TimeTicks GetCurrentTimeTicks() const;
117 // Returns the time elapsed since the last prerender happened.
118 base::TimeDelta GetTimeSinceLastPrerender() const;
120 // Returns whether the PrerenderManager is currently within the prerender
121 // window - effectively, up to 30 seconds after a prerender tag has been
122 // observed.
123 bool WithinWindow() const;
125 // Returns the current experiment.
126 uint8 GetCurrentExperimentId() const;
128 // Returns whether or not there is currently an origin/experiment wash.
129 bool IsOriginExperimentWash() const;
131 // An integer indicating a Prerendering Experiment being currently conducted.
132 // (The last experiment ID seen).
133 uint8 last_experiment_id_;
135 // Origin of the last prerender seen.
136 Origin last_origin_;
138 // A boolean indicating that we have recently encountered a combination of
139 // different experiments and origins, making an attribution of PPLT's to
140 // experiments / origins impossible.
141 bool origin_experiment_wash_;
143 // The time when we last saw a prerender request coming from a renderer.
144 // This is used to record perceived PLT's for a certain amount of time
145 // from the point that we last saw a <link rel=prerender> tag.
146 base::TimeTicks last_prerender_seen_time_;
148 // Indicates whether we have recorded page load events after the most
149 // recent prerender. These must be initialized to true, so that we don't
150 // start recording events before the first prerender occurs.
151 bool seen_any_pageload_;
152 bool seen_pageload_started_after_prerender_;
154 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms);
157 } // namespace prerender
159 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_