Index: chrome/browser/page_load_metrics/observers/google_captcha_observer.cc |
diff --git a/chrome/browser/page_load_metrics/observers/google_captcha_observer.cc b/chrome/browser/page_load_metrics/observers/google_captcha_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9ce8716b576efa8531d848fc11c142487d9a32af |
--- /dev/null |
+++ b/chrome/browser/page_load_metrics/observers/google_captcha_observer.cc |
@@ -0,0 +1,58 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/page_load_metrics/observers/google_captcha_observer.h" |
+ |
+#include "base/metrics/histogram.h" |
+#include "base/strings/string_util.h" |
+#include "components/page_load_metrics/browser/page_load_metrics_macros.h" |
+#include "components/page_load_metrics/common/page_load_timing.h" |
+#include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
+ |
+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.
|
+ |
+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.
|
+ |
+void RecordGoogleCaptchaEvent( |
+ google_captcha_observer::GoogleCaptchaEvent event) { |
+ UMA_HISTOGRAM_ENUMERATION( |
+ kHistogramNameGoogleCaptcha, event, |
+ google_captcha_observer::GOOGLE_CAPTCHA_EVENT_BOUNDARY); |
+} |
+ |
+} // namespace |
+ |
+namespace google_captcha_observer { |
+ |
+bool IsGoogleCaptcha(const GURL& url) { |
+ return (base::StartsWith(url.host(), "ipv4.google.", |
+ base::CompareCase::SENSITIVE) |
+ || base::StartsWith(url.host(), "ipv6.google.", |
+ base::CompareCase::SENSITIVE)) |
+ && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE); |
+} |
+ |
+GoogleCaptchaObserver::GoogleCaptchaObserver( |
+ page_load_metrics::PageLoadMetricsObservable* metrics) |
+ : metrics_(metrics) {} |
+ |
+void GoogleCaptchaObserver::OnCommit( |
+ content::NavigationHandle* navigation_handle) { |
+ if (IsGoogleCaptcha(navigation_handle->GetURL())) |
+ RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SHOWN); |
+} |
+ |
+void GoogleCaptchaObserver::OnRedirect( |
+ content::NavigationHandle* navigation_handle) { |
+ if (navigation_handle->GetReferrer() && |
+ IsGoogleCaptcha(navigation_handle->GetReferrer().url)) |
+ RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SOLVED); |
+} |
+ |
+void GoogleCaptchaObserver::OnPageLoadMetricsGoingAway() { |
+ metrics_->RemoveObserver(this); |
+ delete this; |
+} |
+ |
+} // 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
|