Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: components/page_load_metrics/browser/metrics_web_contents_observer.h

Issue 1449253002: [do not review][page_load_metrics] User Initiated Abort Tracking (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plm_navigation_start
Patch Set: Add 100ms condition to overriding ABORT_OTHER. Remove ABORT_OTHER for committed loads Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ 5 #ifndef COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_
6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_ 6 #define COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_OBSE RVER_H_
7 7
8 #include "base/containers/scoped_ptr_map.h" 8 #include "base/containers/scoped_ptr_map.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_vector.h"
10 #include "base/observer_list.h" 11 #include "base/observer_list.h"
11 #include "base/time/time.h" 12 #include "base/time/time.h"
12 #include "components/page_load_metrics/browser/page_load_metrics_observer.h" 13 #include "components/page_load_metrics/browser/page_load_metrics_observer.h"
13 #include "components/page_load_metrics/common/page_load_timing.h" 14 #include "components/page_load_metrics/common/page_load_timing.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_contents_user_data.h" 17 #include "content/public/browser/web_contents_user_data.h"
17 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
18 19
19 class PageLoadMetricsObserverTest; 20 class PageLoadMetricsObserverTest;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 "PageLoad.Timing2.NavigationToFirstPaint.Background"; 58 "PageLoad.Timing2.NavigationToFirstPaint.Background";
58 const char kBackgroundHistogramFirstImagePaint[] = 59 const char kBackgroundHistogramFirstImagePaint[] =
59 "PageLoad.Timing2.NavigationToFirstImagePaint.Background."; 60 "PageLoad.Timing2.NavigationToFirstImagePaint.Background.";
60 const char kBackgroundHistogramFirstContentfulPaint[] = 61 const char kBackgroundHistogramFirstContentfulPaint[] =
61 "PageLoad.Timing2.NavigationToFirstContentfulPaint.Background"; 62 "PageLoad.Timing2.NavigationToFirstContentfulPaint.Background";
62 63
63 const char kHistogramFirstBackground[] = 64 const char kHistogramFirstBackground[] =
64 "PageLoad.Timing2.NavigationToFirstBackground"; 65 "PageLoad.Timing2.NavigationToFirstBackground";
65 const char kHistogramFirstForeground[] = 66 const char kHistogramFirstForeground[] =
66 "PageLoad.Timing2.NavigationToFirstForeground"; 67 "PageLoad.Timing2.NavigationToFirstForeground";
68 const char kHistogramBackgroundBeforePaint[] =
69 "PageLoad.Timing2.NavigationToFirstBackgroundBeforePaint";
Bryan McQuade 2015/11/23 21:33:43 What do you think about using '.BeforePaint' as a
67 70
68 const char kProvisionalEvents[] = "PageLoad.Events.Provisional"; 71 const char kProvisionalEvents[] = "PageLoad.Events.Provisional";
69 const char kCommittedEvents[] = "PageLoad.Events.Committed"; 72 const char kCommittedEvents[] = "PageLoad.Events.Committed";
70 const char kBackgroundProvisionalEvents[] = 73 const char kBackgroundProvisionalEvents[] =
71 "PageLoad.Events.Provisional.Background"; 74 "PageLoad.Events.Provisional.Background";
72 const char kBackgroundCommittedEvents[] = 75 const char kBackgroundCommittedEvents[] =
73 "PageLoad.Events.Committed.Background"; 76 "PageLoad.Events.Committed.Background";
74 77
75 const char kErrorEvents[] = "PageLoad.Events.InternalError"; 78 const char kErrorEvents[] = "PageLoad.Events.InternalError";
76 79
80 const char kHistogramProvisionalAbortForwardBack[] =
81 "PageLoad.Timing2.Abort.Provisional.ForwardBackBeforePaint";
Bryan McQuade 2015/11/23 21:33:43 I know there are a bunch of different ways to name
Bryan McQuade 2015/11/23 21:33:43 nit: ForwardBack -> ForwardBackNavigation (even th
Charlie Harrison 2015/11/25 20:15:25 Done.
82 const char kHistogramProvisionalAbortReload[] =
83 "PageLoad.Timing2.Abort.Provisional.ReloadBeforePaint";
84 const char kHistogramProvisionalAbortNewNavigation[] =
85 "PageLoad.Timing2.Abort.Provisional.NewNavigationBeforePaint";
86 const char kHistogramProvisionalAbortStop[] =
87 "PageLoad.Timing2.Abort.Provisional.StopBeforePaint";
88 const char kHistogramProvisionalAbortClose[] =
89 "PageLoad.Timing2.Abort.Provisional.CloseBeforePaint";
90 const char kHistogramProvisionalAbortOther[] =
91 "PageLoad.Timing2.Abort.Provisional.OtherAbortBeforePaint";
92 const char kHistogramProvisionalAbortBackground[] =
Bryan McQuade 2015/11/23 21:33:42 looks like we aren't logging this anymore, but it
Charlie Harrison 2015/11/25 20:15:25 Yeah we can log this. I convinced myself it's usef
93 "PageLoad.Timing2.Abort.Provisional.BackgroundBeforePaint";
94 const char kHistogramCommittedAbortForwardBack[] =
95 "PageLoad.Timing2.Abort.Committed.ForwardBackBeforePaint";
96 const char kHistogramCommittedAbortReload[] =
97 "PageLoad.Timing2.Abort.Committed.ReloadBeforePaint";
98 const char kHistogramCommittedAbortNewNavigation[] =
99 "PageLoad.Timing2.Abort.Committed.NewNavigationBeforePaint";
100 const char kHistogramCommittedAbortStop[] =
101 "PageLoad.Timing2.Abort.Committed.StopBeforePaint";
102 const char kHistogramCommittedAbortClose[] =
103 "PageLoad.Timing2.Abort.Committed.CloseBeforePaint";
104
77 const char kRapporMetricsNameCoarseTiming[] = 105 const char kRapporMetricsNameCoarseTiming[] =
78 "PageLoad.CoarseTiming.NavigationToFirstContentfulPaint"; 106 "PageLoad.CoarseTiming.NavigationToFirstContentfulPaint";
79 107
80 // NOTE: Some of these histograms are separated into a separate histogram 108 // NOTE: Some of these histograms are separated into a separate histogram
81 // specified by the ".Background" suffix. For these events, we put them into the 109 // specified by the ".Background" suffix. For these events, we put them into the
82 // background histogram if the web contents was ever in the background from 110 // background histogram if the web contents was ever in the background from
83 // navigation start to the event in question. 111 // navigation start to the event in question.
84 112
85 // ProvisionalLoadEvents count all main frame navigations before they commit. 113 // ProvisionalLoadEvents count all main frame navigations before they commit.
86 // The events in this enum are all disjoint, and summing them yields the total 114 // The events in this enum are all disjoint, and summing them yields the total
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 ERR_IPC_FROM_BAD_URL_SCHEME, 196 ERR_IPC_FROM_BAD_URL_SCHEME,
169 197
170 // If we track a navigation, but the renderer sends us no IPCs. This could 198 // If we track a navigation, but the renderer sends us no IPCs. This could
171 // occur if the browser filters loads less aggressively than the renderer. 199 // occur if the browser filters loads less aggressively than the renderer.
172 ERR_NO_IPCS_RECEIVED, 200 ERR_NO_IPCS_RECEIVED,
173 201
174 // Add values before this final count. 202 // Add values before this final count.
175 ERR_LAST_ENTRY 203 ERR_LAST_ENTRY
176 }; 204 };
177 205
206 // This enum represents how a page load ends. If the action occurs before the
207 // page load finishes (or reaches some point like first paint), then we consider
208 // the load to be aborted.
209 enum UserAbortType {
210 // Represents no abort.
211 ABORT_NONE,
212
213 // If the user presses reload or shift-reload.
214 ABORT_RELOAD,
215
216 // The user presses the back/forward button.
217 ABORT_FORWARD_BACK,
218
219 // If the navigation is replaced by a new navigation. This includes link
220 // clicks, typing in the omnibox (not a reload), and form submissions.
221 ABORT_NEW_NAVIGATION,
222
223 // If the user presses the stop X button.
224 ABORT_STOP,
225
226 // If the navigation is aborted by closing the tab or browser.
227 ABORT_CLOSE,
228
229 // We don't know why the navigation aborted. This is the value we assign to an
230 // aborted load if the only signal we get is a provisional load finishing
231 // without committing, either without error or with net::ERR_ABORTED.
232 ABORT_OTHER,
233
234 // Add values before this final count.
235 ABORT_LAST_ENTRY
236 };
237
178 // This class serves as a functional interface to various chrome// features. 238 // This class serves as a functional interface to various chrome// features.
179 // Impl version is defined in chrome/browser/page_load_metrics. 239 // Impl version is defined in chrome/browser/page_load_metrics.
180 class PageLoadMetricsEmbedderInterface { 240 class PageLoadMetricsEmbedderInterface {
181 public: 241 public:
182 virtual ~PageLoadMetricsEmbedderInterface() {} 242 virtual ~PageLoadMetricsEmbedderInterface() {}
183 virtual rappor::RapporService* GetRapporService() = 0; 243 virtual rappor::RapporService* GetRapporService() = 0;
184 virtual bool IsPrerendering(content::WebContents* web_contents) = 0; 244 virtual bool IsPrerendering(content::WebContents* web_contents) = 0;
185 }; 245 };
186 246
187 // This class tracks a given page load, starting from navigation start / 247 // This class tracks a given page load, starting from navigation start /
(...skipping 14 matching lines...) Expand all
202 void Commit(content::NavigationHandle* navigation_handle); 262 void Commit(content::NavigationHandle* navigation_handle);
203 void WebContentsHidden(); 263 void WebContentsHidden();
204 void WebContentsShown(); 264 void WebContentsShown();
205 265
206 // Returns true if the timing was successfully updated. 266 // Returns true if the timing was successfully updated.
207 bool UpdateTiming(const PageLoadTiming& timing); 267 bool UpdateTiming(const PageLoadTiming& timing);
208 void RecordProvisionalEvent(ProvisionalLoadEvent event); 268 void RecordProvisionalEvent(ProvisionalLoadEvent event);
209 void RecordCommittedEvent(CommittedLoadEvent event, bool backgrounded); 269 void RecordCommittedEvent(CommittedLoadEvent event, bool backgrounded);
210 bool HasBackgrounded(); 270 bool HasBackgrounded();
211 271
272 // If the user performs some abort-like action while we are tracking this page
273 // load, notify the tracker. Note that we may not classify this as an abort if
274 // we've already performed a first paint.
275 void NotifyAbort(UserAbortType abort_type, const base::TimeTicks& timestamp);
276
212 private: 277 private:
213 PageLoadExtraInfo GetPageLoadMetricsInfo(); 278 PageLoadExtraInfo GetPageLoadMetricsInfo();
214 // Only valid to call post-commit. 279 // Only valid to call post-commit.
215 const GURL& GetCommittedURL(); 280 const GURL& GetCommittedURL();
216 281
217 base::TimeDelta GetBackgroundDelta(); 282 base::TimeDelta GetBackgroundDelta();
218 void RecordTimingHistograms(); 283 void RecordTimingHistograms();
284 void RecordAbortTimingHistograms();
219 void RecordRappor(); 285 void RecordRappor();
220 286
221 bool has_commit_; 287 bool has_commit_;
222 288
223 // The navigation start in TimeTicks, not the wall time reported by Blink. 289 // The navigation start in TimeTicks, not the wall time reported by Blink.
224 const base::TimeTicks navigation_start_; 290 const base::TimeTicks navigation_start_;
225 291
292 // Will be ABORT_NONE if we have not aborted this load yet. Otherwise will
293 // be the first abort action the user performed.
294 UserAbortType abort_type_;
295 base::TimeTicks abort_time_;
296
226 // We record separate metrics for events that occur after a background, 297 // We record separate metrics for events that occur after a background,
227 // because metrics like layout/paint are delayed artificially 298 // because metrics like layout/paint are delayed artificially
228 // when they occur in the background. 299 // when they occur in the background.
229 base::TimeTicks background_time_; 300 base::TimeTicks background_time_;
230 base::TimeTicks foreground_time_; 301 base::TimeTicks foreground_time_;
231 bool started_in_foreground_; 302 bool started_in_foreground_;
232 303
233 PageLoadTiming timing_; 304 PageLoadTiming timing_;
234 GURL url_; 305 GURL url_;
235 306
(...skipping 29 matching lines...) Expand all
265 336
266 // content::WebContentsObserver implementation: 337 // content::WebContentsObserver implementation:
267 bool OnMessageReceived(const IPC::Message& message, 338 bool OnMessageReceived(const IPC::Message& message,
268 content::RenderFrameHost* render_frame_host) override; 339 content::RenderFrameHost* render_frame_host) override;
269 void DidStartNavigation( 340 void DidStartNavigation(
270 content::NavigationHandle* navigation_handle) override; 341 content::NavigationHandle* navigation_handle) override;
271 void DidFinishNavigation( 342 void DidFinishNavigation(
272 content::NavigationHandle* navigation_handle) override; 343 content::NavigationHandle* navigation_handle) override;
273 void DidRedirectNavigation( 344 void DidRedirectNavigation(
274 content::NavigationHandle* navigation_handle) override; 345 content::NavigationHandle* navigation_handle) override;
275 346 void NavigationStopped() override;
276 void WasShown() override; 347 void WasShown() override;
277 void WasHidden() override; 348 void WasHidden() override;
278
279 void RenderProcessGone(base::TerminationStatus status) override; 349 void RenderProcessGone(base::TerminationStatus status) override;
280 350
281 private: 351 private:
282 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 352 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
283 353
354 // Notify all loads, provisional and committed, that we performed an action
355 // that might abort them.
356 void NotifyAbortAllLoads(UserAbortType abort_type);
357 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type,
358 const base::TimeTicks& timestamp);
359
284 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); 360 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing);
285 361
286 // True if the web contents is currently in the foreground. 362 // True if the web contents is currently in the foreground.
287 bool in_foreground_; 363 bool in_foreground_;
288 364
289 // This map tracks all of the navigations ongoing that are not committed 365 // This map tracks all of the navigations ongoing that are not committed
290 // yet. Once a navigation is committed, it moves from the map to 366 // yet. Once a navigation is committed, it moves from the map to
291 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only 367 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
292 // valid until commit time, when we remove it from the map. 368 // valid until commit time, when we remove it from the map.
293 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> 369 base::ScopedPtrMap<content::NavigationHandle*, scoped_ptr<PageLoadTracker>>
294 provisional_loads_; 370 provisional_loads_;
371 // Tracks aborted provisional loads for a little bit longer than usual (one
372 // more navigation commit at the max), in order to better understand how the
373 // navigation failed. This is because most provisional loads are destroyed and
374 // vanish before we get signal about what caused the abort (new navigation,
375 // stop button, etc.).
376 ScopedVector<PageLoadTracker> aborted_provisional_loads_;
295 scoped_ptr<PageLoadTracker> committed_load_; 377 scoped_ptr<PageLoadTracker> committed_load_;
296 378
297 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; 379 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_;
298 base::ObserverList<PageLoadMetricsObserver, true> observers_; 380 base::ObserverList<PageLoadMetricsObserver, true> observers_;
299 381
300 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 382 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
301 }; 383 };
302 384
303 } // namespace page_load_metrics 385 } // namespace page_load_metrics
304 386
305 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ 387 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698