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 kUKMMillisecondsSinceFormParsedMetricName[] = | 28 const char kUKMMillisecondsSinceFormParsedMetricName[] = |
29 "MillisecondsSinceFormParsed"; | 29 "MillisecondsSinceFormParsed"; |
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 (!ukm_service || !url.is_valid() || metrics.empty()) { | 797 if (!ukm_recorder || !url.is_valid() || metrics.empty()) { |
797 return false; | 798 return false; |
798 } | 799 } |
799 | 800 |
800 int32_t source_id = ukm_service->GetNewSourceID(); | 801 ukm::SourceId source_id = ukm_recorder->GetNewSourceID(); |
801 ukm_service->UpdateSourceURL(source_id, url); | 802 ukm_recorder->UpdateSourceURL(source_id, url); |
802 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 803 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
803 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); | 804 ukm_recorder->GetEntryBuilder(source_id, ukm_entry_name.c_str()); |
804 | 805 |
805 for (auto it = metrics.begin(); it != metrics.end(); ++it) { | 806 for (auto it = metrics.begin(); it != metrics.end(); ++it) { |
806 builder->AddMetric(it->first, it->second); | 807 builder->AddMetric(it->first, it->second); |
807 } | 808 } |
808 | 809 |
809 return true; | 810 return true; |
810 } | 811 } |
811 | 812 |
812 AutofillMetrics::FormEventLogger::FormEventLogger( | 813 AutofillMetrics::FormEventLogger::FormEventLogger( |
813 bool is_for_credit_card, | 814 bool is_for_credit_card, |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 else if (server_record_type_count_ > 0 && local_record_type_count_ == 0) | 1023 else if (server_record_type_count_ > 0 && local_record_type_count_ == 0) |
1023 name += ".WithOnlyServerData"; | 1024 name += ".WithOnlyServerData"; |
1024 else if (server_record_type_count_ == 0 && local_record_type_count_ > 0) | 1025 else if (server_record_type_count_ == 0 && local_record_type_count_ > 0) |
1025 name += ".WithOnlyLocalData"; | 1026 name += ".WithOnlyLocalData"; |
1026 else | 1027 else |
1027 name += ".WithBothServerAndLocalData"; | 1028 name += ".WithBothServerAndLocalData"; |
1028 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); | 1029 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); |
1029 } | 1030 } |
1030 | 1031 |
1031 AutofillMetrics::FormInteractionsUkmLogger::FormInteractionsUkmLogger( | 1032 AutofillMetrics::FormInteractionsUkmLogger::FormInteractionsUkmLogger( |
1032 ukm::UkmService* ukm_service) | 1033 ukm::UkmRecorder* ukm_recorder) |
1033 : ukm_service_(ukm_service) {} | 1034 : ukm_recorder_(ukm_recorder) {} |
1034 | 1035 |
1035 void AutofillMetrics::FormInteractionsUkmLogger::OnFormsParsed( | 1036 void AutofillMetrics::FormInteractionsUkmLogger::OnFormsParsed( |
1036 const GURL& url) { | 1037 const GURL& url) { |
1037 if (ukm_service_ == nullptr) | 1038 if (ukm_recorder_ == nullptr) |
1038 return; | 1039 return; |
1039 | 1040 |
1040 url_ = url; | 1041 url_ = url; |
1041 form_parsed_timestamp_ = base::TimeTicks::Now(); | 1042 form_parsed_timestamp_ = base::TimeTicks::Now(); |
1042 } | 1043 } |
1043 | 1044 |
1044 void AutofillMetrics::FormInteractionsUkmLogger::LogInteractedWithForm( | 1045 void AutofillMetrics::FormInteractionsUkmLogger::LogInteractedWithForm( |
1045 bool is_for_credit_card, | 1046 bool is_for_credit_card, |
1046 size_t local_record_type_count, | 1047 size_t local_record_type_count, |
1047 size_t server_record_type_count) { | 1048 size_t server_record_type_count) { |
1048 if (!CanLog()) | 1049 if (!CanLog()) |
1049 return; | 1050 return; |
1050 | 1051 |
1051 if (source_id_ == -1) | 1052 if (source_id_ == -1) |
1052 GetNewSourceID(); | 1053 GetNewSourceID(); |
1053 | 1054 |
1054 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1055 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1055 source_id_, internal::kUKMInteractedWithFormEntryName); | 1056 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1057 internal::kUKMInteractedWithFormEntryName); |
1056 builder->AddMetric(internal::kUKMIsForCreditCardMetricName, | 1058 builder->AddMetric(internal::kUKMIsForCreditCardMetricName, |
1057 is_for_credit_card); | 1059 is_for_credit_card); |
1058 builder->AddMetric(internal::kUKMLocalRecordTypeCountMetricName, | 1060 builder->AddMetric(internal::kUKMLocalRecordTypeCountMetricName, |
1059 local_record_type_count); | 1061 local_record_type_count); |
1060 builder->AddMetric(internal::kUKMServerRecordTypeCountMetricName, | 1062 builder->AddMetric(internal::kUKMServerRecordTypeCountMetricName, |
1061 server_record_type_count); | 1063 server_record_type_count); |
1062 } | 1064 } |
1063 | 1065 |
1064 void AutofillMetrics::FormInteractionsUkmLogger::LogSuggestionsShown() { | 1066 void AutofillMetrics::FormInteractionsUkmLogger::LogSuggestionsShown() { |
1065 if (!CanLog()) | 1067 if (!CanLog()) |
1066 return; | 1068 return; |
1067 | 1069 |
1068 if (source_id_ == -1) | 1070 if (source_id_ == -1) |
1069 GetNewSourceID(); | 1071 GetNewSourceID(); |
1070 | 1072 |
1071 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1073 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1072 source_id_, internal::kUKMSuggestionsShownEntryName); | 1074 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1075 internal::kUKMSuggestionsShownEntryName); |
1073 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, | 1076 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, |
1074 MillisecondsSinceFormParsed()); | 1077 MillisecondsSinceFormParsed()); |
1075 } | 1078 } |
1076 | 1079 |
1077 void AutofillMetrics::FormInteractionsUkmLogger::LogSelectedMaskedServerCard() { | 1080 void AutofillMetrics::FormInteractionsUkmLogger::LogSelectedMaskedServerCard() { |
1078 if (!CanLog()) | 1081 if (!CanLog()) |
1079 return; | 1082 return; |
1080 | 1083 |
1081 if (source_id_ == -1) | 1084 if (source_id_ == -1) |
1082 GetNewSourceID(); | 1085 GetNewSourceID(); |
1083 | 1086 |
1084 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1087 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1085 source_id_, internal::kUKMSelectedMaskedServerCardEntryName); | 1088 ukm_recorder_->GetEntryBuilder( |
| 1089 source_id_, internal::kUKMSelectedMaskedServerCardEntryName); |
1086 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, | 1090 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, |
1087 MillisecondsSinceFormParsed()); | 1091 MillisecondsSinceFormParsed()); |
1088 } | 1092 } |
1089 | 1093 |
1090 void AutofillMetrics::FormInteractionsUkmLogger::LogDidFillSuggestion( | 1094 void AutofillMetrics::FormInteractionsUkmLogger::LogDidFillSuggestion( |
1091 int record_type) { | 1095 int record_type) { |
1092 if (!CanLog()) | 1096 if (!CanLog()) |
1093 return; | 1097 return; |
1094 | 1098 |
1095 if (source_id_ == -1) | 1099 if (source_id_ == -1) |
1096 GetNewSourceID(); | 1100 GetNewSourceID(); |
1097 | 1101 |
1098 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1102 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1099 source_id_, internal::kUKMSuggestionFilledEntryName); | 1103 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1104 internal::kUKMSuggestionFilledEntryName); |
1100 builder->AddMetric(internal::kUKMRecordTypeMetricName, record_type); | 1105 builder->AddMetric(internal::kUKMRecordTypeMetricName, record_type); |
1101 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, | 1106 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, |
1102 MillisecondsSinceFormParsed()); | 1107 MillisecondsSinceFormParsed()); |
1103 } | 1108 } |
1104 | 1109 |
1105 void AutofillMetrics::FormInteractionsUkmLogger::LogTextFieldDidChange( | 1110 void AutofillMetrics::FormInteractionsUkmLogger::LogTextFieldDidChange( |
1106 const AutofillField& field) { | 1111 const AutofillField& field) { |
1107 if (!CanLog()) | 1112 if (!CanLog()) |
1108 return; | 1113 return; |
1109 | 1114 |
1110 if (source_id_ == -1) | 1115 if (source_id_ == -1) |
1111 GetNewSourceID(); | 1116 GetNewSourceID(); |
1112 | 1117 |
1113 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1118 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1114 source_id_, internal::kUKMTextFieldDidChangeEntryName); | 1119 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1120 internal::kUKMTextFieldDidChangeEntryName); |
1115 builder->AddMetric(internal::kUKMFieldTypeGroupMetricName, | 1121 builder->AddMetric(internal::kUKMFieldTypeGroupMetricName, |
1116 static_cast<int>(field.Type().group())); | 1122 static_cast<int>(field.Type().group())); |
1117 builder->AddMetric(internal::kUKMHeuristicTypeMetricName, | 1123 builder->AddMetric(internal::kUKMHeuristicTypeMetricName, |
1118 static_cast<int>(field.heuristic_type())); | 1124 static_cast<int>(field.heuristic_type())); |
1119 builder->AddMetric(internal::kUKMServerTypeMetricName, | 1125 builder->AddMetric(internal::kUKMServerTypeMetricName, |
1120 static_cast<int>(field.server_type())); | 1126 static_cast<int>(field.server_type())); |
1121 builder->AddMetric(internal::kUKMHtmlFieldTypeMetricName, | 1127 builder->AddMetric(internal::kUKMHtmlFieldTypeMetricName, |
1122 static_cast<int>(field.html_type())); | 1128 static_cast<int>(field.html_type())); |
1123 builder->AddMetric(internal::kUKMHtmlFieldModeMetricName, | 1129 builder->AddMetric(internal::kUKMHtmlFieldModeMetricName, |
1124 static_cast<int>(field.html_mode())); | 1130 static_cast<int>(field.html_mode())); |
1125 builder->AddMetric(internal::kUKMIsAutofilledMetricName, field.is_autofilled); | 1131 builder->AddMetric(internal::kUKMIsAutofilledMetricName, field.is_autofilled); |
1126 builder->AddMetric(internal::kUKMIsEmptyMetricName, field.IsEmpty()); | 1132 builder->AddMetric(internal::kUKMIsEmptyMetricName, field.IsEmpty()); |
1127 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, | 1133 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, |
1128 MillisecondsSinceFormParsed()); | 1134 MillisecondsSinceFormParsed()); |
1129 } | 1135 } |
1130 | 1136 |
1131 void AutofillMetrics::FormInteractionsUkmLogger::LogFormSubmitted( | 1137 void AutofillMetrics::FormInteractionsUkmLogger::LogFormSubmitted( |
1132 AutofillFormSubmittedState state) { | 1138 AutofillFormSubmittedState state) { |
1133 if (!CanLog()) | 1139 if (!CanLog()) |
1134 return; | 1140 return; |
1135 | 1141 |
1136 if (source_id_ == -1) | 1142 if (source_id_ == -1) |
1137 GetNewSourceID(); | 1143 GetNewSourceID(); |
1138 | 1144 |
1139 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | 1145 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
1140 source_id_, internal::kUKMFormSubmittedEntryName); | 1146 ukm_recorder_->GetEntryBuilder(source_id_, |
| 1147 internal::kUKMFormSubmittedEntryName); |
1141 builder->AddMetric(internal::kUKMAutofillFormSubmittedStateMetricName, | 1148 builder->AddMetric(internal::kUKMAutofillFormSubmittedStateMetricName, |
1142 static_cast<int>(state)); | 1149 static_cast<int>(state)); |
1143 if (form_parsed_timestamp_.is_null()) | 1150 if (form_parsed_timestamp_.is_null()) |
1144 DCHECK(state == NON_FILLABLE_FORM_OR_NEW_DATA || | 1151 DCHECK(state == NON_FILLABLE_FORM_OR_NEW_DATA || |
1145 state == FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS) | 1152 state == FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS) |
1146 << state; | 1153 << state; |
1147 else | 1154 else |
1148 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, | 1155 builder->AddMetric(internal::kUKMMillisecondsSinceFormParsedMetricName, |
1149 MillisecondsSinceFormParsed()); | 1156 MillisecondsSinceFormParsed()); |
1150 } | 1157 } |
1151 | 1158 |
1152 void AutofillMetrics::FormInteractionsUkmLogger::UpdateSourceURL( | 1159 void AutofillMetrics::FormInteractionsUkmLogger::UpdateSourceURL( |
1153 const GURL& url) { | 1160 const GURL& url) { |
1154 url_ = url; | 1161 url_ = url; |
1155 if (CanLog()) | 1162 if (CanLog()) |
1156 ukm_service_->UpdateSourceURL(source_id_, url_); | 1163 ukm_recorder_->UpdateSourceURL(source_id_, url_); |
1157 } | 1164 } |
1158 | 1165 |
1159 bool AutofillMetrics::FormInteractionsUkmLogger::CanLog() const { | 1166 bool AutofillMetrics::FormInteractionsUkmLogger::CanLog() const { |
1160 return ukm_service_ && url_.is_valid(); | 1167 return ukm_recorder_ && url_.is_valid(); |
1161 } | 1168 } |
1162 | 1169 |
1163 int64_t | 1170 int64_t |
1164 AutofillMetrics::FormInteractionsUkmLogger::MillisecondsSinceFormParsed() | 1171 AutofillMetrics::FormInteractionsUkmLogger::MillisecondsSinceFormParsed() |
1165 const { | 1172 const { |
1166 DCHECK(!form_parsed_timestamp_.is_null()); | 1173 DCHECK(!form_parsed_timestamp_.is_null()); |
1167 return (base::TimeTicks::Now() - form_parsed_timestamp_).InMilliseconds(); | 1174 return (base::TimeTicks::Now() - form_parsed_timestamp_).InMilliseconds(); |
1168 } | 1175 } |
1169 | 1176 |
1170 void AutofillMetrics::FormInteractionsUkmLogger::GetNewSourceID() { | 1177 void AutofillMetrics::FormInteractionsUkmLogger::GetNewSourceID() { |
1171 source_id_ = ukm_service_->GetNewSourceID(); | 1178 source_id_ = ukm_recorder_->GetNewSourceID(); |
1172 ukm_service_->UpdateSourceURL(source_id_, url_); | 1179 ukm_recorder_->UpdateSourceURL(source_id_, url_); |
1173 } | 1180 } |
1174 | 1181 |
1175 } // namespace autofill | 1182 } // namespace autofill |
OLD | NEW |