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" |
| 11 #include "base/metrics/user_metrics_action.h" |
10 #include "components/page_load_metrics/browser/page_load_metrics_macros.h" | 12 #include "components/page_load_metrics/browser/page_load_metrics_macros.h" |
11 #include "components/page_load_metrics/common/page_load_metrics_messages.h" | 13 #include "components/page_load_metrics/common/page_load_metrics_messages.h" |
12 #include "components/page_load_metrics/common/page_load_timing.h" | 14 #include "components/page_load_metrics/common/page_load_timing.h" |
13 #include "components/rappor/rappor_service.h" | 15 #include "components/rappor/rappor_service.h" |
14 #include "components/rappor/rappor_utils.h" | 16 #include "components/rappor/rappor_utils.h" |
15 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/navigation_details.h" | 18 #include "content/public/browser/navigation_details.h" |
17 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
18 #include "content/public/browser/render_frame_host.h" | 20 #include "content/public/browser/render_frame_host.h" |
19 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 return 2; | 114 return 2; |
113 if (seconds < 16) | 115 if (seconds < 16) |
114 return 3; | 116 return 3; |
115 if (seconds < 32) | 117 if (seconds < 32) |
116 return 4; | 118 return 4; |
117 return 5; | 119 return 5; |
118 } | 120 } |
119 | 121 |
120 } // namespace | 122 } // namespace |
121 | 123 |
| 124 bool IsGoogleCaptcha(const GURL& url) { |
| 125 return (base::StartsWith(url.host(), "ipv4.google.", |
| 126 base::CompareCase::SENSITIVE) |
| 127 || base::StartsWith(url.host(), "ipv6.google.", |
| 128 base::CompareCase::SENSITIVE)) |
| 129 && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE); |
| 130 } |
| 131 |
122 PageLoadTracker::PageLoadTracker( | 132 PageLoadTracker::PageLoadTracker( |
123 bool in_foreground, | 133 bool in_foreground, |
124 rappor::RapporService* const rappor_service, | 134 rappor::RapporService* const rappor_service, |
125 base::ObserverList<PageLoadMetricsObserver, true>* observers) | 135 base::ObserverList<PageLoadMetricsObserver, true>* observers) |
126 : has_commit_(false), | 136 : has_commit_(false), |
127 started_in_foreground_(in_foreground), | 137 started_in_foreground_(in_foreground), |
128 rappor_service_(rappor_service), | 138 rappor_service_(rappor_service), |
129 observers_(observers) {} | 139 observers_(observers) {} |
130 | 140 |
131 PageLoadTracker::~PageLoadTracker() { | 141 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 | 442 // Passing a raw pointer to observers_ is safe because the |
433 // MetricsWebContentsObserver owns the PageLoadMetricsObserver list and is | 443 // MetricsWebContentsObserver owns the PageLoadMetricsObserver list and is |
434 // torn down after the PageLoadTracker. | 444 // torn down after the PageLoadTracker. |
435 provisional_loads_.insert(navigation_handle, | 445 provisional_loads_.insert(navigation_handle, |
436 make_scoped_ptr(new PageLoadTracker( | 446 make_scoped_ptr(new PageLoadTracker( |
437 in_foreground_, rappor_service_, &observers_))); | 447 in_foreground_, rappor_service_, &observers_))); |
438 } | 448 } |
439 | 449 |
440 void MetricsWebContentsObserver::DidFinishNavigation( | 450 void MetricsWebContentsObserver::DidFinishNavigation( |
441 content::NavigationHandle* navigation_handle) { | 451 content::NavigationHandle* navigation_handle) { |
| 452 if (IsGoogleCaptcha(navigation_handle->GetURL())) { |
| 453 RecordAction(base::UserMetricsAction("GoogleCaptchaShown")); |
| 454 } |
| 455 |
442 if (!navigation_handle->IsInMainFrame()) | 456 if (!navigation_handle->IsInMainFrame()) |
443 return; | 457 return; |
444 | 458 |
445 scoped_ptr<PageLoadTracker> finished_nav( | 459 scoped_ptr<PageLoadTracker> finished_nav( |
446 provisional_loads_.take_and_erase(navigation_handle)); | 460 provisional_loads_.take_and_erase(navigation_handle)); |
447 // There's a chance a navigation could have started before we were added to a | 461 // 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. | 462 // tab. Bail out early if this is the case. |
449 if (!finished_nav) | 463 if (!finished_nav) |
450 return; | 464 return; |
451 | 465 |
(...skipping 22 matching lines...) Expand all Loading... |
474 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 488 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
475 DCHECK(!browser_url.is_empty()); | 489 DCHECK(!browser_url.is_empty()); |
476 DCHECK(!mime_type.empty()); | 490 DCHECK(!mime_type.empty()); |
477 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) | 491 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) |
478 return; | 492 return; |
479 | 493 |
480 committed_load_ = finished_nav.Pass(); | 494 committed_load_ = finished_nav.Pass(); |
481 committed_load_->Commit(navigation_handle); | 495 committed_load_->Commit(navigation_handle); |
482 } | 496 } |
483 | 497 |
| 498 void MetricsWebContentsObserver::DidRedirectNavigation( |
| 499 content::NavigationHandle* navigation_handle) { |
| 500 if (IsGoogleCaptcha(navigation_handle->GetReferrer().url)) { |
| 501 RecordAction(base::UserMetricsAction("GoogleCaptchaSolved")); |
| 502 } |
| 503 } |
| 504 |
484 void MetricsWebContentsObserver::WasShown() { | 505 void MetricsWebContentsObserver::WasShown() { |
485 in_foreground_ = true; | 506 in_foreground_ = true; |
486 if (committed_load_) | 507 if (committed_load_) |
487 committed_load_->WebContentsShown(); | 508 committed_load_->WebContentsShown(); |
488 for (const auto& kv : provisional_loads_) { | 509 for (const auto& kv : provisional_loads_) { |
489 kv.second->WebContentsShown(); | 510 kv.second->WebContentsShown(); |
490 } | 511 } |
491 } | 512 } |
492 | 513 |
493 void MetricsWebContentsObserver::WasHidden() { | 514 void MetricsWebContentsObserver::WasHidden() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 557 |
537 if (!committed_load_->UpdateTiming(timing)) { | 558 if (!committed_load_->UpdateTiming(timing)) { |
538 // If the page load tracker cannot update its timing, something is wrong | 559 // 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). | 560 // 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. | 561 // We expect this to be a rare occurrence. |
541 RecordInternalError(ERR_BAD_TIMING_IPC); | 562 RecordInternalError(ERR_BAD_TIMING_IPC); |
542 } | 563 } |
543 } | 564 } |
544 | 565 |
545 } // namespace page_load_metrics | 566 } // namespace page_load_metrics |
OLD | NEW |