• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_METRICS_H_
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_METRICS_H_
7 #pragma once
8 
9 #include <stddef.h>
10 #include <string>
11 
12 #include "base/basictypes.h"
13 #include "chrome/browser/autofill/field_types.h"
14 
15 class AutofillMetrics {
16  public:
17   enum CreditCardInfoBarMetric {
18     CREDIT_CARD_INFOBAR_SHOWN = 0,  // We showed an infobar prompting to save
19                                     // credit card info.
20     CREDIT_CARD_INFOBAR_ACCEPTED,   // The user explicitly accepted the infobar.
21     CREDIT_CARD_INFOBAR_DENIED,     // The user explicitly denied the infobar.
22     CREDIT_CARD_INFOBAR_IGNORED,    // The user completely ignored the infobar
23                                     // (logged on tab close).
24     NUM_CREDIT_CARD_INFO_BAR_METRICS
25   };
26 
27   // Metrics measuring how well we predict field types. Exactly one metric from
28   // each set is logged for each fillable field in a submitted form.
29   enum HeuristicTypeQualityMetric {
30     HEURISTIC_TYPE_UNKNOWN = 0,  // Our heuristics offered no prediction.
31     HEURISTIC_TYPE_MATCH,        // Our heuristics predicted correctly.
32     HEURISTIC_TYPE_MISMATCH,     // Our heuristics predicted incorrectly.
33     NUM_HEURISTIC_TYPE_QUALITY_METRICS
34   };
35   enum ServerTypeQualityMetric {
36     SERVER_TYPE_UNKNOWN = 0,  // The server offered no prediction.
37     SERVER_TYPE_MATCH,        // The server predicted correctly.
38     SERVER_TYPE_MISMATCH,     // The server predicted incorrectly.
39     NUM_SERVER_TYPE_QUALITY_METRICS
40   };
41   enum PredictedTypeQualityMetric {
42     PREDICTED_TYPE_UNKNOWN = 0,  // Neither server nor heuristics offered a
43                                  // prediction.
44     PREDICTED_TYPE_MATCH,        // Overall, predicted correctly.
45     PREDICTED_TYPE_MISMATCH,     // Overall, predicted incorrectly.
46     NUM_PREDICTED_TYPE_QUALITY_METRICS
47   };
48 
49   enum QualityMetric {
50     // Logged for each potentially fillable field in a submitted form.
51     FIELD_SUBMITTED = 0,
52 
53     // A simple successs metric, logged for each field that returns true for
54     // |is_autofilled()|.
55     FIELD_AUTOFILLED,
56 
57     // A simple failure metric, logged for each field that returns false for
58     // |is_autofilled()| but has a value that is present in the personal data
59     // manager.
60     FIELD_NOT_AUTOFILLED,
61 
62     // The below are only logged when |FIELD_AUTOFILL_FAILED| is also logged.
63     NOT_AUTOFILLED_HEURISTIC_TYPE_UNKNOWN,
64     NOT_AUTOFILLED_HEURISTIC_TYPE_MATCH,
65     NOT_AUTOFILLED_HEURISTIC_TYPE_MISMATCH,
66     NOT_AUTOFILLED_SERVER_TYPE_UNKNOWN,
67     NOT_AUTOFILLED_SERVER_TYPE_MATCH,
68     NOT_AUTOFILLED_SERVER_TYPE_MISMATCH,
69     NUM_QUALITY_METRICS
70   };
71 
72   // Each of these is logged at most once per query to the server, which in turn
73   // occurs at most once per page load.
74   enum ServerQueryMetric {
75     QUERY_SENT = 0,           // Sent a query to the server.
76     QUERY_RESPONSE_RECEIVED,  // Received a response.
77     QUERY_RESPONSE_PARSED,    // Successfully parsed the server response.
78 
79     // The response was parseable, but provided no improvements relative to our
80     // heuristics.
81     QUERY_RESPONSE_MATCHED_LOCAL_HEURISTICS,
82 
83     // Our heuristics detected at least one auto-fillable field, and the server
84     // response overrode the type of at least one field.
85     QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS,
86 
87     // Our heuristics did not detect any auto-fillable fields, but the server
88     // response did detect at least one.
89     QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS,
90     NUM_SERVER_QUERY_METRICS
91   };
92 
93   AutofillMetrics();
94   virtual ~AutofillMetrics();
95 
96   virtual void Log(CreditCardInfoBarMetric metric) const;
97   virtual void Log(HeuristicTypeQualityMetric metric,
98                    AutofillFieldType field_type,
99                    const std::string& experiment_id) const;
100   virtual void Log(PredictedTypeQualityMetric metric,
101                    AutofillFieldType field_type,
102                    const std::string& experiment_id) const;
103   virtual void Log(QualityMetric metric,
104                    const std::string& experiment_id) const;
105   virtual void Log(ServerQueryMetric metric) const;
106   virtual void Log(ServerTypeQualityMetric metric,
107                    AutofillFieldType field_type,
108                    const std::string& experiment_id) const;
109 
110   // This should be called each time a page containing forms is loaded.
111   virtual void LogIsAutofillEnabledAtPageLoad(bool enabled) const;
112 
113   // This should be called each time a new profile is launched.
114   virtual void LogIsAutofillEnabledAtStartup(bool enabled) const;
115 
116   // This should be called each time a new profile is launched.
117   virtual void LogStoredProfileCount(size_t num_profiles) const;
118 
119   // Log the number of Autofill suggestions presented to the user when filling a
120   // form.
121   virtual void LogAddressSuggestionsCount(size_t num_suggestions) const;
122 
123  private:
124   DISALLOW_COPY_AND_ASSIGN(AutofillMetrics);
125 };
126 
127 #endif  // CHROME_BROWSER_AUTOFILL_AUTOFILL_METRICS_H_
128