Chromium Code Reviews| 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 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "components/autofill/core/browser/autofill_experiments.h" | 15 #include "components/autofill/core/browser/autofill_experiments.h" |
| 15 #include "components/autofill/core/browser/autofill_type.h" | 16 #include "components/autofill/core/browser/autofill_type.h" |
| 16 #include "components/autofill/core/browser/form_structure.h" | 17 #include "components/autofill/core/browser/form_structure.h" |
| 17 #include "components/autofill/core/common/form_data.h" | 18 #include "components/autofill/core/common/form_data.h" |
| 18 #include "components/ukm/ukm_entry_builder.h" | 19 #include "components/ukm/ukm_entry_builder.h" |
| 19 | 20 |
| 20 namespace internal { | 21 namespace internal { |
| 21 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; | 22 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; |
| 22 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; | 23 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; |
| 23 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; | 24 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; |
| 24 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; | 25 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; |
| 26 const char kUKMFormInteractionsEntryName[] = "Autofill.FormInteractions"; | |
| 27 const char kUKMFormInteractionsAutofillFormSubmittedStateMetricName[] = | |
| 28 "AutofillFormSubmittedState"; | |
| 29 const char kUKMFormInteractionsUserHappinessMetricMetricName[] = | |
| 30 "UserHappinessMetric"; | |
| 31 const char kUKMFormInteractionsAddressFormEventMetricName[] = | |
| 32 "FormEvent.Address"; | |
| 33 const char kUKMFormInteractionsCreditCardFormEventMetricName[] = | |
| 34 "FormEvent.CreditCard"; | |
| 35 const char kUKMFormInteractionsUnmaskPromptEventMetricName[] = | |
| 36 "UnmaskPromptEvent"; | |
| 25 } // namespace internal | 37 } // namespace internal |
| 26 | 38 |
| 27 namespace autofill { | 39 namespace autofill { |
| 28 | 40 |
| 29 namespace { | 41 namespace { |
| 30 | 42 |
| 31 // Note: if adding an enum value here, update the corresponding description for | 43 // Note: if adding an enum value here, update the corresponding description for |
| 32 // AutofillTypeQualityByFieldType in histograms.xml. | 44 // AutofillTypeQualityByFieldType in histograms.xml. |
| 33 enum FieldTypeGroupForMetrics { | 45 enum FieldTypeGroupForMetrics { |
| 34 GROUP_AMBIGUOUS = 0, | 46 GROUP_AMBIGUOUS = 0, |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 | 621 |
| 610 // static | 622 // static |
| 611 void AutofillMetrics::LogProfileActionOnFormSubmitted( | 623 void AutofillMetrics::LogProfileActionOnFormSubmitted( |
| 612 AutofillProfileAction action) { | 624 AutofillProfileAction action) { |
| 613 UMA_HISTOGRAM_ENUMERATION("Autofill.ProfileActionOnFormSubmitted", action, | 625 UMA_HISTOGRAM_ENUMERATION("Autofill.ProfileActionOnFormSubmitted", action, |
| 614 AUTOFILL_PROFILE_ACTION_ENUM_SIZE); | 626 AUTOFILL_PROFILE_ACTION_ENUM_SIZE); |
| 615 } | 627 } |
| 616 | 628 |
| 617 // static | 629 // static |
| 618 void AutofillMetrics::LogAutofillFormSubmittedState( | 630 void AutofillMetrics::LogAutofillFormSubmittedState( |
| 619 AutofillFormSubmittedState state) { | 631 AutofillFormSubmittedState state, |
| 632 AutofillMetrics::UkmLogger* ukm_logger) { | |
| 620 UMA_HISTOGRAM_ENUMERATION("Autofill.FormSubmittedState", state, | 633 UMA_HISTOGRAM_ENUMERATION("Autofill.FormSubmittedState", state, |
| 621 AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE); | 634 AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE); |
| 622 | 635 |
| 623 switch (state) { | 636 switch (state) { |
| 624 case NON_FILLABLE_FORM_OR_NEW_DATA: | 637 case NON_FILLABLE_FORM_OR_NEW_DATA: |
| 625 base::RecordAction( | 638 base::RecordAction( |
| 626 base::UserMetricsAction("Autofill_FormSubmitted_NonFillable")); | 639 base::UserMetricsAction("Autofill_FormSubmitted_NonFillable")); |
| 627 break; | 640 break; |
| 628 | 641 |
| 629 case FILLABLE_FORM_AUTOFILLED_ALL: | 642 case FILLABLE_FORM_AUTOFILLED_ALL: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 643 | 656 |
| 644 case FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS: | 657 case FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS: |
| 645 base::RecordAction(base::UserMetricsAction( | 658 base::RecordAction(base::UserMetricsAction( |
| 646 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); | 659 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); |
| 647 break; | 660 break; |
| 648 | 661 |
| 649 default: | 662 default: |
| 650 NOTREACHED(); | 663 NOTREACHED(); |
| 651 break; | 664 break; |
| 652 } | 665 } |
| 666 ukm_logger->LogAutofillFormSubmittedState(state); | |
| 653 } | 667 } |
| 654 | 668 |
| 655 // static | 669 // static |
| 656 void AutofillMetrics::LogDetermineHeuristicTypesTiming( | 670 void AutofillMetrics::LogDetermineHeuristicTypesTiming( |
| 657 const base::TimeDelta& duration) { | 671 const base::TimeDelta& duration) { |
| 658 UMA_HISTOGRAM_TIMES("Autofill.Timing.DetermineHeuristicTypes", duration); | 672 UMA_HISTOGRAM_TIMES("Autofill.Timing.DetermineHeuristicTypes", duration); |
| 659 } | 673 } |
| 660 | 674 |
| 661 // static | 675 // static |
| 662 void AutofillMetrics::LogParseFormTiming(const base::TimeDelta& duration) { | 676 void AutofillMetrics::LogParseFormTiming(const base::TimeDelta& duration) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 752 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
| 739 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); | 753 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); |
| 740 | 754 |
| 741 for (auto it = metrics.begin(); it != metrics.end(); ++it) { | 755 for (auto it = metrics.begin(); it != metrics.end(); ++it) { |
| 742 builder->AddMetric(it->first.c_str(), it->second); | 756 builder->AddMetric(it->first.c_str(), it->second); |
| 743 } | 757 } |
| 744 | 758 |
| 745 return true; | 759 return true; |
| 746 } | 760 } |
| 747 | 761 |
| 748 AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card) | 762 AutofillMetrics::FormEventLogger::FormEventLogger( |
| 763 bool is_for_credit_card, | |
| 764 AutofillMetrics::UkmLogger* ukm_logger) | |
| 749 : is_for_credit_card_(is_for_credit_card), | 765 : is_for_credit_card_(is_for_credit_card), |
| 750 is_server_data_available_(false), | 766 is_server_data_available_(false), |
| 751 is_local_data_available_(false), | 767 is_local_data_available_(false), |
| 752 is_context_secure_(false), | 768 is_context_secure_(false), |
| 753 has_logged_interacted_(false), | 769 has_logged_interacted_(false), |
| 754 has_logged_suggestions_shown_(false), | 770 has_logged_suggestions_shown_(false), |
| 755 has_logged_masked_server_card_suggestion_selected_(false), | 771 has_logged_masked_server_card_suggestion_selected_(false), |
| 756 has_logged_suggestion_filled_(false), | 772 has_logged_suggestion_filled_(false), |
| 757 has_logged_will_submit_(false), | 773 has_logged_will_submit_(false), |
| 758 has_logged_submitted_(false), | 774 has_logged_submitted_(false), |
| 759 logged_suggestion_filled_was_server_data_(false), | 775 logged_suggestion_filled_was_server_data_(false), |
| 760 logged_suggestion_filled_was_masked_server_card_(false) {} | 776 logged_suggestion_filled_was_masked_server_card_(false), |
| 777 ukm_logger_(ukm_logger) {} | |
| 761 | 778 |
| 762 void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() { | 779 void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() { |
| 763 if (!has_logged_interacted_) { | 780 if (!has_logged_interacted_) { |
| 764 has_logged_interacted_ = true; | 781 has_logged_interacted_ = true; |
| 765 Log(AutofillMetrics::FORM_EVENT_INTERACTED_ONCE); | 782 Log(AutofillMetrics::FORM_EVENT_INTERACTED_ONCE); |
| 766 } | 783 } |
| 767 } | 784 } |
| 768 | 785 |
| 769 void AutofillMetrics::FormEventLogger::OnDidPollSuggestions( | 786 void AutofillMetrics::FormEventLogger::OnDidPollSuggestions( |
| 770 const FormFieldData& field) { | 787 const FormFieldData& field) { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 939 // segmentation. http://crbug.com/454018 | 956 // segmentation. http://crbug.com/454018 |
| 940 if (!is_server_data_available_ && !is_local_data_available_) | 957 if (!is_server_data_available_ && !is_local_data_available_) |
| 941 name += ".WithNoData"; | 958 name += ".WithNoData"; |
| 942 else if (is_server_data_available_ && !is_local_data_available_) | 959 else if (is_server_data_available_ && !is_local_data_available_) |
| 943 name += ".WithOnlyServerData"; | 960 name += ".WithOnlyServerData"; |
| 944 else if (!is_server_data_available_ && is_local_data_available_) | 961 else if (!is_server_data_available_ && is_local_data_available_) |
| 945 name += ".WithOnlyLocalData"; | 962 name += ".WithOnlyLocalData"; |
| 946 else | 963 else |
| 947 name += ".WithBothServerAndLocalData"; | 964 name += ".WithBothServerAndLocalData"; |
| 948 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); | 965 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); |
| 966 | |
| 967 if (is_for_credit_card_) | |
| 968 ukm_logger_->LogCreditCardFormEvent(event); | |
| 969 else | |
| 970 ukm_logger_->LogAddressFormEvent(event); | |
| 971 } | |
| 972 | |
| 973 AutofillMetrics::UkmLogger::UkmLogger(ukm::UkmService* ukm_service) | |
| 974 : ukm_service_(ukm_service) {} | |
| 975 | |
| 976 AutofillMetrics::UkmLogger::~UkmLogger() { | |
| 977 LogUkm(); | |
|
sebsg
2017/04/07 13:17:24
Wouldn't this cause us to log twice if LogAutofill
csashi
2017/04/09 19:17:26
I meant to clear |metrics_| after logging but forg
| |
| 978 } | |
| 979 | |
| 980 void AutofillMetrics::UkmLogger::LogAutofillFormSubmittedState( | |
| 981 AutofillFormSubmittedState state) { | |
| 982 metrics_.push_back( | |
| 983 std::make_pair(AUTOFILL_FORM_SUBMITTED_STATE, static_cast<int>(state))); | |
| 984 // User submitted form, we can finalize the events for this form. | |
| 985 LogUkm(); | |
| 986 } | |
| 987 | |
| 988 void AutofillMetrics::UkmLogger::LogUserHappinessMetric( | |
| 989 UserHappinessMetric metric) { | |
| 990 metrics_.push_back( | |
| 991 std::make_pair(USER_HAPPINESS_METRIC, static_cast<int>(metric))); | |
| 992 } | |
| 993 | |
| 994 void AutofillMetrics::UkmLogger::LogAddressFormEvent(FormEvent event) { | |
| 995 metrics_.push_back( | |
| 996 std::make_pair(ADDRESS_FORM_EVENT, static_cast<int>(event))); | |
| 997 } | |
| 998 | |
| 999 void AutofillMetrics::UkmLogger::LogCreditCardFormEvent(FormEvent event) { | |
| 1000 metrics_.push_back( | |
| 1001 std::make_pair(CREDIT_CARD_FORM_EVENT, static_cast<int>(event))); | |
| 1002 } | |
| 1003 | |
| 1004 void AutofillMetrics::UkmLogger::LogUnmaskPromptEvent(UnmaskPromptEvent event) { | |
| 1005 metrics_.push_back( | |
| 1006 std::make_pair(UNMASK_PROMPT_EVENT, static_cast<int>(event))); | |
| 1007 } | |
| 1008 | |
| 1009 void AutofillMetrics::UkmLogger::LogUkm() { | |
| 1010 // TODO(csashi): Merge with |LogUkm| that takes a std::map of | |
| 1011 // metric_name->value. | |
| 1012 if (!IsUkmLoggingEnabled() || !ukm_service_ || !url_.is_valid() || | |
| 1013 metrics_.empty()) { | |
| 1014 return; | |
| 1015 } | |
| 1016 | |
| 1017 int32_t source_id = ukm_service_->GetNewSourceID(); | |
| 1018 ukm_service_->UpdateSourceURL(source_id, url_); | |
| 1019 std::unique_ptr<ukm::UkmEntryBuilder> builder = ukm_service_->GetEntryBuilder( | |
| 1020 source_id, internal::kUKMFormInteractionsEntryName); | |
| 1021 | |
| 1022 for (auto it = metrics_.begin(); it != metrics_.end(); ++it) { | |
| 1023 const char* metric_name = nullptr; | |
| 1024 switch (it->first) { | |
| 1025 case AutofillMetrics::UkmLogger::AUTOFILL_FORM_SUBMITTED_STATE: | |
| 1026 metric_name = | |
| 1027 internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName; | |
| 1028 break; | |
| 1029 case AutofillMetrics::UkmLogger::USER_HAPPINESS_METRIC: | |
| 1030 metric_name = | |
| 1031 internal::kUKMFormInteractionsUserHappinessMetricMetricName; | |
| 1032 break; | |
| 1033 case AutofillMetrics::UkmLogger::ADDRESS_FORM_EVENT: | |
| 1034 metric_name = internal::kUKMFormInteractionsAddressFormEventMetricName; | |
| 1035 break; | |
| 1036 case AutofillMetrics::UkmLogger::CREDIT_CARD_FORM_EVENT: | |
| 1037 metric_name = | |
| 1038 internal::kUKMFormInteractionsCreditCardFormEventMetricName; | |
| 1039 break; | |
| 1040 case AutofillMetrics::UkmLogger::UNMASK_PROMPT_EVENT: | |
| 1041 metric_name = internal::kUKMFormInteractionsUnmaskPromptEventMetricName; | |
| 1042 break; | |
| 1043 default: | |
| 1044 NOTREACHED(); | |
| 1045 } | |
| 1046 builder->AddMetric(metric_name, it->second); | |
| 1047 } | |
| 949 } | 1048 } |
| 950 | 1049 |
| 951 } // namespace autofill | 1050 } // namespace autofill |
| OLD | NEW |