OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_ |
6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_ | 6 #define CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" | 13 #include "chrome/browser/page_load_metrics/page_load_metrics_observer.h" |
| 14 #include "chrome/browser/page_load_metrics/user_input_tracker.h" |
14 #include "chrome/common/page_load_metrics/page_load_timing.h" | 15 #include "chrome/common/page_load_metrics/page_load_timing.h" |
15 #include "ui/base/page_transition_types.h" | 16 #include "ui/base/page_transition_types.h" |
16 | 17 |
17 class GURL; | 18 class GURL; |
18 | 19 |
19 namespace blink { | 20 namespace blink { |
20 class WebInputEvent; | 21 class WebInputEvent; |
21 } // namespace blink | 22 } // namespace blink |
22 | 23 |
23 namespace content { | 24 namespace content { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 class PageLoadTracker { | 121 class PageLoadTracker { |
121 public: | 122 public: |
122 // Caller must guarantee that the embedder_interface pointer outlives this | 123 // Caller must guarantee that the embedder_interface pointer outlives this |
123 // class. The PageLoadTracker must not hold on to | 124 // class. The PageLoadTracker must not hold on to |
124 // currently_committed_load_or_null or navigation_handle beyond the scope of | 125 // currently_committed_load_or_null or navigation_handle beyond the scope of |
125 // the constructor. | 126 // the constructor. |
126 PageLoadTracker(bool in_foreground, | 127 PageLoadTracker(bool in_foreground, |
127 PageLoadMetricsEmbedderInterface* embedder_interface, | 128 PageLoadMetricsEmbedderInterface* embedder_interface, |
128 const GURL& currently_committed_url, | 129 const GURL& currently_committed_url, |
129 content::NavigationHandle* navigation_handle, | 130 content::NavigationHandle* navigation_handle, |
| 131 UserInitiatedInfo user_initiated_info, |
130 int aborted_chain_size, | 132 int aborted_chain_size, |
131 int aborted_chain_size_same_url); | 133 int aborted_chain_size_same_url); |
132 ~PageLoadTracker(); | 134 ~PageLoadTracker(); |
133 void Redirect(content::NavigationHandle* navigation_handle); | 135 void Redirect(content::NavigationHandle* navigation_handle); |
134 void Commit(content::NavigationHandle* navigation_handle); | 136 void Commit(content::NavigationHandle* navigation_handle); |
135 void FailedProvisionalLoad(content::NavigationHandle* navigation_handle); | 137 void FailedProvisionalLoad(content::NavigationHandle* navigation_handle); |
136 void WebContentsHidden(); | 138 void WebContentsHidden(); |
137 void WebContentsShown(); | 139 void WebContentsShown(); |
138 | 140 |
139 void OnInputEvent(const blink::WebInputEvent& event); | 141 void OnInputEvent(const blink::WebInputEvent& event); |
(...skipping 28 matching lines...) Expand all Loading... |
168 void AddObserver(std::unique_ptr<PageLoadMetricsObserver> observer); | 170 void AddObserver(std::unique_ptr<PageLoadMetricsObserver> observer); |
169 | 171 |
170 // If the user performs some abort-like action while we are tracking this page | 172 // If the user performs some abort-like action while we are tracking this page |
171 // load, notify the tracker. Note that we may not classify this as an abort if | 173 // load, notify the tracker. Note that we may not classify this as an abort if |
172 // we've already performed a first paint. | 174 // we've already performed a first paint. |
173 // is_certainly_browser_timestamp signifies if the timestamp passed is taken | 175 // is_certainly_browser_timestamp signifies if the timestamp passed is taken |
174 // in the | 176 // in the |
175 // browser process or not. We need this to possibly clamp browser timestamp on | 177 // browser process or not. We need this to possibly clamp browser timestamp on |
176 // a machine with inter process time tick skew. | 178 // a machine with inter process time tick skew. |
177 void NotifyAbort(UserAbortType abort_type, | 179 void NotifyAbort(UserAbortType abort_type, |
178 bool user_initiated, | 180 UserInitiatedInfo user_initiated_info, |
179 base::TimeTicks timestamp, | 181 base::TimeTicks timestamp, |
180 bool is_certainly_browser_timestamp); | 182 bool is_certainly_browser_timestamp); |
181 void UpdateAbort(UserAbortType abort_type, | 183 void UpdateAbort(UserAbortType abort_type, |
182 bool user_initiated, | 184 UserInitiatedInfo user_initiated_info, |
183 base::TimeTicks timestamp, | 185 base::TimeTicks timestamp, |
184 bool is_certainly_browser_timestamp); | 186 bool is_certainly_browser_timestamp); |
185 | 187 |
186 // This method returns true if this page load has been aborted with type of | 188 // This method returns true if this page load has been aborted with type of |
187 // ABORT_OTHER, and the |abort_cause_time| is within a sufficiently close | 189 // ABORT_OTHER, and the |abort_cause_time| is within a sufficiently close |
188 // delta to when it was aborted. Note that only provisional loads can be | 190 // delta to when it was aborted. Note that only provisional loads can be |
189 // aborted with ABORT_OTHER. While this heuristic is coarse, it works better | 191 // aborted with ABORT_OTHER. While this heuristic is coarse, it works better |
190 // and is simpler than other feasible methods. See https://goo.gl/WKRG98. | 192 // and is simpler than other feasible methods. See https://goo.gl/WKRG98. |
191 bool IsLikelyProvisionalAbort(base::TimeTicks abort_cause_time) const; | 193 bool IsLikelyProvisionalAbort(base::TimeTicks abort_cause_time) const; |
192 | 194 |
193 bool MatchesOriginalNavigation(content::NavigationHandle* navigation_handle); | 195 bool MatchesOriginalNavigation(content::NavigationHandle* navigation_handle); |
194 | 196 |
195 // Only valid to call post-commit. | 197 // Only valid to call post-commit. |
196 const GURL& committed_url() const { | 198 const GURL& committed_url() const { |
197 DCHECK(!committed_url_.is_empty()); | 199 DCHECK(!committed_url_.is_empty()); |
198 return committed_url_; | 200 return committed_url_; |
199 } | 201 } |
200 | 202 |
201 base::TimeTicks navigation_start() const { return navigation_start_; } | 203 base::TimeTicks navigation_start() const { return navigation_start_; } |
202 | 204 |
203 PageLoadExtraInfo ComputePageLoadExtraInfo(); | 205 PageLoadExtraInfo ComputePageLoadExtraInfo(); |
204 | 206 |
205 ui::PageTransition page_transition() const { return page_transition_; } | 207 ui::PageTransition page_transition() const { return page_transition_; } |
206 | 208 |
| 209 UserInitiatedInfo user_initiated_info() const { return user_initiated_info_; } |
| 210 |
| 211 UserInputTracker* input_tracker() { return &input_tracker_; } |
| 212 |
207 private: | 213 private: |
208 // This function converts a TimeTicks value taken in the browser process | 214 // This function converts a TimeTicks value taken in the browser process |
209 // to navigation_start_ if: | 215 // to navigation_start_ if: |
210 // - base::TimeTicks is not comparable across processes because the clock | 216 // - base::TimeTicks is not comparable across processes because the clock |
211 // is not system wide monotonic. | 217 // is not system wide monotonic. |
212 // - *event_time < navigation_start_ | 218 // - *event_time < navigation_start_ |
213 void ClampBrowserTimestampIfInterProcessTimeTickSkew( | 219 void ClampBrowserTimestampIfInterProcessTimeTickSkew( |
214 base::TimeTicks* event_time); | 220 base::TimeTicks* event_time); |
215 | 221 |
216 void UpdateAbortInternal(UserAbortType abort_type, | 222 void UpdateAbortInternal(UserAbortType abort_type, |
217 bool user_initiated, | 223 UserInitiatedInfo user_initiated_info, |
218 base::TimeTicks timestamp, | 224 base::TimeTicks timestamp, |
219 bool is_certainly_browser_timestamp); | 225 bool is_certainly_browser_timestamp); |
220 | 226 |
221 // If |final_navigation| is null, then this is an "unparented" abort chain, | 227 // If |final_navigation| is null, then this is an "unparented" abort chain, |
222 // and represents a sequence of provisional aborts that never ends with a | 228 // and represents a sequence of provisional aborts that never ends with a |
223 // committed load. | 229 // committed load. |
224 void LogAbortChainHistograms(content::NavigationHandle* final_navigation); | 230 void LogAbortChainHistograms(content::NavigationHandle* final_navigation); |
225 | 231 |
| 232 UserInputTracker input_tracker_; |
| 233 |
226 // Whether we stopped tracking this navigation after it was initiated. We may | 234 // Whether we stopped tracking this navigation after it was initiated. We may |
227 // stop tracking a navigation if it doesn't meet the criteria for tracking | 235 // stop tracking a navigation if it doesn't meet the criteria for tracking |
228 // metrics in DidFinishNavigation. | 236 // metrics in DidFinishNavigation. |
229 bool did_stop_tracking_; | 237 bool did_stop_tracking_; |
230 | 238 |
231 // Whether the application went into the background when this PageLoadTracker | 239 // Whether the application went into the background when this PageLoadTracker |
232 // was active. This is a temporary boolean for UMA tracking. | 240 // was active. This is a temporary boolean for UMA tracking. |
233 bool app_entered_background_; | 241 bool app_entered_background_; |
234 | 242 |
235 // The navigation start in TimeTicks, not the wall time reported by Blink. | 243 // The navigation start in TimeTicks, not the wall time reported by Blink. |
(...skipping 12 matching lines...) Expand all Loading... |
248 UserAbortType abort_type_; | 256 UserAbortType abort_type_; |
249 | 257 |
250 // Whether the abort for this page load was user initiated. For example, if | 258 // Whether the abort for this page load was user initiated. For example, if |
251 // this page load was aborted by a new navigation, this field tracks whether | 259 // this page load was aborted by a new navigation, this field tracks whether |
252 // that new navigation was user-initiated. This field is only useful if this | 260 // that new navigation was user-initiated. This field is only useful if this |
253 // page load's abort type is a value other than ABORT_NONE. Note that this | 261 // page load's abort type is a value other than ABORT_NONE. Note that this |
254 // value is currently experimental, and is subject to change. In particular, | 262 // value is currently experimental, and is subject to change. In particular, |
255 // this field is never set to true for some abort types, such as stop and | 263 // this field is never set to true for some abort types, such as stop and |
256 // close, since we don't yet have sufficient instrumentation to know if a stop | 264 // close, since we don't yet have sufficient instrumentation to know if a stop |
257 // or close was caused by a user action. | 265 // or close was caused by a user action. |
258 bool abort_user_initiated_; | 266 UserInitiatedInfo abort_user_initiated_info_; |
259 | 267 |
260 base::TimeTicks abort_time_; | 268 base::TimeTicks abort_time_; |
261 | 269 |
262 // We record separate metrics for events that occur after a background, | 270 // We record separate metrics for events that occur after a background, |
263 // because metrics like layout/paint are delayed artificially | 271 // because metrics like layout/paint are delayed artificially |
264 // when they occur in the background. | 272 // when they occur in the background. |
265 base::TimeTicks background_time_; | 273 base::TimeTicks background_time_; |
266 base::TimeTicks foreground_time_; | 274 base::TimeTicks foreground_time_; |
267 bool started_in_foreground_; | 275 bool started_in_foreground_; |
268 | 276 |
269 PageLoadTiming timing_; | 277 PageLoadTiming timing_; |
270 PageLoadMetadata metadata_; | 278 PageLoadMetadata metadata_; |
271 | 279 |
272 ui::PageTransition page_transition_; | 280 ui::PageTransition page_transition_; |
273 | 281 |
274 // Note: these are only approximations, based on WebContents attribution from | 282 // Note: these are only approximations, based on WebContents attribution from |
275 // ResourceRequestInfo objects while this is the currently committed load in | 283 // ResourceRequestInfo objects while this is the currently committed load in |
276 // the WebContents. | 284 // the WebContents. |
277 int num_cache_requests_; | 285 int num_cache_requests_; |
278 int num_network_requests_; | 286 int num_network_requests_; |
279 | 287 |
280 // This is derived from the user gesture bit in the renderer. For browser | 288 // Whether this page load was user initiated. |
281 // initiated navigations this will always be true. | 289 UserInitiatedInfo user_initiated_info_; |
282 bool user_initiated_; | |
283 | 290 |
284 // This is a subtle member. If a provisional load A gets aborted by | 291 // This is a subtle member. If a provisional load A gets aborted by |
285 // provisional load B, which gets aborted by C that eventually commits, then | 292 // provisional load B, which gets aborted by C that eventually commits, then |
286 // there exists an abort chain of length 2, starting at A's navigation_start. | 293 // there exists an abort chain of length 2, starting at A's navigation_start. |
287 // This is useful because it allows histograming abort chain lengths based on | 294 // This is useful because it allows histograming abort chain lengths based on |
288 // what the last load's transition type is. i.e. holding down F-5 to spam | 295 // what the last load's transition type is. i.e. holding down F-5 to spam |
289 // reload will produce a long chain with the RELOAD transition. | 296 // reload will produce a long chain with the RELOAD transition. |
290 const int aborted_chain_size_; | 297 const int aborted_chain_size_; |
291 | 298 |
292 // This member counts consecutive provisional aborts that share a url. It will | 299 // This member counts consecutive provisional aborts that share a url. It will |
293 // always be less than or equal to |aborted_chain_size_|. | 300 // always be less than or equal to |aborted_chain_size_|. |
294 const int aborted_chain_size_same_url_; | 301 const int aborted_chain_size_same_url_; |
295 | 302 |
296 // Interface to chrome features. Must outlive the class. | 303 // Interface to chrome features. Must outlive the class. |
297 PageLoadMetricsEmbedderInterface* const embedder_interface_; | 304 PageLoadMetricsEmbedderInterface* const embedder_interface_; |
298 | 305 |
299 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_; | 306 std::vector<std::unique_ptr<PageLoadMetricsObserver>> observers_; |
300 | 307 |
301 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); | 308 DISALLOW_COPY_AND_ASSIGN(PageLoadTracker); |
302 }; | 309 }; |
303 | 310 |
304 } // namespace page_load_metrics | 311 } // namespace page_load_metrics |
305 | 312 |
306 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_ | 313 #endif // CHROME_BROWSER_PAGE_LOAD_METRICS_PAGE_LOAD_TRACKER_H_ |
OLD | NEW |