1 // Copyright (c) 2014 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 #ifndef CHROME_BROWSER_INTERSTITIALS_SECURITY_INTERSTITIAL_METRICS_HELPER_H_
6 #define CHROME_BROWSER_INTERSTITIALS_SECURITY_INTERSTITIAL_METRICS_HELPER_H_
10 #include "base/task/cancelable_task_tracker.h"
11 #include "base/time/time.h"
18 namespace extensions
{
19 class ExperienceSamplingEvent
;
22 // Most of the security interstitials share a common layout and set of
23 // choices. SecurityInterstitialMetricsHelper is intended to help the security
24 // interstitials record user choices in a common way via METRICS histograms
25 // and RAPPOR metrics.
26 class SecurityInterstitialMetricsHelper
{
28 // These enums are used for histograms. Don't reorder, delete, or insert
29 // elements. New elements should be added at the end (right before the max).
30 enum SecurityInterstitialDecision
{
37 enum SecurityInterstitialInteraction
{
45 SET_EXTENDED_REPORTING_ENABLED
,
46 SET_EXTENDED_REPORTING_DISABLED
,
47 EXTENDED_REPORTING_IS_ENABLED
,
51 enum RapporReporting
{
57 // url: URL of page that triggered the interstitial. Only origin is used.
58 // uma_prefix: Histogram prefix for UMA.
59 // examples: "phishing", "ssl_overridable"
60 // rappor_prefix: Metric prefix for Rappor.
61 // examples: "phishing", "ssl"
62 // rappor_reporting: Used to skip rappor rapporting if desired.
63 // sampling_event_name: Event name for Experience Sampling.
64 // e.g. "phishing_interstitial_"
65 SecurityInterstitialMetricsHelper(content::WebContents
* web_contents
,
67 const std::string
& uma_prefix
,
68 const std::string
& rappor_prefix
,
69 RapporReporting rappor_reporting
,
70 const std::string
& sampling_event_name
);
71 ~SecurityInterstitialMetricsHelper();
73 // Record a user decision or interaction to the appropriate UMA histogram
74 // and potentially in a RAPPOR metric.
75 void RecordUserDecision(SecurityInterstitialDecision decision
);
76 void RecordUserInteraction(SecurityInterstitialInteraction interaction
);
79 // Used to query the HistoryService to see if the URL is in history.
80 void OnGotHistoryCount(bool success
, int num_visits
, base::Time first_visit
);
82 content::WebContents
* web_contents_
;
83 const GURL request_url_
;
84 const std::string uma_prefix_
;
85 const std::string rappor_prefix_
;
86 const RapporReporting rappor_reporting_
;
87 const std::string sampling_event_name_
;
89 base::CancelableTaskTracker request_tracker_
;
90 #if defined(ENABLE_EXTENSIONS)
91 scoped_ptr
<extensions::ExperienceSamplingEvent
> sampling_event_
;
94 DISALLOW_COPY_AND_ASSIGN(SecurityInterstitialMetricsHelper
);
97 #endif // CHROME_BROWSER_INTERSTITIALS_SECURITY_INTERSTITIAL_METRICS_HELPER_H_