blob: 9d47fd0435ea6a911d2a889c06c8ede9484a3977 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// 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_util.h"
#include "components/page_load_metrics/common/page_load_timing.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
namespace google_captcha_observer {
namespace {
const char kGoogleCaptchaEvents[] = "PageLoad.Clients.GoogleCaptcha.Events";
enum GoogleCaptchaEvent {
// A Google CAPTCHA page was shown to the user.
GOOGLE_CAPTCHA_SHOWN,
// A Google CAPTCHA page was solved by the user.
GOOGLE_CAPTCHA_SOLVED,
// Add new values before this final count.
GOOGLE_CAPTCHA_EVENT_BOUNDARY,
};
void RecordGoogleCaptchaEvent(GoogleCaptchaEvent event) {
UMA_HISTOGRAM_ENUMERATION(
kGoogleCaptchaEvents, event,
GOOGLE_CAPTCHA_EVENT_BOUNDARY);
}
} // namespace
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() : saw_solution_(false) {}
void GoogleCaptchaObserver::OnCommit(
content::NavigationHandle* navigation_handle) {
if (!navigation_handle->IsSamePage()
&& IsGoogleCaptcha(navigation_handle->GetURL())) {
RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SHOWN);
}
}
void GoogleCaptchaObserver::OnRedirect(
content::NavigationHandle* navigation_handle) {
if (IsGoogleCaptcha(navigation_handle->GetReferrer().url) && !saw_solution_) {
RecordGoogleCaptchaEvent(GOOGLE_CAPTCHA_SOLVED);
saw_solution_ = true;
}
}
} // namespace google_captcha_observer
|