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 #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> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/string_piece_forward.h" | |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 16 #include "components/autofill/core/browser/autofill_client.h" | 15 #include "components/autofill/core/browser/autofill_client.h" |
| 17 #include "components/autofill/core/browser/autofill_profile.h" | 16 #include "components/autofill/core/browser/autofill_profile.h" |
| 18 #include "components/autofill/core/browser/credit_card.h" | 17 #include "components/autofill/core/browser/credit_card.h" |
| 19 #include "components/autofill/core/browser/field_types.h" | 18 #include "components/autofill/core/browser/field_types.h" |
| 20 #include "components/autofill/core/common/autofill_pref_names.h" | 19 #include "components/autofill/core/common/autofill_pref_names.h" |
| 21 #include "components/autofill/core/common/form_field_data.h" | 20 #include "components/autofill/core/common/form_field_data.h" |
| 21 #include "components/autofill/core/common/signatures_util.h" | |
| 22 #include "components/ukm/public/ukm_recorder.h" | 22 #include "components/ukm/public/ukm_recorder.h" |
| 23 | 23 |
| 24 namespace internal { | 24 namespace internal { |
| 25 // Name constants are exposed here so they can be referenced from tests. | 25 // Name constants are exposed here so they can be referenced from tests. |
| 26 extern const char kUKMCardUploadDecisionEntryName[]; | 26 extern const char kUKMCardUploadDecisionEntryName[]; |
| 27 extern const char kUKMCardUploadDecisionMetricName[]; | 27 extern const char kUKMCardUploadDecisionMetricName[]; |
| 28 extern const char kUKMDeveloperEngagementEntryName[]; | 28 extern const char kUKMDeveloperEngagementEntryName[]; |
| 29 extern const char kUKMDeveloperEngagementMetricName[]; | 29 extern const char kUKMDeveloperEngagementMetricName[]; |
| 30 | 30 |
| 31 // Each form interaction event has a separate |UkmEntry|. | 31 // Each form interaction event has a separate |UkmEntry|. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 62 // |UkmEntry| for user editing text field. Metrics contain field's attributes. | 62 // |UkmEntry| for user editing text field. Metrics contain field's attributes. |
| 63 extern const char kUKMTextFieldDidChangeEntryName[]; | 63 extern const char kUKMTextFieldDidChangeEntryName[]; |
| 64 extern const char kUKMFieldTypeGroupMetricName[]; | 64 extern const char kUKMFieldTypeGroupMetricName[]; |
| 65 extern const char kUKMHtmlFieldModeMetricName[]; | 65 extern const char kUKMHtmlFieldModeMetricName[]; |
| 66 extern const char kUKMIsAutofilledMetricName[]; | 66 extern const char kUKMIsAutofilledMetricName[]; |
| 67 extern const char kUKMIsEmptyMetricName[]; | 67 extern const char kUKMIsEmptyMetricName[]; |
| 68 | 68 |
| 69 // |UkmEntry| for |AutofillFormSubmittedState|. | 69 // |UkmEntry| for |AutofillFormSubmittedState|. |
| 70 extern const char kUKMFormSubmittedEntryName[]; | 70 extern const char kUKMFormSubmittedEntryName[]; |
| 71 extern const char kUKMAutofillFormSubmittedStateMetricName[]; | 71 extern const char kUKMAutofillFormSubmittedStateMetricName[]; |
| 72 | |
| 73 // |UkmEntry| for capturing field fill status and type prediction quality. | |
| 74 extern const char kUKMFieldTypeEntryName[]; | |
| 75 extern const char kUKMFieldFillStatusEntryName[]; | |
| 76 extern const char kUKMFormSignatureMetricName[]; | |
| 77 extern const char kUKMFieldSignatureMetricName[]; | |
| 78 extern const char kUKMValidationEventMetricName[]; | |
| 79 extern const char kUKMPredictionSourceMetricName[]; | |
| 80 extern const char kUKMPredictedTypeMetricName[]; | |
| 81 extern const char kUKMActualTypeMetricName[]; | |
| 82 extern const char kUKMWasSuggestionShownMetricName[]; | |
| 83 extern const char kUKMWasPreviouslyAutofilledMetricName[]; | |
| 84 | |
| 72 } // namespace internal | 85 } // namespace internal |
| 73 | 86 |
| 74 namespace autofill { | 87 namespace autofill { |
| 75 | 88 |
| 76 class AutofillField; | 89 class AutofillField; |
| 77 | 90 |
| 78 class AutofillMetrics { | 91 class AutofillMetrics { |
| 79 public: | 92 public: |
| 80 enum AutofillProfileAction { | 93 enum AutofillProfileAction { |
| 81 EXISTING_PROFILE_USED, | 94 EXISTING_PROFILE_USED, |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 // UNKNOWN not in (T,U). | 414 // UNKNOWN not in (T,U). |
| 402 // | 415 // |
| 403 // This is captured as a type-specific log entry for T. Is is also captured | 416 // This is captured as a type-specific log entry for T. Is is also captured |
| 404 // as an aggregate (non-type-specific) log entry. | 417 // as an aggregate (non-type-specific) log entry. |
| 405 FALSE_NEGATIVE_MISMATCH, | 418 FALSE_NEGATIVE_MISMATCH, |
| 406 | 419 |
| 407 // This must be last. | 420 // This must be last. |
| 408 NUM_FIELD_TYPE_QUALITY_METRICS | 421 NUM_FIELD_TYPE_QUALITY_METRICS |
| 409 }; | 422 }; |
| 410 | 423 |
| 424 enum QualityMetricPredictionSource { | |
| 425 PREDICTION_SOURCE_UNKNOWN, // Not used. The prediction source is unknown. | |
| 426 PREDICTION_SOURCE_HEURISTIC, // Local heuristic field-type prediction. | |
| 427 PREDICTION_SOURCE_SERVER, // Crowd-sourced server field type prediction. | |
| 428 PREDICTION_SOURCE_OVERALL, // Overall field-type prediction seen by user. | |
| 429 NUM_QUALITY_METRIC_SOURCES | |
| 430 }; | |
| 431 | |
| 411 enum QualityMetricType { | 432 enum QualityMetricType { |
| 412 TYPE_SUBMISSION = 0, // Logged based on user's submitted data. | 433 TYPE_SUBMISSION = 0, // Logged based on user's submitted data. |
| 413 TYPE_NO_SUBMISSION, // Logged based on user's entered data. | 434 TYPE_NO_SUBMISSION, // Logged based on user's entered data. |
| 414 TYPE_AUTOCOMPLETE_BASED, // Logged based on the value of autocomplete attr. | 435 TYPE_AUTOCOMPLETE_BASED, // Logged based on the value of autocomplete attr. |
| 415 NUM_QUALITY_METRIC_TYPES, | 436 NUM_QUALITY_METRIC_TYPES, |
| 416 }; | 437 }; |
| 417 | 438 |
| 418 // Each of these is logged at most once per query to the server, which in turn | 439 // Each of these is logged at most once per query to the server, which in turn |
| 419 // occurs at most once per page load. | 440 // occurs at most once per page load. |
| 420 enum ServerQueryMetric { | 441 enum ServerQueryMetric { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 | 693 |
| 673 // For mesuring how wallet addresses are converted to local profiles. | 694 // For mesuring how wallet addresses are converted to local profiles. |
| 674 enum WalletAddressConversionType : int { | 695 enum WalletAddressConversionType : int { |
| 675 // The converted wallet address was merged into an existing local profile. | 696 // The converted wallet address was merged into an existing local profile. |
| 676 CONVERTED_ADDRESS_MERGED, | 697 CONVERTED_ADDRESS_MERGED, |
| 677 // The converted wallet address was added as a new local profile. | 698 // The converted wallet address was added as a new local profile. |
| 678 CONVERTED_ADDRESS_ADDED, | 699 CONVERTED_ADDRESS_ADDED, |
| 679 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES | 700 NUM_CONVERTED_ADDRESS_CONVERSION_TYPES |
| 680 }; | 701 }; |
| 681 | 702 |
| 703 class UkmTimestampPin; | |
|
sebsg
2017/06/19 14:48:09
As discussed, please remove or add comment.
Roger McFarlane (Chromium)
2017/06/21 21:01:54
Done.
| |
| 704 | |
| 682 // Utility to log URL keyed form interaction events. | 705 // Utility to log URL keyed form interaction events. |
| 683 class FormInteractionsUkmLogger { | 706 class FormInteractionsUkmLogger { |
| 684 public: | 707 public: |
| 685 explicit FormInteractionsUkmLogger(ukm::UkmRecorder* ukm_recorder); | 708 explicit FormInteractionsUkmLogger(ukm::UkmRecorder* ukm_recorder); |
| 686 | 709 |
| 710 bool has_pinned_timestamp() const { return !pinned_timestamp_.is_null(); } | |
| 711 void set_pinned_timestamp(base::TimeTicks t) { pinned_timestamp_ = t; } | |
| 712 | |
| 687 const GURL& url() const { return url_; } | 713 const GURL& url() const { return url_; } |
| 688 | 714 |
| 689 void OnFormsParsed(const GURL& url); | 715 void OnFormsParsed(const GURL& url); |
| 690 void LogInteractedWithForm(bool is_for_credit_card, | 716 void LogInteractedWithForm(bool is_for_credit_card, |
| 691 size_t local_record_type_count, | 717 size_t local_record_type_count, |
| 692 size_t server_record_type_count); | 718 size_t server_record_type_count); |
| 693 void LogSuggestionsShown(const AutofillField& field); | 719 void LogSuggestionsShown(const AutofillField& field); |
| 694 void LogSelectedMaskedServerCard(); | 720 void LogSelectedMaskedServerCard(); |
| 695 void LogDidFillSuggestion(int record_type); | 721 void LogDidFillSuggestion(int record_type); |
| 696 void LogTextFieldDidChange(const AutofillField& field); | 722 void LogTextFieldDidChange(const AutofillField& field); |
| 723 void LogFieldFillStatus(const FormStructure& form, | |
| 724 const AutofillField& field, | |
| 725 QualityMetricType metric_type); | |
| 726 void LogFieldType(FormSignature form_signature, | |
| 727 FieldSignature field_signature, | |
| 728 QualityMetricPredictionSource prediction_source, | |
| 729 QualityMetricType metric_type, | |
| 730 ServerFieldType predicted_type, | |
| 731 ServerFieldType actual_type); | |
| 697 void LogFormSubmitted(AutofillFormSubmittedState state); | 732 void LogFormSubmitted(AutofillFormSubmittedState state); |
| 698 | 733 |
| 699 // We initialize |url_| with the form's URL when we log the first form | 734 // We initialize |url_| with the form's URL when we log the first form |
| 700 // interaction. Later, we may update |url_| with the |source_url()| for the | 735 // interaction. Later, we may update |url_| with the |source_url()| for the |
| 701 // submitted form. | 736 // submitted form. |
| 702 void UpdateSourceURL(const GURL& url); | 737 void UpdateSourceURL(const GURL& url); |
| 703 | 738 |
| 704 private: | 739 private: |
| 705 bool CanLog() const; | 740 bool CanLog() const; |
| 706 int64_t MillisecondsSinceFormParsed() const; | 741 int64_t MillisecondsSinceFormParsed() const; |
| 707 void GetNewSourceID(); | 742 void GetNewSourceID(); |
| 708 | 743 |
| 709 ukm::UkmRecorder* ukm_recorder_; // Weak reference. | 744 ukm::UkmRecorder* ukm_recorder_; // Weak reference. |
| 710 ukm::SourceId source_id_ = -1; | 745 ukm::SourceId source_id_ = -1; |
| 711 GURL url_; | 746 GURL url_; |
| 712 base::TimeTicks form_parsed_timestamp_; | 747 base::TimeTicks form_parsed_timestamp_; |
| 748 base::TimeTicks pinned_timestamp_; | |
| 749 }; | |
| 750 | |
| 751 // Utility class to pin the timestamp used by the FormInteractionsUkmLogger | |
| 752 // while an instance of this class is in scope. Pinned timestamps cannot be | |
| 753 // nested. | |
| 754 class UkmTimestampPin { | |
| 755 public: | |
| 756 UkmTimestampPin(FormInteractionsUkmLogger* logger) : logger_(logger) { | |
| 757 DCHECK(!logger->has_pinned_timestamp()); | |
| 758 logger->set_pinned_timestamp(base::TimeTicks::Now()); | |
| 759 } | |
| 760 ~UkmTimestampPin() { | |
| 761 DCHECK(logger_->has_pinned_timestamp()); | |
| 762 logger_->set_pinned_timestamp(base::TimeTicks()); | |
| 763 } | |
| 764 | |
| 765 private: | |
| 766 FormInteractionsUkmLogger* const logger_; | |
| 767 DISALLOW_IMPLICIT_CONSTRUCTORS(UkmTimestampPin); | |
| 713 }; | 768 }; |
| 714 | 769 |
| 715 // |upload_decision_metrics| is a bitmask of |CardUploadDecisionMetric|. | 770 // |upload_decision_metrics| is a bitmask of |CardUploadDecisionMetric|. |
| 716 static void LogCardUploadDecisionMetrics(int upload_decision_metrics); | 771 static void LogCardUploadDecisionMetrics(int upload_decision_metrics); |
| 717 static void LogCreditCardInfoBarMetric( | 772 static void LogCreditCardInfoBarMetric( |
| 718 InfoBarMetric metric, | 773 InfoBarMetric metric, |
| 719 bool is_uploading, | 774 bool is_uploading, |
| 720 int previous_save_credit_card_prompt_user_decision); | 775 int previous_save_credit_card_prompt_user_decision); |
| 721 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); | 776 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); |
| 722 static void LogSaveCardPromptMetric( | 777 static void LogSaveCardPromptMetric( |
| 723 SaveCardPromptMetric metric, | 778 SaveCardPromptMetric metric, |
| 724 bool is_uploading, | 779 bool is_uploading, |
| 725 bool is_reshow, | 780 bool is_reshow, |
| 726 int previous_save_credit_card_prompt_user_decision); | 781 int previous_save_credit_card_prompt_user_decision); |
| 727 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); | 782 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); |
| 728 | 783 |
| 729 // Should be called when credit card scan is finished. |duration| should be | 784 // Should be called when credit card scan is finished. |duration| should be |
| 730 // the time elapsed between launching the credit card scanner and getting back | 785 // the time elapsed between launching the credit card scanner and getting back |
| 731 // the result. |completed| should be true if a credit card was scanned, false | 786 // the result. |completed| should be true if a credit card was scanned, false |
| 732 // if the scan was cancelled. | 787 // if the scan was cancelled. |
| 733 static void LogScanCreditCardCompleted(const base::TimeDelta& duration, | 788 static void LogScanCreditCardCompleted(const base::TimeDelta& duration, |
| 734 bool completed); | 789 bool completed); |
| 735 | 790 |
| 736 static void LogDeveloperEngagementMetric(DeveloperEngagementMetric metric); | 791 static void LogDeveloperEngagementMetric(DeveloperEngagementMetric metric); |
| 737 | 792 |
| 738 static void LogHeuristicPredictionQualityMetrics( | 793 static void LogHeuristicPredictionQualityMetrics( |
| 739 const ServerFieldTypeSet& possible_types, | 794 FormInteractionsUkmLogger* form_interactions_ukm_logger, |
| 740 ServerFieldType predicted_type, | 795 const FormStructure& form, |
| 796 const AutofillField& field, | |
| 741 QualityMetricType metric_type); | 797 QualityMetricType metric_type); |
| 742 static void LogServerPredictionQualityMetrics( | 798 static void LogServerPredictionQualityMetrics( |
| 743 const ServerFieldTypeSet& possible_types, | 799 FormInteractionsUkmLogger* form_interactions_ukm_logger, |
| 744 ServerFieldType predicted_type, | 800 const FormStructure& form, |
| 801 const AutofillField& field, | |
| 745 QualityMetricType metric_type); | 802 QualityMetricType metric_type); |
| 746 static void LogOverallPredictionQualityMetrics( | 803 static void LogOverallPredictionQualityMetrics( |
| 747 const ServerFieldTypeSet& possible_types, | 804 FormInteractionsUkmLogger* form_interactions_ukm_logger, |
| 748 ServerFieldType predicted_type, | 805 const FormStructure& form, |
| 806 const AutofillField& field, | |
| 749 QualityMetricType metric_type); | 807 QualityMetricType metric_type); |
| 750 | 808 |
| 751 static void LogServerQueryMetric(ServerQueryMetric metric); | 809 static void LogServerQueryMetric(ServerQueryMetric metric); |
| 752 | 810 |
| 753 static void LogUserHappinessMetric(UserHappinessMetric metric); | 811 static void LogUserHappinessMetric(UserHappinessMetric metric); |
| 754 | 812 |
| 755 // Logs |event| to the unmask prompt events histogram. | 813 // Logs |event| to the unmask prompt events histogram. |
| 756 static void LogUnmaskPromptEvent(UnmaskPromptEvent event); | 814 static void LogUnmaskPromptEvent(UnmaskPromptEvent event); |
| 757 | 815 |
| 758 // Logs the time elapsed between the unmask prompt being shown and it | 816 // Logs the time elapsed between the unmask prompt being shown and it |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 962 | 1020 |
| 963 private: | 1021 private: |
| 964 static const int kNumCardUploadDecisionMetrics = 12; | 1022 static const int kNumCardUploadDecisionMetrics = 12; |
| 965 | 1023 |
| 966 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); | 1024 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); |
| 967 }; | 1025 }; |
| 968 | 1026 |
| 969 } // namespace autofill | 1027 } // namespace autofill |
| 970 | 1028 |
| 971 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ | 1029 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ |
| OLD | NEW |