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