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 kUKMFormInteractionsFormEventMetricName[]; |
| 38 extern const char kUKMFormInteractionsUnmaskPromptEventMetricName[]; |
32 } // namespace internal | 39 } // namespace internal |
33 | 40 |
34 namespace autofill { | 41 namespace autofill { |
35 | 42 |
36 class AutofillMetrics { | 43 class AutofillMetrics { |
37 public: | 44 public: |
38 enum AutofillProfileAction { | 45 enum AutofillProfileAction { |
39 EXISTING_PROFILE_USED, | 46 EXISTING_PROFILE_USED, |
40 EXISTING_PROFILE_UPDATED, | 47 EXISTING_PROFILE_UPDATED, |
41 NEW_PROFILE_CREATED, | 48 NEW_PROFILE_CREATED, |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 | 543 |
537 // For mesuring how wallet addresses are converted to local profiles. | 544 // For mesuring how wallet addresses are converted to local profiles. |
538 enum WalletAddressConversionType : int { | 545 enum WalletAddressConversionType : int { |
539 // The converted wallet address was merged into an existing local profile. | 546 // The converted wallet address was merged into an existing local profile. |
540 CONVERTED_ADDRESS_MERGED, | 547 CONVERTED_ADDRESS_MERGED, |
541 // The converted wallet address was added as a new local profile. | 548 // The converted wallet address was added as a new local profile. |
542 CONVERTED_ADDRESS_ADDED, | 549 CONVERTED_ADDRESS_ADDED, |
543 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES | 550 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES |
544 }; | 551 }; |
545 | 552 |
| 553 // Utility to log URL keyed |AutofillFormSubmittedState|, |
| 554 // |UserHappinessMetric|, |FormEvent| and |UnmaskPromptEvent|. |
| 555 class UkmLogger { |
| 556 public: |
| 557 explicit UkmLogger(ukm::UkmService* ukm_service); |
| 558 ~UkmLogger(); |
| 559 |
| 560 const GURL& url() const { return url_; } |
| 561 void set_url(const GURL& url) { url_ = url; } |
| 562 |
| 563 void LogAutofillFormSubmittedState(AutofillFormSubmittedState state); |
| 564 void LogUserHappinessMetric(UserHappinessMetric metric); |
| 565 void LogAddressFormEvent(FormEvent event); |
| 566 void LogCreditCardFormEvent(FormEvent event); |
| 567 void LogUnmaskPromptEvent(UnmaskPromptEvent event); |
| 568 void LogUkm(); |
| 569 |
| 570 private: |
| 571 enum MetricType { |
| 572 AUTOFILL_FORM_SUBMITTED_STATE, // |AutofillFormSubmittedState| |
| 573 USER_HAPPINESS_METRIC, // |UserHappinessMetric| |
| 574 ADDRESS_FORM_EVENT, // |FormEvent| for address |
| 575 CREDIT_CARD_FORM_EVENT, // |FormEvent| for credit_card |
| 576 UNMASK_PROMPT_EVENT, // |UnmaskPromptEvent| |
| 577 |
| 578 NUM_METRIC_TYPES, |
| 579 }; |
| 580 ukm::UkmService* ukm_service_; // Weak reference. |
| 581 GURL url_; |
| 582 std::vector<std::pair<MetricType, int>> metrics_; |
| 583 }; |
| 584 |
546 static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric); | 585 static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric); |
547 static void LogCreditCardInfoBarMetric(InfoBarMetric metric, | 586 static void LogCreditCardInfoBarMetric(InfoBarMetric metric, |
548 bool is_uploading); | 587 bool is_uploading); |
549 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); | 588 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); |
550 static void LogSaveCardPromptMetric(SaveCardPromptMetric metric, | 589 static void LogSaveCardPromptMetric(SaveCardPromptMetric metric, |
551 bool is_uploading, | 590 bool is_uploading, |
552 bool is_reshow); | 591 bool is_reshow); |
553 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); | 592 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); |
554 | 593 |
555 // Should be called when credit card scan is finished. |duration| should be | 594 // 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 | 701 |
663 // This should be called each time a server response is parsed for a form. | 702 // This should be called each time a server response is parsed for a form. |
664 static void LogServerResponseHasDataForForm(bool has_data); | 703 static void LogServerResponseHasDataForForm(bool has_data); |
665 | 704 |
666 // This should be called at each form submission to indicate what profile | 705 // This should be called at each form submission to indicate what profile |
667 // action happened. | 706 // action happened. |
668 static void LogProfileActionOnFormSubmitted(AutofillProfileAction action); | 707 static void LogProfileActionOnFormSubmitted(AutofillProfileAction action); |
669 | 708 |
670 // This should be called at each form submission to indicate the autofilled | 709 // This should be called at each form submission to indicate the autofilled |
671 // state of the form. | 710 // state of the form. |
672 static void LogAutofillFormSubmittedState(AutofillFormSubmittedState state); | 711 static void LogAutofillFormSubmittedState(AutofillFormSubmittedState state, |
| 712 UkmLogger* ukm_logger); |
673 | 713 |
674 // This should be called when determining the heuristic types for a form's | 714 // This should be called when determining the heuristic types for a form's |
675 // fields. | 715 // fields. |
676 static void LogDetermineHeuristicTypesTiming(const base::TimeDelta& duration); | 716 static void LogDetermineHeuristicTypesTiming(const base::TimeDelta& duration); |
677 | 717 |
678 // This should be called when parsing each form. | 718 // This should be called when parsing each form. |
679 static void LogParseFormTiming(const base::TimeDelta& duration); | 719 static void LogParseFormTiming(const base::TimeDelta& duration); |
680 | 720 |
681 // Log how many profiles were considered for the deduplication process. | 721 // Log how many profiles were considered for the deduplication process. |
682 static void LogNumberOfProfilesConsideredForDedupe(size_t num_considered); | 722 static void LogNumberOfProfilesConsideredForDedupe(size_t num_considered); |
(...skipping 27 matching lines...) Expand all Loading... |
710 const GURL& url, | 750 const GURL& url, |
711 AutofillMetrics::DeveloperEngagementMetric metric); | 751 AutofillMetrics::DeveloperEngagementMetric metric); |
712 | 752 |
713 // Logs the the |ukm_entry_name| with the specified |url| and the specified | 753 // Logs the the |ukm_entry_name| with the specified |url| and the specified |
714 // |metrics|. Returns whether the ukm was sucessfully logged. | 754 // |metrics|. Returns whether the ukm was sucessfully logged. |
715 static bool LogUkm(ukm::UkmService* ukm_service, | 755 static bool LogUkm(ukm::UkmService* ukm_service, |
716 const GURL& url, | 756 const GURL& url, |
717 const std::string& ukm_entry_name, | 757 const std::string& ukm_entry_name, |
718 const std::map<std::string, int>& metrics); | 758 const std::map<std::string, int>& metrics); |
719 | 759 |
720 // Utility to autofill form events in the relevant histograms depending on | 760 // Utility to log autofill form events in the relevant histograms depending on |
721 // the presence of server and/or local data. | 761 // the presence of server and/or local data. |
722 class FormEventLogger { | 762 class FormEventLogger { |
723 public: | 763 public: |
724 FormEventLogger(bool is_for_credit_card); | 764 FormEventLogger(bool is_for_credit_card, UkmLogger* ukm_logger); |
725 | 765 |
726 inline void set_is_server_data_available(bool is_server_data_available) { | 766 inline void set_is_server_data_available(bool is_server_data_available) { |
727 is_server_data_available_ = is_server_data_available; | 767 is_server_data_available_ = is_server_data_available; |
728 } | 768 } |
729 | 769 |
730 inline void set_is_local_data_available(bool is_local_data_available) { | 770 inline void set_is_local_data_available(bool is_local_data_available) { |
731 is_local_data_available_ = is_local_data_available; | 771 is_local_data_available_ = is_local_data_available; |
732 } | 772 } |
733 | 773 |
734 inline void set_is_context_secure(bool is_context_secure) { | 774 inline void set_is_context_secure(bool is_context_secure) { |
(...skipping 29 matching lines...) Expand all Loading... |
764 bool has_logged_suggestions_shown_; | 804 bool has_logged_suggestions_shown_; |
765 bool has_logged_masked_server_card_suggestion_selected_; | 805 bool has_logged_masked_server_card_suggestion_selected_; |
766 bool has_logged_suggestion_filled_; | 806 bool has_logged_suggestion_filled_; |
767 bool has_logged_will_submit_; | 807 bool has_logged_will_submit_; |
768 bool has_logged_submitted_; | 808 bool has_logged_submitted_; |
769 bool logged_suggestion_filled_was_server_data_; | 809 bool logged_suggestion_filled_was_server_data_; |
770 bool logged_suggestion_filled_was_masked_server_card_; | 810 bool logged_suggestion_filled_was_masked_server_card_; |
771 | 811 |
772 // The last field that was polled for suggestions. | 812 // The last field that was polled for suggestions. |
773 FormFieldData last_polled_field_; | 813 FormFieldData last_polled_field_; |
| 814 |
| 815 UkmLogger* ukm_logger_; // Weak reference. |
774 }; | 816 }; |
775 | 817 |
776 private: | 818 private: |
777 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); | 819 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); |
778 }; | 820 }; |
779 | 821 |
780 } // namespace autofill | 822 } // namespace autofill |
781 | 823 |
782 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ | 824 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ |
OLD | NEW |