Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "components/page_load_metrics/browser/page_load_metrics_macros.h" | 11 #include "components/page_load_metrics/browser/page_load_metrics_macros.h" |
| 11 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 12 #include "components/page_load_metrics/common/page_load_metrics_messages.h" |
| 12 #include "components/page_load_metrics/common/page_load_timing.h" | 13 #include "components/page_load_metrics/common/page_load_timing.h" |
| 13 #include "components/rappor/rappor_service.h" | 14 #include "components/rappor/rappor_service.h" |
| 14 #include "components/rappor/rappor_utils.h" | 15 #include "components/rappor/rappor_utils.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/navigation_details.h" | 17 #include "content/public/browser/navigation_details.h" |
| 17 #include "content/public/browser/navigation_handle.h" | 18 #include "content/public/browser/navigation_handle.h" |
| 18 #include "content/public/browser/render_frame_host.h" | 19 #include "content/public/browser/render_frame_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 base::Time WallTimeFromTimeTicks(const base::TimeTicks& time) { | 80 base::Time WallTimeFromTimeTicks(const base::TimeTicks& time) { |
| 80 return base::Time::FromDoubleT( | 81 return base::Time::FromDoubleT( |
| 81 (time - base::TimeTicks::UnixEpoch()).InSecondsF()); | 82 (time - base::TimeTicks::UnixEpoch()).InSecondsF()); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void RecordInternalError(InternalErrorLoadEvent event) { | 85 void RecordInternalError(InternalErrorLoadEvent event) { |
| 85 UMA_HISTOGRAM_ENUMERATION( | 86 UMA_HISTOGRAM_ENUMERATION( |
| 86 "PageLoad.Events.InternalError", event, ERR_LAST_ENTRY); | 87 "PageLoad.Events.InternalError", event, ERR_LAST_ENTRY); |
| 87 } | 88 } |
| 88 | 89 |
| 90 void RecordGoogleCaptchaEvent(GoogleCaptchaEvent event) { | |
| 91 UMA_HISTOGRAM_ENUMERATION( | |
| 92 kHistogramNameGoogleCaptcha, event, GOOGLE_CAPTCHA_EVENT_BOUNDARY); | |
| 93 } | |
| 94 | |
| 89 base::TimeDelta GetFirstContentfulPaint(const PageLoadTiming& timing) { | 95 base::TimeDelta GetFirstContentfulPaint(const PageLoadTiming& timing) { |
| 90 if (timing.first_text_paint.is_zero()) | 96 if (timing.first_text_paint.is_zero()) |
| 91 return timing.first_image_paint; | 97 return timing.first_image_paint; |
| 92 if (timing.first_image_paint.is_zero()) | 98 if (timing.first_image_paint.is_zero()) |
| 93 return timing.first_text_paint; | 99 return timing.first_text_paint; |
| 94 return std::min(timing.first_text_paint, timing.first_image_paint); | 100 return std::min(timing.first_text_paint, timing.first_image_paint); |
| 95 } | 101 } |
| 96 | 102 |
| 97 // The number of buckets in the bitfield histogram. These buckets are described | 103 // The number of buckets in the bitfield histogram. These buckets are described |
| 98 // in rappor.xml in PageLoad.CoarseTiming.NavigationToFirstContentfulPaint. | 104 // in rappor.xml in PageLoad.CoarseTiming.NavigationToFirstContentfulPaint. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 112 return 2; | 118 return 2; |
| 113 if (seconds < 16) | 119 if (seconds < 16) |
| 114 return 3; | 120 return 3; |
| 115 if (seconds < 32) | 121 if (seconds < 32) |
| 116 return 4; | 122 return 4; |
| 117 return 5; | 123 return 5; |
| 118 } | 124 } |
| 119 | 125 |
| 120 } // namespace | 126 } // namespace |
| 121 | 127 |
| 128 bool IsGoogleCaptcha(const GURL& url) { | |
| 129 return (base::StartsWith(url.host(), "ipv4.google.", | |
| 130 base::CompareCase::SENSITIVE) | |
| 131 || base::StartsWith(url.host(), "ipv6.google.", | |
| 132 base::CompareCase::SENSITIVE)) | |
| 133 && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE); | |
| 134 } | |
| 135 | |
| 122 PageLoadTracker::PageLoadTracker( | 136 PageLoadTracker::PageLoadTracker( |
| 123 bool in_foreground, | 137 bool in_foreground, |
| 124 rappor::RapporService* const rappor_service, | 138 rappor::RapporService* const rappor_service, |
| 125 base::ObserverList<PageLoadMetricsObserver, true>* observers) | 139 base::ObserverList<PageLoadMetricsObserver, true>* observers) |
| 126 : has_commit_(false), | 140 : has_commit_(false), |
| 127 started_in_foreground_(in_foreground), | 141 started_in_foreground_(in_foreground), |
| 128 rappor_service_(rappor_service), | 142 rappor_service_(rappor_service), |
| 129 observers_(observers) {} | 143 observers_(observers) {} |
| 130 | 144 |
| 131 PageLoadTracker::~PageLoadTracker() { | 145 PageLoadTracker::~PageLoadTracker() { |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 // Passing a raw pointer to observers_ is safe because the | 446 // Passing a raw pointer to observers_ is safe because the |
| 433 // MetricsWebContentsObserver owns the PageLoadMetricsObserver list and is | 447 // MetricsWebContentsObserver owns the PageLoadMetricsObserver list and is |
| 434 // torn down after the PageLoadTracker. | 448 // torn down after the PageLoadTracker. |
| 435 provisional_loads_.insert(navigation_handle, | 449 provisional_loads_.insert(navigation_handle, |
| 436 make_scoped_ptr(new PageLoadTracker( | 450 make_scoped_ptr(new PageLoadTracker( |
| 437 in_foreground_, rappor_service_, &observers_))); | 451 in_foreground_, rappor_service_, &observers_))); |
| 438 } | 452 } |
| 439 | 453 |
| 440 void MetricsWebContentsObserver::DidFinishNavigation( | 454 void MetricsWebContentsObserver::DidFinishNavigation( |
| 441 content::NavigationHandle* navigation_handle) { | 455 content::NavigationHandle* navigation_handle) { |
| 456 if (IsGoogleCaptcha(navigation_handle->GetURL())) { | |
|
Alexei Svitkine (slow)
2015/11/13 20:17:12
Nit: No {}s
Matt Welsh
2015/11/13 20:26:01
Done.
| |
| 457 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SHOWN); | |
| 458 } | |
| 459 | |
| 442 if (!navigation_handle->IsInMainFrame()) | 460 if (!navigation_handle->IsInMainFrame()) |
| 443 return; | 461 return; |
| 444 | 462 |
| 445 scoped_ptr<PageLoadTracker> finished_nav( | 463 scoped_ptr<PageLoadTracker> finished_nav( |
| 446 provisional_loads_.take_and_erase(navigation_handle)); | 464 provisional_loads_.take_and_erase(navigation_handle)); |
| 447 // There's a chance a navigation could have started before we were added to a | 465 // There's a chance a navigation could have started before we were added to a |
| 448 // tab. Bail out early if this is the case. | 466 // tab. Bail out early if this is the case. |
| 449 if (!finished_nav) | 467 if (!finished_nav) |
| 450 return; | 468 return; |
| 451 | 469 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 474 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 492 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
| 475 DCHECK(!browser_url.is_empty()); | 493 DCHECK(!browser_url.is_empty()); |
| 476 DCHECK(!mime_type.empty()); | 494 DCHECK(!mime_type.empty()); |
| 477 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) | 495 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) |
| 478 return; | 496 return; |
| 479 | 497 |
| 480 committed_load_ = finished_nav.Pass(); | 498 committed_load_ = finished_nav.Pass(); |
| 481 committed_load_->Commit(navigation_handle); | 499 committed_load_->Commit(navigation_handle); |
| 482 } | 500 } |
| 483 | 501 |
| 502 void MetricsWebContentsObserver::DidRedirectNavigation( | |
| 503 content::NavigationHandle* navigation_handle) { | |
| 504 if (IsGoogleCaptcha(navigation_handle->GetReferrer().url)) { | |
|
Alexei Svitkine (slow)
2015/11/13 20:17:12
Nit: No {}s
Matt Welsh
2015/11/13 20:26:01
Done.
| |
| 505 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SOLVED); | |
| 506 } | |
| 507 } | |
| 508 | |
| 484 void MetricsWebContentsObserver::WasShown() { | 509 void MetricsWebContentsObserver::WasShown() { |
| 485 in_foreground_ = true; | 510 in_foreground_ = true; |
| 486 if (committed_load_) | 511 if (committed_load_) |
| 487 committed_load_->WebContentsShown(); | 512 committed_load_->WebContentsShown(); |
| 488 for (const auto& kv : provisional_loads_) { | 513 for (const auto& kv : provisional_loads_) { |
| 489 kv.second->WebContentsShown(); | 514 kv.second->WebContentsShown(); |
| 490 } | 515 } |
| 491 } | 516 } |
| 492 | 517 |
| 493 void MetricsWebContentsObserver::WasHidden() { | 518 void MetricsWebContentsObserver::WasHidden() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 | 561 |
| 537 if (!committed_load_->UpdateTiming(timing)) { | 562 if (!committed_load_->UpdateTiming(timing)) { |
| 538 // If the page load tracker cannot update its timing, something is wrong | 563 // 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). | 564 // 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. | 565 // We expect this to be a rare occurrence. |
| 541 RecordInternalError(ERR_BAD_TIMING_IPC); | 566 RecordInternalError(ERR_BAD_TIMING_IPC); |
| 542 } | 567 } |
| 543 } | 568 } |
| 544 | 569 |
| 545 } // namespace page_load_metrics | 570 } // namespace page_load_metrics |
| OLD | NEW |