OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/autofill/core/browser/autofill_metrics.h" | 5 #include "components/autofill/core/browser/autofill_metrics.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
14 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "components/autofill/core/browser/autofill_experiments.h" | 16 #include "components/autofill/core/browser/autofill_experiments.h" |
17 #include "components/autofill/core/browser/autofill_field.h" | 17 #include "components/autofill/core/browser/autofill_field.h" |
18 #include "components/autofill/core/browser/autofill_type.h" | 18 #include "components/autofill/core/browser/autofill_type.h" |
19 #include "components/autofill/core/browser/form_structure.h" | 19 #include "components/autofill/core/browser/form_structure.h" |
20 #include "components/autofill/core/common/form_data.h" | 20 #include "components/autofill/core/common/form_data.h" |
21 #include "components/ukm/ukm_entry_builder.h" | 21 #include "components/ukm/public/ukm_entry_builder.h" |
22 | 22 |
23 namespace internal { | 23 namespace internal { |
24 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; | 24 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; |
25 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; | 25 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; |
26 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; | 26 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; |
27 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; | 27 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; |
28 const char kUKMMillisecondsSinceFormLoadedMetricName[] = | 28 const char kUKMMillisecondsSinceFormLoadedMetricName[] = |
29 "MillisecondsSinceFormLoaded"; | 29 "MillisecondsSinceFormLoaded"; |
30 const char kUKMInteractedWithFormEntryName[] = "Autofill.InteractedWithForm"; | 30 const char kUKMInteractedWithFormEntryName[] = "Autofill.InteractedWithForm"; |
31 const char kUKMIsForCreditCardMetricName[] = "IsForCreditCard"; | 31 const char kUKMIsForCreditCardMetricName[] = "IsForCreditCard"; |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES); | 753 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES); |
754 } | 754 } |
755 | 755 |
756 // static | 756 // static |
757 void AutofillMetrics::LogShowedHttpNotSecureExplanation() { | 757 void AutofillMetrics::LogShowedHttpNotSecureExplanation() { |
758 base::RecordAction( | 758 base::RecordAction( |
759 base::UserMetricsAction("Autofill_ShowedHttpNotSecureExplanation")); | 759 base::UserMetricsAction("Autofill_ShowedHttpNotSecureExplanation")); |
760 } | 760 } |
761 | 761 |
762 // static | 762 // static |
763 void AutofillMetrics::LogCardUploadDecisionsUkm(ukm::UkmService* ukm_service, | 763 void AutofillMetrics::LogCardUploadDecisionsUkm(ukm::UkmRecorder* ukm_recorder, |
764 const GURL& url, | 764 const GURL& url, |
765 int upload_decision_metrics) { | 765 int upload_decision_metrics) { |
766 DCHECK(upload_decision_metrics); | 766 DCHECK(upload_decision_metrics); |
767 DCHECK_LT(upload_decision_metrics, 1 << kNumCardUploadDecisionMetrics); | 767 DCHECK_LT(upload_decision_metrics, 1 << kNumCardUploadDecisionMetrics); |
768 | 768 |
769 const std::vector<std::pair<const char*, int>> metrics = { | 769 const std::vector<std::pair<const char*, int>> metrics = { |
770 {internal::kUKMCardUploadDecisionMetricName, upload_decision_metrics}}; | 770 {internal::kUKMCardUploadDecisionMetricName, upload_decision_metrics}}; |
771 LogUkm(ukm_service, url, internal::kUKMCardUploadDecisionEntryName, metrics); | 771 LogUkm(ukm_recorder, url, internal::kUKMCardUploadDecisionEntryName, metrics); |
772 } | 772 } |
773 | 773 |
774 // static | 774 // static |
775 void AutofillMetrics::LogDeveloperEngagementUkm( | 775 void AutofillMetrics::LogDeveloperEngagementUkm( |
776 ukm::UkmService* ukm_service, | 776 ukm::UkmRecorder* ukm_recorder, |
777 const GURL& url, | 777 const GURL& url, |
778 int developer_engagement_metrics) { | 778 int developer_engagement_metrics) { |
779 DCHECK(developer_engagement_metrics); | 779 DCHECK(developer_engagement_metrics); |
780 DCHECK_LT(developer_engagement_metrics, | 780 DCHECK_LT(developer_engagement_metrics, |
781 1 << NUM_DEVELOPER_ENGAGEMENT_METRICS); | 781 1 << NUM_DEVELOPER_ENGAGEMENT_METRICS); |
782 | 782 |
783 const std::vector<std::pair<const char*, int>> metrics = { | 783 const std::vector<std::pair<const char*, int>> metrics = { |
784 {internal::kUKMDeveloperEngagementMetricName, | 784 {internal::kUKMDeveloperEngagementMetricName, |
785 developer_engagement_metrics}}; | 785 developer_engagement_metrics}}; |
786 | 786 |
787 LogUkm(ukm_service, url, internal::kUKMDeveloperEngagementEntryName, metrics); | 787 LogUkm(ukm_recorder, url, internal::kUKMDeveloperEngagementEntryName, |
| 788 metrics); |
788 } | 789 } |
789 | 790 |
790 // static | 791 // static |
791 bool AutofillMetrics::LogUkm( | 792 bool AutofillMetrics::LogUkm( |
792 ukm::UkmService* ukm_service, | 793 ukm::UkmRecorder* ukm_recorder, |
793 const GURL& url, | 794 const GURL& url, |
794 const std::string& ukm_entry_name, | 795 const std::string& ukm_entry_name, |
795 const std::vector<std::pair<const char*, int>>& metrics) { | 796 const std::vector<std::pair<const char*, int>>& metrics) { |
796 if (!IsUkmLoggingEnabled() || !ukm_service || !url.is_valid() || | 797 if (!IsUkmLoggingEnabled() || !ukm_recorder || !url.is_valid() || |
797 metrics.empty()) { | 798 metrics.empty()) { |
798 return false; | 799 return false; |
799 } | 800 } |
800 | 801 |
801 int32_t source_id = ukm_service->GetNewSourceID(); | 802 ukm::SourceId source_id = ukm_recorder->GetNewSourceID(); |
802 ukm_service->UpdateSourceURL(source_id, url); | 803 ukm_recorder->UpdateSourceURL(source_id, url); |
803 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 804 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
804 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); | 805 ukm_recorder->GetEntryBuilder(source_id, ukm_entry_name.c_str()); |
805 | 806 |
806 for (auto it = metrics.begin(); it != metrics.end(); ++it) { | 807 for (auto it = metrics.begin(); it != metrics.end(); ++it) { |
807 builder->AddMetric(it->first, it->second); | 808 builder->AddMetric(it->first, it->second); |
808 } | 809 } |
809 | 810 |
810 return true; | 811 return true; |
811 } | 812 } |
812 | 813 |
813 AutofillMetrics::FormEventLogger::FormEventLogger( | 814 AutofillMetrics::FormEventLogger::FormEventLogger( |
814 bool is_for_credit_card, | 815 bool is_for_credit_card, |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 else if (server_record_type_count_ > 0 && local_record_type_count_ == 0) | 1024 else if (server_record_type_count_ > 0 && local_record_type_count_ == 0) |
1024 name += ".WithOnlyServerData"; | 1025 name += ".WithOnlyServerData"; |
1025 else if (server_record_type_count_ == 0 && local_record_type_count_ > 0) | 1026 else if (server_record_type_count_ == 0 && local_record_type_count_ > 0) |
1026 name += ".WithOnlyLocalData"; | 1027 name += ".WithOnlyLocalData"; |
1027 else | 1028 else |
1028 name += ".WithBothServerAndLocalData"; | 1029 name += ".WithBothServerAndLocalData"; |
1029 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); | 1030 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); |
1030 } | 1031 } |
1031 | 1032 |
1032 AutofillMetrics::FormInteractionsUkmLogger::FormInteractionsUkmLogger( | 1033 AutofillMetrics::FormInteractionsUkmLogger::FormInteractionsUkmLogger( |
1033 ukm::UkmService* ukm_service) | 1034 ukm::UkmRecorder* ukm_recorder) |
1034 : ukm_service_(ukm_service) {} | 1035 : ukm_recorder_(ukm_recorder) {} |
1035 | 1036 |
1036 void AutofillMetrics::FormInteractionsUkmLogger::OnFormsLoaded( | 1037 void AutofillMetrics::FormInteractionsUkmLogger::OnFormsLoaded( |
1037 const GURL& url) { | 1038 const GURL& url) { |
1038 if (!IsUkmLoggingEnabled() || ukm_service_ == nullptr) | 1039 if (!IsUkmLoggingEnabled() || ukm_recorder_ == nullptr) |
1039 return; | 1040 return; |
1040 | 1041 |
1041 url_ = url; | 1042 url_ = url; |
1042 form_loaded_timestamp_ = base::TimeTicks::Now(); | 1043 form_loaded_timestamp_ = base::TimeTicks::Now(); |
1043 } | 1044 } |
1044 | 1045 |
1045 void AutofillMetrics::FormInteractionsUkmLogger::LogInteractedWithForm( | 1046 void AutofillMetrics::FormInteractionsUkmLogger::LogInteractedWithForm( |
1046 bool is_for_credit_card, | 1047 bool is_for_credit_card, |
1047 size_t local_record_type_count, | 1048 size_t local_record_type_count, |
1048 size_t server_record_type_count) { | 1049 size_t server_record_type_count) { |
1049 if (!CanLog()) | 1050 if (!CanLog()) |
1050 return; | 1051 return; |
1051 | 1052 |
1052 if (source_id_ == -1) | 1053 if (source_id_ == -1) |
1053 GetNewSourceID(); | 1054 GetNewSourceID(); |
1054 | 1055 |
1055 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1056 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1056 source_id_, internal::kUKMInteractedWithFormEntryName); | 1057 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1058 internal::kUKMInteractedWithFormEntryName); |
1057 builder->AddMetric(internal::kUKMIsForCreditCardMetricName, | 1059 builder->AddMetric(internal::kUKMIsForCreditCardMetricName, |
1058 is_for_credit_card); | 1060 is_for_credit_card); |
1059 builder->AddMetric(internal::kUKMLocalRecordTypeCountMetricName, | 1061 builder->AddMetric(internal::kUKMLocalRecordTypeCountMetricName, |
1060 local_record_type_count); | 1062 local_record_type_count); |
1061 builder->AddMetric(internal::kUKMServerRecordTypeCountMetricName, | 1063 builder->AddMetric(internal::kUKMServerRecordTypeCountMetricName, |
1062 server_record_type_count); | 1064 server_record_type_count); |
1063 } | 1065 } |
1064 | 1066 |
1065 void AutofillMetrics::FormInteractionsUkmLogger::LogSuggestionsShown() { | 1067 void AutofillMetrics::FormInteractionsUkmLogger::LogSuggestionsShown() { |
1066 if (!CanLog()) | 1068 if (!CanLog()) |
1067 return; | 1069 return; |
1068 | 1070 |
1069 if (source_id_ == -1) | 1071 if (source_id_ == -1) |
1070 GetNewSourceID(); | 1072 GetNewSourceID(); |
1071 | 1073 |
1072 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1074 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1073 source_id_, internal::kUKMSuggestionsShownEntryName); | 1075 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1076 internal::kUKMSuggestionsShownEntryName); |
1074 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, | 1077 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, |
1075 MillisecondsSinceFormLoaded()); | 1078 MillisecondsSinceFormLoaded()); |
1076 } | 1079 } |
1077 | 1080 |
1078 void AutofillMetrics::FormInteractionsUkmLogger::LogSelectedMaskedServerCard() { | 1081 void AutofillMetrics::FormInteractionsUkmLogger::LogSelectedMaskedServerCard() { |
1079 if (!CanLog()) | 1082 if (!CanLog()) |
1080 return; | 1083 return; |
1081 | 1084 |
1082 if (source_id_ == -1) | 1085 if (source_id_ == -1) |
1083 GetNewSourceID(); | 1086 GetNewSourceID(); |
1084 | 1087 |
1085 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1088 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1086 source_id_, internal::kUKMSelectedMaskedServerCardEntryName); | 1089 ukm_recorder_->GetEntryBuilder( |
| 1090 source_id_, internal::kUKMSelectedMaskedServerCardEntryName); |
1087 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, | 1091 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, |
1088 MillisecondsSinceFormLoaded()); | 1092 MillisecondsSinceFormLoaded()); |
1089 } | 1093 } |
1090 | 1094 |
1091 void AutofillMetrics::FormInteractionsUkmLogger::LogDidFillSuggestion( | 1095 void AutofillMetrics::FormInteractionsUkmLogger::LogDidFillSuggestion( |
1092 int record_type) { | 1096 int record_type) { |
1093 if (!CanLog()) | 1097 if (!CanLog()) |
1094 return; | 1098 return; |
1095 | 1099 |
1096 if (source_id_ == -1) | 1100 if (source_id_ == -1) |
1097 GetNewSourceID(); | 1101 GetNewSourceID(); |
1098 | 1102 |
1099 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1103 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1100 source_id_, internal::kUKMSuggestionFilledEntryName); | 1104 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1105 internal::kUKMSuggestionFilledEntryName); |
1101 builder->AddMetric(internal::kUKMRecordTypeMetricName, record_type); | 1106 builder->AddMetric(internal::kUKMRecordTypeMetricName, record_type); |
1102 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, | 1107 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, |
1103 MillisecondsSinceFormLoaded()); | 1108 MillisecondsSinceFormLoaded()); |
1104 } | 1109 } |
1105 | 1110 |
1106 void AutofillMetrics::FormInteractionsUkmLogger::LogTextFieldDidChange( | 1111 void AutofillMetrics::FormInteractionsUkmLogger::LogTextFieldDidChange( |
1107 const AutofillField& field) { | 1112 const AutofillField& field) { |
1108 if (!CanLog()) | 1113 if (!CanLog()) |
1109 return; | 1114 return; |
1110 | 1115 |
1111 if (source_id_ == -1) | 1116 if (source_id_ == -1) |
1112 GetNewSourceID(); | 1117 GetNewSourceID(); |
1113 | 1118 |
1114 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1119 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1115 source_id_, internal::kUKMTextFieldDidChangeEntryName); | 1120 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1121 internal::kUKMTextFieldDidChangeEntryName); |
1116 builder->AddMetric(internal::kUKMFieldTypeGroupMetricName, | 1122 builder->AddMetric(internal::kUKMFieldTypeGroupMetricName, |
1117 static_cast<int>(field.Type().group())); | 1123 static_cast<int>(field.Type().group())); |
1118 builder->AddMetric(internal::kUKMHeuristicTypeMetricName, | 1124 builder->AddMetric(internal::kUKMHeuristicTypeMetricName, |
1119 static_cast<int>(field.heuristic_type())); | 1125 static_cast<int>(field.heuristic_type())); |
1120 builder->AddMetric(internal::kUKMServerTypeMetricName, | 1126 builder->AddMetric(internal::kUKMServerTypeMetricName, |
1121 static_cast<int>(field.server_type())); | 1127 static_cast<int>(field.server_type())); |
1122 builder->AddMetric(internal::kUKMHtmlFieldTypeMetricName, | 1128 builder->AddMetric(internal::kUKMHtmlFieldTypeMetricName, |
1123 static_cast<int>(field.html_type())); | 1129 static_cast<int>(field.html_type())); |
1124 builder->AddMetric(internal::kUKMHtmlFieldModeMetricName, | 1130 builder->AddMetric(internal::kUKMHtmlFieldModeMetricName, |
1125 static_cast<int>(field.html_mode())); | 1131 static_cast<int>(field.html_mode())); |
1126 builder->AddMetric(internal::kUKMIsAutofilledMetricName, field.is_autofilled); | 1132 builder->AddMetric(internal::kUKMIsAutofilledMetricName, field.is_autofilled); |
1127 builder->AddMetric(internal::kUKMIsEmptyMetricName, field.IsEmpty()); | 1133 builder->AddMetric(internal::kUKMIsEmptyMetricName, field.IsEmpty()); |
1128 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, | 1134 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, |
1129 MillisecondsSinceFormLoaded()); | 1135 MillisecondsSinceFormLoaded()); |
1130 } | 1136 } |
1131 | 1137 |
1132 void AutofillMetrics::FormInteractionsUkmLogger::LogFormSubmitted( | 1138 void AutofillMetrics::FormInteractionsUkmLogger::LogFormSubmitted( |
1133 AutofillFormSubmittedState state) { | 1139 AutofillFormSubmittedState state) { |
1134 if (!CanLog()) | 1140 if (!CanLog()) |
1135 return; | 1141 return; |
1136 | 1142 |
1137 if (source_id_ == -1) | 1143 if (source_id_ == -1) |
1138 GetNewSourceID(); | 1144 GetNewSourceID(); |
1139 | 1145 |
1140 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1146 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1141 source_id_, internal::kUKMFormSubmittedEntryName); | 1147 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1148 internal::kUKMFormSubmittedEntryName); |
1142 builder->AddMetric(internal::kUKMAutofillFormSubmittedStateMetricName, | 1149 builder->AddMetric(internal::kUKMAutofillFormSubmittedStateMetricName, |
1143 static_cast<int>(state)); | 1150 static_cast<int>(state)); |
1144 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, | 1151 builder->AddMetric(internal::kUKMMillisecondsSinceFormLoadedMetricName, |
1145 MillisecondsSinceFormLoaded()); | 1152 MillisecondsSinceFormLoaded()); |
1146 } | 1153 } |
1147 | 1154 |
1148 void AutofillMetrics::FormInteractionsUkmLogger::UpdateSourceURL( | 1155 void AutofillMetrics::FormInteractionsUkmLogger::UpdateSourceURL( |
1149 const GURL& url) { | 1156 const GURL& url) { |
1150 url_ = url; | 1157 url_ = url; |
1151 if (CanLog()) | 1158 if (CanLog()) |
1152 ukm_service_->UpdateSourceURL(source_id_, url_); | 1159 ukm_recorder_->UpdateSourceURL(source_id_, url_); |
1153 } | 1160 } |
1154 | 1161 |
1155 bool AutofillMetrics::FormInteractionsUkmLogger::CanLog() const { | 1162 bool AutofillMetrics::FormInteractionsUkmLogger::CanLog() const { |
1156 return IsUkmLoggingEnabled() && ukm_service_ && url_.is_valid(); | 1163 return IsUkmLoggingEnabled() && ukm_recorder_ && url_.is_valid(); |
1157 } | 1164 } |
1158 | 1165 |
1159 int64_t | 1166 int64_t |
1160 AutofillMetrics::FormInteractionsUkmLogger::MillisecondsSinceFormLoaded() | 1167 AutofillMetrics::FormInteractionsUkmLogger::MillisecondsSinceFormLoaded() |
1161 const { | 1168 const { |
1162 DCHECK(!form_loaded_timestamp_.is_null()); | 1169 DCHECK(!form_loaded_timestamp_.is_null()); |
1163 return (base::TimeTicks::Now() - form_loaded_timestamp_).InMilliseconds(); | 1170 return (base::TimeTicks::Now() - form_loaded_timestamp_).InMilliseconds(); |
1164 } | 1171 } |
1165 | 1172 |
1166 void AutofillMetrics::FormInteractionsUkmLogger::GetNewSourceID() { | 1173 void AutofillMetrics::FormInteractionsUkmLogger::GetNewSourceID() { |
1167 source_id_ = ukm_service_->GetNewSourceID(); | 1174 source_id_ = ukm_recorder_->GetNewSourceID(); |
1168 ukm_service_->UpdateSourceURL(source_id_, url_); | 1175 ukm_recorder_->UpdateSourceURL(source_id_, url_); |
1169 } | 1176 } |
1170 | 1177 |
1171 } // namespace autofill | 1178 } // namespace autofill |
OLD | NEW |