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 #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" |
| 11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 12 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
| 13 #include "components/history/core/browser/history_service.h" | 13 #include "components/history/core/browser/history_service.h" |
| 14 #include "components/rappor/rappor_service.h" | 14 #include "components/rappor/public/rappor_utils.h" |
| 15 #include "components/rappor/rappor_utils.h" | 15 #include "components/rappor/rappor_service_impl.h" |
| 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 16 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 17 | 17 |
| 18 using base::RecordAction; | 18 using base::RecordAction; |
| 19 using base::UserMetricsAction; | 19 using base::UserMetricsAction; |
| 20 | 20 |
| 21 namespace security_interstitials { | 21 namespace security_interstitials { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Used for setting bits in Rappor's "interstitial.*.flags" | 25 // Used for setting bits in Rappor's "interstitial.*.flags" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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() {} | 117 MetricsHelper::ReportDetails::~ReportDetails() {} |
| 118 | 118 |
| 119 MetricsHelper::MetricsHelper( | 119 MetricsHelper::MetricsHelper( |
| 120 const GURL& request_url, | 120 const GURL& request_url, |
|
estark
2016/12/07 00:45:02
did `git cl format` do this?
Navid Zolghadr
2016/12/07 00:49:34
I certainly did not do it manually. I just re-ran
| |
| 121 const ReportDetails settings, | 121 const ReportDetails settings, |
| 122 history::HistoryService* history_service, | 122 history::HistoryService* history_service, |
| 123 const base::WeakPtr<rappor::RapporService>& rappor_service) | 123 const base::WeakPtr<rappor::RapporService>& rappor_service) |
| 124 : request_url_(request_url), | 124 : request_url_(request_url), |
| 125 settings_(settings), | 125 settings_(settings), |
| 126 rappor_service_(rappor_service), | 126 rappor_service_(rappor_service), |
| 127 num_visits_(-1) { | 127 num_visits_(-1) { |
| 128 DCHECK(!settings_.metric_prefix.empty()); | 128 DCHECK(!settings_.metric_prefix.empty()); |
| 129 if (settings_.rappor_report_type == rappor::NUM_RAPPOR_TYPES) // Default. | 129 if (settings_.rappor_report_type == rappor::NUM_RAPPOR_TYPES) // Default. |
| 130 rappor_service_.reset(); | 130 rappor_service_.reset(); |
| 131 DCHECK(!rappor_service_ || !settings_.rappor_prefix.empty()); | 131 DCHECK(!rappor_service_ || !settings_.rappor_prefix.empty()); |
| 132 if (history_service) { | 132 if (history_service) { |
| 133 history_service->GetVisibleVisitCountToHost( | 133 history_service->GetVisibleVisitCountToHost( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 if (num_visits_ >= 0) { | 187 if (num_visits_ >= 0) { |
| 188 int flags = 0; | 188 int flags = 0; |
| 189 if (decision == PROCEED) | 189 if (decision == PROCEED) |
| 190 flags |= 1 << InterstitialFlagBits::DID_PROCEED; | 190 flags |= 1 << InterstitialFlagBits::DID_PROCEED; |
| 191 if (num_visits_ > 0) | 191 if (num_visits_ > 0) |
| 192 flags |= 1 << InterstitialFlagBits::IS_REPEAT_VISIT; | 192 flags |= 1 << InterstitialFlagBits::IS_REPEAT_VISIT; |
| 193 // e.g. "interstitial.malware.flags" | 193 // e.g. "interstitial.malware.flags" |
| 194 sample->SetFlagsField("flags", flags, | 194 sample->SetFlagsField("flags", flags, |
| 195 InterstitialFlagBits::HIGHEST_USED_BIT + 1); | 195 InterstitialFlagBits::HIGHEST_USED_BIT + 1); |
| 196 } | 196 } |
| 197 rappor_service_->RecordSampleObj("interstitial." + rappor_prefix, | 197 rappor_service_->RecordSample("interstitial." + rappor_prefix, |
| 198 std::move(sample)); | 198 std::move(sample)); |
| 199 } | 199 } |
| 200 | 200 |
| 201 void MetricsHelper::RecordUserInteraction(Interaction interaction) { | 201 void MetricsHelper::RecordUserInteraction(Interaction interaction) { |
| 202 const std::string histogram_name( | 202 const std::string histogram_name( |
| 203 "interstitial." + settings_.metric_prefix + ".interaction"); | 203 "interstitial." + settings_.metric_prefix + ".interaction"); |
| 204 RecordSingleInteractionToMetrics(interaction, histogram_name); | 204 RecordSingleInteractionToMetrics(interaction, histogram_name); |
| 205 if (!settings_.extra_suffix.empty()) { | 205 if (!settings_.extra_suffix.empty()) { |
| 206 RecordSingleInteractionToMetrics( | 206 RecordSingleInteractionToMetrics( |
| 207 interaction, histogram_name + "." + settings_.extra_suffix); | 207 interaction, histogram_name + "." + settings_.extra_suffix); |
| 208 } | 208 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 220 } | 220 } |
| 221 | 221 |
| 222 void MetricsHelper::OnGotHistoryCount(bool success, | 222 void MetricsHelper::OnGotHistoryCount(bool success, |
| 223 int num_visits, | 223 int num_visits, |
| 224 base::Time /*first_visit*/) { | 224 base::Time /*first_visit*/) { |
| 225 if (success) | 225 if (success) |
| 226 num_visits_ = num_visits; | 226 num_visits_ = num_visits; |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace security_interstitials | 229 } // namespace security_interstitials |
| OLD | NEW |