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

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

Powered by Google App Engine
This is Rietveld 408576698