Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5789)

Unified Diff: chrome/browser/page_load_metrics/observers/google_captcha_observer.cc

Issue 1441393002: Add UMA to count the number of Google CAPTCHA pages shown and solved by users. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding missing files (whoops) Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698