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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 const GURL& url, | 717 const GURL& url, |
711 AutofillMetrics::DeveloperEngagementMetric metric); | 718 AutofillMetrics::DeveloperEngagementMetric metric); |
712 | 719 |
713 // Logs the the |ukm_entry_name| with the specified |url| and the specified | 720 // Logs the the |ukm_entry_name| with the specified |url| and the specified |
714 // |metrics|. Returns whether the ukm was sucessfully logged. | 721 // |metrics|. Returns whether the ukm was sucessfully logged. |
715 static bool LogUkm(ukm::UkmService* ukm_service, | 722 static bool LogUkm(ukm::UkmService* ukm_service, |
716 const GURL& url, | 723 const GURL& url, |
717 const std::string& ukm_entry_name, | 724 const std::string& ukm_entry_name, |
718 const std::map<std::string, int>& metrics); | 725 const std::map<std::string, int>& metrics); |
719 | 726 |
720 // Utility to autofill form events in the relevant histograms depending on | 727 // Utility to log URL keyed |AutofillFormSubmittedState|, |
| 728 // |UserHappinessMetric|, |FormEvent| and |UnmaskPromptEvent|. |
| 729 class UkmLogger { |
| 730 public: |
| 731 explicit UkmLogger(ukm::UkmService* ukm_service); |
| 732 ~UkmLogger(); |
| 733 |
| 734 void set_url(const GURL& url) { url_ = url; } |
| 735 void LogAutofillFormSubmittedState(const GURL& source_url, |
| 736 AutofillFormSubmittedState state); |
| 737 void LogUserHappinessMetric(UserHappinessMetric metric); |
| 738 void LogAddressFormEvent(FormEvent event); |
| 739 void LogCreditCardFormEvent(FormEvent event); |
| 740 void LogUnmaskPromptEvent(UnmaskPromptEvent event); |
| 741 void LogUkm(); |
| 742 |
| 743 private: |
| 744 enum MetricType { |
| 745 AUTOFILL_FORM_SUBMITTED_STATE, // |AutofillFormSubmittedState| |
| 746 USER_HAPPINESS_METRIC, // |UserHappinessMetric| |
| 747 ADDRESS_FORM_EVENT, // |FormEvent| for address |
| 748 CREDIT_CARD_FORM_EVENT, // |FormEvent| for credit_card |
| 749 UNMASK_PROMPT_EVENT, // |UnmaskPromptEvent| |
| 750 |
| 751 NUM_METRIC_TYPES, |
| 752 }; |
| 753 ukm::UkmService* ukm_service_; // Weak reference. |
| 754 GURL url_; |
| 755 std::vector<std::pair<MetricType, int>> metrics_; |
| 756 }; |
| 757 |
| 758 // Utility to log autofill form events in the relevant histograms depending on |
721 // the presence of server and/or local data. | 759 // the presence of server and/or local data. |
722 class FormEventLogger { | 760 class FormEventLogger { |
723 public: | 761 public: |
724 FormEventLogger(bool is_for_credit_card); | 762 FormEventLogger(bool is_for_credit_card, UkmLogger* ukm_logger); |
725 | 763 |
726 inline void set_is_server_data_available(bool is_server_data_available) { | 764 inline void set_is_server_data_available(bool is_server_data_available) { |
727 is_server_data_available_ = is_server_data_available; | 765 is_server_data_available_ = is_server_data_available; |
728 } | 766 } |
729 | 767 |
730 inline void set_is_local_data_available(bool is_local_data_available) { | 768 inline void set_is_local_data_available(bool is_local_data_available) { |
731 is_local_data_available_ = is_local_data_available; | 769 is_local_data_available_ = is_local_data_available; |
732 } | 770 } |
733 | 771 |
734 inline void set_is_context_secure(bool is_context_secure) { | 772 inline void set_is_context_secure(bool is_context_secure) { |
(...skipping 29 matching lines...) Expand all Loading... |
764 bool has_logged_suggestions_shown_; | 802 bool has_logged_suggestions_shown_; |
765 bool has_logged_masked_server_card_suggestion_selected_; | 803 bool has_logged_masked_server_card_suggestion_selected_; |
766 bool has_logged_suggestion_filled_; | 804 bool has_logged_suggestion_filled_; |
767 bool has_logged_will_submit_; | 805 bool has_logged_will_submit_; |
768 bool has_logged_submitted_; | 806 bool has_logged_submitted_; |
769 bool logged_suggestion_filled_was_server_data_; | 807 bool logged_suggestion_filled_was_server_data_; |
770 bool logged_suggestion_filled_was_masked_server_card_; | 808 bool logged_suggestion_filled_was_masked_server_card_; |
771 | 809 |
772 // The last field that was polled for suggestions. | 810 // The last field that was polled for suggestions. |
773 FormFieldData last_polled_field_; | 811 FormFieldData last_polled_field_; |
| 812 |
| 813 UkmLogger* ukm_logger_; // Weak reference. |
774 }; | 814 }; |
775 | 815 |
776 private: | 816 private: |
777 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); | 817 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); |
778 }; | 818 }; |
779 | 819 |
780 } // namespace autofill | 820 } // namespace autofill |
781 | 821 |
782 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ | 822 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ |
OLD | NEW |