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" |
20 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
21 #include "content/public/browser/web_contents_user_data.h" | 22 #include "content/public/browser/web_contents_user_data.h" |
22 #include "ipc/ipc_message.h" | 23 #include "ipc/ipc_message.h" |
23 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
24 | 25 |
25 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 26 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
26 page_load_metrics::MetricsWebContentsObserver); | 27 page_load_metrics::MetricsWebContentsObserver); |
27 | 28 |
28 namespace page_load_metrics { | 29 namespace page_load_metrics { |
29 | 30 |
31 const char kUMAGoogleCaptchaHistogram[] = | |
32 "GoogleCaptcha.Event"; | |
33 | |
30 namespace { | 34 namespace { |
31 | 35 |
32 // The url we see from the renderer side is not always the same as what | 36 // The url we see from the renderer side is not always the same as what |
33 // we see from the browser side (e.g. chrome://newtab). We want to be | 37 // we see from the browser side (e.g. chrome://newtab). We want to be |
34 // sure here that we aren't logging UMA for internal pages. | 38 // sure here that we aren't logging UMA for internal pages. |
35 bool IsRelevantNavigation( | 39 bool IsRelevantNavigation( |
36 content::NavigationHandle* navigation_handle, | 40 content::NavigationHandle* navigation_handle, |
37 const GURL& browser_url, | 41 const GURL& browser_url, |
38 const std::string& mime_type) { | 42 const std::string& mime_type) { |
39 DCHECK(navigation_handle->HasCommitted()); | 43 DCHECK(navigation_handle->HasCommitted()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 return 2; | 116 return 2; |
113 if (seconds < 16) | 117 if (seconds < 16) |
114 return 3; | 118 return 3; |
115 if (seconds < 32) | 119 if (seconds < 32) |
116 return 4; | 120 return 4; |
117 return 5; | 121 return 5; |
118 } | 122 } |
119 | 123 |
120 } // namespace | 124 } // namespace |
121 | 125 |
126 bool IsGoogleCaptcha(const GURL& url) { | |
127 return (base::StartsWith(url.host(), "ipv4.google.", | |
128 base::CompareCase::SENSITIVE) | |
129 || base::StartsWith(url.host(), "ipv6.google.", | |
130 base::CompareCase::SENSITIVE)) | |
131 && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE); | |
132 } | |
133 | |
122 PageLoadTracker::PageLoadTracker( | 134 PageLoadTracker::PageLoadTracker( |
123 bool in_foreground, | 135 bool in_foreground, |
124 rappor::RapporService* const rappor_service, | 136 rappor::RapporService* const rappor_service, |
125 base::ObserverList<PageLoadMetricsObserver, true>* observers) | 137 base::ObserverList<PageLoadMetricsObserver, true>* observers) |
126 : has_commit_(false), | 138 : has_commit_(false), |
127 started_in_foreground_(in_foreground), | 139 started_in_foreground_(in_foreground), |
128 rappor_service_(rappor_service), | 140 rappor_service_(rappor_service), |
129 observers_(observers) {} | 141 observers_(observers) {} |
130 | 142 |
131 PageLoadTracker::~PageLoadTracker() { | 143 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 | 444 // Passing a raw pointer to observers_ is safe because the |
433 // MetricsWebContentsObserver owns the PageLoadMetricsObserver list and is | 445 // MetricsWebContentsObserver owns the PageLoadMetricsObserver list and is |
434 // torn down after the PageLoadTracker. | 446 // torn down after the PageLoadTracker. |
435 provisional_loads_.insert(navigation_handle, | 447 provisional_loads_.insert(navigation_handle, |
436 make_scoped_ptr(new PageLoadTracker( | 448 make_scoped_ptr(new PageLoadTracker( |
437 in_foreground_, rappor_service_, &observers_))); | 449 in_foreground_, rappor_service_, &observers_))); |
438 } | 450 } |
439 | 451 |
440 void MetricsWebContentsObserver::DidFinishNavigation( | 452 void MetricsWebContentsObserver::DidFinishNavigation( |
441 content::NavigationHandle* navigation_handle) { | 453 content::NavigationHandle* navigation_handle) { |
454 if (IsGoogleCaptcha(navigation_handle->GetURL())) { | |
455 UMA_HISTOGRAM_ENUMERATION(kUMAGoogleCaptchaHistogram, GOOGLE_CAPTCHA_SHOWN, | |
Alexei Svitkine (slow)
2015/11/13 19:41:57
Nit: Can you make a helper function to log this hi
Matt Welsh
2015/11/13 20:15:19
Done.
| |
456 GOOGLE_CAPTCHA_EVENT_BOUNDARY); | |
457 } | |
458 | |
442 if (!navigation_handle->IsInMainFrame()) | 459 if (!navigation_handle->IsInMainFrame()) |
443 return; | 460 return; |
444 | 461 |
445 scoped_ptr<PageLoadTracker> finished_nav( | 462 scoped_ptr<PageLoadTracker> finished_nav( |
446 provisional_loads_.take_and_erase(navigation_handle)); | 463 provisional_loads_.take_and_erase(navigation_handle)); |
447 // There's a chance a navigation could have started before we were added to a | 464 // 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. | 465 // tab. Bail out early if this is the case. |
449 if (!finished_nav) | 466 if (!finished_nav) |
450 return; | 467 return; |
451 | 468 |
(...skipping 22 matching lines...) Expand all Loading... | |
474 const std::string& mime_type = web_contents()->GetContentsMimeType(); | 491 const std::string& mime_type = web_contents()->GetContentsMimeType(); |
475 DCHECK(!browser_url.is_empty()); | 492 DCHECK(!browser_url.is_empty()); |
476 DCHECK(!mime_type.empty()); | 493 DCHECK(!mime_type.empty()); |
477 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) | 494 if (!IsRelevantNavigation(navigation_handle, browser_url, mime_type)) |
478 return; | 495 return; |
479 | 496 |
480 committed_load_ = finished_nav.Pass(); | 497 committed_load_ = finished_nav.Pass(); |
481 committed_load_->Commit(navigation_handle); | 498 committed_load_->Commit(navigation_handle); |
482 } | 499 } |
483 | 500 |
501 void MetricsWebContentsObserver::DidRedirectNavigation( | |
502 content::NavigationHandle* navigation_handle) { | |
503 if (IsGoogleCaptcha(navigation_handle->GetReferrer().url)) { | |
504 UMA_HISTOGRAM_ENUMERATION(kUMAGoogleCaptchaHistogram, GOOGLE_CAPTCHA_SOLVED, | |
505 GOOGLE_CAPTCHA_EVENT_BOUNDARY); | |
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 |