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 #ifndef COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_
6 #define COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_
10 #include "base/task/cancelable_task_tracker.h"
11 #include "base/time/time.h"
12 #include "components/rappor/rappor_service.h"
19 namespace security_interstitials
{
21 // MetricsHelper records user warning interactions in a common way via METRICS
22 // histograms and, optionally, RAPPOR metrics. The class will generate the
23 // following histograms:
24 // METRICS: interstitial.<metric_prefix>.decision[.repeat_visit]
25 // METRICS: interstitial.<metric_prefix>.interaction[.repeat_visi]
26 // RAPPOR: interstitial.<rappor_prefix>
27 // wherein |metric_prefix| and |rappor_prefix| are specified via ReportDetails.
28 // repeat_visit is also generated if the user has seen the page before.
30 // If |extra_suffix| is not empty, MetricsHelper will append ".<extra_suffix>"
31 // to generate an additional 2 or 4 more metrics.
34 // These enums are used for histograms. Don't reorder, delete, or insert
35 // elements. New elements should be added at the end (right before the max).
51 SET_EXTENDED_REPORTING_ENABLED
,
52 SET_EXTENDED_REPORTING_DISABLED
,
53 EXTENDED_REPORTING_IS_ENABLED
,
54 REPORT_PHISHING_ERROR
,
58 // metric_prefix: Histogram prefix for UMA.
59 // examples: "phishing", "ssl_overridable"
60 // extra_suffix: If not-empty, will generate second set of metrics by
61 // placing at the end of the metric name. Examples:
62 // "from_datasaver", "from_device"
63 // rappor_prefix: Metric prefix for Rappor.
64 // examples: "phishing", "ssl2"
65 // rappor_report_type: Used to differentiate UMA and Safe Browsing statistics.
66 // The rappor preferences can be left blank if rappor_service is not set.
67 struct ReportDetails
{
69 std::string metric_prefix
;
70 std::string extra_suffix
;
71 std::string rappor_prefix
;
72 rappor::RapporType rappor_report_type
;
76 // url: URL of page that triggered the interstitial. Only origin is used.
77 // history_service: Set this to record metrics based on whether the user
78 // has visited this hostname before.
79 // rappor_service: If you want RAPPOR statistics, provide a service,
80 // settings.rappor_prefix, and settings.rappor_report_type.
81 // settings: Specify reporting details (prefixes and report types).
82 // sampling_event_name: Event name for Experience Sampling.
83 // e.g. "phishing_interstitial_"
84 MetricsHelper(const GURL
& url
,
85 const ReportDetails settings
,
86 history::HistoryService
* history_service
,
87 rappor::RapporService
* rappor_service
);
88 virtual ~MetricsHelper() {}
90 // Records a user decision or interaction to the appropriate UMA metrics
91 // histogram and potentially in a RAPPOR metric.
92 void RecordUserDecision(Decision decision
);
93 void RecordUserInteraction(Interaction interaction
);
96 // Subclasses should implement any embedder-specific recording logic in these
97 // methods. They'll be invoked from RecordUserDecision/Interaction.
98 virtual void RecordExtraUserDecisionMetrics(Decision decision
) = 0;
99 virtual void RecordExtraUserInteractionMetrics(Interaction interaction
) = 0;
102 // Used to query the HistoryService to see if the URL is in history. It will
103 // only be invoked if the constructor received |history_service|.
104 void OnGotHistoryCount(bool success
, int num_visits
, base::Time first_visit
);
106 void RecordUserDecisionToMetrics(Decision decision
,
107 const std::string
& histogram_name
);
108 void RecordUserDecisionToRappor(Decision decision
);
109 const GURL request_url_
;
110 const ReportDetails settings_
;
111 rappor::RapporService
* rappor_service_
;
113 base::CancelableTaskTracker request_tracker_
;
115 DISALLOW_COPY_AND_ASSIGN(MetricsHelper
);
118 } // namespace security_interstitials
120 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_