Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: components/security_interstitials/core/metrics_helper.h

Issue 2575623002: Componentizing SafeBrowsingBlockingPage Part 1 (Closed)
Patch Set: nits Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
25 // following histograms: 24 // following histograms:
26 // METRICS: interstitial.<metric_prefix>.decision[.repeat_visit] 25 // METRICS: interstitial.<metric_prefix>.decision[.repeat_visit]
27 // METRICS: interstitial.<metric_prefix>.interaction[.repeat_visi] 26 // METRICS: interstitial.<metric_prefix>.interaction[.repeat_visi]
28 // RAPPOR: interstitial.<rappor_prefix> (SafeBrowsing parameters) 27 // 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. 28 // repeat_visit is also generated if the user has seen the page before.
32 // 29 //
33 // If |extra_suffix| is not empty, MetricsHelper will append ".<extra_suffix>" 30 // If |extra_suffix| is not empty, MetricsHelper will append ".<extra_suffix>"
34 // to generate an additional 2 or 4 more metrics. 31 // to generate an additional 2 or 4 more metrics.
35 class MetricsHelper { 32 class MetricsHelper {
36 public: 33 public:
37 // These enums are used for histograms. Don't reorder, delete, or insert 34 // 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). 35 // elements. New elements should be added at the end (right before the max).
39 enum Decision { 36 enum Decision {
40 SHOW, 37 SHOW,
(...skipping 16 matching lines...) Expand all
57 REPORT_PHISHING_ERROR, 54 REPORT_PHISHING_ERROR,
58 SHOW_WHITEPAPER, 55 SHOW_WHITEPAPER,
59 MAX_INTERACTION 56 MAX_INTERACTION
60 }; 57 };
61 58
62 // metric_prefix: Histogram prefix for UMA. 59 // metric_prefix: Histogram prefix for UMA.
63 // examples: "phishing", "ssl_overridable" 60 // examples: "phishing", "ssl_overridable"
64 // extra_suffix: If not-empty, will generate second set of metrics by 61 // extra_suffix: If not-empty, will generate second set of metrics by
65 // placing at the end of the metric name. Examples: 62 // placing at the end of the metric name. Examples:
66 // "from_datasaver", "from_device" 63 // "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 { 64 struct ReportDetails {
78 ReportDetails(); 65 ReportDetails();
79 ReportDetails(const ReportDetails& other); 66 ReportDetails(const ReportDetails& other);
80 ~ReportDetails(); 67 ~ReportDetails();
81 std::string metric_prefix; 68 std::string metric_prefix;
82 std::string extra_suffix; 69 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 }; 70 };
88 71
89 // Args: 72 // Args:
90 // url: URL of page that triggered the interstitial. Only origin is used. 73 // 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 74 // history_service: Set this to record metrics based on whether the user
92 // has visited this hostname before. 75 // 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). 76 // settings: Specify reporting details (prefixes and report types).
96 // sampling_event_name: Event name for Experience Sampling. 77 // sampling_event_name: Event name for Experience Sampling.
97 // e.g. "phishing_interstitial_" 78 // e.g. "phishing_interstitial_"
98 MetricsHelper(const GURL& url, 79 MetricsHelper(const GURL& url,
99 const ReportDetails settings, 80 const ReportDetails settings,
100 history::HistoryService* history_service, 81 history::HistoryService* history_service);
101 const base::WeakPtr<rappor::RapporService>& rappor_service);
102 virtual ~MetricsHelper(); 82 virtual ~MetricsHelper();
103 83
104 // Records a user decision or interaction to the appropriate UMA metrics 84 // Records a user decision or interaction to the appropriate UMA metrics
105 // histogram and potentially in a RAPPOR metric. 85 // histogram.
106 void RecordUserDecision(Decision decision); 86 void RecordUserDecision(Decision decision);
107 void RecordUserInteraction(Interaction interaction); 87 void RecordUserInteraction(Interaction interaction);
108 void RecordShutdownMetrics(); 88 void RecordShutdownMetrics();
109 89
110 // Number of times user visited this origin before. -1 means not-yet-set. 90 // Number of times user visited this origin before. -1 means not-yet-set.
111 int NumVisits(); 91 int NumVisits();
112 92
113 protected: 93 protected:
114 // Subclasses should implement any embedder-specific recording logic in these 94 // Subclasses should implement any embedder-specific recording logic in these
115 // methods. They'll be invoked from the matching Record methods. 95 // methods. They'll be invoked from the matching Record methods.
116 virtual void RecordExtraUserDecisionMetrics(Decision decision) = 0; 96 virtual void RecordExtraUserDecisionMetrics(Decision decision) = 0;
117 virtual void RecordExtraUserInteractionMetrics(Interaction interaction) = 0; 97 virtual void RecordExtraUserInteractionMetrics(Interaction interaction) = 0;
118 virtual void RecordExtraShutdownMetrics() = 0; 98 virtual void RecordExtraShutdownMetrics() = 0;
119 99
120 private: 100 private:
121 // Used to query the HistoryService to see if the URL is in history. It will 101 // 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|. 102 // only be invoked if the constructor received |history_service|.
123 void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit); 103 void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit);
124 104
125 void RecordUserDecisionToMetrics(Decision decision, 105 void RecordUserDecisionToMetrics(Decision decision,
126 const std::string& histogram_name); 106 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_; 107 const GURL request_url_;
131 const ReportDetails settings_; 108 const ReportDetails settings_;
132 base::WeakPtr<rappor::RapporService> rappor_service_;
133 int num_visits_; 109 int num_visits_;
134 base::CancelableTaskTracker request_tracker_; 110 base::CancelableTaskTracker request_tracker_;
135 111
136 DISALLOW_COPY_AND_ASSIGN(MetricsHelper); 112 DISALLOW_COPY_AND_ASSIGN(MetricsHelper);
137 }; 113 };
138 114
139 } // namespace security_interstitials 115 } // namespace security_interstitials
140 116
141 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ 117 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698