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.
5 #include "chrome/browser/interstitials/chrome_metrics_helper.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/history/history_service_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/history/core/browser/history_service.h"
11 #include "components/rappor/rappor_service.h"
12 #include "content/public/browser/web_contents.h"
14 #if defined(ENABLE_EXTENSIONS)
15 #include "chrome/browser/extensions/api/experience_sampling_private/experience_sampling.h"
18 ChromeMetricsHelper::ChromeMetricsHelper(
19 content::WebContents
* web_contents
,
20 const GURL
& request_url
,
21 const security_interstitials::MetricsHelper::ReportDetails settings
,
22 const std::string
& sampling_event_name
)
23 : security_interstitials::MetricsHelper(
26 HistoryServiceFactory::GetForProfile(
27 Profile::FromBrowserContext(web_contents
->GetBrowserContext()),
28 ServiceAccessType::EXPLICIT_ACCESS
),
29 g_browser_process
->rappor_service()),
30 web_contents_(web_contents
),
31 request_url_(request_url
),
32 sampling_event_name_(sampling_event_name
) {
33 DCHECK(!sampling_event_name_
.empty());
36 ChromeMetricsHelper::~ChromeMetricsHelper() {}
38 void ChromeMetricsHelper::RecordExtraUserDecisionMetrics(
39 security_interstitials::MetricsHelper::Decision decision
) {
40 #if defined(ENABLE_EXTENSIONS)
41 if (!sampling_event_
.get()) {
42 sampling_event_
.reset(new extensions::ExperienceSamplingEvent(
43 sampling_event_name_
, request_url_
,
44 web_contents_
->GetLastCommittedURL(),
45 web_contents_
->GetBrowserContext()));
49 sampling_event_
->CreateUserDecisionEvent(
50 extensions::ExperienceSamplingEvent::kProceed
);
53 sampling_event_
->CreateUserDecisionEvent(
54 extensions::ExperienceSamplingEvent::kDeny
);
57 case PROCEEDING_DISABLED
:
64 void ChromeMetricsHelper::RecordExtraUserInteractionMetrics(
65 security_interstitials::MetricsHelper::Interaction interaction
) {
66 #if defined(ENABLE_EXTENSIONS)
67 if (!sampling_event_
.get()) {
68 sampling_event_
.reset(new extensions::ExperienceSamplingEvent(
69 sampling_event_name_
, request_url_
,
70 web_contents_
->GetLastCommittedURL(),
71 web_contents_
->GetBrowserContext()));
73 switch (interaction
) {
75 sampling_event_
->set_has_viewed_learn_more(true);
78 sampling_event_
->set_has_viewed_details(true);
80 case SHOW_PRIVACY_POLICY
:
83 case OPEN_TIME_SETTINGS
:
85 case SET_EXTENDED_REPORTING_ENABLED
:
86 case SET_EXTENDED_REPORTING_DISABLED
:
87 case EXTENDED_REPORTING_IS_ENABLED
:
88 case REPORT_PHISHING_ERROR
: