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 // PrerenderHistograms is responsible for recording all prerender specific
21 // histograms for PrerenderManager. It keeps track of the type of prerender
22 // currently underway (based on the PrerenderOrigin of the most recent
23 // prerenders, and any experiments detected).
24 // PrerenderHistograms does not necessarily record all histograms related to
25 // prerendering, only the ones in the context of PrerenderManager.
26 class PrerenderHistograms
{
28 // Owned by a PrerenderManager object for the lifetime of the
30 PrerenderHistograms();
32 // Records the perceived page load time for a page - effectively the time from
33 // when the user navigates to a page to when it finishes loading. The actual
34 // load may have started prior to navigation due to prerender hints.
35 void RecordPerceivedPageLoadTime(Origin origin
,
36 base::TimeDelta perceived_page_load_time
,
38 bool was_complete_prerender
,
41 // Records, in a histogram, the percentage of the page load time that had
42 // elapsed by the time it is swapped in. Values outside of [0, 1.0] are
43 // invalid and ignored.
44 void RecordPercentLoadDoneAtSwapin(Origin origin
, double fraction
) const;
46 // Records the actual pageload time of a prerender that has not been swapped
47 // in yet, but finished loading.
48 void RecordPageLoadTimeNotSwappedIn(Origin origin
,
49 base::TimeDelta page_load_time
,
50 const GURL
& url
) const;
52 // Records the time from when a page starts prerendering to when the user
53 // navigates to it. This must be called on the UI thread.
54 void RecordTimeUntilUsed(Origin origin
,
55 base::TimeDelta time_until_used
) const;
57 // Record a PerSessionCount data point.
58 void RecordPerSessionCount(Origin origin
, int count
) const;
60 // Record time between two prerender requests.
61 void RecordTimeBetweenPrerenderRequests(Origin origin
,
62 base::TimeDelta time
) const;
64 // Record a final status of a prerendered page in a histogram.
65 void RecordFinalStatus(Origin origin
,
67 PrerenderContents::MatchCompleteStatus mc_status
,
68 FinalStatus final_status
) const;
70 // To be called when a new prerender is added.
71 void RecordPrerender(Origin origin
, const GURL
& url
);
73 // To be called when a new prerender is started.
74 void RecordPrerenderStarted(Origin origin
) const;
76 // To be called when we know how many prerenders are running after starting
78 void RecordConcurrency(size_t prerender_count
) const;
80 // Called when we swap in a prerender.
81 void RecordUsedPrerender(Origin origin
) const;
83 // Record the time since a page was recently visited.
84 void RecordTimeSinceLastRecentVisit(Origin origin
,
85 base::TimeDelta time
) const;
87 // Records a prerender event.
88 void RecordEvent(Origin origin
, uint8 experiment_id
, PrerenderEvent event
)
91 // Record a prerender cookie status bitmap. Must be in the range
92 // [0, PrerenderContents::kNumCookieStatuses).
93 void RecordCookieStatus(Origin origin
,
95 int cookie_status
) const;
98 base::TimeTicks
GetCurrentTimeTicks() const;
100 // Returns the time elapsed since the last prerender happened.
101 base::TimeDelta
GetTimeSinceLastPrerender() const;
103 // Returns whether the PrerenderManager is currently within the prerender
104 // window - effectively, up to 30 seconds after a prerender tag has been
106 bool WithinWindow() const;
108 // Returns the current experiment.
109 uint8
GetCurrentExperimentId() const;
111 // Returns whether or not there is currently an origin/experiment wash.
112 bool IsOriginExperimentWash() const;
114 // An integer indicating a Prerendering Experiment being currently conducted.
115 // (The last experiment ID seen).
116 uint8 last_experiment_id_
;
118 // Origin of the last prerender seen.
121 // A boolean indicating that we have recently encountered a combination of
122 // different experiments and origins, making an attribution of PPLT's to
123 // experiments / origins impossible.
124 bool origin_experiment_wash_
;
126 // The time when we last saw a prerender request coming from a renderer.
127 // This is used to record perceived PLT's for a certain amount of time
128 // from the point that we last saw a <link rel=prerender> tag.
129 base::TimeTicks last_prerender_seen_time_
;
131 // Indicates whether we have recorded page load events after the most
132 // recent prerender. These must be initialized to true, so that we don't
133 // start recording events before the first prerender occurs.
134 bool seen_any_pageload_
;
135 bool seen_pageload_started_after_prerender_
;
137 DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms
);
140 } // namespace prerender
142 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_