OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ | 5 #ifndef COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ |
6 #define COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ | 6 #define COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/task/cancelable_task_tracker.h" | 12 #include "base/task/cancelable_task_tracker.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "components/rappor/rappor_service_impl.h" | |
15 #include "url/gurl.h" | 14 #include "url/gurl.h" |
16 | 15 |
17 namespace history { | 16 namespace history { |
18 class HistoryService; | 17 class HistoryService; |
19 } | 18 } |
20 | 19 |
21 namespace security_interstitials { | 20 namespace security_interstitials { |
22 | 21 |
23 // MetricsHelper records user warning interactions in a common way via METRICS | 22 // MetricsHelper records user warning interactions in a common way via METRICS |
24 // histograms and, optionally, RAPPOR metrics. The class will generate the | 23 // histograms. The class will generate the following histograms: |
25 // following histograms: | |
26 // METRICS: interstitial.<metric_prefix>.decision[.repeat_visit] | 24 // METRICS: interstitial.<metric_prefix>.decision[.repeat_visit] |
27 // METRICS: interstitial.<metric_prefix>.interaction[.repeat_visi] | 25 // METRICS: interstitial.<metric_prefix>.interaction[.repeat_visit] |
28 // RAPPOR: interstitial.<rappor_prefix> (SafeBrowsing parameters) | 26 // wherein |metric_prefix| is specified via ReportDetails. |
29 // RAPPOR: interstitial.<rappor_prefix>2 (Low frequency parameters) | |
30 // wherein |metric_prefix| and |rappor_prefix| are specified via ReportDetails. | |
31 // repeat_visit is also generated if the user has seen the page before. | 27 // repeat_visit is also generated if the user has seen the page before. |
32 // | 28 // |
33 // If |extra_suffix| is not empty, MetricsHelper will append ".<extra_suffix>" | 29 // If |extra_suffix| is not empty, MetricsHelper will append ".<extra_suffix>" |
34 // to generate an additional 2 or 4 more metrics. | 30 // to generate an additional 2 or 4 more metrics. |
35 class MetricsHelper { | 31 class MetricsHelper { |
36 public: | 32 public: |
37 // These enums are used for histograms. Don't reorder, delete, or insert | 33 // These enums are used for histograms. Don't reorder, delete, or insert |
38 // elements. New elements should be added at the end (right before the max). | 34 // elements. New elements should be added at the end (right before the max). |
39 enum Decision { | 35 enum Decision { |
40 SHOW, | 36 SHOW, |
(...skipping 16 matching lines...) Expand all Loading... |
57 REPORT_PHISHING_ERROR, | 53 REPORT_PHISHING_ERROR, |
58 SHOW_WHITEPAPER, | 54 SHOW_WHITEPAPER, |
59 MAX_INTERACTION | 55 MAX_INTERACTION |
60 }; | 56 }; |
61 | 57 |
62 // metric_prefix: Histogram prefix for UMA. | 58 // metric_prefix: Histogram prefix for UMA. |
63 // examples: "phishing", "ssl_overridable" | 59 // examples: "phishing", "ssl_overridable" |
64 // extra_suffix: If not-empty, will generate second set of metrics by | 60 // extra_suffix: If not-empty, will generate second set of metrics by |
65 // placing at the end of the metric name. Examples: | 61 // placing at the end of the metric name. Examples: |
66 // "from_datasaver", "from_device" | 62 // "from_datasaver", "from_device" |
67 // rappor_prefix: Metric prefix for Rappor. | |
68 // examples: "phishing2", "ssl3" | |
69 // rappor_report_type: Specifies the low-frequency RAPPOR configuration to use | |
70 // (i.e. UMA or Safe Browsing). | |
71 // deprecated_rappor_report_type: Specifies the deprecated RAPPOR | |
72 // configuration to use for comparison with the | |
73 // low-frequency metric. | |
74 // The rappor preferences can be left blank if rappor_service is not set. | |
75 // TODO(dominickn): remove deprecated_rappor_report_type once sufficient | |
76 // comparison data has been collected and analysed - crbug.com/605836. | |
77 struct ReportDetails { | 63 struct ReportDetails { |
78 ReportDetails(); | 64 ReportDetails(); |
79 ReportDetails(const ReportDetails& other); | 65 ReportDetails(const ReportDetails& other); |
80 ~ReportDetails(); | 66 ~ReportDetails(); |
81 std::string metric_prefix; | 67 std::string metric_prefix; |
82 std::string extra_suffix; | 68 std::string extra_suffix; |
83 std::string rappor_prefix; | |
84 std::string deprecated_rappor_prefix; | |
85 rappor::RapporType rappor_report_type; | |
86 rappor::RapporType deprecated_rappor_report_type; | |
87 }; | 69 }; |
88 | 70 |
89 // Args: | 71 // Args: |
90 // url: URL of page that triggered the interstitial. Only origin is used. | 72 // url: URL of page that triggered the interstitial. Only origin is used. |
91 // history_service: Set this to record metrics based on whether the user | 73 // history_service: Set this to record metrics based on whether the user |
92 // has visited this hostname before. | 74 // has visited this hostname before. |
93 // rappor_service: If you want RAPPOR statistics, provide a service, | |
94 // settings.rappor_prefix, and settings.rappor_report_type. | |
95 // settings: Specify reporting details (prefixes and report types). | 75 // settings: Specify reporting details (prefixes and report types). |
96 // sampling_event_name: Event name for Experience Sampling. | 76 // sampling_event_name: Event name for Experience Sampling. |
97 // e.g. "phishing_interstitial_" | 77 // e.g. "phishing_interstitial_" |
98 MetricsHelper(const GURL& url, | 78 MetricsHelper(const GURL& url, |
99 const ReportDetails settings, | 79 const ReportDetails settings, |
100 history::HistoryService* history_service, | 80 history::HistoryService* history_service); |
101 const base::WeakPtr<rappor::RapporService>& rappor_service); | |
102 virtual ~MetricsHelper(); | 81 virtual ~MetricsHelper(); |
103 | 82 |
104 // Records a user decision or interaction to the appropriate UMA metrics | 83 // Records a user decision or interaction to the appropriate UMA metrics |
105 // histogram and potentially in a RAPPOR metric. | 84 // histogram. |
106 void RecordUserDecision(Decision decision); | 85 void RecordUserDecision(Decision decision); |
107 void RecordUserInteraction(Interaction interaction); | 86 void RecordUserInteraction(Interaction interaction); |
108 void RecordShutdownMetrics(); | 87 void RecordShutdownMetrics(); |
109 | 88 |
110 // Number of times user visited this origin before. -1 means not-yet-set. | 89 // Number of times user visited this origin before. -1 means not-yet-set. |
111 int NumVisits(); | 90 int NumVisits(); |
112 | 91 |
113 protected: | 92 protected: |
114 // Subclasses should implement any embedder-specific recording logic in these | 93 // Subclasses should implement any embedder-specific recording logic in these |
115 // methods. They'll be invoked from the matching Record methods. | 94 // methods. They'll be invoked from the matching Record methods. |
116 virtual void RecordExtraUserDecisionMetrics(Decision decision) = 0; | 95 virtual void RecordExtraUserDecisionMetrics(Decision decision) = 0; |
117 virtual void RecordExtraUserInteractionMetrics(Interaction interaction) = 0; | 96 virtual void RecordExtraUserInteractionMetrics(Interaction interaction) = 0; |
118 virtual void RecordExtraShutdownMetrics() = 0; | 97 virtual void RecordExtraShutdownMetrics() = 0; |
119 | 98 |
120 private: | 99 private: |
121 // Used to query the HistoryService to see if the URL is in history. It will | 100 // Used to query the HistoryService to see if the URL is in history. It will |
122 // only be invoked if the constructor received |history_service|. | 101 // only be invoked if the constructor received |history_service|. |
123 void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit); | 102 void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit); |
124 | 103 |
125 void RecordUserDecisionToMetrics(Decision decision, | 104 void RecordUserDecisionToMetrics(Decision decision, |
126 const std::string& histogram_name); | 105 const std::string& histogram_name); |
127 void RecordUserDecisionToRappor(Decision decision, | |
128 const rappor::RapporType rappor_report_type, | |
129 const std::string& rappor_prefix); | |
130 const GURL request_url_; | 106 const GURL request_url_; |
131 const ReportDetails settings_; | 107 const ReportDetails settings_; |
132 base::WeakPtr<rappor::RapporService> rappor_service_; | |
133 int num_visits_; | 108 int num_visits_; |
134 base::CancelableTaskTracker request_tracker_; | 109 base::CancelableTaskTracker request_tracker_; |
135 | 110 |
136 DISALLOW_COPY_AND_ASSIGN(MetricsHelper); | 111 DISALLOW_COPY_AND_ASSIGN(MetricsHelper); |
137 }; | 112 }; |
138 | 113 |
139 } // namespace security_interstitials | 114 } // namespace security_interstitials |
140 | 115 |
141 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ | 116 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ |
OLD | NEW |