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

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

Issue 1476503004: [page_load_metrics] User Initiated Abort Tracking (Observer version) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new_observer
Patch Set: Update for EventOccurredInForeground Created 5 years 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 <map> 8 #include <map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/scoped_vector.h"
Bryan McQuade 2015/12/10 17:04:23 now that we're using std::vector directly, can we
Charlie Harrison 2015/12/10 17:59:31 Done. Also removing observer_list.
11 #include "base/observer_list.h" 12 #include "base/observer_list.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "components/page_load_metrics/browser/page_load_metrics_observer.h" 14 #include "components/page_load_metrics/browser/page_load_metrics_observer.h"
14 #include "components/page_load_metrics/common/page_load_timing.h" 15 #include "components/page_load_metrics/common/page_load_timing.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/browser/web_contents_user_data.h" 18 #include "content/public/browser/web_contents_user_data.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
19 20
20 class PageLoadMetricsObserverTest; 21 class PageLoadMetricsObserverTest;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 66
66 const char kHistogramFirstContentfulPaintHigh[] = 67 const char kHistogramFirstContentfulPaintHigh[] =
67 "PageLoad.Timing2.NavigationToFirstContentfulPaint.HighResolutionClock"; 68 "PageLoad.Timing2.NavigationToFirstContentfulPaint.HighResolutionClock";
68 const char kHistogramFirstContentfulPaintLow[] = 69 const char kHistogramFirstContentfulPaintLow[] =
69 "PageLoad.Timing2.NavigationToFirstContentfulPaint.LowResolutionClock"; 70 "PageLoad.Timing2.NavigationToFirstContentfulPaint.LowResolutionClock";
70 71
71 const char kHistogramFirstBackground[] = 72 const char kHistogramFirstBackground[] =
72 "PageLoad.Timing2.NavigationToFirstBackground"; 73 "PageLoad.Timing2.NavigationToFirstBackground";
73 const char kHistogramFirstForeground[] = 74 const char kHistogramFirstForeground[] =
74 "PageLoad.Timing2.NavigationToFirstForeground"; 75 "PageLoad.Timing2.NavigationToFirstForeground";
76 const char kHistogramBackgroundBeforePaint[] =
77 "PageLoad.Timing2.NavigationToFirstBackgroundBeforePaint";
78 const char kHistogramProvisionalBackground[] =
79 "PageLoad.Timing2.Provisional.NavigationToFirstBackground";
Bryan McQuade 2015/12/10 17:04:23 I prefer the name 'BeforeCommit' rather than 'Prov
Charlie Harrison 2015/12/10 17:59:31 Done. Switched it to using BeforeCommit / AfterCom
75 80
76 const char kProvisionalEvents[] = "PageLoad.Events.Provisional"; 81 const char kProvisionalEvents[] = "PageLoad.Events.Provisional";
77 const char kCommittedEvents[] = "PageLoad.Events.Committed"; 82 const char kCommittedEvents[] = "PageLoad.Events.Committed";
78 const char kBackgroundProvisionalEvents[] = 83 const char kBackgroundProvisionalEvents[] =
79 "PageLoad.Events.Provisional.Background"; 84 "PageLoad.Events.Provisional.Background";
80 const char kBackgroundCommittedEvents[] = 85 const char kBackgroundCommittedEvents[] =
81 "PageLoad.Events.Committed.Background"; 86 "PageLoad.Events.Committed.Background";
82 87
83 const char kErrorEvents[] = "PageLoad.Events.InternalError"; 88 const char kErrorEvents[] = "PageLoad.Events.InternalError";
84 89
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 void RecordProvisionalEvent(ProvisionalLoadEvent event); 222 void RecordProvisionalEvent(ProvisionalLoadEvent event);
218 void RecordCommittedEvent(CommittedRelevantLoadEvent event, 223 void RecordCommittedEvent(CommittedRelevantLoadEvent event,
219 bool backgrounded); 224 bool backgrounded);
220 bool HasBackgrounded(); 225 bool HasBackgrounded();
221 226
222 void set_renderer_tracked(bool renderer_tracked); 227 void set_renderer_tracked(bool renderer_tracked);
223 bool renderer_tracked() { return renderer_tracked_; } 228 bool renderer_tracked() { return renderer_tracked_; }
224 229
225 void AddObserver(scoped_ptr<PageLoadMetricsObserver> observer); 230 void AddObserver(scoped_ptr<PageLoadMetricsObserver> observer);
226 231
232 // If the user performs some abort-like action while we are tracking this page
233 // load, notify the tracker. Note that we may not classify this as an abort if
234 // we've already performed a first paint.
235 void NotifyAbort(UserAbortType abort_type, const base::TimeTicks& timestamp);
236
227 private: 237 private:
228 PageLoadExtraInfo GetPageLoadMetricsInfo(); 238 PageLoadExtraInfo GetPageLoadMetricsInfo();
229 // Only valid to call post-commit. 239 // Only valid to call post-commit.
230 const GURL& committed_url(); 240 const GURL& committed_url();
231 241
232 base::TimeDelta GetBackgroundDelta(); 242 void RecordTimingHistograms(const PageLoadExtraInfo& info);
233 void RecordTimingHistograms(); 243 void RecordRappor(const PageLoadExtraInfo& info);
234 void RecordRappor();
235 244
236 // Whether the renderer should be sending timing IPCs to this page load. 245 // Whether the renderer should be sending timing IPCs to this page load.
237 bool renderer_tracked_; 246 bool renderer_tracked_;
238 247
239 bool has_commit_; 248 bool has_commit_;
240 249
241 // The navigation start in TimeTicks, not the wall time reported by Blink. 250 // The navigation start in TimeTicks, not the wall time reported by Blink.
242 const base::TimeTicks navigation_start_; 251 const base::TimeTicks navigation_start_;
243 252
253 // Will be ABORT_NONE if we have not aborted this load yet. Otherwise will
254 // be the first abort action the user performed.
255 UserAbortType abort_type_;
256 base::TimeTicks abort_time_;
257
244 // We record separate metrics for events that occur after a background, 258 // We record separate metrics for events that occur after a background,
245 // because metrics like layout/paint are delayed artificially 259 // because metrics like layout/paint are delayed artificially
246 // when they occur in the background. 260 // when they occur in the background.
247 base::TimeTicks background_time_; 261 base::TimeTicks background_time_;
248 base::TimeTicks foreground_time_; 262 base::TimeTicks foreground_time_;
249 bool started_in_foreground_; 263 bool started_in_foreground_;
250 264
251 PageLoadTiming timing_; 265 PageLoadTiming timing_;
252 GURL url_; 266 GURL url_;
253 267
(...skipping 24 matching lines...) Expand all
278 292
279 // content::WebContentsObserver implementation: 293 // content::WebContentsObserver implementation:
280 bool OnMessageReceived(const IPC::Message& message, 294 bool OnMessageReceived(const IPC::Message& message,
281 content::RenderFrameHost* render_frame_host) override; 295 content::RenderFrameHost* render_frame_host) override;
282 void DidStartNavigation( 296 void DidStartNavigation(
283 content::NavigationHandle* navigation_handle) override; 297 content::NavigationHandle* navigation_handle) override;
284 void DidFinishNavigation( 298 void DidFinishNavigation(
285 content::NavigationHandle* navigation_handle) override; 299 content::NavigationHandle* navigation_handle) override;
286 void DidRedirectNavigation( 300 void DidRedirectNavigation(
287 content::NavigationHandle* navigation_handle) override; 301 content::NavigationHandle* navigation_handle) override;
288 302 void NavigationStopped() override;
289 void WasShown() override; 303 void WasShown() override;
290 void WasHidden() override; 304 void WasHidden() override;
291
292 void RenderProcessGone(base::TerminationStatus status) override; 305 void RenderProcessGone(base::TerminationStatus status) override;
293 306
294 private: 307 private:
295 friend class content::WebContentsUserData<MetricsWebContentsObserver>; 308 friend class content::WebContentsUserData<MetricsWebContentsObserver>;
296 309
310 // Notify all loads, provisional and committed, that we performed an action
311 // that might abort them.
312 void NotifyAbortAllLoads(UserAbortType abort_type);
313 void NotifyAbortAllLoadsWithTimestamp(UserAbortType abort_type,
314 const base::TimeTicks& timestamp);
315
297 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing); 316 void OnTimingUpdated(content::RenderFrameHost*, const PageLoadTiming& timing);
298 317
299 // True if the web contents is currently in the foreground. 318 // True if the web contents is currently in the foreground.
300 bool in_foreground_; 319 bool in_foreground_;
301 320
302 // The PageLoadTrackers must be deleted before the |embedded_interface_|, 321 // The PageLoadTrackers must be deleted before the |embedded_interface_|,
303 // because they hold a pointer to the |embedder_interface_|. 322 // because they hold a pointer to the |embedder_interface_|.
304 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_; 323 scoped_ptr<PageLoadMetricsEmbedderInterface> embedder_interface_;
305 324
306 // This map tracks all of the navigations ongoing that are not committed 325 // This map tracks all of the navigations ongoing that are not committed
307 // yet. Once a navigation is committed, it moves from the map to 326 // yet. Once a navigation is committed, it moves from the map to
308 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only 327 // committed_load_. Note that a PageLoadTrackers NavigationHandle is only
309 // valid until commit time, when we remove it from the map. 328 // valid until commit time, when we remove it from the map.
310 std::map<content::NavigationHandle*, scoped_ptr<PageLoadTracker>> 329 std::map<content::NavigationHandle*, scoped_ptr<PageLoadTracker>>
311 provisional_loads_; 330 provisional_loads_;
331 // Tracks aborted provisional loads for a little bit longer than usual (one
332 // more navigation commit at the max), in order to better understand how the
333 // navigation failed. This is because most provisional loads are destroyed and
334 // vanish before we get signal about what caused the abort (new navigation,
335 // stop button, etc.).
336 std::vector<scoped_ptr<PageLoadTracker>> aborted_provisional_loads_;
312 scoped_ptr<PageLoadTracker> committed_load_; 337 scoped_ptr<PageLoadTracker> committed_load_;
313 338
314 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver); 339 DISALLOW_COPY_AND_ASSIGN(MetricsWebContentsObserver);
315 }; 340 };
316 341
317 } // namespace page_load_metrics 342 } // namespace page_load_metrics
318 343
319 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_ 344 #endif // COMPONENTS_PAGE_LOAD_METRICS_BROWSER_PAGE_LOAD_METRICS_WEB_CONTENTS_O BSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698