Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: components/autofill/core/browser/autofill_metrics.h

Issue 2800853004: UKM that threads together multiple form interaction events. (Closed)
Patch Set: Updates unit tests. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 UkmLogger {
sebsg 2017/04/10 19:20:19 Do you think we could rename to something like For
csashi 2017/04/10 20:15:58 Done.
557 public:
558 explicit UkmLogger(ukm::UkmService* ukm_service);
559 ~UkmLogger();
560
561 const GURL& url() const { return url_; }
562 void set_url(const GURL& url) { url_ = url; }
563
564 void LogAutofillFormSubmittedState(AutofillFormSubmittedState state);
565 void LogUserHappinessMetric(UserHappinessMetric metric);
566 void LogAddressFormEvent(FormEvent event);
567 void LogCreditCardFormEvent(FormEvent event);
568 void LogUnmaskPromptEvent(UnmaskPromptEvent event);
569 void LogUkm();
570
571 private:
572 enum MetricType {
573 AUTOFILL_FORM_SUBMITTED_STATE, // |AutofillFormSubmittedState|
574 USER_HAPPINESS_METRIC, // |UserHappinessMetric|
575 ADDRESS_FORM_EVENT, // |FormEvent| for address
576 CREDIT_CARD_FORM_EVENT, // |FormEvent| for credit_card
577 UNMASK_PROMPT_EVENT, // |UnmaskPromptEvent|
578
579 NUM_METRIC_TYPES,
580 };
581 ukm::UkmService* ukm_service_; // Weak reference.
582 GURL url_;
583 std::vector<std::pair<MetricType, int>> metrics_;
584 };
585
546 static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric); 586 static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric);
547 static void LogCreditCardInfoBarMetric(InfoBarMetric metric, 587 static void LogCreditCardInfoBarMetric(InfoBarMetric metric,
548 bool is_uploading); 588 bool is_uploading);
549 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric); 589 static void LogCreditCardFillingInfoBarMetric(InfoBarMetric metric);
550 static void LogSaveCardPromptMetric(SaveCardPromptMetric metric, 590 static void LogSaveCardPromptMetric(SaveCardPromptMetric metric,
551 bool is_uploading, 591 bool is_uploading,
552 bool is_reshow); 592 bool is_reshow);
553 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric); 593 static void LogScanCreditCardPromptMetric(ScanCreditCardPromptMetric metric);
554 594
555 // Should be called when credit card scan is finished. |duration| should be 595 // Should be called when credit card scan is finished. |duration| should be
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 702
663 // This should be called each time a server response is parsed for a form. 703 // This should be called each time a server response is parsed for a form.
664 static void LogServerResponseHasDataForForm(bool has_data); 704 static void LogServerResponseHasDataForForm(bool has_data);
665 705
666 // This should be called at each form submission to indicate what profile 706 // This should be called at each form submission to indicate what profile
667 // action happened. 707 // action happened.
668 static void LogProfileActionOnFormSubmitted(AutofillProfileAction action); 708 static void LogProfileActionOnFormSubmitted(AutofillProfileAction action);
669 709
670 // This should be called at each form submission to indicate the autofilled 710 // This should be called at each form submission to indicate the autofilled
671 // state of the form. 711 // state of the form.
672 static void LogAutofillFormSubmittedState(AutofillFormSubmittedState state); 712 static void LogAutofillFormSubmittedState(AutofillFormSubmittedState state,
713 UkmLogger* ukm_logger);
673 714
674 // This should be called when determining the heuristic types for a form's 715 // This should be called when determining the heuristic types for a form's
675 // fields. 716 // fields.
676 static void LogDetermineHeuristicTypesTiming(const base::TimeDelta& duration); 717 static void LogDetermineHeuristicTypesTiming(const base::TimeDelta& duration);
677 718
678 // This should be called when parsing each form. 719 // This should be called when parsing each form.
679 static void LogParseFormTiming(const base::TimeDelta& duration); 720 static void LogParseFormTiming(const base::TimeDelta& duration);
680 721
681 // Log how many profiles were considered for the deduplication process. 722 // Log how many profiles were considered for the deduplication process.
682 static void LogNumberOfProfilesConsideredForDedupe(size_t num_considered); 723 static void LogNumberOfProfilesConsideredForDedupe(size_t num_considered);
(...skipping 25 matching lines...) Expand all
708 static void LogDeveloperEngagementUkm( 749 static void LogDeveloperEngagementUkm(
709 ukm::UkmService* ukm_service, 750 ukm::UkmService* ukm_service,
710 const GURL& url, 751 const GURL& url,
711 AutofillMetrics::DeveloperEngagementMetric metric); 752 AutofillMetrics::DeveloperEngagementMetric metric);
712 753
713 // Logs the the |ukm_entry_name| with the specified |url| and the specified 754 // Logs the the |ukm_entry_name| with the specified |url| and the specified
714 // |metrics|. Returns whether the ukm was sucessfully logged. 755 // |metrics|. Returns whether the ukm was sucessfully logged.
715 static bool LogUkm(ukm::UkmService* ukm_service, 756 static bool LogUkm(ukm::UkmService* ukm_service,
716 const GURL& url, 757 const GURL& url,
717 const std::string& ukm_entry_name, 758 const std::string& ukm_entry_name,
718 const std::map<std::string, int>& metrics); 759 const std::vector<std::pair<const char*, int>>& metrics);
719 760
720 // Utility to autofill form events in the relevant histograms depending on 761 // Utility to log autofill form events in the relevant histograms depending on
721 // the presence of server and/or local data. 762 // the presence of server and/or local data.
722 class FormEventLogger { 763 class FormEventLogger {
723 public: 764 public:
724 FormEventLogger(bool is_for_credit_card); 765 FormEventLogger(bool is_for_credit_card, UkmLogger* ukm_logger);
725 766
726 inline void set_is_server_data_available(bool is_server_data_available) { 767 inline void set_is_server_data_available(bool is_server_data_available) {
727 is_server_data_available_ = is_server_data_available; 768 is_server_data_available_ = is_server_data_available;
728 } 769 }
729 770
730 inline void set_is_local_data_available(bool is_local_data_available) { 771 inline void set_is_local_data_available(bool is_local_data_available) {
731 is_local_data_available_ = is_local_data_available; 772 is_local_data_available_ = is_local_data_available;
732 } 773 }
733 774
734 inline void set_is_context_secure(bool is_context_secure) { 775 inline void set_is_context_secure(bool is_context_secure) {
(...skipping 12 matching lines...) Expand all
747 // the card is upgraded to a full card. 788 // the card is upgraded to a full card.
748 void OnDidFillSuggestion(const CreditCard& credit_card); 789 void OnDidFillSuggestion(const CreditCard& credit_card);
749 790
750 void OnDidFillSuggestion(const AutofillProfile& profile); 791 void OnDidFillSuggestion(const AutofillProfile& profile);
751 792
752 void OnWillSubmitForm(); 793 void OnWillSubmitForm();
753 794
754 void OnFormSubmitted(); 795 void OnFormSubmitted();
755 796
756 private: 797 private:
757 void Log(FormEvent event) const; 798 void Log(FormEvent event, bool log_ukm) const;
758 799
759 bool is_for_credit_card_; 800 bool is_for_credit_card_;
760 bool is_server_data_available_; 801 bool is_server_data_available_;
761 bool is_local_data_available_; 802 bool is_local_data_available_;
762 bool is_context_secure_; 803 bool is_context_secure_;
763 bool has_logged_interacted_; 804 bool has_logged_interacted_;
764 bool has_logged_suggestions_shown_; 805 bool has_logged_suggestions_shown_;
765 bool has_logged_masked_server_card_suggestion_selected_; 806 bool has_logged_masked_server_card_suggestion_selected_;
766 bool has_logged_suggestion_filled_; 807 bool has_logged_suggestion_filled_;
767 bool has_logged_will_submit_; 808 bool has_logged_will_submit_;
768 bool has_logged_submitted_; 809 bool has_logged_submitted_;
769 bool logged_suggestion_filled_was_server_data_; 810 bool logged_suggestion_filled_was_server_data_;
770 bool logged_suggestion_filled_was_masked_server_card_; 811 bool logged_suggestion_filled_was_masked_server_card_;
771 812
772 // The last field that was polled for suggestions. 813 // The last field that was polled for suggestions.
773 FormFieldData last_polled_field_; 814 FormFieldData last_polled_field_;
815
816 UkmLogger* ukm_logger_; // Weak reference.
774 }; 817 };
775 818
776 private: 819 private:
777 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics); 820 DISALLOW_IMPLICIT_CONSTRUCTORS(AutofillMetrics);
778 }; 821 };
779 822
780 } // namespace autofill 823 } // namespace autofill
781 824
782 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_ 825 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_METRICS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698