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

Unified Diff: components/autofill/core/browser/autofill_metrics.h

Issue 2800853004: UKM that threads together multiple form interaction events. (Closed)
Patch Set: Logs each form interaction event in a separate UkmEntry, includes time_delta as a metric. 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/autofill_metrics.h
diff --git a/components/autofill/core/browser/autofill_metrics.h b/components/autofill/core/browser/autofill_metrics.h
index 15ee9a173c9debb9119f586cc6c5ce5773b62a2e..33341c454c2c0b1d9caf09903836a27200bf20a3 100644
--- a/components/autofill/core/browser/autofill_metrics.h
+++ b/components/autofill/core/browser/autofill_metrics.h
@@ -7,18 +7,17 @@
#include <stddef.h>
#include <string>
+#include <utility>
+#include <vector>
#include "base/macros.h"
+#include "base/time/time.h"
#include "components/autofill/core/browser/autofill_client.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/common/form_field_data.h"
-namespace base {
-class TimeDelta;
-} // namespace base
-
namespace ukm {
class UkmService;
} // namespace ukm
@@ -29,6 +28,17 @@ extern const char kUKMCardUploadDecisionEntryName[];
extern const char kUKMCardUploadDecisionMetricName[];
extern const char kUKMDeveloperEngagementEntryName[];
extern const char kUKMDeveloperEngagementMetricName[];
+
+// Each form interaction event has a separate |UkmEntry|.
+// Each |UkmEntry| has 2 metrics:
+// 1. The value of the corresponding enum (e.g. value of |UserHappiness|).
+// 2. Time elapsed, in milliseconds, since we loaded the form.
+extern const char kUKMAutofillFormSubmittedStateName[];
+extern const char kUKMUserHappinessMetricName[];
+extern const char kUKMAddressFormEventName[];
+extern const char kUKMCreditCardFormEventName[];
+extern const char kUKMUnmaskPromptEventName[];
+extern const char kUKMMillisecondsSinceFormLoadedMetricName[];
} // namespace internal
namespace autofill {
@@ -543,6 +553,49 @@ class AutofillMetrics {
NUM_CONVERTED_ADDRESS_CONVERSION_TYPES
};
+ // Utility to log URL keyed |AutofillFormSubmittedState|,
+ // |UserHappinessMetric|, |FormEvent| and |UnmaskPromptEvent|.
+ class FormInteractionsUkmLogger {
+ public:
+ explicit FormInteractionsUkmLogger(ukm::UkmService* ukm_service);
+ ~FormInteractionsUkmLogger();
+
+ const GURL& url() const { return url_; }
+ void set_url(const GURL& url) { url_ = url; }
+ void set_form_loaded_timestamp(
+ const base::TimeTicks& form_loaded_timestamp) {
+ form_loaded_timestamp_ = form_loaded_timestamp;
+ }
+
+ // The following Log functions only log the form interactions to private
+ // class variables. |SubmitUkm| is the only method that calls the
+ // |UkmService|.
+ void LogAutofillFormSubmittedState(AutofillFormSubmittedState state);
+ void LogUserHappinessMetric(UserHappinessMetric metric);
+ void LogAddressFormEvent(FormEvent event);
+ void LogCreditCardFormEvent(FormEvent event);
+ void LogUnmaskPromptEvent(UnmaskPromptEvent event);
+
+ void SubmitUkm();
+
+ private:
+ struct Event {
+ Event(const char* const name, int value, const int64_t time_delta_millis)
+ : name(name), value(value), time_delta_millis(time_delta_millis) {}
+
+ const char* const name;
+ const int value;
+ const int64_t time_delta_millis;
+ };
+
+ void AddEvent(const char* const name, int value);
+
+ ukm::UkmService* ukm_service_; // Weak reference.
+ base::TimeTicks form_loaded_timestamp_;
+ GURL url_;
+ std::vector<Event> events_;
+ };
+
static void LogCardUploadDecisionMetric(CardUploadDecisionMetric metric);
static void LogCreditCardInfoBarMetric(InfoBarMetric metric,
bool is_uploading);
@@ -669,7 +722,9 @@ class AutofillMetrics {
// This should be called at each form submission to indicate the autofilled
// state of the form.
- static void LogAutofillFormSubmittedState(AutofillFormSubmittedState state);
+ static void LogAutofillFormSubmittedState(
+ AutofillFormSubmittedState state,
+ FormInteractionsUkmLogger* form_interactions_ukm_logger);
// This should be called when determining the heuristic types for a form's
// fields.
@@ -708,20 +763,21 @@ class AutofillMetrics {
static void LogDeveloperEngagementUkm(
ukm::UkmService* ukm_service,
const GURL& url,
- AutofillMetrics::DeveloperEngagementMetric metric);
+ std::vector<AutofillMetrics::DeveloperEngagementMetric> metrics);
// Logs the the |ukm_entry_name| with the specified |url| and the specified
// |metrics|. Returns whether the ukm was sucessfully logged.
static bool LogUkm(ukm::UkmService* ukm_service,
const GURL& url,
const std::string& ukm_entry_name,
- const std::map<std::string, int>& metrics);
+ const std::vector<std::pair<const char*, int>>& metrics);
- // Utility to autofill form events in the relevant histograms depending on
+ // Utility to log autofill form events in the relevant histograms depending on
// the presence of server and/or local data.
class FormEventLogger {
public:
- FormEventLogger(bool is_for_credit_card);
+ FormEventLogger(bool is_for_credit_card,
+ FormInteractionsUkmLogger* form_interactions_ukm_logger);
inline void set_is_server_data_available(bool is_server_data_available) {
is_server_data_available_ = is_server_data_available;
@@ -754,7 +810,7 @@ class AutofillMetrics {
void OnFormSubmitted();
private:
- void Log(FormEvent event) const;
+ void Log(FormEvent event, bool log_ukm) const;
bool is_for_credit_card_;
bool is_server_data_available_;
@@ -771,6 +827,9 @@ class AutofillMetrics {
// The last field that was polled for suggestions.
FormFieldData last_polled_field_;
+
+ FormInteractionsUkmLogger*
+ form_interactions_ukm_logger_; // Weak reference.
};
private:

Powered by Google App Engine
This is Rietveld 408576698