Chromium Code Reviews| 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.h" | 14 #include "components/rappor/rappor_service.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace history { | 17 namespace history { |
| 18 class HistoryService; | 18 class HistoryService; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace security_interstitials { | 21 namespace security_interstitials { |
| 22 | 22 |
| 23 // MetricsHelper records user warning interactions in a common way via METRICS | 23 // MetricsHelper records user warning interactions in a common way via METRICS |
| 24 // histograms and, optionally, RAPPOR metrics. The class will generate the | 24 // histograms and, optionally, RAPPOR metrics. The class will generate the |
| 25 // following histograms: | 25 // following histograms: |
| 26 // METRICS: interstitial.<metric_prefix>.decision[.repeat_visit] | 26 // METRICS: interstitial.<metric_prefix>.decision[.repeat_visit] |
| 27 // METRICS: interstitial.<metric_prefix>.interaction[.repeat_visi] | 27 // METRICS: interstitial.<metric_prefix>.interaction[.repeat_visi] |
| 28 // RAPPOR: interstitial.<rappor_prefix> | 28 // RAPPOR: interstitial.<rappor_prefix> (SafeBrowsing parameters) |
| 29 // RAPPOR: interstitial.<rappor_prefix>2 (Low frequency parameters) | |
| 29 // wherein |metric_prefix| and |rappor_prefix| are specified via ReportDetails. | 30 // wherein |metric_prefix| and |rappor_prefix| are specified via ReportDetails. |
| 30 // repeat_visit is also generated if the user has seen the page before. | 31 // repeat_visit is also generated if the user has seen the page before. |
| 31 // | 32 // |
| 32 // If |extra_suffix| is not empty, MetricsHelper will append ".<extra_suffix>" | 33 // If |extra_suffix| is not empty, MetricsHelper will append ".<extra_suffix>" |
| 33 // to generate an additional 2 or 4 more metrics. | 34 // to generate an additional 2 or 4 more metrics. |
| 34 class MetricsHelper { | 35 class MetricsHelper { |
| 35 public: | 36 public: |
| 36 // These enums are used for histograms. Don't reorder, delete, or insert | 37 // These enums are used for histograms. Don't reorder, delete, or insert |
| 37 // elements. New elements should be added at the end (right before the max). | 38 // elements. New elements should be added at the end (right before the max). |
| 38 enum Decision { | 39 enum Decision { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 56 REPORT_PHISHING_ERROR, | 57 REPORT_PHISHING_ERROR, |
| 57 MAX_INTERACTION | 58 MAX_INTERACTION |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 // metric_prefix: Histogram prefix for UMA. | 61 // metric_prefix: Histogram prefix for UMA. |
| 61 // examples: "phishing", "ssl_overridable" | 62 // examples: "phishing", "ssl_overridable" |
| 62 // extra_suffix: If not-empty, will generate second set of metrics by | 63 // extra_suffix: If not-empty, will generate second set of metrics by |
| 63 // placing at the end of the metric name. Examples: | 64 // placing at the end of the metric name. Examples: |
| 64 // "from_datasaver", "from_device" | 65 // "from_datasaver", "from_device" |
| 65 // rappor_prefix: Metric prefix for Rappor. | 66 // rappor_prefix: Metric prefix for Rappor. |
| 66 // examples: "phishing", "ssl2" | 67 // examples: "phishing2", "ssl3" |
| 67 // rappor_report_type: Used to differentiate UMA and Safe Browsing statistics. | 68 // rappor_report_type: Specifies the low-frequency RAPPOR configuration to use |
| 69 // (i.e. UMA or Safe Browsing). | |
|
tsergeant
2016/04/26 04:40:51
Nit: Align this line with the colon, like above.
dominickn
2016/04/26 09:44:30
Done.
| |
| 70 // deprecated_rappor_report_type: Specifies the deprecated RAPPOR | |
| 71 // configuration to use for comparison with the low-frequency metric. | |
| 68 // The rappor preferences can be left blank if rappor_service is not set. | 72 // The rappor preferences can be left blank if rappor_service is not set. |
| 73 // TODO(dominickn): remove deprecated_rappor_report_type once sufficient | |
| 74 // comparison data has been collected and analysed - crbug.com/605836. | |
| 69 struct ReportDetails { | 75 struct ReportDetails { |
| 70 ReportDetails(); | 76 ReportDetails(); |
| 71 ReportDetails(const ReportDetails& other); | 77 ReportDetails(const ReportDetails& other); |
| 78 ~ReportDetails(); | |
| 72 std::string metric_prefix; | 79 std::string metric_prefix; |
| 73 std::string extra_suffix; | 80 std::string extra_suffix; |
| 74 std::string rappor_prefix; | 81 std::string rappor_prefix; |
| 82 std::string deprecated_rappor_prefix; | |
| 75 rappor::RapporType rappor_report_type; | 83 rappor::RapporType rappor_report_type; |
| 84 rappor::RapporType deprecated_rappor_report_type; | |
| 76 }; | 85 }; |
| 77 | 86 |
| 78 // Args: | 87 // Args: |
| 79 // url: URL of page that triggered the interstitial. Only origin is used. | 88 // url: URL of page that triggered the interstitial. Only origin is used. |
| 80 // history_service: Set this to record metrics based on whether the user | 89 // history_service: Set this to record metrics based on whether the user |
| 81 // has visited this hostname before. | 90 // has visited this hostname before. |
| 82 // rappor_service: If you want RAPPOR statistics, provide a service, | 91 // rappor_service: If you want RAPPOR statistics, provide a service, |
| 83 // settings.rappor_prefix, and settings.rappor_report_type. | 92 // settings.rappor_prefix, and settings.rappor_report_type. |
| 84 // settings: Specify reporting details (prefixes and report types). | 93 // settings: Specify reporting details (prefixes and report types). |
| 85 // sampling_event_name: Event name for Experience Sampling. | 94 // sampling_event_name: Event name for Experience Sampling. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 106 virtual void RecordExtraUserInteractionMetrics(Interaction interaction) = 0; | 115 virtual void RecordExtraUserInteractionMetrics(Interaction interaction) = 0; |
| 107 virtual void RecordExtraShutdownMetrics() = 0; | 116 virtual void RecordExtraShutdownMetrics() = 0; |
| 108 | 117 |
| 109 private: | 118 private: |
| 110 // Used to query the HistoryService to see if the URL is in history. It will | 119 // Used to query the HistoryService to see if the URL is in history. It will |
| 111 // only be invoked if the constructor received |history_service|. | 120 // only be invoked if the constructor received |history_service|. |
| 112 void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit); | 121 void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit); |
| 113 | 122 |
| 114 void RecordUserDecisionToMetrics(Decision decision, | 123 void RecordUserDecisionToMetrics(Decision decision, |
| 115 const std::string& histogram_name); | 124 const std::string& histogram_name); |
| 116 void RecordUserDecisionToRappor(Decision decision); | 125 void RecordUserDecisionToRappor(Decision decision, |
| 126 const rappor::RapporType rappor_report_type, | |
| 127 const std::string& rappor_prefix); | |
| 117 const GURL request_url_; | 128 const GURL request_url_; |
| 118 const ReportDetails settings_; | 129 const ReportDetails settings_; |
| 119 base::WeakPtr<rappor::RapporService> rappor_service_; | 130 base::WeakPtr<rappor::RapporService> rappor_service_; |
| 120 int num_visits_; | 131 int num_visits_; |
| 121 base::CancelableTaskTracker request_tracker_; | 132 base::CancelableTaskTracker request_tracker_; |
| 122 | 133 |
| 123 DISALLOW_COPY_AND_ASSIGN(MetricsHelper); | 134 DISALLOW_COPY_AND_ASSIGN(MetricsHelper); |
| 124 }; | 135 }; |
| 125 | 136 |
| 126 } // namespace security_interstitials | 137 } // namespace security_interstitials |
| 127 | 138 |
| 128 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ | 139 #endif // COMPONENTS_SECURITY_INTERSTITIALS_CORE_METRICS_HELPER_H_ |
| OLD | NEW |