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> | |
| 9 #include <vector> | |
| 8 | 10 |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/metrics/user_metrics.h" | 14 #include "base/metrics/user_metrics.h" |
| 13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 14 #include "components/autofill/core/browser/autofill_experiments.h" | 16 #include "components/autofill/core/browser/autofill_experiments.h" |
| 15 #include "components/autofill/core/browser/autofill_type.h" | 17 #include "components/autofill/core/browser/autofill_type.h" |
| 16 #include "components/autofill/core/browser/form_structure.h" | 18 #include "components/autofill/core/browser/form_structure.h" |
| 17 #include "components/autofill/core/common/form_data.h" | 19 #include "components/autofill/core/common/form_data.h" |
| 18 #include "components/ukm/ukm_entry_builder.h" | 20 #include "components/ukm/ukm_entry_builder.h" |
| 19 | 21 |
| 20 namespace internal { | 22 namespace internal { |
| 21 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; | 23 const char kUKMCardUploadDecisionEntryName[] = "Autofill.CardUploadDecision"; |
| 22 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; | 24 const char kUKMCardUploadDecisionMetricName[] = "UploadDecision"; |
| 23 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; | 25 const char kUKMDeveloperEngagementEntryName[] = "Autofill.DeveloperEngagement"; |
| 24 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; | 26 const char kUKMDeveloperEngagementMetricName[] = "DeveloperEngagement"; |
| 27 const char kUKMFormInteractionsEntryName[] = "Autofill.FormInteractions"; | |
| 28 const char kUKMFormInteractionsAutofillFormSubmittedStateMetricName[] = | |
| 29 "AutofillFormSubmittedState"; | |
| 30 const char kUKMFormInteractionsUserHappinessMetricMetricName[] = | |
| 31 "UserHappinessMetric"; | |
| 32 const char kUKMFormInteractionsAddressFormEventMetricName[] = | |
| 33 "FormEvent.Address"; | |
| 34 const char kUKMFormInteractionsCreditCardFormEventMetricName[] = | |
| 35 "FormEvent.CreditCard"; | |
| 36 const char kUKMFormInteractionsUnmaskPromptEventMetricName[] = | |
| 37 "UnmaskPromptEvent"; | |
| 25 } // namespace internal | 38 } // namespace internal |
| 26 | 39 |
| 27 namespace autofill { | 40 namespace autofill { |
| 28 | 41 |
| 29 namespace { | 42 namespace { |
| 30 | 43 |
| 31 // Note: if adding an enum value here, update the corresponding description for | 44 // Note: if adding an enum value here, update the corresponding description for |
| 32 // AutofillTypeQualityByFieldType in histograms.xml. | 45 // AutofillTypeQualityByFieldType in histograms.xml. |
| 33 enum FieldTypeGroupForMetrics { | 46 enum FieldTypeGroupForMetrics { |
| 34 GROUP_AMBIGUOUS = 0, | 47 GROUP_AMBIGUOUS = 0, |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 | 622 |
| 610 // static | 623 // static |
| 611 void AutofillMetrics::LogProfileActionOnFormSubmitted( | 624 void AutofillMetrics::LogProfileActionOnFormSubmitted( |
| 612 AutofillProfileAction action) { | 625 AutofillProfileAction action) { |
| 613 UMA_HISTOGRAM_ENUMERATION("Autofill.ProfileActionOnFormSubmitted", action, | 626 UMA_HISTOGRAM_ENUMERATION("Autofill.ProfileActionOnFormSubmitted", action, |
| 614 AUTOFILL_PROFILE_ACTION_ENUM_SIZE); | 627 AUTOFILL_PROFILE_ACTION_ENUM_SIZE); |
| 615 } | 628 } |
| 616 | 629 |
| 617 // static | 630 // static |
| 618 void AutofillMetrics::LogAutofillFormSubmittedState( | 631 void AutofillMetrics::LogAutofillFormSubmittedState( |
| 619 AutofillFormSubmittedState state) { | 632 AutofillFormSubmittedState state, |
| 633 AutofillMetrics::FormInteractionsUkmLogger* form_interactions_ukm_logger) { | |
| 620 UMA_HISTOGRAM_ENUMERATION("Autofill.FormSubmittedState", state, | 634 UMA_HISTOGRAM_ENUMERATION("Autofill.FormSubmittedState", state, |
| 621 AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE); | 635 AUTOFILL_FORM_SUBMITTED_STATE_ENUM_SIZE); |
| 622 | 636 |
| 623 switch (state) { | 637 switch (state) { |
| 624 case NON_FILLABLE_FORM_OR_NEW_DATA: | 638 case NON_FILLABLE_FORM_OR_NEW_DATA: |
| 625 base::RecordAction( | 639 base::RecordAction( |
| 626 base::UserMetricsAction("Autofill_FormSubmitted_NonFillable")); | 640 base::UserMetricsAction("Autofill_FormSubmitted_NonFillable")); |
| 627 break; | 641 break; |
| 628 | 642 |
| 629 case FILLABLE_FORM_AUTOFILLED_ALL: | 643 case FILLABLE_FORM_AUTOFILLED_ALL: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 643 | 657 |
| 644 case FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS: | 658 case FILLABLE_FORM_AUTOFILLED_NONE_DID_NOT_SHOW_SUGGESTIONS: |
| 645 base::RecordAction(base::UserMetricsAction( | 659 base::RecordAction(base::UserMetricsAction( |
| 646 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); | 660 "Autofill_FormSubmitted_FilledNone_SuggestionsNotShown")); |
| 647 break; | 661 break; |
| 648 | 662 |
| 649 default: | 663 default: |
| 650 NOTREACHED(); | 664 NOTREACHED(); |
| 651 break; | 665 break; |
| 652 } | 666 } |
| 667 form_interactions_ukm_logger->LogAutofillFormSubmittedState(state); | |
| 653 } | 668 } |
| 654 | 669 |
| 655 // static | 670 // static |
| 656 void AutofillMetrics::LogDetermineHeuristicTypesTiming( | 671 void AutofillMetrics::LogDetermineHeuristicTypesTiming( |
| 657 const base::TimeDelta& duration) { | 672 const base::TimeDelta& duration) { |
| 658 UMA_HISTOGRAM_TIMES("Autofill.Timing.DetermineHeuristicTypes", duration); | 673 UMA_HISTOGRAM_TIMES("Autofill.Timing.DetermineHeuristicTypes", duration); |
| 659 } | 674 } |
| 660 | 675 |
| 661 // static | 676 // static |
| 662 void AutofillMetrics::LogParseFormTiming(const base::TimeDelta& duration) { | 677 void AutofillMetrics::LogParseFormTiming(const base::TimeDelta& duration) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 } | 714 } |
| 700 | 715 |
| 701 // static | 716 // static |
| 702 void AutofillMetrics::LogCardUploadDecisionUkm( | 717 void AutofillMetrics::LogCardUploadDecisionUkm( |
| 703 ukm::UkmService* ukm_service, | 718 ukm::UkmService* ukm_service, |
| 704 const GURL& url, | 719 const GURL& url, |
| 705 AutofillMetrics::CardUploadDecisionMetric upload_decision) { | 720 AutofillMetrics::CardUploadDecisionMetric upload_decision) { |
| 706 if (upload_decision >= AutofillMetrics::NUM_CARD_UPLOAD_DECISION_METRICS) | 721 if (upload_decision >= AutofillMetrics::NUM_CARD_UPLOAD_DECISION_METRICS) |
| 707 return; | 722 return; |
| 708 | 723 |
| 709 const std::map<std::string, int> metrics = { | 724 const std::vector<std::pair<const char*, int>> metrics = { |
| 710 {internal::kUKMCardUploadDecisionMetricName, | 725 {internal::kUKMCardUploadDecisionMetricName, |
| 711 static_cast<int>(upload_decision)}}; | 726 static_cast<int>(upload_decision)}}; |
| 712 LogUkm(ukm_service, url, internal::kUKMCardUploadDecisionEntryName, metrics); | 727 LogUkm(ukm_service, url, internal::kUKMCardUploadDecisionEntryName, metrics); |
| 713 } | 728 } |
| 714 | 729 |
| 715 // static | 730 // static |
| 716 void AutofillMetrics::LogDeveloperEngagementUkm( | 731 void AutofillMetrics::LogDeveloperEngagementUkm( |
| 717 ukm::UkmService* ukm_service, | 732 ukm::UkmService* ukm_service, |
| 718 const GURL& url, | 733 const GURL& url, |
| 719 AutofillMetrics::DeveloperEngagementMetric metric) { | 734 AutofillMetrics::DeveloperEngagementMetric metric) { |
| 720 const std::map<std::string, int> form_structure_metrics = { | 735 const std::vector<std::pair<const char*, int>> form_structure_metrics = { |
| 721 {internal::kUKMDeveloperEngagementMetricName, static_cast<int>(metric)}}; | 736 {internal::kUKMDeveloperEngagementMetricName, static_cast<int>(metric)}}; |
| 722 LogUkm(ukm_service, url, internal::kUKMDeveloperEngagementEntryName, | 737 LogUkm(ukm_service, url, internal::kUKMDeveloperEngagementEntryName, |
| 723 form_structure_metrics); | 738 form_structure_metrics); |
| 724 } | 739 } |
| 725 | 740 |
| 726 // static | 741 // static |
| 727 bool AutofillMetrics::LogUkm(ukm::UkmService* ukm_service, | 742 bool AutofillMetrics::LogUkm( |
|
Steven Holte
2017/04/10 22:42:32
This appears to be logging a source for every entr
csashi
2017/04/11 00:40:23
FWIW, I was following the logging pattern that had
| |
| 728 const GURL& url, | 743 ukm::UkmService* ukm_service, |
| 729 const std::string& ukm_entry_name, | 744 const GURL& url, |
| 730 const std::map<std::string, int>& metrics) { | 745 const std::string& ukm_entry_name, |
| 746 const std::vector<std::pair<const char*, int>>& metrics) { | |
| 731 if (!IsUkmLoggingEnabled() || !ukm_service || !url.is_valid() || | 747 if (!IsUkmLoggingEnabled() || !ukm_service || !url.is_valid() || |
| 732 metrics.empty()) { | 748 metrics.empty()) { |
| 733 return false; | 749 return false; |
| 734 } | 750 } |
| 735 | 751 |
| 736 int32_t source_id = ukm_service->GetNewSourceID(); | 752 int32_t source_id = ukm_service->GetNewSourceID(); |
| 737 ukm_service->UpdateSourceURL(source_id, url); | 753 ukm_service->UpdateSourceURL(source_id, url); |
| 738 std::unique_ptr<ukm::UkmEntryBuilder> builder = | 754 std::unique_ptr<ukm::UkmEntryBuilder> builder = |
| 739 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); | 755 ukm_service->GetEntryBuilder(source_id, ukm_entry_name.c_str()); |
| 740 | 756 |
| 741 for (auto it = metrics.begin(); it != metrics.end(); ++it) { | 757 for (auto it = metrics.begin(); it != metrics.end(); ++it) { |
| 742 builder->AddMetric(it->first.c_str(), it->second); | 758 builder->AddMetric(it->first, it->second); |
| 743 } | 759 } |
| 744 | 760 |
| 745 return true; | 761 return true; |
| 746 } | 762 } |
| 747 | 763 |
| 748 AutofillMetrics::FormEventLogger::FormEventLogger(bool is_for_credit_card) | 764 AutofillMetrics::FormEventLogger::FormEventLogger( |
| 765 bool is_for_credit_card, | |
| 766 AutofillMetrics::FormInteractionsUkmLogger* form_interactions_ukm_logger) | |
| 749 : is_for_credit_card_(is_for_credit_card), | 767 : is_for_credit_card_(is_for_credit_card), |
| 750 is_server_data_available_(false), | 768 is_server_data_available_(false), |
| 751 is_local_data_available_(false), | 769 is_local_data_available_(false), |
| 752 is_context_secure_(false), | 770 is_context_secure_(false), |
| 753 has_logged_interacted_(false), | 771 has_logged_interacted_(false), |
| 754 has_logged_suggestions_shown_(false), | 772 has_logged_suggestions_shown_(false), |
| 755 has_logged_masked_server_card_suggestion_selected_(false), | 773 has_logged_masked_server_card_suggestion_selected_(false), |
| 756 has_logged_suggestion_filled_(false), | 774 has_logged_suggestion_filled_(false), |
| 757 has_logged_will_submit_(false), | 775 has_logged_will_submit_(false), |
| 758 has_logged_submitted_(false), | 776 has_logged_submitted_(false), |
| 759 logged_suggestion_filled_was_server_data_(false), | 777 logged_suggestion_filled_was_server_data_(false), |
| 760 logged_suggestion_filled_was_masked_server_card_(false) {} | 778 logged_suggestion_filled_was_masked_server_card_(false), |
| 779 form_interactions_ukm_logger_(form_interactions_ukm_logger) {} | |
| 761 | 780 |
| 762 void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() { | 781 void AutofillMetrics::FormEventLogger::OnDidInteractWithAutofillableForm() { |
| 763 if (!has_logged_interacted_) { | 782 if (!has_logged_interacted_) { |
| 764 has_logged_interacted_ = true; | 783 has_logged_interacted_ = true; |
| 765 Log(AutofillMetrics::FORM_EVENT_INTERACTED_ONCE); | 784 Log(AutofillMetrics::FORM_EVENT_INTERACTED_ONCE, false /* log_ukm */); |
| 766 } | 785 } |
| 767 } | 786 } |
| 768 | 787 |
| 769 void AutofillMetrics::FormEventLogger::OnDidPollSuggestions( | 788 void AutofillMetrics::FormEventLogger::OnDidPollSuggestions( |
| 770 const FormFieldData& field) { | 789 const FormFieldData& field) { |
| 771 // Record only one poll user action for consecutive polls of the same field. | 790 // Record only one poll user action for consecutive polls of the same field. |
| 772 // This is to avoid recording too many poll actions (for example when a user | 791 // This is to avoid recording too many poll actions (for example when a user |
| 773 // types in a field, triggering multiple queries) to make the analysis more | 792 // types in a field, triggering multiple queries) to make the analysis more |
| 774 // simple. | 793 // simple. |
| 775 if (!field.SameFieldAs(last_polled_field_)) { | 794 if (!field.SameFieldAs(last_polled_field_)) { |
| 776 if (is_for_credit_card_) { | 795 if (is_for_credit_card_) { |
| 777 base::RecordAction( | 796 base::RecordAction( |
| 778 base::UserMetricsAction("Autofill_PolledCreditCardSuggestions")); | 797 base::UserMetricsAction("Autofill_PolledCreditCardSuggestions")); |
| 779 } else { | 798 } else { |
| 780 base::RecordAction( | 799 base::RecordAction( |
| 781 base::UserMetricsAction("Autofill_PolledProfileSuggestions")); | 800 base::UserMetricsAction("Autofill_PolledProfileSuggestions")); |
| 782 } | 801 } |
| 783 | 802 |
| 784 last_polled_field_ = field; | 803 last_polled_field_ = field; |
| 785 } | 804 } |
| 786 } | 805 } |
| 787 | 806 |
| 788 void AutofillMetrics::FormEventLogger::OnDidShowSuggestions() { | 807 void AutofillMetrics::FormEventLogger::OnDidShowSuggestions() { |
| 789 Log(AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN); | 808 Log(AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN, true /* log_ukm */); |
| 790 if (!has_logged_suggestions_shown_) { | 809 if (!has_logged_suggestions_shown_) { |
| 791 has_logged_suggestions_shown_ = true; | 810 has_logged_suggestions_shown_ = true; |
| 792 Log(AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE); | 811 Log(AutofillMetrics::FORM_EVENT_SUGGESTIONS_SHOWN_ONCE, |
| 812 false /* log_ukm */); | |
| 793 } | 813 } |
| 794 | 814 |
| 795 if (is_for_credit_card_) { | 815 if (is_for_credit_card_) { |
| 796 base::RecordAction( | 816 base::RecordAction( |
| 797 base::UserMetricsAction("Autofill_ShowedCreditCardSuggestions")); | 817 base::UserMetricsAction("Autofill_ShowedCreditCardSuggestions")); |
| 798 } else { | 818 } else { |
| 799 base::RecordAction( | 819 base::RecordAction( |
| 800 base::UserMetricsAction("Autofill_ShowedProfileSuggestions")); | 820 base::UserMetricsAction("Autofill_ShowedProfileSuggestions")); |
| 801 } | 821 } |
| 802 } | 822 } |
| 803 | 823 |
| 804 void AutofillMetrics::FormEventLogger::OnDidSelectMaskedServerCardSuggestion() { | 824 void AutofillMetrics::FormEventLogger::OnDidSelectMaskedServerCardSuggestion() { |
| 805 DCHECK(is_for_credit_card_); | 825 DCHECK(is_for_credit_card_); |
| 806 Log(AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED); | 826 Log(AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED, |
| 827 true /* log_ukm */); | |
| 807 if (!has_logged_masked_server_card_suggestion_selected_) { | 828 if (!has_logged_masked_server_card_suggestion_selected_) { |
| 808 has_logged_masked_server_card_suggestion_selected_ = true; | 829 has_logged_masked_server_card_suggestion_selected_ = true; |
| 809 Log(AutofillMetrics | 830 Log(AutofillMetrics :: |
| 810 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE); | 831 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SELECTED_ONCE, |
| 832 false /* log_ukm */); | |
| 811 } | 833 } |
| 812 } | 834 } |
| 813 | 835 |
| 814 void AutofillMetrics::FormEventLogger::OnDidFillSuggestion( | 836 void AutofillMetrics::FormEventLogger::OnDidFillSuggestion( |
| 815 const CreditCard& credit_card) { | 837 const CreditCard& credit_card) { |
| 816 DCHECK(is_for_credit_card_); | 838 DCHECK(is_for_credit_card_); |
| 817 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) | 839 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) |
| 818 Log(AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED); | 840 Log(AutofillMetrics::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED, |
| 841 true /* log_ukm */); | |
| 819 else if (credit_card.record_type() == CreditCard::FULL_SERVER_CARD) | 842 else if (credit_card.record_type() == CreditCard::FULL_SERVER_CARD) |
| 820 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED); | 843 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED, |
| 844 true /* log_ukm */); | |
| 821 else | 845 else |
| 822 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED); | 846 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, |
| 847 true /* log_ukm */); | |
| 823 | 848 |
| 824 if (!has_logged_suggestion_filled_) { | 849 if (!has_logged_suggestion_filled_) { |
| 825 has_logged_suggestion_filled_ = true; | 850 has_logged_suggestion_filled_ = true; |
| 826 logged_suggestion_filled_was_server_data_ = | 851 logged_suggestion_filled_was_server_data_ = |
| 827 credit_card.record_type() == CreditCard::MASKED_SERVER_CARD || | 852 credit_card.record_type() == CreditCard::MASKED_SERVER_CARD || |
| 828 credit_card.record_type() == CreditCard::FULL_SERVER_CARD; | 853 credit_card.record_type() == CreditCard::FULL_SERVER_CARD; |
| 829 logged_suggestion_filled_was_masked_server_card_ = | 854 logged_suggestion_filled_was_masked_server_card_ = |
| 830 credit_card.record_type() == CreditCard::MASKED_SERVER_CARD; | 855 credit_card.record_type() == CreditCard::MASKED_SERVER_CARD; |
| 831 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) { | 856 if (credit_card.record_type() == CreditCard::MASKED_SERVER_CARD) { |
| 832 Log(AutofillMetrics | 857 Log(AutofillMetrics :: |
| 833 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE); | 858 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_FILLED_ONCE, |
| 859 false /* log_ukm */); | |
| 834 } else if (credit_card.record_type() == CreditCard::FULL_SERVER_CARD) { | 860 } else if (credit_card.record_type() == CreditCard::FULL_SERVER_CARD) { |
| 835 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE); | 861 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE, |
| 862 false /* log_ukm */); | |
| 836 } else { | 863 } else { |
| 837 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE); | 864 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, |
| 865 false /* log_ukm */); | |
| 838 } | 866 } |
| 839 } | 867 } |
| 840 | 868 |
| 841 base::RecordAction( | 869 base::RecordAction( |
| 842 base::UserMetricsAction("Autofill_FilledCreditCardSuggestion")); | 870 base::UserMetricsAction("Autofill_FilledCreditCardSuggestion")); |
| 843 } | 871 } |
| 844 | 872 |
| 845 void AutofillMetrics::FormEventLogger::OnDidFillSuggestion( | 873 void AutofillMetrics::FormEventLogger::OnDidFillSuggestion( |
| 846 const AutofillProfile& profile) { | 874 const AutofillProfile& profile) { |
| 847 DCHECK(!is_for_credit_card_); | 875 DCHECK(!is_for_credit_card_); |
| 848 if (profile.record_type() == AutofillProfile::SERVER_PROFILE) | 876 if (profile.record_type() == AutofillProfile::SERVER_PROFILE) |
| 849 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED); | 877 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED, |
| 878 true /* log_ukm */); | |
| 850 else | 879 else |
| 851 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED); | 880 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED, |
| 881 true /* log_ukm */); | |
| 852 | 882 |
| 853 if (!has_logged_suggestion_filled_) { | 883 if (!has_logged_suggestion_filled_) { |
| 854 has_logged_suggestion_filled_ = true; | 884 has_logged_suggestion_filled_ = true; |
| 855 logged_suggestion_filled_was_server_data_ = | 885 logged_suggestion_filled_was_server_data_ = |
| 856 profile.record_type() == AutofillProfile::SERVER_PROFILE; | 886 profile.record_type() == AutofillProfile::SERVER_PROFILE; |
| 857 Log(profile.record_type() == AutofillProfile::SERVER_PROFILE | 887 Log(profile.record_type() == AutofillProfile::SERVER_PROFILE |
| 858 ? AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE | 888 ? AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_FILLED_ONCE |
| 859 : AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE); | 889 : AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_FILLED_ONCE, |
| 890 false /* log_ukm */); | |
| 860 } | 891 } |
| 861 | 892 |
| 862 base::RecordAction( | 893 base::RecordAction( |
| 863 base::UserMetricsAction("Autofill_FilledProfileSuggestion")); | 894 base::UserMetricsAction("Autofill_FilledProfileSuggestion")); |
| 864 } | 895 } |
| 865 | 896 |
| 866 void AutofillMetrics::FormEventLogger::OnWillSubmitForm() { | 897 void AutofillMetrics::FormEventLogger::OnWillSubmitForm() { |
| 867 // Not logging this kind of form if we haven't logged a user interaction. | 898 // Not logging this kind of form if we haven't logged a user interaction. |
| 868 if (!has_logged_interacted_) | 899 if (!has_logged_interacted_) |
| 869 return; | 900 return; |
| 870 | 901 |
| 871 // Not logging twice. | 902 // Not logging twice. |
| 872 if (has_logged_will_submit_) | 903 if (has_logged_will_submit_) |
| 873 return; | 904 return; |
| 874 has_logged_will_submit_ = true; | 905 has_logged_will_submit_ = true; |
| 875 | 906 |
| 876 if (!has_logged_suggestion_filled_) { | 907 if (!has_logged_suggestion_filled_) { |
| 877 Log(AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE); | 908 Log(AutofillMetrics::FORM_EVENT_NO_SUGGESTION_WILL_SUBMIT_ONCE, |
| 909 false /* log_ukm */); | |
| 878 } else if (logged_suggestion_filled_was_masked_server_card_) { | 910 } else if (logged_suggestion_filled_was_masked_server_card_) { |
| 879 Log(AutofillMetrics:: | 911 Log(AutofillMetrics:: |
| 880 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE); | 912 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_WILL_SUBMIT_ONCE, |
| 913 false /* log_ukm */); | |
| 881 } else if (logged_suggestion_filled_was_server_data_) { | 914 } else if (logged_suggestion_filled_was_server_data_) { |
| 882 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE); | 915 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_WILL_SUBMIT_ONCE, |
| 916 false /* log_ukm */); | |
| 883 } else { | 917 } else { |
| 884 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE); | 918 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_WILL_SUBMIT_ONCE, |
| 919 false /* log_ukm */); | |
| 885 } | 920 } |
| 886 | 921 |
| 887 if (has_logged_suggestions_shown_) { | 922 if (has_logged_suggestions_shown_) { |
| 888 Log(AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE); | 923 Log(AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_WILL_SUBMIT_ONCE, |
| 924 false /* log_ukm */); | |
| 889 } | 925 } |
| 890 | 926 |
| 891 base::RecordAction(base::UserMetricsAction("Autofill_OnWillSubmitForm")); | 927 base::RecordAction(base::UserMetricsAction("Autofill_OnWillSubmitForm")); |
| 892 } | 928 } |
| 893 | 929 |
| 894 void AutofillMetrics::FormEventLogger::OnFormSubmitted() { | 930 void AutofillMetrics::FormEventLogger::OnFormSubmitted() { |
| 895 // Not logging this kind of form if we haven't logged a user interaction. | 931 // Not logging this kind of form if we haven't logged a user interaction. |
| 896 if (!has_logged_interacted_) | 932 if (!has_logged_interacted_) |
| 897 return; | 933 return; |
| 898 | 934 |
| 899 // Not logging twice. | 935 // Not logging twice. |
| 900 if (has_logged_submitted_) | 936 if (has_logged_submitted_) |
| 901 return; | 937 return; |
| 902 has_logged_submitted_ = true; | 938 has_logged_submitted_ = true; |
| 903 | 939 |
| 904 if (!has_logged_suggestion_filled_) { | 940 if (!has_logged_suggestion_filled_) { |
| 905 Log(AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE); | 941 Log(AutofillMetrics::FORM_EVENT_NO_SUGGESTION_SUBMITTED_ONCE, |
| 942 false /* log_ukm */); | |
| 906 } else if (logged_suggestion_filled_was_masked_server_card_) { | 943 } else if (logged_suggestion_filled_was_masked_server_card_) { |
| 907 Log(AutofillMetrics | 944 Log(AutofillMetrics :: |
| 908 ::FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE); | 945 FORM_EVENT_MASKED_SERVER_CARD_SUGGESTION_SUBMITTED_ONCE, |
| 946 false /* log_ukm */); | |
| 909 } else if (logged_suggestion_filled_was_server_data_) { | 947 } else if (logged_suggestion_filled_was_server_data_) { |
| 910 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE); | 948 Log(AutofillMetrics::FORM_EVENT_SERVER_SUGGESTION_SUBMITTED_ONCE, |
| 949 false /* log_ukm */); | |
| 911 } else { | 950 } else { |
| 912 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE); | 951 Log(AutofillMetrics::FORM_EVENT_LOCAL_SUGGESTION_SUBMITTED_ONCE, |
| 952 false /* log_ukm */); | |
| 913 } | 953 } |
| 914 | 954 |
| 915 if (has_logged_suggestions_shown_) { | 955 if (has_logged_suggestions_shown_) { |
| 916 Log(AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE); | 956 Log(AutofillMetrics::FORM_EVENT_SUGGESTION_SHOWN_SUBMITTED_ONCE, |
| 957 false /* log_ukm */); | |
| 917 } | 958 } |
| 918 } | 959 } |
| 919 | 960 |
| 920 void AutofillMetrics::FormEventLogger::Log(FormEvent event) const { | 961 void AutofillMetrics::FormEventLogger::Log(FormEvent event, |
| 962 bool log_ukm) const { | |
| 921 DCHECK_LT(event, NUM_FORM_EVENTS); | 963 DCHECK_LT(event, NUM_FORM_EVENTS); |
| 922 std::string name("Autofill.FormEvents."); | 964 std::string name("Autofill.FormEvents."); |
| 923 if (is_for_credit_card_) | 965 if (is_for_credit_card_) |
| 924 name += "CreditCard"; | 966 name += "CreditCard"; |
| 925 else | 967 else |
| 926 name += "Address"; | 968 name += "Address"; |
| 927 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); | 969 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); |
| 928 | 970 |
| 929 // Log again in a different histogram for credit card forms on nonsecure | 971 // Log again in a different histogram for credit card forms on nonsecure |
| 930 // pages, so that form interactions on nonsecure pages can be analyzed on | 972 // pages, so that form interactions on nonsecure pages can be analyzed on |
| 931 // their own. | 973 // their own. |
| 932 if (is_for_credit_card_ && !is_context_secure_) { | 974 if (is_for_credit_card_ && !is_context_secure_) { |
| 933 LogUMAHistogramEnumeration(name + ".OnNonsecurePage", event, | 975 LogUMAHistogramEnumeration(name + ".OnNonsecurePage", event, |
| 934 NUM_FORM_EVENTS); | 976 NUM_FORM_EVENTS); |
| 935 } | 977 } |
| 936 | 978 |
| 937 // Logging again in a different histogram for segmentation purposes. | 979 // Logging again in a different histogram for segmentation purposes. |
| 938 // TODO(waltercacau): Re-evaluate if we still need such fine grained | 980 // TODO(waltercacau): Re-evaluate if we still need such fine grained |
| 939 // segmentation. http://crbug.com/454018 | 981 // segmentation. http://crbug.com/454018 |
| 940 if (!is_server_data_available_ && !is_local_data_available_) | 982 if (!is_server_data_available_ && !is_local_data_available_) |
| 941 name += ".WithNoData"; | 983 name += ".WithNoData"; |
| 942 else if (is_server_data_available_ && !is_local_data_available_) | 984 else if (is_server_data_available_ && !is_local_data_available_) |
| 943 name += ".WithOnlyServerData"; | 985 name += ".WithOnlyServerData"; |
| 944 else if (!is_server_data_available_ && is_local_data_available_) | 986 else if (!is_server_data_available_ && is_local_data_available_) |
| 945 name += ".WithOnlyLocalData"; | 987 name += ".WithOnlyLocalData"; |
| 946 else | 988 else |
| 947 name += ".WithBothServerAndLocalData"; | 989 name += ".WithBothServerAndLocalData"; |
| 948 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); | 990 LogUMAHistogramEnumeration(name, event, NUM_FORM_EVENTS); |
| 991 | |
| 992 if (log_ukm) { | |
| 993 if (is_for_credit_card_) | |
| 994 form_interactions_ukm_logger_->LogCreditCardFormEvent(event); | |
| 995 else | |
| 996 form_interactions_ukm_logger_->LogAddressFormEvent(event); | |
| 997 } | |
| 998 } | |
| 999 | |
| 1000 AutofillMetrics::FormInteractionsUkmLogger::FormInteractionsUkmLogger( | |
| 1001 ukm::UkmService* ukm_service) | |
| 1002 : ukm_service_(ukm_service) {} | |
| 1003 | |
| 1004 AutofillMetrics::FormInteractionsUkmLogger::~FormInteractionsUkmLogger() { | |
| 1005 // Submit pending events, if any. If the browser tab starts loading a new page | |
| 1006 // when the user types a new URL prior to form submission, | |
| 1007 // |LogAutofillFormSubmittedState| would not be invoked. | |
| 1008 SubmitUkm(); | |
| 1009 } | |
| 1010 | |
| 1011 void AutofillMetrics::FormInteractionsUkmLogger::LogAutofillFormSubmittedState( | |
| 1012 AutofillFormSubmittedState state) { | |
| 1013 metrics_.push_back( | |
| 1014 std::make_pair(AUTOFILL_FORM_SUBMITTED_STATE, static_cast<int>(state))); | |
| 1015 // User submitted form, we can submit the events for this form. | |
| 1016 SubmitUkm(); | |
| 1017 } | |
| 1018 | |
| 1019 void AutofillMetrics::FormInteractionsUkmLogger::LogUserHappinessMetric( | |
| 1020 UserHappinessMetric metric) { | |
| 1021 metrics_.push_back( | |
| 1022 std::make_pair(USER_HAPPINESS_METRIC, static_cast<int>(metric))); | |
| 1023 } | |
| 1024 | |
| 1025 void AutofillMetrics::FormInteractionsUkmLogger::LogAddressFormEvent( | |
| 1026 FormEvent event) { | |
| 1027 metrics_.push_back( | |
| 1028 std::make_pair(ADDRESS_FORM_EVENT, static_cast<int>(event))); | |
| 1029 } | |
| 1030 | |
| 1031 void AutofillMetrics::FormInteractionsUkmLogger::LogCreditCardFormEvent( | |
| 1032 FormEvent event) { | |
| 1033 metrics_.push_back( | |
| 1034 std::make_pair(CREDIT_CARD_FORM_EVENT, static_cast<int>(event))); | |
| 1035 } | |
| 1036 | |
| 1037 void AutofillMetrics::FormInteractionsUkmLogger::LogUnmaskPromptEvent( | |
| 1038 UnmaskPromptEvent event) { | |
| 1039 metrics_.push_back( | |
| 1040 std::make_pair(UNMASK_PROMPT_EVENT, static_cast<int>(event))); | |
| 1041 } | |
| 1042 | |
| 1043 void AutofillMetrics::FormInteractionsUkmLogger::SubmitUkm() { | |
| 1044 std::vector<std::pair<const char*, int>> metrics; | |
| 1045 for (const auto& it : metrics_) { | |
| 1046 const char* metric_name = nullptr; | |
| 1047 switch (it.first) { | |
| 1048 case AutofillMetrics::FormInteractionsUkmLogger:: | |
| 1049 AUTOFILL_FORM_SUBMITTED_STATE: | |
|
Steven Holte
2017/04/10 22:42:31
Why store all of this in multiple maps before putt
csashi
2017/04/11 00:40:23
I am not using 'maps' - I have a vector of metrics
Steven Holte
2017/04/11 17:37:57
If I understand this right, you intending to infer
csashi
2017/04/12 00:13:53
Done.
Your understanding is correct. I was intend
| |
| 1050 metric_name = | |
| 1051 internal::kUKMFormInteractionsAutofillFormSubmittedStateMetricName; | |
| 1052 break; | |
| 1053 case AutofillMetrics::FormInteractionsUkmLogger::USER_HAPPINESS_METRIC: | |
| 1054 metric_name = | |
| 1055 internal::kUKMFormInteractionsUserHappinessMetricMetricName; | |
| 1056 break; | |
| 1057 case AutofillMetrics::FormInteractionsUkmLogger::ADDRESS_FORM_EVENT: | |
| 1058 metric_name = internal::kUKMFormInteractionsAddressFormEventMetricName; | |
| 1059 break; | |
| 1060 case AutofillMetrics::FormInteractionsUkmLogger::CREDIT_CARD_FORM_EVENT: | |
| 1061 metric_name = | |
| 1062 internal::kUKMFormInteractionsCreditCardFormEventMetricName; | |
| 1063 break; | |
| 1064 case AutofillMetrics::FormInteractionsUkmLogger::UNMASK_PROMPT_EVENT: | |
| 1065 metric_name = internal::kUKMFormInteractionsUnmaskPromptEventMetricName; | |
| 1066 break; | |
| 1067 default: | |
| 1068 NOTREACHED(); | |
| 1069 } | |
| 1070 metrics.push_back(std::make_pair(metric_name, it.second)); | |
| 1071 } | |
| 1072 AutofillMetrics::LogUkm(ukm_service_, url_, | |
| 1073 internal::kUKMFormInteractionsEntryName, metrics); | |
| 1074 metrics_.clear(); | |
| 949 } | 1075 } |
| 950 | 1076 |
| 951 } // namespace autofill | 1077 } // namespace autofill |
| OLD | NEW |