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

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

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 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/user_metrics.h" 10 #include "base/metrics/user_metrics.h"
11 #include "components/page_load_metrics/browser/page_load_metrics_util.h" 11 #include "components/page_load_metrics/browser/page_load_metrics_util.h"
12 #include "components/page_load_metrics/common/page_load_metrics_messages.h" 12 #include "components/page_load_metrics/common/page_load_metrics_messages.h"
13 #include "components/page_load_metrics/common/page_load_timing.h" 13 #include "components/page_load_metrics/common/page_load_timing.h"
14 #include "components/rappor/rappor_service.h" 14 #include "components/rappor/rappor_service.h"
15 #include "components/rappor/rappor_utils.h" 15 #include "components/rappor/rappor_utils.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/navigation_details.h" 17 #include "content/public/browser/navigation_details.h"
18 #include "content/public/browser/navigation_handle.h" 18 #include "content/public/browser/navigation_handle.h"
19 #include "content/public/browser/render_frame_host.h" 19 #include "content/public/browser/render_frame_host.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_contents_observer.h" 21 #include "content/public/browser/web_contents_observer.h"
22 #include "content/public/browser/web_contents_user_data.h" 22 #include "content/public/browser/web_contents_user_data.h"
23 #include "ipc/ipc_message.h" 23 #include "ipc/ipc_message.h"
24 #include "ipc/ipc_message_macros.h" 24 #include "ipc/ipc_message_macros.h"
25 #include "ui/base/page_transition_types.h"
25 26
26 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 27 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
27 page_load_metrics::MetricsWebContentsObserver); 28 page_load_metrics::MetricsWebContentsObserver);
28 29
29 namespace page_load_metrics { 30 namespace page_load_metrics {
30 31
31 namespace { 32 namespace {
32 33
33 // The url we see from the renderer side is not always the same as what 34 // The url we see from the renderer side is not always the same as what
34 // we see from the browser side (e.g. chrome://newtab). We want to be 35 // we see from the browser side (e.g. chrome://newtab). We want to be
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return false; 75 return false;
75 } 76 }
76 77
77 return true; 78 return true;
78 } 79 }
79 80
80 void RecordInternalError(InternalErrorLoadEvent event) { 81 void RecordInternalError(InternalErrorLoadEvent event) {
81 UMA_HISTOGRAM_ENUMERATION(kErrorEvents, event, ERR_LAST_ENTRY); 82 UMA_HISTOGRAM_ENUMERATION(kErrorEvents, event, ERR_LAST_ENTRY);
82 } 83 }
83 84
85 UserAbortType AbortTypeForPageTransition(ui::PageTransition transition) {
86 if (ui::PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD))
87 return ABORT_RELOAD;
88 else if (transition & ui::PAGE_TRANSITION_FORWARD_BACK)
89 return ABORT_FORWARD_BACK;
90 else
91 return ABORT_NEW_NAVIGATION;
92 }
93
84 // The number of buckets in the bitfield histogram. These buckets are described 94 // The number of buckets in the bitfield histogram. These buckets are described
85 // in rappor.xml in PageLoad.CoarseTiming.NavigationToFirstContentfulPaint. 95 // in rappor.xml in PageLoad.CoarseTiming.NavigationToFirstContentfulPaint.
86 // The bucket flag is defined by 1 << bucket_index, and is the bitfield 96 // The bucket flag is defined by 1 << bucket_index, and is the bitfield
87 // representing which timing bucket the page load falls into, i.e. 000010 97 // representing which timing bucket the page load falls into, i.e. 000010
88 // would be the bucket flag showing that the page took between 2 and 4 seconds 98 // would be the bucket flag showing that the page took between 2 and 4 seconds
89 // to load. 99 // to load.
90 const size_t kNumRapporHistogramBuckets = 6; 100 const size_t kNumRapporHistogramBuckets = 6;
91 101
92 uint64_t RapporHistogramBucketIndex(const base::TimeDelta& time) { 102 uint64_t RapporHistogramBucketIndex(const base::TimeDelta& time) {
93 int64 seconds = time.InSeconds(); 103 int64 seconds = time.InSeconds();
(...skipping 12 matching lines...) Expand all
106 116
107 } // namespace 117 } // namespace
108 118
109 PageLoadTracker::PageLoadTracker( 119 PageLoadTracker::PageLoadTracker(
110 bool in_foreground, 120 bool in_foreground,
111 PageLoadMetricsEmbedderInterface* embedder_interface, 121 PageLoadMetricsEmbedderInterface* embedder_interface,
112 content::NavigationHandle* navigation_handle) 122 content::NavigationHandle* navigation_handle)
113 : renderer_tracked_(false), 123 : renderer_tracked_(false),
114 has_commit_(false), 124 has_commit_(false),
115 navigation_start_(navigation_handle->NavigationStart()), 125 navigation_start_(navigation_handle->NavigationStart()),
126 abort_type_(ABORT_NONE),
116 started_in_foreground_(in_foreground), 127 started_in_foreground_(in_foreground),
117 embedder_interface_(embedder_interface) { 128 embedder_interface_(embedder_interface) {
118 embedder_interface_->RegisterObservers(this); 129 embedder_interface_->RegisterObservers(this);
119 for (const auto& observer : observers_) { 130 for (const auto& observer : observers_) {
120 observer->OnStart(navigation_handle); 131 observer->OnStart(navigation_handle);
121 } 132 }
122 } 133 }
123 134
124 PageLoadTracker::~PageLoadTracker() { 135 PageLoadTracker::~PageLoadTracker() {
125 if (has_commit_) {
126 RecordTimingHistograms();
127 RecordRappor();
128 }
129 PageLoadExtraInfo info = GetPageLoadMetricsInfo(); 136 PageLoadExtraInfo info = GetPageLoadMetricsInfo();
137 RecordRappor(info);
138 RecordTimingHistograms(info);
130 for (const auto& observer : observers_) { 139 for (const auto& observer : observers_) {
131 observer->OnComplete(timing_, info); 140 observer->OnComplete(timing_, info);
132 } 141 }
133 } 142 }
134 143
135 void PageLoadTracker::WebContentsHidden() { 144 void PageLoadTracker::WebContentsHidden() {
136 // Only log the first time we background in a given page load. 145 // Only log the first time we background in a given page load.
137 if (started_in_foreground_ && background_time_.is_null()) 146 if (started_in_foreground_ && background_time_.is_null())
138 background_time_ = base::TimeTicks::Now(); 147 background_time_ = base::TimeTicks::Now();
139 } 148 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 198 }
190 199
191 void PageLoadTracker::AddObserver( 200 void PageLoadTracker::AddObserver(
192 scoped_ptr<PageLoadMetricsObserver> observer) { 201 scoped_ptr<PageLoadMetricsObserver> observer) {
193 observers_.push_back(std::move(observer)); 202 observers_.push_back(std::move(observer));
194 } 203 }
195 204
196 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() { 205 PageLoadExtraInfo PageLoadTracker::GetPageLoadMetricsInfo() {
197 base::TimeDelta first_background_time; 206 base::TimeDelta first_background_time;
198 base::TimeDelta first_foreground_time; 207 base::TimeDelta first_foreground_time;
208 base::TimeDelta time_to_abort;
199 if (!background_time_.is_null() && started_in_foreground_) 209 if (!background_time_.is_null() && started_in_foreground_)
200 first_background_time = background_time_ - navigation_start_; 210 first_background_time = background_time_ - navigation_start_;
201 if (!foreground_time_.is_null() && !started_in_foreground_) 211 if (!foreground_time_.is_null() && !started_in_foreground_)
202 first_foreground_time = foreground_time_ - navigation_start_; 212 first_foreground_time = foreground_time_ - navigation_start_;
213 if (abort_type_ != ABORT_NONE)
214 time_to_abort = abort_time_ - navigation_start_;
Bryan McQuade 2015/12/10 17:04:23 can we DCHECK that abort_time_ is not zero when ab
Charlie Harrison 2015/12/10 17:59:31 Done.
203 return PageLoadExtraInfo(first_background_time, first_foreground_time, 215 return PageLoadExtraInfo(first_background_time, first_foreground_time,
204 started_in_foreground_, has_commit_); 216 started_in_foreground_, has_commit_, abort_type_,
217 time_to_abort);
205 } 218 }
206 219
207 const GURL& PageLoadTracker::committed_url() { 220 const GURL& PageLoadTracker::committed_url() {
208 DCHECK(has_commit_); 221 DCHECK(has_commit_);
209 return url_; 222 return url_;
210 } 223 }
211 224
212 // Blink calculates navigation start using TimeTicks, but converts to epoch time 225 // We consider the first abort passed here as the true abort, unless it is
213 // in its public API. Thus, to compare time values to navigation start, we 226 // ABORT_OTHER.
214 // calculate the current time since the epoch using TimeTicks, and convert to 227 void PageLoadTracker::NotifyAbort(UserAbortType abort_type,
215 // Time. This method is similar to how blink converts TimeTicks to epoch time. 228 const base::TimeTicks& timestamp) {
216 // There may be slight inaccuracies due to inter-process timestamps, but 229 DCHECK(abort_type != ABORT_NONE);
217 // this solution is the best we have right now. 230 if (abort_type_ == ABORT_NONE) {
218 // 231 abort_type_ = abort_type;
219 // returns a TimeDelta which is 232 abort_time_ = timestamp;
220 // - Infinity if we were never backgrounded
221 // - null (TimeDelta()) if we started backgrounded
222 // - elapsed time to first background if we started in the foreground and
223 // backgrounded.
224 base::TimeDelta PageLoadTracker::GetBackgroundDelta() {
225 if (started_in_foreground_) {
226 return background_time_.is_null() ? base::TimeDelta::Max()
227 : background_time_ - navigation_start_;
228 } 233 }
229 return base::TimeDelta(); 234
235 // If we got a better signal than ABORT_OTHER in the last 100ms, treat it
236 // as the cause of the abort (Some ABORT_OTHER signals occur before the true
237 // signal). Note that this only occurs for provisional loads. While this
Bryan McQuade 2015/12/10 17:04:23 'this only occurs for provisional loads' -> 'abort
Charlie Harrison 2015/12/10 17:59:31 Done.
238 // heuristic is coarse, it works better and is simpler than other feasible
239 // methods. See https://goo.gl/WKRG98.
Bryan McQuade 2015/12/10 17:04:23 navigating to https://goo.gl/WKRG98 requires me to
Charlie Harrison 2015/12/10 17:59:31 Done.
240 if (abort_type_ == ABORT_OTHER && abort_type != ABORT_OTHER &&
241 (timestamp - abort_time_).InMilliseconds() < 100) {
Bryan McQuade 2015/12/10 17:04:23 below we have std::min(abort_time_, timestamp); wh
Charlie Harrison 2015/12/10 17:59:31 It is valid for timestamp < abort_time. In this ca
242 abort_type_ = abort_type;
243 abort_time_ = std::min(abort_time_, timestamp);
244 }
230 } 245 }
231 246
232 void PageLoadTracker::RecordTimingHistograms() { 247 void PageLoadTracker::RecordTimingHistograms(const PageLoadExtraInfo& info) {
233 DCHECK(has_commit_); 248 if (!background_time_.is_null() &&
Bryan McQuade 2015/12/10 17:04:23 can we use info.first_background_time instead of b
Charlie Harrison 2015/12/10 17:59:31 Done.
234 if (!renderer_tracked()) 249 !EventOccurredInForeground(timing_.first_paint, info)) {
250 if (has_commit_) {
251 PAGE_LOAD_HISTOGRAM(kHistogramBackgroundBeforePaint,
252 background_time_ - navigation_start_);
253 } else {
254 PAGE_LOAD_HISTOGRAM(kHistogramProvisionalBackground,
255 background_time_ - navigation_start_);
256 }
257 }
258
259 // The rest of the histograms require the load to have commit and be relevant.
260 if (!has_commit_ || !renderer_tracked())
235 return; 261 return;
236 262
263 // The rest of the timing histograms require us to have received IPCs from the
264 // renderer. Record UMA for how often this occurs (usually for quickly aborted
265 // loads). For now, don't update observers if this is the case.
237 if (timing_.IsEmpty()) { 266 if (timing_.IsEmpty()) {
238 RecordInternalError(ERR_NO_IPCS_RECEIVED); 267 RecordInternalError(ERR_NO_IPCS_RECEIVED);
239 return; 268 return;
240 } 269 }
241 270
242 base::TimeDelta background_delta = GetBackgroundDelta();
243
244 if (!timing_.dom_content_loaded_event_start.is_zero()) { 271 if (!timing_.dom_content_loaded_event_start.is_zero()) {
245 if (timing_.dom_content_loaded_event_start < background_delta) { 272 if (EventOccurredInForeground(timing_.dom_content_loaded_event_start,
273 info)) {
246 PAGE_LOAD_HISTOGRAM(kHistogramDomContentLoaded, 274 PAGE_LOAD_HISTOGRAM(kHistogramDomContentLoaded,
247 timing_.dom_content_loaded_event_start); 275 timing_.dom_content_loaded_event_start);
248 } else { 276 } else {
249 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramDomContentLoaded, 277 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramDomContentLoaded,
250 timing_.dom_content_loaded_event_start); 278 timing_.dom_content_loaded_event_start);
251 } 279 }
252 } 280 }
253 if (!timing_.load_event_start.is_zero()) { 281 if (!timing_.load_event_start.is_zero()) {
254 if (timing_.load_event_start < background_delta) { 282 if (EventOccurredInForeground(timing_.load_event_start, info)) {
255 PAGE_LOAD_HISTOGRAM(kHistogramLoad, timing_.load_event_start); 283 PAGE_LOAD_HISTOGRAM(kHistogramLoad, timing_.load_event_start);
256 } else { 284 } else {
257 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramLoad, timing_.load_event_start); 285 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramLoad, timing_.load_event_start);
258 } 286 }
259 } 287 }
260 if (timing_.first_layout.is_zero()) { 288 if (timing_.first_layout.is_zero()) {
261 RecordCommittedEvent(RELEVANT_LOAD_FAILED_BEFORE_FIRST_LAYOUT, 289 RecordCommittedEvent(RELEVANT_LOAD_FAILED_BEFORE_FIRST_LAYOUT,
262 HasBackgrounded()); 290 HasBackgrounded());
263 } else { 291 } else {
264 if (timing_.first_layout < background_delta) { 292 if (EventOccurredInForeground(timing_.first_layout, info)) {
265 PAGE_LOAD_HISTOGRAM(kHistogramFirstLayout, timing_.first_layout); 293 PAGE_LOAD_HISTOGRAM(kHistogramFirstLayout, timing_.first_layout);
266 RecordCommittedEvent(RELEVANT_LOAD_SUCCESSFUL_FIRST_LAYOUT, false); 294 RecordCommittedEvent(RELEVANT_LOAD_SUCCESSFUL_FIRST_LAYOUT, false);
267 } else { 295 } else {
268 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstLayout, 296 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstLayout,
269 timing_.first_layout); 297 timing_.first_layout);
270 RecordCommittedEvent(RELEVANT_LOAD_SUCCESSFUL_FIRST_LAYOUT, true); 298 RecordCommittedEvent(RELEVANT_LOAD_SUCCESSFUL_FIRST_LAYOUT, true);
271 } 299 }
272 } 300 }
273 if (!timing_.first_paint.is_zero()) { 301 if (!timing_.first_paint.is_zero()) {
274 if (timing_.first_paint < background_delta) { 302 if (EventOccurredInForeground(timing_.first_paint, info)) {
275 PAGE_LOAD_HISTOGRAM(kHistogramFirstPaint, timing_.first_paint); 303 PAGE_LOAD_HISTOGRAM(kHistogramFirstPaint, timing_.first_paint);
276 } else { 304 } else {
277 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstPaint, timing_.first_paint); 305 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstPaint, timing_.first_paint);
278 } 306 }
279 } 307 }
280 if (!timing_.first_text_paint.is_zero()) { 308 if (!timing_.first_text_paint.is_zero()) {
281 if (timing_.first_text_paint < background_delta) { 309 if (EventOccurredInForeground(timing_.first_text_paint, info)) {
282 PAGE_LOAD_HISTOGRAM(kHistogramFirstTextPaint, timing_.first_text_paint); 310 PAGE_LOAD_HISTOGRAM(kHistogramFirstTextPaint, timing_.first_text_paint);
283 } else { 311 } else {
284 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstTextPaint, 312 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstTextPaint,
285 timing_.first_text_paint); 313 timing_.first_text_paint);
286 } 314 }
287 } 315 }
288 if (!timing_.first_image_paint.is_zero()) { 316 if (!timing_.first_image_paint.is_zero()) {
289 if (timing_.first_image_paint < background_delta) { 317 if (EventOccurredInForeground(timing_.first_image_paint, info)) {
290 PAGE_LOAD_HISTOGRAM(kHistogramFirstImagePaint, timing_.first_image_paint); 318 PAGE_LOAD_HISTOGRAM(kHistogramFirstImagePaint, timing_.first_image_paint);
291 } else { 319 } else {
292 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstImagePaint, 320 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstImagePaint,
293 timing_.first_image_paint); 321 timing_.first_image_paint);
294 } 322 }
295 } 323 }
296 base::TimeDelta first_contentful_paint = GetFirstContentfulPaint(timing_); 324 base::TimeDelta first_contentful_paint = GetFirstContentfulPaint(timing_);
297 if (!first_contentful_paint.is_zero()) { 325 if (!first_contentful_paint.is_zero()) {
298 if (first_contentful_paint < background_delta) { 326 if (EventOccurredInForeground(first_contentful_paint, info)) {
299 PAGE_LOAD_HISTOGRAM(kHistogramFirstContentfulPaint, 327 PAGE_LOAD_HISTOGRAM(kHistogramFirstContentfulPaint,
300 first_contentful_paint); 328 first_contentful_paint);
301 // Bucket these histograms into high/low resolution clock systems. This 329 // Bucket these histograms into high/low resolution clock systems. This
302 // might point us to directions that will de-noise some UMA. 330 // might point us to directions that will de-noise some UMA.
303 if (base::TimeTicks::IsHighResolution()) { 331 if (base::TimeTicks::IsHighResolution()) {
304 PAGE_LOAD_HISTOGRAM(kHistogramFirstContentfulPaintHigh, 332 PAGE_LOAD_HISTOGRAM(kHistogramFirstContentfulPaintHigh,
305 first_contentful_paint); 333 first_contentful_paint);
306 } else { 334 } else {
307 PAGE_LOAD_HISTOGRAM(kHistogramFirstContentfulPaintLow, 335 PAGE_LOAD_HISTOGRAM(kHistogramFirstContentfulPaintLow,
308 first_contentful_paint); 336 first_contentful_paint);
309 } 337 }
310 } else { 338 } else {
311 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstContentfulPaint, 339 PAGE_LOAD_HISTOGRAM(kBackgroundHistogramFirstContentfulPaint,
312 first_contentful_paint); 340 first_contentful_paint);
313 } 341 }
314 } 342 }
315 343
316 // Log time to first foreground / time to first background. Log counts that we 344 // Log time to first foreground / time to first background. Log counts that we
317 // started a relevant page load in the foreground / background. 345 // started a relevant page load in the foreground / background.
318 if (!background_time_.is_null()) { 346 if (!background_time_.is_null()) {
319 PAGE_LOAD_HISTOGRAM(kHistogramFirstBackground, background_delta); 347 PAGE_LOAD_HISTOGRAM(kHistogramFirstBackground,
348 background_time_ - navigation_start_);
320 } else if (!foreground_time_.is_null()) { 349 } else if (!foreground_time_.is_null()) {
321 PAGE_LOAD_HISTOGRAM(kHistogramFirstForeground, 350 PAGE_LOAD_HISTOGRAM(kHistogramFirstForeground,
322 foreground_time_ - navigation_start_); 351 foreground_time_ - navigation_start_);
323 } 352 }
324 } 353 }
325 354
326 void PageLoadTracker::RecordProvisionalEvent(ProvisionalLoadEvent event) { 355 void PageLoadTracker::RecordProvisionalEvent(ProvisionalLoadEvent event) {
327 if (HasBackgrounded()) { 356 if (HasBackgrounded()) {
328 UMA_HISTOGRAM_ENUMERATION(kBackgroundProvisionalEvents, event, 357 UMA_HISTOGRAM_ENUMERATION(kBackgroundProvisionalEvents, event,
329 PROVISIONAL_LOAD_LAST_ENTRY); 358 PROVISIONAL_LOAD_LAST_ENTRY);
(...skipping 10 matching lines...) Expand all
340 bool backgrounded) { 369 bool backgrounded) {
341 if (backgrounded) { 370 if (backgrounded) {
342 UMA_HISTOGRAM_ENUMERATION(kBackgroundCommittedEvents, event, 371 UMA_HISTOGRAM_ENUMERATION(kBackgroundCommittedEvents, event,
343 RELEVANT_LOAD_LAST_ENTRY); 372 RELEVANT_LOAD_LAST_ENTRY);
344 } else { 373 } else {
345 UMA_HISTOGRAM_ENUMERATION(kCommittedEvents, event, 374 UMA_HISTOGRAM_ENUMERATION(kCommittedEvents, event,
346 RELEVANT_LOAD_LAST_ENTRY); 375 RELEVANT_LOAD_LAST_ENTRY);
347 } 376 }
348 } 377 }
349 378
350 void PageLoadTracker::RecordRappor() { 379 void PageLoadTracker::RecordRappor(const PageLoadExtraInfo& info) {
380 if (!info.has_commit)
381 return;
351 DCHECK(!committed_url().is_empty()); 382 DCHECK(!committed_url().is_empty());
352 rappor::RapporService* rappor_service = 383 rappor::RapporService* rappor_service =
353 embedder_interface_->GetRapporService(); 384 embedder_interface_->GetRapporService();
354 if (!rappor_service) 385 if (!rappor_service)
355 return; 386 return;
356 base::TimeDelta first_contentful_paint = GetFirstContentfulPaint(timing_); 387 base::TimeDelta first_contentful_paint = GetFirstContentfulPaint(timing_);
357 // Log the eTLD+1 of sites that show poor loading performance. 388 // Log the eTLD+1 of sites that show poor loading performance.
358 if (!first_contentful_paint.is_zero() && 389 if (EventOccurredInForeground(first_contentful_paint, info)) {
359 first_contentful_paint < GetBackgroundDelta()) {
360 scoped_ptr<rappor::Sample> sample = 390 scoped_ptr<rappor::Sample> sample =
361 rappor_service->CreateSample(rappor::UMA_RAPPOR_TYPE); 391 rappor_service->CreateSample(rappor::UMA_RAPPOR_TYPE);
362 sample->SetStringField( 392 sample->SetStringField(
363 "Domain", rappor::GetDomainAndRegistrySampleFromGURL(committed_url())); 393 "Domain", rappor::GetDomainAndRegistrySampleFromGURL(committed_url()));
364 uint64_t bucket_index = RapporHistogramBucketIndex(first_contentful_paint); 394 uint64_t bucket_index = RapporHistogramBucketIndex(first_contentful_paint);
365 sample->SetFlagsField("Bucket", uint64_t(1) << bucket_index, 395 sample->SetFlagsField("Bucket", uint64_t(1) << bucket_index,
366 kNumRapporHistogramBuckets); 396 kNumRapporHistogramBuckets);
367 // The IsSlow flag is just a one bit boolean if the first layout was > 10s. 397 // The IsSlow flag is just a one bit boolean if the first layout was > 10s.
368 sample->SetFlagsField("IsSlow", first_contentful_paint.InSecondsF() >= 10, 398 sample->SetFlagsField("IsSlow", first_contentful_paint.InSecondsF() >= 10,
369 1); 399 1);
(...skipping 17 matching lines...) Expand all
387 417
388 MetricsWebContentsObserver* metrics = FromWebContents(web_contents); 418 MetricsWebContentsObserver* metrics = FromWebContents(web_contents);
389 if (!metrics) { 419 if (!metrics) {
390 metrics = 420 metrics =
391 new MetricsWebContentsObserver(web_contents, embedder_interface.Pass()); 421 new MetricsWebContentsObserver(web_contents, embedder_interface.Pass());
392 web_contents->SetUserData(UserDataKey(), metrics); 422 web_contents->SetUserData(UserDataKey(), metrics);
393 } 423 }
394 return metrics; 424 return metrics;
395 } 425 }
396 426
397 MetricsWebContentsObserver::~MetricsWebContentsObserver() {} 427 MetricsWebContentsObserver::~MetricsWebContentsObserver() {
428 NotifyAbortAllLoads(ABORT_CLOSE);
429 }
398 430
399 bool MetricsWebContentsObserver::OnMessageReceived( 431 bool MetricsWebContentsObserver::OnMessageReceived(
400 const IPC::Message& message, 432 const IPC::Message& message,
401 content::RenderFrameHost* render_frame_host) { 433 content::RenderFrameHost* render_frame_host) {
402 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 434 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
403 bool handled = true; 435 bool handled = true;
404 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MetricsWebContentsObserver, message, 436 IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(MetricsWebContentsObserver, message,
405 render_frame_host) 437 render_frame_host)
406 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_TimingUpdated, OnTimingUpdated) 438 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_TimingUpdated, OnTimingUpdated)
407 IPC_MESSAGE_UNHANDLED(handled = false) 439 IPC_MESSAGE_UNHANDLED(handled = false)
(...skipping 30 matching lines...) Expand all
438 provisional_loads_.erase(navigation_handle); 470 provisional_loads_.erase(navigation_handle);
439 471
440 // There's a chance a navigation could have started before we were added to a 472 // There's a chance a navigation could have started before we were added to a
441 // tab. Bail out early if this is the case. 473 // tab. Bail out early if this is the case.
442 if (!finished_nav) 474 if (!finished_nav)
443 return; 475 return;
444 476
445 // Handle a pre-commit error here. Navigations that result in an error page 477 // Handle a pre-commit error here. Navigations that result in an error page
446 // will be ignored. Note that downloads/204s will result in HasCommitted() 478 // will be ignored. Note that downloads/204s will result in HasCommitted()
447 // returning false. 479 // returning false.
480 // TODO(csharrison): Track changes to NavigationHandle for signals when this
481 // is the case (HTTP response headers).
448 if (!navigation_handle->HasCommitted()) { 482 if (!navigation_handle->HasCommitted()) {
449 net::Error error = navigation_handle->GetNetErrorCode(); 483 net::Error error = navigation_handle->GetNetErrorCode();
450 finished_nav->RecordProvisionalEvent( 484 ProvisionalLoadEvent event = error == net::OK ? PROVISIONAL_LOAD_STOPPED
451 error == net::OK ? PROVISIONAL_LOAD_STOPPED
452 : error == net::ERR_ABORTED ? PROVISIONAL_LOAD_ERR_ABORTED 485 : error == net::ERR_ABORTED ? PROVISIONAL_LOAD_ERR_ABORTED
453 : PROVISIONAL_LOAD_ERR_FAILED_NON_ABORT); 486 : PROVISIONAL_LOAD_ERR_FAILED_NON_ABORT;
487 finished_nav->RecordProvisionalEvent(event);
488 if (event != PROVISIONAL_LOAD_ERR_FAILED_NON_ABORT) {
489 finished_nav->NotifyAbort(ABORT_OTHER, base::TimeTicks::Now());
490 aborted_provisional_loads_.push_back(std::move(finished_nav));
491 }
454 return; 492 return;
455 } 493 }
456 finished_nav->RecordProvisionalEvent(PROVISIONAL_LOAD_COMMITTED); 494 finished_nav->RecordProvisionalEvent(PROVISIONAL_LOAD_COMMITTED);
457 495
458 // Don't treat a same-page nav as a new page load. 496 // Don't treat a same-page nav as a new page load.
459 if (navigation_handle->IsSamePage()) 497 if (navigation_handle->IsSamePage())
460 return; 498 return;
461 499
500 // Notify other loads that they may have been aborted by this committed load.
501 // Note that by using the committed navigation start as the abort cause, we
502 // lose data on provisional loads that were aborted by other provisional
503 // loads. Those will either be listed as ABORT_OTHER or as being aborted by
504 // this load.
505 NotifyAbortAllLoadsWithTimestamp(
506 AbortTypeForPageTransition(navigation_handle->GetPageTransition()),
507 navigation_handle->NavigationStart());
508
462 committed_load_ = finished_nav.Pass(); 509 committed_load_ = finished_nav.Pass();
510 aborted_provisional_loads_.clear();
463 511
464 const GURL& browser_url = web_contents()->GetLastCommittedURL(); 512 const GURL& browser_url = web_contents()->GetLastCommittedURL();
465 const std::string& mime_type = web_contents()->GetContentsMimeType(); 513 const std::string& mime_type = web_contents()->GetContentsMimeType();
466 DCHECK(!browser_url.is_empty()); 514 DCHECK(!browser_url.is_empty());
467 DCHECK(!mime_type.empty()); 515 DCHECK(!mime_type.empty());
468 committed_load_->set_renderer_tracked( 516 committed_load_->set_renderer_tracked(
469 IsRelevantNavigation(navigation_handle, browser_url, mime_type)); 517 IsRelevantNavigation(navigation_handle, browser_url, mime_type));
470 518
471 committed_load_->Commit(navigation_handle); 519 committed_load_->Commit(navigation_handle);
472 } 520 }
473 521
522 void MetricsWebContentsObserver::NavigationStopped() {
523 NotifyAbortAllLoads(ABORT_STOP);
524 }
525
474 void MetricsWebContentsObserver::DidRedirectNavigation( 526 void MetricsWebContentsObserver::DidRedirectNavigation(
475 content::NavigationHandle* navigation_handle) { 527 content::NavigationHandle* navigation_handle) {
476 if (!navigation_handle->IsInMainFrame()) 528 if (!navigation_handle->IsInMainFrame())
477 return; 529 return;
478 auto it = provisional_loads_.find(navigation_handle); 530 auto it = provisional_loads_.find(navigation_handle);
479 if (it == provisional_loads_.end()) 531 if (it == provisional_loads_.end())
480 return; 532 return;
481 it->second->Redirect(navigation_handle); 533 it->second->Redirect(navigation_handle);
482 } 534 }
483 535
(...skipping 13 matching lines...) Expand all
497 for (const auto& kv : provisional_loads_) { 549 for (const auto& kv : provisional_loads_) {
498 kv.second->WebContentsHidden(); 550 kv.second->WebContentsHidden();
499 } 551 }
500 } 552 }
501 553
502 // This will occur when the process for the main RenderFrameHost exits, either 554 // This will occur when the process for the main RenderFrameHost exits, either
503 // normally or from a crash. We eagerly log data from the last committed load if 555 // normally or from a crash. We eagerly log data from the last committed load if
504 // we have one. 556 // we have one.
505 void MetricsWebContentsObserver::RenderProcessGone( 557 void MetricsWebContentsObserver::RenderProcessGone(
506 base::TerminationStatus status) { 558 base::TerminationStatus status) {
559 NotifyAbortAllLoads(ABORT_CLOSE);
507 committed_load_.reset(); 560 committed_load_.reset();
561 provisional_loads_.clear();
562 aborted_provisional_loads_.clear();
563 }
564
565 void MetricsWebContentsObserver::NotifyAbortAllLoads(UserAbortType abort_type) {
566 NotifyAbortAllLoadsWithTimestamp(abort_type, base::TimeTicks::Now());
567 }
568
569 void MetricsWebContentsObserver::NotifyAbortAllLoadsWithTimestamp(
570 UserAbortType abort_type,
571 const base::TimeTicks& timestamp) {
572 if (committed_load_)
573 committed_load_->NotifyAbort(abort_type, timestamp);
574 for (const auto& kv : provisional_loads_) {
575 kv.second->NotifyAbort(abort_type, timestamp);
576 }
577 for (const auto& plt : aborted_provisional_loads_) {
578 plt->NotifyAbort(abort_type, timestamp);
Bryan McQuade 2015/12/10 17:04:23 I'm finding following the logic in NotifyAbort a b
Charlie Harrison 2015/12/10 17:59:31 This isn't quite true. We can notify aborts multip
579 }
508 } 580 }
509 581
510 void MetricsWebContentsObserver::OnTimingUpdated( 582 void MetricsWebContentsObserver::OnTimingUpdated(
511 content::RenderFrameHost* render_frame_host, 583 content::RenderFrameHost* render_frame_host,
512 const PageLoadTiming& timing) { 584 const PageLoadTiming& timing) {
513 bool error = false; 585 bool error = false;
514 if (!committed_load_ || !committed_load_->renderer_tracked()) { 586 if (!committed_load_ || !committed_load_->renderer_tracked()) {
515 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD); 587 RecordInternalError(ERR_IPC_WITH_NO_RELEVANT_LOAD);
516 error = true; 588 error = true;
517 } 589 }
(...skipping 18 matching lines...) Expand all
536 608
537 if (!committed_load_->UpdateTiming(timing)) { 609 if (!committed_load_->UpdateTiming(timing)) {
538 // If the page load tracker cannot update its timing, something is wrong 610 // If the page load tracker cannot update its timing, something is wrong
539 // with the IPC (it's from another load, or it's invalid in some other way). 611 // with the IPC (it's from another load, or it's invalid in some other way).
540 // We expect this to be a rare occurrence. 612 // We expect this to be a rare occurrence.
541 RecordInternalError(ERR_BAD_TIMING_IPC); 613 RecordInternalError(ERR_BAD_TIMING_IPC);
542 } 614 }
543 } 615 }
544 616
545 } // namespace page_load_metrics 617 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698