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

Side by Side Diff: chrome/browser/page_load_metrics/observers/google_captcha_observer.cc

Issue 1465533002: (Merging on behalf of mdw@) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2564
Patch Set: 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 unified diff | Download patch
OLDNEW
(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 google_captcha_observer {
14
15 namespace {
16
17 const char kGoogleCaptchaEvents[] = "PageLoad.Clients.GoogleCaptcha.Events";
18
19 enum GoogleCaptchaEvent {
20 // A Google CAPTCHA page was shown to the user.
21 GOOGLE_CAPTCHA_SHOWN,
22 // A Google CAPTCHA page was solved by the user.
23 GOOGLE_CAPTCHA_SOLVED,
24 // Add new values before this final count.
25 GOOGLE_CAPTCHA_EVENT_BOUNDARY,
26 };
27
28 void RecordGoogleCaptchaEvent(GoogleCaptchaEvent event) {
29 UMA_HISTOGRAM_ENUMERATION(
30 kGoogleCaptchaEvents, event,
31 GOOGLE_CAPTCHA_EVENT_BOUNDARY);
32 }
33
34 } // namespace
35
36 bool IsGoogleCaptcha(const GURL& url) {
37 return (base::StartsWith(url.host(), "ipv4.google.",
38 base::CompareCase::SENSITIVE)
39 || base::StartsWith(url.host(), "ipv6.google.",
40 base::CompareCase::SENSITIVE))
41 && base::StartsWith(url.path(), "/sorry", base::CompareCase::SENSITIVE);
42 }
43
44 GoogleCaptchaObserver::GoogleCaptchaObserver(
45 page_load_metrics::PageLoadMetricsObservable* metrics)
46 : metrics_(metrics) {}
47
48 void GoogleCaptchaObserver::OnCommit(
49 content::NavigationHandle* navigation_handle) {
50 if (IsGoogleCaptcha(navigation_handle->GetURL()))
51 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SHOWN);
52 }
53
54 void GoogleCaptchaObserver::OnRedirect(
55 content::NavigationHandle* navigation_handle) {
56 if (IsGoogleCaptcha(navigation_handle->GetReferrer().url))
57 RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SOLVED);
58 }
59
60 void GoogleCaptchaObserver::OnPageLoadMetricsGoingAway() {
61 metrics_->RemoveObserver(this);
62 delete this;
63 }
64
65 } // namespace google_captcha_observer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698