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