OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/page_load_metrics/observers/google_captcha_observer.h" | |
6 | |
7 #include "base/metrics/histogram.h" | |
8 #include "base/strings/string_util.h" | |
9 #include "components/page_load_metrics/browser/page_load_metrics_macros.h" | |
10 #include "components/page_load_metrics/common/page_load_timing.h" | |
11 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | |
12 | |
13 namespace { | |
Charlie Harrison
2015/11/14 01:19:55
Nest the anonymous namespace within the google_cap
Matt Welsh
2015/11/16 18:30:53
Done.
| |
14 | |
15 const char kHistogramNameGoogleCaptcha[] = "PageLoad.Events.GoogleCaptcha"; | |
Charlie Harrison
2015/11/14 01:19:55
Can you follow the same naming style as other hist
Matt Welsh
2015/11/16 18:30:53
Done.
| |
16 | |
17 void RecordGoogleCaptchaEvent( | |
18 google_captcha_observer::GoogleCaptchaEvent event) { | |
19 UMA_HISTOGRAM_ENUMERATION( | |
20 kHistogramNameGoogleCaptcha, event, | |
21 google_captcha_observer::GOOGLE_CAPTCHA_EVENT_BOUNDARY); | |
22 } | |
23 | |
24 } // namespace | |
25 | |
26 namespace google_captcha_observer { | |
27 | |
28 bool IsGoogleCaptcha(const GURL& url) { | |
29 return (base::StartsWith(url.host(), "ipv4.google.", | |
30 base::CompareCase::SENSITIVE) | |
31 || base::StartsWith(url.host(), "ipv6.google.", | |
32 base::CompareCase::SENSITIVE)) | |
33 && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE); | |
34 } | |
35 | |
36 GoogleCaptchaObserver::GoogleCaptchaObserver( | |
37 page_load_metrics::PageLoadMetricsObservable* metrics) | |
38 : metrics_(metrics) {} | |
39 | |
40 void GoogleCaptchaObserver::OnCommit( | |
41 content::NavigationHandle* navigation_handle) { | |
42 if (IsGoogleCaptcha(navigation_handle->GetURL())) | |
43 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SHOWN); | |
44 } | |
45 | |
46 void GoogleCaptchaObserver::OnRedirect( | |
47 content::NavigationHandle* navigation_handle) { | |
48 if (navigation_handle->GetReferrer() && | |
49 IsGoogleCaptcha(navigation_handle->GetReferrer().url)) | |
50 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SOLVED); | |
51 } | |
52 | |
53 void GoogleCaptchaObserver::OnPageLoadMetricsGoingAway() { | |
54 metrics_->RemoveObserver(this); | |
55 delete this; | |
56 } | |
57 | |
58 } // namespace google_captcha_observer | |
Charlie Harrison
2015/11/14 01:19:55
nit: two spaces between } and // (ditto other plac
Matt Welsh
2015/11/16 18:30:53
Done. How do I autoformat my code to adhere to Chr
Charlie Harrison
2015/11/16 19:12:38
"git cl format" should do it. See https://code.goo
| |
OLD | NEW |