| 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 #include "components/security_interstitials/core/metrics_helper.h" | 5 #include "components/security_interstitials/core/metrics_helper.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } // namespace | 107 } // namespace |
| 108 | 108 |
| 109 MetricsHelper::~MetricsHelper() {} | 109 MetricsHelper::~MetricsHelper() {} |
| 110 | 110 |
| 111 MetricsHelper::ReportDetails::ReportDetails() | 111 MetricsHelper::ReportDetails::ReportDetails() |
| 112 : rappor_report_type(rappor::NUM_RAPPOR_TYPES) {} | 112 : rappor_report_type(rappor::NUM_RAPPOR_TYPES) {} |
| 113 | 113 |
| 114 MetricsHelper::ReportDetails::ReportDetails(const ReportDetails& other) = | 114 MetricsHelper::ReportDetails::ReportDetails(const ReportDetails& other) = |
| 115 default; | 115 default; |
| 116 | 116 |
| 117 MetricsHelper::ReportDetails::~ReportDetails() {} |
| 118 |
| 117 MetricsHelper::MetricsHelper( | 119 MetricsHelper::MetricsHelper( |
| 118 const GURL& request_url, | 120 const GURL& request_url, |
| 119 const ReportDetails settings, | 121 const ReportDetails settings, |
| 120 history::HistoryService* history_service, | 122 history::HistoryService* history_service, |
| 121 const base::WeakPtr<rappor::RapporService>& rappor_service) | 123 const base::WeakPtr<rappor::RapporService>& rappor_service) |
| 122 : request_url_(request_url), | 124 : request_url_(request_url), |
| 123 settings_(settings), | 125 settings_(settings), |
| 124 rappor_service_(rappor_service), | 126 rappor_service_(rappor_service), |
| 125 num_visits_(-1) { | 127 num_visits_(-1) { |
| 126 DCHECK(!settings_.metric_prefix.empty()); | 128 DCHECK(!settings_.metric_prefix.empty()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 141 RecordUserDecisionToMetrics(decision, histogram_name); | 143 RecordUserDecisionToMetrics(decision, histogram_name); |
| 142 // Record additional information about sites that users have visited before. | 144 // Record additional information about sites that users have visited before. |
| 143 // Report |decision| and SHOW together, filtered by the same history state | 145 // Report |decision| and SHOW together, filtered by the same history state |
| 144 // so they they are paired regardless of when if num_visits_ is populated. | 146 // so they they are paired regardless of when if num_visits_ is populated. |
| 145 if (num_visits_ > 0 && (decision == PROCEED || decision == DONT_PROCEED)) { | 147 if (num_visits_ > 0 && (decision == PROCEED || decision == DONT_PROCEED)) { |
| 146 RecordUserDecisionToMetrics(SHOW, histogram_name + ".repeat_visit"); | 148 RecordUserDecisionToMetrics(SHOW, histogram_name + ".repeat_visit"); |
| 147 RecordUserDecisionToMetrics(decision, histogram_name + ".repeat_visit"); | 149 RecordUserDecisionToMetrics(decision, histogram_name + ".repeat_visit"); |
| 148 } | 150 } |
| 149 | 151 |
| 150 MaybeRecordDecisionAsAction(decision, settings_.metric_prefix); | 152 MaybeRecordDecisionAsAction(decision, settings_.metric_prefix); |
| 151 RecordUserDecisionToRappor(decision); | 153 RecordUserDecisionToRappor(decision, settings_.rappor_report_type, |
| 154 settings_.rappor_prefix); |
| 155 RecordUserDecisionToRappor(decision, settings_.deprecated_rappor_report_type, |
| 156 settings_.deprecated_rappor_prefix); |
| 152 RecordExtraUserDecisionMetrics(decision); | 157 RecordExtraUserDecisionMetrics(decision); |
| 153 } | 158 } |
| 154 | 159 |
| 155 void MetricsHelper::RecordUserDecisionToMetrics( | 160 void MetricsHelper::RecordUserDecisionToMetrics( |
| 156 Decision decision, | 161 Decision decision, |
| 157 const std::string& histogram_name) { | 162 const std::string& histogram_name) { |
| 158 // Record the decision, and additionally |with extra_suffix|. | 163 // Record the decision, and additionally |with extra_suffix|. |
| 159 RecordSingleDecisionToMetrics(decision, histogram_name); | 164 RecordSingleDecisionToMetrics(decision, histogram_name); |
| 160 if (!settings_.extra_suffix.empty()) { | 165 if (!settings_.extra_suffix.empty()) { |
| 161 RecordSingleDecisionToMetrics( | 166 RecordSingleDecisionToMetrics( |
| 162 decision, histogram_name + "." + settings_.extra_suffix); | 167 decision, histogram_name + "." + settings_.extra_suffix); |
| 163 } | 168 } |
| 164 } | 169 } |
| 165 | 170 |
| 166 void MetricsHelper::RecordUserDecisionToRappor(Decision decision) { | 171 void MetricsHelper::RecordUserDecisionToRappor( |
| 172 Decision decision, |
| 173 const rappor::RapporType rappor_report_type, |
| 174 const std::string& rappor_prefix) { |
| 167 if (!rappor_service_ || (decision != PROCEED && decision != DONT_PROCEED)) | 175 if (!rappor_service_ || (decision != PROCEED && decision != DONT_PROCEED)) |
| 168 return; | 176 return; |
| 169 | 177 |
| 170 std::unique_ptr<rappor::Sample> sample = | 178 std::unique_ptr<rappor::Sample> sample = |
| 171 rappor_service_->CreateSample(settings_.rappor_report_type); | 179 rappor_service_->CreateSample(rappor_report_type); |
| 172 | 180 |
| 173 // This will populate, for example, "intersitial.malware.domain" or | 181 // This will populate, for example, "intersitial.malware2.domain" or |
| 174 // "interstitial.ssl2.domain". |domain| will be empty for hosts w/o TLDs. | 182 // "interstitial.ssl3.domain". The domain will be empty for hosts w/o TLDs. |
| 175 const std::string domain = | 183 sample->SetStringField( |
| 176 rappor::GetDomainAndRegistrySampleFromGURL(request_url_); | 184 "domain", rappor::GetDomainAndRegistrySampleFromGURL(request_url_)); |
| 177 sample->SetStringField("domain", domain); | |
| 178 | 185 |
| 179 // Only report history and decision if we have history data. | 186 // Only report history and decision if we have history data. |
| 180 if (num_visits_ >= 0) { | 187 if (num_visits_ >= 0) { |
| 181 int flags = 0; | 188 int flags = 0; |
| 182 if (decision == PROCEED) | 189 if (decision == PROCEED) |
| 183 flags |= 1 << InterstitialFlagBits::DID_PROCEED; | 190 flags |= 1 << InterstitialFlagBits::DID_PROCEED; |
| 184 if (num_visits_ > 0) | 191 if (num_visits_ > 0) |
| 185 flags |= 1 << InterstitialFlagBits::IS_REPEAT_VISIT; | 192 flags |= 1 << InterstitialFlagBits::IS_REPEAT_VISIT; |
| 186 // e.g. "interstitial.malware.flags" | 193 // e.g. "interstitial.malware.flags" |
| 187 sample->SetFlagsField("flags", flags, | 194 sample->SetFlagsField("flags", flags, |
| 188 InterstitialFlagBits::HIGHEST_USED_BIT + 1); | 195 InterstitialFlagBits::HIGHEST_USED_BIT + 1); |
| 189 } | 196 } |
| 190 rappor_service_->RecordSampleObj("interstitial." + settings_.rappor_prefix, | 197 rappor_service_->RecordSampleObj("interstitial." + rappor_prefix, |
| 191 std::move(sample)); | 198 std::move(sample)); |
| 192 } | 199 } |
| 193 | 200 |
| 194 void MetricsHelper::RecordUserInteraction(Interaction interaction) { | 201 void MetricsHelper::RecordUserInteraction(Interaction interaction) { |
| 195 const std::string histogram_name( | 202 const std::string histogram_name( |
| 196 "interstitial." + settings_.metric_prefix + ".interaction"); | 203 "interstitial." + settings_.metric_prefix + ".interaction"); |
| 197 RecordSingleInteractionToMetrics(interaction, histogram_name); | 204 RecordSingleInteractionToMetrics(interaction, histogram_name); |
| 198 if (!settings_.extra_suffix.empty()) { | 205 if (!settings_.extra_suffix.empty()) { |
| 199 RecordSingleInteractionToMetrics( | 206 RecordSingleInteractionToMetrics( |
| 200 interaction, histogram_name + "." + settings_.extra_suffix); | 207 interaction, histogram_name + "." + settings_.extra_suffix); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 213 } | 220 } |
| 214 | 221 |
| 215 void MetricsHelper::OnGotHistoryCount(bool success, | 222 void MetricsHelper::OnGotHistoryCount(bool success, |
| 216 int num_visits, | 223 int num_visits, |
| 217 base::Time /*first_visit*/) { | 224 base::Time /*first_visit*/) { |
| 218 if (success) | 225 if (success) |
| 219 num_visits_ = num_visits; | 226 num_visits_ = num_visits; |
| 220 } | 227 } |
| 221 | 228 |
| 222 } // namespace security_interstitials | 229 } // namespace security_interstitials |
| OLD | NEW |