| 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 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ |
| 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 11 #include <vector> |
| 10 | 12 |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/time/time.h" |
| 12 #include "components/autofill/core/browser/autofill_client.h" | 15 #include "components/autofill/core/browser/autofill_client.h" |
| 13 #include "components/autofill/core/browser/autofill_profile.h" | 16 #include "components/autofill/core/browser/autofill_profile.h" |
| 14 #include "components/autofill/core/browser/credit_card.h" | 17 #include "components/autofill/core/browser/credit_card.h" |
| 15 #include "components/autofill/core/browser/field_types.h" | 18 #include "components/autofill/core/browser/field_types.h" |
| 16 #include "components/autofill/core/common/form_field_data.h" | 19 #include "components/autofill/core/common/form_field_data.h" |
| 17 | 20 |
| 18 namespace base { | |
| 19 class TimeDelta; | |
| 20 } // namespace base | |
| 21 | |
| 22 namespace ukm { | 21 namespace ukm { |
| 23 class UkmService; | 22 class UkmService; |
| 24 } // namespace ukm | 23 } // namespace ukm |
| 25 | 24 |
| 26 namespace internal { | 25 namespace internal { |
| 27 // Name constants are exposed here so they can be referenced from tests. | 26 // Name constants are exposed here so they can be referenced from tests. |
| 28 extern const char kUKMCardUploadDecisionEntryName[]; | 27 extern const char kUKMCardUploadDecisionEntryName[]; |
| 29 extern const char kUKMCardUploadDecisionMetricName[]; | 28 extern const char kUKMCardUploadDecisionMetricName[]; |
| 30 extern const char kUKMDeveloperEngagementEntryName[]; | 29 extern const char kUKMDeveloperEngagementEntryName[]; |
| 31 extern const char kUKMDeveloperEngagementMetricName[]; | 30 extern const char kUKMDeveloperEngagementMetricName[]; |
| 31 |
| 32 // Each form interaction event has a separate |UkmEntry|. |
| 33 // Each |UkmEntry| has 2 metrics: |
| 34 // 1. The value of the corresponding enum (e.g. value of |UserHappiness|). |
| 35 // 2. Time elapsed, in milliseconds, since we loaded the form. |
| 36 extern const char kUKMAutofillFormSubmittedStateName[]; |
| 37 extern const char kUKMUserHappinessMetricName[]; |
| 38 extern const char kUKMAddressFormEventName[]; |
| 39 extern const char kUKMCreditCardFormEventName[]; |
| 40 extern const char kUKMUnmaskPromptEventName[]; |
| 41 extern const char kUKMMillisecondsSinceFormLoadedMetricName[]; |
| 32 } // namespace internal | 42 } // namespace internal |
| 33 | 43 |
| 34 namespace autofill { | 44 namespace autofill { |
| 35 | 45 |
| 36 class AutofillMetrics { | 46 class AutofillMetrics { |
| 37 public: | 47 public: |
| 38 enum AutofillProfileAction { | 48 enum AutofillProfileAction { |
| 39 EXISTING_PROFILE_USED, | 49 EXISTING_PROFILE_USED, |
| 40 EXISTING_PROFILE_UPDATED, | 50 EXISTING_PROFILE_UPDATED, |
| 41 NEW_PROFILE_CREATED, | 51 NEW_PROFILE_CREATED, |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 546 |
| 537 // For mesuring how wallet addresses are converted to local profiles. | 547 // For mesuring how wallet addresses are converted to local profiles. |
| 538 enum WalletAddressConversionType : int { | 548 enum WalletAddressConversionType : int { |
| 539 // The converted wallet address was merged into an existing local profile. | 549 // The converted wallet address was merged into an existing local profile. |
| 540 CONVERTED_ADDRESS_MERGED, | 550 CONVERTED_ADDRESS_MERGED, |
| 541 // The converted wallet address was added as a new local profile. | 551 // The converted wallet address was added as a new local profile. |
| 542 CONVERTED_ADDRESS_ADDED, | 552 CONVERTED_ADDRESS_ADDED, |
| 543 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES | 553 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES |
| 544 }; | 554 }; |
| 545 | 555 |
| 556 // Utility to log URL keyed |AutofillFormSubmittedState|, |
| 557 // |UserHappinessMetric|, |FormEvent| and |UnmaskPromptEvent|. |
| 558 class FormInteractionsUkmLogger { |
| 559 public: |
| 560 explicit FormInteractionsUkmLogger(ukm::UkmService* ukm_service); |
| 561 ~FormInteractionsUkmLogger(); |
| 562 |
| 563 const GURL& url() const { return url_; } |
| 564 void set_url(const GURL& url) { url_ = url; } |
| 565 void set_form_loaded_timestamp( |
| 566 const base::TimeTicks& form_loaded_timestamp) { |
| 567 form_loaded_timestamp_ = form_loaded_timestamp; |
| 568 } |
| 569 |
| 570 // The following Log functions only log the form interactions to private |
| 571 // class variables. |SubmitUkm| is the only method that calls the |
| 572 // |UkmService|. |
| 573 void LogAutofillFormSubmittedState(AutofillFormSubmittedState state); |
| 574 void LogUserHappinessMetric(UserHappinessMetric metric); |
| 575 void LogAddressFormEvent(FormEvent event); |
| 576 void LogCreditCardFormEvent(FormEvent event); |
| 577 void LogUnmaskPromptEvent(UnmaskPromptEvent event); |
| 578 |
| 579 void SubmitUkm(); |
| 580 |
| 581 private: |
| 582 struct Event { |
| 583 Event(const char* const name, int value, const int64_t time_delta_millis) |
| 584 : name(name), value(value), time_delta_millis(time_delta_millis) {} |
| 585 |
| 586 const char* const name; |
| 587 const int value; |
| 588 const int64_t time_delta_millis; |
| 589 }; |
| 590 |
| 591 void AddEvent(const char* const name, int value); |
| 592 |
| 593 ukm::UkmService* ukm_service_; // Weak reference. |
| 594 base::TimeTicks form_loaded_timestamp_; |
| 595 GURL url_; |
| 596 std::vector<Event> events_; |
| 597 }; |
| 598 |
| 546 static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric); | 599 static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric); |
| 547 static void LogCreditCardInfoBarMetric(InfoBarMetric metric, | 600 static void LogCreditCardInfoBarMetric(InfoBarMetric metric, |
| 548 bool is_uploading); | 601 bool is_uploading); |
| 549 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); | 602 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); |
| 550 static void LogSaveCardPromptMetric(SaveCardPromptMetric metric, | 603 static void LogSaveCardPromptMetric(SaveCardPromptMetric metric, |
| 551 bool is_uploading, | 604 bool is_uploading, |
| 552 bool is_reshow); | 605 bool is_reshow); |
| 553 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); | 606 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); |
| 554 | 607 |
| 555 // Should be called when credit card scan is finished. |duration| should be | 608 // Should be called when credit card scan is finished. |duration| should be |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 715 |
| 663 // This should be called each time a server response is parsed for a form. | 716 // This should be called each time a server response is parsed for a form. |
| 664 static void LogServerResponseHasDataForForm(bool has_data); | 717 static void LogServerResponseHasDataForForm(bool has_data); |
| 665 | 718 |
| 666 // This should be called at each form submission to indicate what profile | 719 // This should be called at each form submission to indicate what profile |
| 667 // action happened. | 720 // action happened. |
| 668 static void LogProfileActionOnFormSubmitted(AutofillProfileAction action); | 721 static void LogProfileActionOnFormSubmitted(AutofillProfileAction action); |
| 669 | 722 |
| 670 // This should be called at each form submission to indicate the autofilled | 723 // This should be called at each form submission to indicate the autofilled |
| 671 // state of the form. | 724 // state of the form. |
| 672 static void LogAutofillFormSubmittedState(AutofillFormSubmittedState state); | 725 static void LogAutofillFormSubmittedState( |
| 726 AutofillFormSubmittedState state, |
| 727 FormInteractionsUkmLogger* form_interactions_ukm_logger); |
| 673 | 728 |
| 674 // This should be called when determining the heuristic types for a form's | 729 // This should be called when determining the heuristic types for a form's |
| 675 // fields. | 730 // fields. |
| 676 static void LogDetermineHeuristicTypesTiming(const base::TimeDelta& duration); | 731 static void LogDetermineHeuristicTypesTiming(const base::TimeDelta& duration); |
| 677 | 732 |
| 678 // This should be called when parsing each form. | 733 // This should be called when parsing each form. |
| 679 static void LogParseFormTiming(const base::TimeDelta& duration); | 734 static void LogParseFormTiming(const base::TimeDelta& duration); |
| 680 | 735 |
| 681 // Log how many profiles were considered for the deduplication process. | 736 // Log how many profiles were considered for the deduplication process. |
| 682 static void LogNumberOfProfilesConsideredForDedupe(size_t num_considered); | 737 static void LogNumberOfProfilesConsideredForDedupe(size_t num_considered); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 701 static void LogCardUploadDecisionUkm( | 756 static void LogCardUploadDecisionUkm( |
| 702 ukm::UkmService* ukm_service, | 757 ukm::UkmService* ukm_service, |
| 703 const GURL& url, | 758 const GURL& url, |
| 704 AutofillMetrics::CardUploadDecisionMetric upload_decision); | 759 AutofillMetrics::CardUploadDecisionMetric upload_decision); |
| 705 | 760 |
| 706 // Logs the developer engagement ukm for the specified |url| and autofill | 761 // Logs the developer engagement ukm for the specified |url| and autofill |
| 707 // fields in the form structure. | 762 // fields in the form structure. |
| 708 static void LogDeveloperEngagementUkm( | 763 static void LogDeveloperEngagementUkm( |
| 709 ukm::UkmService* ukm_service, | 764 ukm::UkmService* ukm_service, |
| 710 const GURL& url, | 765 const GURL& url, |
| 711 AutofillMetrics::DeveloperEngagementMetric metric); | 766 std::vector<AutofillMetrics::DeveloperEngagementMetric> metrics); |
| 712 | 767 |
| 713 // Logs the the |ukm_entry_name| with the specified |url| and the specified | 768 // Logs the the |ukm_entry_name| with the specified |url| and the specified |
| 714 // |metrics|. Returns whether the ukm was sucessfully logged. | 769 // |metrics|. Returns whether the ukm was sucessfully logged. |
| 715 static bool LogUkm(ukm::UkmService* ukm_service, | 770 static bool LogUkm(ukm::UkmService* ukm_service, |
| 716 const GURL& url, | 771 const GURL& url, |
| 717 const std::string& ukm_entry_name, | 772 const std::string& ukm_entry_name, |
| 718 const std::map<std::string, int>& metrics); | 773 const std::vector<std::pair<const char*, int>>& metrics); |
| 719 | 774 |
| 720 // Utility to autofill form events in the relevant histograms depending on | 775 // Utility to log autofill form events in the relevant histograms depending on |
| 721 // the presence of server and/or local data. | 776 // the presence of server and/or local data. |
| 722 class FormEventLogger { | 777 class FormEventLogger { |
| 723 public: | 778 public: |
| 724 FormEventLogger(bool is_for_credit_card); | 779 FormEventLogger(bool is_for_credit_card, |
| 780 FormInteractionsUkmLogger* form_interactions_ukm_logger); |
| 725 | 781 |
| 726 inline void set_is_server_data_available(bool is_server_data_available) { | 782 inline void set_is_server_data_available(bool is_server_data_available) { |
| 727 is_server_data_available_ = is_server_data_available; | 783 is_server_data_available_ = is_server_data_available; |
| 728 } | 784 } |
| 729 | 785 |
| 730 inline void set_is_local_data_available(bool is_local_data_available) { | 786 inline void set_is_local_data_available(bool is_local_data_available) { |
| 731 is_local_data_available_ = is_local_data_available; | 787 is_local_data_available_ = is_local_data_available; |
| 732 } | 788 } |
| 733 | 789 |
| 734 inline void set_is_context_secure(bool is_context_secure) { | 790 inline void set_is_context_secure(bool is_context_secure) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 747 // the card is upgraded to a full card. | 803 // the card is upgraded to a full card. |
| 748 void OnDidFillSuggestion(const CreditCard& credit_card); | 804 void OnDidFillSuggestion(const CreditCard& credit_card); |
| 749 | 805 |
| 750 void OnDidFillSuggestion(const AutofillProfile& profile); | 806 void OnDidFillSuggestion(const AutofillProfile& profile); |
| 751 | 807 |
| 752 void OnWillSubmitForm(); | 808 void OnWillSubmitForm(); |
| 753 | 809 |
| 754 void OnFormSubmitted(); | 810 void OnFormSubmitted(); |
| 755 | 811 |
| 756 private: | 812 private: |
| 757 void Log(FormEvent event) const; | 813 void Log(FormEvent event, bool log_ukm) const; |
| 758 | 814 |
| 759 bool is_for_credit_card_; | 815 bool is_for_credit_card_; |
| 760 bool is_server_data_available_; | 816 bool is_server_data_available_; |
| 761 bool is_local_data_available_; | 817 bool is_local_data_available_; |
| 762 bool is_context_secure_; | 818 bool is_context_secure_; |
| 763 bool has_logged_interacted_; | 819 bool has_logged_interacted_; |
| 764 bool has_logged_suggestions_shown_; | 820 bool has_logged_suggestions_shown_; |
| 765 bool has_logged_masked_server_card_suggestion_selected_; | 821 bool has_logged_masked_server_card_suggestion_selected_; |
| 766 bool has_logged_suggestion_filled_; | 822 bool has_logged_suggestion_filled_; |
| 767 bool has_logged_will_submit_; | 823 bool has_logged_will_submit_; |
| 768 bool has_logged_submitted_; | 824 bool has_logged_submitted_; |
| 769 bool logged_suggestion_filled_was_server_data_; | 825 bool logged_suggestion_filled_was_server_data_; |
| 770 bool logged_suggestion_filled_was_masked_server_card_; | 826 bool logged_suggestion_filled_was_masked_server_card_; |
| 771 | 827 |
| 772 // The last field that was polled for suggestions. | 828 // The last field that was polled for suggestions. |
| 773 FormFieldData last_polled_field_; | 829 FormFieldData last_polled_field_; |
| 830 |
| 831 FormInteractionsUkmLogger* |
| 832 form_interactions_ukm_logger_; // Weak reference. |
| 774 }; | 833 }; |
| 775 | 834 |
| 776 private: | 835 private: |
| 777 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); | 836 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); |
| 778 }; | 837 }; |
| 779 | 838 |
| 780 } // namespace autofill | 839 } // namespace autofill |
| 781 | 840 |
| 782 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ | 841 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ |
| OLD | NEW |