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