• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_
7 
8 #include <string>
9 
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"
16 #include "url/gurl.h"
17 
18 namespace prerender {
19 
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 {
27  public:
28   // Owned by a PrerenderManager object for the lifetime of the
29   // PrerenderManager.
30   PrerenderHistograms();
31 
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,
37                                    bool was_prerender,
38                                    bool was_complete_prerender,
39                                    const GURL& url);
40 
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;
45 
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;
51 
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;
56 
57   // Record a PerSessionCount data point.
58   void RecordPerSessionCount(Origin origin, int count) const;
59 
60   // Record time between two prerender requests.
61   void RecordTimeBetweenPrerenderRequests(Origin origin,
62                                           base::TimeDelta time) const;
63 
64   // Record a final status of a prerendered page in a histogram.
65   void RecordFinalStatus(Origin origin,
66                          uint8 experiment_id,
67                          PrerenderContents::MatchCompleteStatus mc_status,
68                          FinalStatus final_status) const;
69 
70   // To be called when a new prerender is added.
71   void RecordPrerender(Origin origin, const GURL& url);
72 
73   // To be called when a new prerender is started.
74   void RecordPrerenderStarted(Origin origin) const;
75 
76   // To be called when we know how many prerenders are running after starting
77   // a prerender.
78   void RecordConcurrency(size_t prerender_count) const;
79 
80   // Called when we swap in a prerender.
81   void RecordUsedPrerender(Origin origin) const;
82 
83   // Record the time since a page was recently visited.
84   void RecordTimeSinceLastRecentVisit(Origin origin,
85                                       base::TimeDelta time) const;
86 
87   // Record a percentage of pixels of the final page already in place at
88   // swap-in.
89   void RecordFractionPixelsFinalAtSwapin(Origin origin, double fraction) const;
90 
91   // Records a prerender event.
92   void RecordEvent(Origin origin, uint8 experiment_id, PrerenderEvent event)
93       const;
94 
95   // Record a prerender cookie status bitmap. Must be in the range
96   // [0, PrerenderContents::kNumCookieStatuses).
97   void RecordCookieStatus(Origin origin,
98                           uint8 experiment_id,
99                           int cookie_status) const;
100 
101   void RecordPrerenderPageVisitedStatus(Origin origin,
102                                         uint8 experiment_id,
103                                         bool visited_before) const;
104 
105  private:
106   base::TimeTicks GetCurrentTimeTicks() const;
107 
108   // Returns the time elapsed since the last prerender happened.
109   base::TimeDelta GetTimeSinceLastPrerender() const;
110 
111   // Returns whether the PrerenderManager is currently within the prerender
112   // window - effectively, up to 30 seconds after a prerender tag has been
113   // observed.
114   bool WithinWindow() const;
115 
116   // Returns the current experiment.
117   uint8 GetCurrentExperimentId() const;
118 
119   // Returns whether or not there is currently an origin/experiment wash.
120   bool IsOriginExperimentWash() const;
121 
122   // An integer indicating a Prerendering Experiment being currently conducted.
123   // (The last experiment ID seen).
124   uint8 last_experiment_id_;
125 
126   // Origin of the last prerender seen.
127   Origin last_origin_;
128 
129   // A boolean indicating that we have recently encountered a combination of
130   // different experiments and origins, making an attribution of PPLT's to
131   // experiments / origins impossible.
132   bool origin_experiment_wash_;
133 
134   // The time when we last saw a prerender request coming from a renderer.
135   // This is used to record perceived PLT's for a certain amount of time
136   // from the point that we last saw a <link rel=prerender> tag.
137   base::TimeTicks last_prerender_seen_time_;
138 
139   // Indicates whether we have recorded page load events after the most
140   // recent prerender.  These must be initialized to true, so that we don't
141   // start recording events before the first prerender occurs.
142   bool seen_any_pageload_;
143   bool seen_pageload_started_after_prerender_;
144 
145   DISALLOW_COPY_AND_ASSIGN(PrerenderHistograms);
146 };
147 
148 }  // namespace prerender
149 
150 #endif  // CHROME_BROWSER_PRERENDER_PRERENDER_HISTOGRAMS_H_
151