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

Side by Side Diff: chrome/browser/page_load_metrics/observers/core_page_load_metrics_observer.cc

Issue 2152683004: Refactor PageLoadMetricsObserver completion callback policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@relevantloads
Patch Set: fix metric Created 4 years, 5 months 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 "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse rver.h" 5 #include "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse rver.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 421 }
422 } 422 }
423 423
424 void CorePageLoadMetricsObserver::OnComplete( 424 void CorePageLoadMetricsObserver::OnComplete(
425 const page_load_metrics::PageLoadTiming& timing, 425 const page_load_metrics::PageLoadTiming& timing,
426 const page_load_metrics::PageLoadExtraInfo& info) { 426 const page_load_metrics::PageLoadExtraInfo& info) {
427 RecordTimingHistograms(timing, info); 427 RecordTimingHistograms(timing, info);
428 RecordRappor(timing, info); 428 RecordRappor(timing, info);
429 } 429 }
430 430
431 CorePageLoadMetricsObserver::FailedProvisionalLoadInfo:: 431 void CorePageLoadMetricsObserver::OnFailedProvisionalLoad(
432 FailedProvisionalLoadInfo() 432 const page_load_metrics::FailedProvisionalLoadInfo& failed_load_info,
433 : error(net::OK) {} 433 const page_load_metrics::PageLoadExtraInfo& extra_info) {
434 if (extra_info.started_in_foreground && extra_info.first_background_time) {
435 PAGE_LOAD_HISTOGRAM(internal::kHistogramBackgroundBeforeCommit,
Charlie Harrison 2016/07/18 20:02:18 Since we call this twice now, can you bump it into
Bryan McQuade 2016/07/19 12:55:38 I think we only log the background before commit h
Charlie Harrison 2016/07/19 13:26:03 Ah you're right, I was misreading the histogram na
436 extra_info.first_background_time.value());
437 }
434 438
435 CorePageLoadMetricsObserver::FailedProvisionalLoadInfo::
436 ~FailedProvisionalLoadInfo() {}
437
438 void CorePageLoadMetricsObserver::OnFailedProvisionalLoad(
439 content::NavigationHandle* navigation_handle) {
440 // Only handle actual failures; provisional loads that failed due to another 439 // Only handle actual failures; provisional loads that failed due to another
441 // committed load or due to user action are recorded in 440 // committed load or due to user action are recorded in
442 // AbortsPageLoadMetricsObserver. 441 // AbortsPageLoadMetricsObserver.
443 net::Error error = navigation_handle->GetNetErrorCode(); 442 if (failed_load_info.error != net::OK &&
444 if (error == net::OK || error == net::ERR_ABORTED) { 443 failed_load_info.error != net::ERR_ABORTED) {
445 return; 444 if (WasStartedInForegroundOptionalEventInForeground(
445 failed_load_info.time_to_failed_provisional_load, extra_info)) {
446 PAGE_LOAD_HISTOGRAM(internal::kHistogramFailedProvisionalLoad,
447 failed_load_info.time_to_failed_provisional_load);
448 }
446 } 449 }
447
448 // Saving the related timing and other data in this Observer instead of
449 // PageLoadTracker which saves commit and abort times, as it seems
450 // not every observer implementation would be interested in this metric.
451 failed_provisional_load_info_.interval =
452 base::TimeTicks::Now() - navigation_handle->NavigationStart();
453 failed_provisional_load_info_.error = error;
454 } 450 }
455 451
456 void CorePageLoadMetricsObserver::RecordTimingHistograms( 452 void CorePageLoadMetricsObserver::RecordTimingHistograms(
457 const page_load_metrics::PageLoadTiming& timing, 453 const page_load_metrics::PageLoadTiming& timing,
458 const page_load_metrics::PageLoadExtraInfo& info) { 454 const page_load_metrics::PageLoadExtraInfo& info) {
459 // Record metrics for pages which start in the foreground and are 455 // Record metrics for pages which start in the foreground and are
460 // backgrounded. 456 // backgrounded.
461 if (info.started_in_foreground && info.first_background_time) { 457 if (info.started_in_foreground && info.first_background_time) {
462 const base::TimeDelta first_background_time = 458 const base::TimeDelta first_background_time =
463 info.first_background_time.value(); 459 info.first_background_time.value();
464 460
465 if (!info.time_to_commit) { 461 if (!timing.first_paint || timing.first_paint > first_background_time) {
466 PAGE_LOAD_HISTOGRAM(internal::kHistogramBackgroundBeforeCommit,
467 first_background_time);
468 } else if (!timing.first_paint ||
469 timing.first_paint > first_background_time) {
470 PAGE_LOAD_HISTOGRAM(internal::kHistogramBackgroundBeforePaint, 462 PAGE_LOAD_HISTOGRAM(internal::kHistogramBackgroundBeforePaint,
471 first_background_time); 463 first_background_time);
472 } 464 }
473 if (timing.parse_start && first_background_time >= timing.parse_start && 465 if (timing.parse_start && first_background_time >= timing.parse_start &&
474 (!timing.parse_stop || timing.parse_stop > first_background_time)) { 466 (!timing.parse_stop || timing.parse_stop > first_background_time)) {
475 PAGE_LOAD_HISTOGRAM(internal::kHistogramBackgroundDuringParse, 467 PAGE_LOAD_HISTOGRAM(internal::kHistogramBackgroundDuringParse,
476 first_background_time); 468 first_background_time);
477 } 469 }
478 } 470 }
479 471
480 if (failed_provisional_load_info_.error != net::OK) {
481 DCHECK(failed_provisional_load_info_.interval);
482
483 // Ignores a background failed provisional load.
484 if (WasStartedInForegroundOptionalEventInForeground(
485 failed_provisional_load_info_.interval, info)) {
486 PAGE_LOAD_HISTOGRAM(internal::kHistogramFailedProvisionalLoad,
487 failed_provisional_load_info_.interval.value());
488 }
489 }
490
491 // The rest of the histograms require the load to have committed and be
492 // relevant. If |timing.IsEmpty()|, then this load was not tracked by the
493 // renderer.
494 if (!info.time_to_commit || timing.IsEmpty())
495 return;
496
497 const base::TimeDelta time_to_commit = info.time_to_commit.value(); 472 const base::TimeDelta time_to_commit = info.time_to_commit.value();
498 if (WasStartedInForegroundOptionalEventInForeground(info.time_to_commit, 473 if (WasStartedInForegroundOptionalEventInForeground(info.time_to_commit,
499 info)) { 474 info)) {
500 PAGE_LOAD_HISTOGRAM(internal::kHistogramCommit, time_to_commit); 475 PAGE_LOAD_HISTOGRAM(internal::kHistogramCommit, time_to_commit);
501 } else { 476 } else {
502 PAGE_LOAD_HISTOGRAM(internal::kBackgroundHistogramCommit, time_to_commit); 477 PAGE_LOAD_HISTOGRAM(internal::kBackgroundHistogramCommit, time_to_commit);
503 } 478 }
504 if (timing.dom_content_loaded_event_start) { 479 if (timing.dom_content_loaded_event_start) {
505 if (WasStartedInForegroundOptionalEventInForeground( 480 if (WasStartedInForegroundOptionalEventInForeground(
506 timing.dom_content_loaded_event_start, info)) { 481 timing.dom_content_loaded_event_start, info)) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 RapporHistogramBucketIndex(timing.first_contentful_paint.value()); 665 RapporHistogramBucketIndex(timing.first_contentful_paint.value());
691 sample->SetFlagsField("Bucket", uint64_t(1) << bucket_index, 666 sample->SetFlagsField("Bucket", uint64_t(1) << bucket_index,
692 kNumRapporHistogramBuckets); 667 kNumRapporHistogramBuckets);
693 // The IsSlow flag is just a one bit boolean if the first contentful paint 668 // The IsSlow flag is just a one bit boolean if the first contentful paint
694 // was > 10s. 669 // was > 10s.
695 sample->SetFlagsField( 670 sample->SetFlagsField(
696 "IsSlow", timing.first_contentful_paint.value().InSecondsF() >= 10, 1); 671 "IsSlow", timing.first_contentful_paint.value().InSecondsF() >= 10, 1);
697 rappor_service->RecordSampleObj(internal::kRapporMetricsNameCoarseTiming, 672 rappor_service->RecordSampleObj(internal::kRapporMetricsNameCoarseTiming,
698 std::move(sample)); 673 std::move(sample));
699 } 674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698