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

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

Issue 714273003: [Autofill, Clean-up] Clean up the Autofill metrics tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: anonymouse -> anonymous Created 6 years, 1 month 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
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_metrics_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "components/autofill/core/browser/autofill_type.h" 11 #include "components/autofill/core/browser/autofill_type.h"
12 #include "components/autofill/core/browser/form_structure.h" 12 #include "components/autofill/core/browser/form_structure.h"
13 #include "components/autofill/core/common/form_data.h" 13 #include "components/autofill/core/common/form_data.h"
14 14
15 namespace autofill { 15 namespace autofill {
16 16
17 namespace { 17 namespace {
18 18
19 enum FieldTypeGroupForMetrics { 19 enum FieldTypeGroupForMetrics {
20 AMBIGUOUS = 0, 20 GROUP_AMBIGUOUS = 0,
21 NAME, 21 GROUP_NAME,
22 COMPANY, 22 GROUP_COMPANY,
23 ADDRESS_LINE_1, 23 GROUP_ADDRESS_LINE_1,
24 ADDRESS_LINE_2, 24 GROUP_ADDRESS_LINE_2,
25 ADDRESS_CITY, 25 GROUP_ADDRESS_CITY,
26 ADDRESS_STATE, 26 GROUP_ADDRESS_STATE,
27 ADDRESS_ZIP, 27 GROUP_ADDRESS_ZIP,
28 ADDRESS_COUNTRY, 28 GROUP_ADDRESS_COUNTRY,
29 PHONE, 29 GROUP_PHONE,
30 FAX, // Deprecated. 30 GROUP_FAX, // Deprecated.
31 EMAIL, 31 GROUP_EMAIL,
32 CREDIT_CARD_NAME, 32 GROUP_CREDIT_CARD_NAME,
33 CREDIT_CARD_NUMBER, 33 GROUP_CREDIT_CARD_NUMBER,
34 CREDIT_CARD_DATE, 34 GROUP_CREDIT_CARD_DATE,
35 CREDIT_CARD_TYPE, 35 GROUP_CREDIT_CARD_TYPE,
36 PASSWORD, 36 GROUP_PASSWORD,
37 ADDRESS_LINE_3, 37 GROUP_ADDRESS_LINE_3,
38 NUM_FIELD_TYPE_GROUPS_FOR_METRICS 38 NUM_FIELD_TYPE_GROUPS_FOR_METRICS
39 }; 39 };
40 40
41 } // namespace
42
41 // First, translates |field_type| to the corresponding logical |group| from 43 // First, translates |field_type| to the corresponding logical |group| from
42 // |FieldTypeGroupForMetrics|. Then, interpolates this with the given |metric|, 44 // |FieldTypeGroupForMetrics|. Then, interpolates this with the given |metric|,
43 // which should be in the range [0, |num_possible_metrics|). 45 // which should be in the range [0, |num_possible_metrics|).
44 // Returns the interpolated index. 46 // Returns the interpolated index.
45 // 47 //
46 // The interpolation maps the pair (|group|, |metric|) to a single index, so 48 // The interpolation maps the pair (|group|, |metric|) to a single index, so
47 // that all the indicies for a given group are adjacent. In particular, with 49 // that all the indicies for a given group are adjacent. In particular, with
48 // the groups {AMBIGUOUS, NAME, ...} combining with the metrics {UNKNOWN, MATCH, 50 // the groups {AMBIGUOUS, NAME, ...} combining with the metrics {UNKNOWN, MATCH,
49 // MISMATCH}, we create this set of mapped indices: 51 // MISMATCH}, we create this set of mapped indices:
50 // { 52 // {
51 // AMBIGUOUS+UNKNOWN, 53 // AMBIGUOUS+UNKNOWN,
52 // AMBIGUOUS+MATCH, 54 // AMBIGUOUS+MATCH,
53 // AMBIGUOUS+MISMATCH, 55 // AMBIGUOUS+MISMATCH,
54 // NAME+UNKNOWN, 56 // NAME+UNKNOWN,
55 // NAME+MATCH, 57 // NAME+MATCH,
56 // NAME+MISMATCH, 58 // NAME+MISMATCH,
57 // ... 59 // ...
58 // }. 60 // }.
59 // 61 //
60 // Clients must ensure that |field_type| is one of the types Chrome supports 62 // Clients must ensure that |field_type| is one of the types Chrome supports
61 // natively, e.g. |field_type| must not be a billng address. 63 // natively, e.g. |field_type| must not be a billng address.
62 int GetFieldTypeGroupMetric(const ServerFieldType field_type, 64 // NOTE: This is defined outside of the anonymous namespace so that it can be
63 const int metric, 65 // accessed from the unit test file. It is not exposed in the header file,
64 const int num_possible_metrics) { 66 // however, because it is not intended for consumption outside of the metrics
65 DCHECK_LT(metric, num_possible_metrics); 67 // implementation.
68 int GetFieldTypeGroupMetric(ServerFieldType field_type,
69 AutofillMetrics::FieldTypeQualityMetric metric) {
70 DCHECK_LT(metric, AutofillMetrics::NUM_FIELD_TYPE_QUALITY_METRICS);
66 71
67 FieldTypeGroupForMetrics group = AMBIGUOUS; 72 FieldTypeGroupForMetrics group = GROUP_AMBIGUOUS;
68 switch (AutofillType(field_type).group()) { 73 switch (AutofillType(field_type).group()) {
69 case ::autofill::NO_GROUP: 74 case NO_GROUP:
70 group = AMBIGUOUS; 75 group = GROUP_AMBIGUOUS;
71 break; 76 break;
72 77
73 case ::autofill::NAME: 78 case NAME:
74 case ::autofill::NAME_BILLING: 79 case NAME_BILLING:
75 group = NAME; 80 group = GROUP_NAME;
76 break; 81 break;
77 82
78 case ::autofill::COMPANY: 83 case COMPANY:
79 group = COMPANY; 84 group = GROUP_COMPANY;
80 break; 85 break;
81 86
82 case ::autofill::ADDRESS_HOME: 87 case ADDRESS_HOME:
83 case ::autofill::ADDRESS_BILLING: 88 case ADDRESS_BILLING:
84 switch (AutofillType(field_type).GetStorableType()) { 89 switch (AutofillType(field_type).GetStorableType()) {
85 case ADDRESS_HOME_LINE1: 90 case ADDRESS_HOME_LINE1:
86 group = ADDRESS_LINE_1; 91 group = GROUP_ADDRESS_LINE_1;
87 break; 92 break;
88 case ADDRESS_HOME_LINE2: 93 case ADDRESS_HOME_LINE2:
89 group = ADDRESS_LINE_2; 94 group = GROUP_ADDRESS_LINE_2;
90 break; 95 break;
91 case ADDRESS_HOME_LINE3: 96 case ADDRESS_HOME_LINE3:
92 group = ADDRESS_LINE_3; 97 group = GROUP_ADDRESS_LINE_3;
93 break; 98 break;
94 case ADDRESS_HOME_CITY: 99 case ADDRESS_HOME_CITY:
95 group = ADDRESS_CITY; 100 group = GROUP_ADDRESS_CITY;
96 break; 101 break;
97 case ADDRESS_HOME_STATE: 102 case ADDRESS_HOME_STATE:
98 group = ADDRESS_STATE; 103 group = GROUP_ADDRESS_STATE;
99 break; 104 break;
100 case ADDRESS_HOME_ZIP: 105 case ADDRESS_HOME_ZIP:
101 group = ADDRESS_ZIP; 106 group = GROUP_ADDRESS_ZIP;
102 break; 107 break;
103 case ADDRESS_HOME_COUNTRY: 108 case ADDRESS_HOME_COUNTRY:
104 group = ADDRESS_COUNTRY; 109 group = GROUP_ADDRESS_COUNTRY;
105 break; 110 break;
106 default: 111 default:
107 NOTREACHED(); 112 NOTREACHED();
108 group = AMBIGUOUS; 113 group = GROUP_AMBIGUOUS;
109 break; 114 break;
110 } 115 }
111 break; 116 break;
112 117
113 case ::autofill::EMAIL: 118 case EMAIL:
114 group = EMAIL; 119 group = GROUP_EMAIL;
115 break; 120 break;
116 121
117 case ::autofill::PHONE_HOME: 122 case PHONE_HOME:
118 case ::autofill::PHONE_BILLING: 123 case PHONE_BILLING:
119 group = PHONE; 124 group = GROUP_PHONE;
120 break; 125 break;
121 126
122 case ::autofill::CREDIT_CARD: 127 case CREDIT_CARD:
123 switch (field_type) { 128 switch (field_type) {
124 case ::autofill::CREDIT_CARD_NAME: 129 case CREDIT_CARD_NAME:
125 group = CREDIT_CARD_NAME; 130 group = GROUP_CREDIT_CARD_NAME;
126 break; 131 break;
127 case ::autofill::CREDIT_CARD_NUMBER: 132 case CREDIT_CARD_NUMBER:
128 group = CREDIT_CARD_NUMBER; 133 group = GROUP_CREDIT_CARD_NUMBER;
129 break; 134 break;
130 case ::autofill::CREDIT_CARD_TYPE: 135 case CREDIT_CARD_TYPE:
131 group = CREDIT_CARD_TYPE; 136 group = GROUP_CREDIT_CARD_TYPE;
132 break; 137 break;
133 case ::autofill::CREDIT_CARD_EXP_MONTH: 138 case CREDIT_CARD_EXP_MONTH:
134 case ::autofill::CREDIT_CARD_EXP_2_DIGIT_YEAR: 139 case CREDIT_CARD_EXP_2_DIGIT_YEAR:
135 case ::autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR: 140 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
136 case ::autofill::CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: 141 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR:
137 case ::autofill::CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: 142 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR:
138 group = CREDIT_CARD_DATE; 143 group = GROUP_CREDIT_CARD_DATE;
139 break; 144 break;
140 default: 145 default:
141 NOTREACHED(); 146 NOTREACHED();
142 group = AMBIGUOUS; 147 group = GROUP_AMBIGUOUS;
143 break; 148 break;
144 } 149 }
145 break; 150 break;
146 151
147 case ::autofill::PASSWORD_FIELD: 152 case PASSWORD_FIELD:
148 group = PASSWORD; 153 group = GROUP_PASSWORD;
149 break; 154 break;
150 155
151 case ::autofill::TRANSACTION: 156 case TRANSACTION:
152 NOTREACHED(); 157 NOTREACHED();
153 break; 158 break;
154 } 159 }
155 160
156 // Interpolate the |metric| with the |group|, so that all metrics for a given 161 // Interpolate the |metric| with the |group|, so that all metrics for a given
157 // |group| are adjacent. 162 // |group| are adjacent.
158 return (group * num_possible_metrics) + metric; 163 return (group * AutofillMetrics::NUM_FIELD_TYPE_QUALITY_METRICS) + metric;
159 } 164 }
160 165
166 namespace {
167
161 std::string WalletApiMetricToString( 168 std::string WalletApiMetricToString(
162 AutofillMetrics::WalletApiCallMetric metric) { 169 AutofillMetrics::WalletApiCallMetric metric) {
163 switch (metric) { 170 switch (metric) {
164 case AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS: 171 case AutofillMetrics::ACCEPT_LEGAL_DOCUMENTS:
165 return "AcceptLegalDocuments"; 172 return "AcceptLegalDocuments";
166 case AutofillMetrics::AUTHENTICATE_INSTRUMENT: 173 case AutofillMetrics::AUTHENTICATE_INSTRUMENT:
167 return "AuthenticateInstrument"; 174 return "AuthenticateInstrument";
168 case AutofillMetrics::GET_FULL_WALLET: 175 case AutofillMetrics::GET_FULL_WALLET:
169 return "GetFullWallet"; 176 return "GetFullWallet";
170 case AutofillMetrics::GET_WALLET_ITEMS: 177 case AutofillMetrics::GET_WALLET_ITEMS:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 50, 234 50,
228 base::HistogramBase::kUmaTargetedHistogramFlag); 235 base::HistogramBase::kUmaTargetedHistogramFlag);
229 histogram->AddTime(duration); 236 histogram->AddTime(duration);
230 } 237 }
231 238
232 // Logs a type quality metric. The primary histogram name is constructed based 239 // Logs a type quality metric. The primary histogram name is constructed based
233 // on |base_name|. The field-specific histogram name also factors in the 240 // on |base_name|. The field-specific histogram name also factors in the
234 // |field_type|. Logs a sample of |metric|, which should be in the range 241 // |field_type|. Logs a sample of |metric|, which should be in the range
235 // [0, |num_possible_metrics|). 242 // [0, |num_possible_metrics|).
236 void LogTypeQualityMetric(const std::string& base_name, 243 void LogTypeQualityMetric(const std::string& base_name,
237 const int metric, 244 AutofillMetrics::FieldTypeQualityMetric metric,
238 const int num_possible_metrics, 245 ServerFieldType field_type) {
239 const ServerFieldType field_type) { 246 DCHECK_LT(metric, AutofillMetrics::NUM_FIELD_TYPE_QUALITY_METRICS);
240 DCHECK_LT(metric, num_possible_metrics);
241 247
242 std::string histogram_name = base_name; 248 LogUMAHistogramEnumeration(base_name, metric,
243 LogUMAHistogramEnumeration(histogram_name, metric, num_possible_metrics); 249 AutofillMetrics::NUM_FIELD_TYPE_QUALITY_METRICS);
244 250
245 std::string sub_histogram_name = base_name + ".ByFieldType"; 251 int field_type_group_metric = GetFieldTypeGroupMetric(field_type, metric);
246 const int field_type_group_metric = 252 int num_field_type_group_metrics =
247 GetFieldTypeGroupMetric(field_type, metric, num_possible_metrics); 253 AutofillMetrics::NUM_FIELD_TYPE_QUALITY_METRICS *
248 const int num_field_type_group_metrics = 254 NUM_FIELD_TYPE_GROUPS_FOR_METRICS;
249 num_possible_metrics * NUM_FIELD_TYPE_GROUPS_FOR_METRICS; 255 LogUMAHistogramEnumeration(base_name + ".ByFieldType",
250 LogUMAHistogramEnumeration(sub_histogram_name,
251 field_type_group_metric, 256 field_type_group_metric,
252 num_field_type_group_metrics); 257 num_field_type_group_metrics);
253 } 258 }
254 259
255 } // namespace 260 } // namespace
256 261
257 AutofillMetrics::AutofillMetrics() { 262 AutofillMetrics::AutofillMetrics() {
258 } 263 }
259 264
260 AutofillMetrics::~AutofillMetrics() { 265 AutofillMetrics::~AutofillMetrics() {
261 } 266 }
262 267
263 void AutofillMetrics::LogCreditCardInfoBarMetric(InfoBarMetric metric) const { 268 void AutofillMetrics::LogCreditCardInfoBarMetric(InfoBarMetric metric) const {
264 DCHECK_LT(metric, NUM_INFO_BAR_METRICS); 269 DCHECK_LT(metric, NUM_INFO_BAR_METRICS);
265
266 UMA_HISTOGRAM_ENUMERATION("Autofill.CreditCardInfoBar", metric, 270 UMA_HISTOGRAM_ENUMERATION("Autofill.CreditCardInfoBar", metric,
267 NUM_INFO_BAR_METRICS); 271 NUM_INFO_BAR_METRICS);
268 } 272 }
269 273
270 void AutofillMetrics::LogDialogDismissalState( 274 void AutofillMetrics::LogDialogDismissalState(
271 DialogDismissalState state) const { 275 DialogDismissalState state) const {
272 UMA_HISTOGRAM_ENUMERATION("RequestAutocomplete.DismissalState", 276 UMA_HISTOGRAM_ENUMERATION("RequestAutocomplete.DismissalState",
273 state, NUM_DIALOG_DISMISSAL_STATES); 277 state, NUM_DIALOG_DISMISSAL_STATES);
274 } 278 }
275 279
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 required_action, NUM_WALLET_REQUIRED_ACTIONS); 347 required_action, NUM_WALLET_REQUIRED_ACTIONS);
344 } 348 }
345 349
346 void AutofillMetrics::LogWalletResponseCode(int response_code) const { 350 void AutofillMetrics::LogWalletResponseCode(int response_code) const {
347 UMA_HISTOGRAM_SPARSE_SLOWLY("Wallet.ResponseCode", response_code); 351 UMA_HISTOGRAM_SPARSE_SLOWLY("Wallet.ResponseCode", response_code);
348 } 352 }
349 353
350 void AutofillMetrics::LogDeveloperEngagementMetric( 354 void AutofillMetrics::LogDeveloperEngagementMetric(
351 DeveloperEngagementMetric metric) const { 355 DeveloperEngagementMetric metric) const {
352 DCHECK_LT(metric, NUM_DEVELOPER_ENGAGEMENT_METRICS); 356 DCHECK_LT(metric, NUM_DEVELOPER_ENGAGEMENT_METRICS);
353
354 UMA_HISTOGRAM_ENUMERATION("Autofill.DeveloperEngagement", metric, 357 UMA_HISTOGRAM_ENUMERATION("Autofill.DeveloperEngagement", metric,
355 NUM_DEVELOPER_ENGAGEMENT_METRICS); 358 NUM_DEVELOPER_ENGAGEMENT_METRICS);
356 } 359 }
357 360
358 void AutofillMetrics::LogHeuristicTypePrediction( 361 void AutofillMetrics::LogHeuristicTypePrediction(
359 FieldTypeQualityMetric metric, 362 FieldTypeQualityMetric metric,
360 ServerFieldType field_type) const { 363 ServerFieldType field_type) const {
361 LogTypeQualityMetric("Autofill.Quality.HeuristicType", 364 LogTypeQualityMetric("Autofill.Quality.HeuristicType", metric, field_type);
362 metric, NUM_FIELD_TYPE_QUALITY_METRICS, field_type);
363 } 365 }
364 366
365 void AutofillMetrics::LogOverallTypePrediction( 367 void AutofillMetrics::LogOverallTypePrediction(
366 FieldTypeQualityMetric metric, 368 FieldTypeQualityMetric metric,
367 ServerFieldType field_type) const { 369 ServerFieldType field_type) const {
368 LogTypeQualityMetric("Autofill.Quality.PredictedType", 370 LogTypeQualityMetric("Autofill.Quality.PredictedType", metric, field_type);
369 metric, NUM_FIELD_TYPE_QUALITY_METRICS, field_type);
370 } 371 }
371 372
372 void AutofillMetrics::LogServerTypePrediction( 373 void AutofillMetrics::LogServerTypePrediction(
373 FieldTypeQualityMetric metric, 374 FieldTypeQualityMetric metric,
374 ServerFieldType field_type) const { 375 ServerFieldType field_type) const {
375 LogTypeQualityMetric("Autofill.Quality.ServerType", 376 LogTypeQualityMetric("Autofill.Quality.ServerType", metric, field_type);
376 metric, NUM_FIELD_TYPE_QUALITY_METRICS, field_type);
377 } 377 }
378 378
379 void AutofillMetrics::LogServerQueryMetric(ServerQueryMetric metric) const { 379 void AutofillMetrics::LogServerQueryMetric(ServerQueryMetric metric) const {
380 DCHECK_LT(metric, NUM_SERVER_QUERY_METRICS); 380 DCHECK_LT(metric, NUM_SERVER_QUERY_METRICS);
381
382 UMA_HISTOGRAM_ENUMERATION("Autofill.ServerQueryResponse", metric, 381 UMA_HISTOGRAM_ENUMERATION("Autofill.ServerQueryResponse", metric,
383 NUM_SERVER_QUERY_METRICS); 382 NUM_SERVER_QUERY_METRICS);
384 } 383 }
385 384
386 void AutofillMetrics::LogUserHappinessMetric(UserHappinessMetric metric) const { 385 void AutofillMetrics::LogUserHappinessMetric(UserHappinessMetric metric) const {
387 DCHECK_LT(metric, NUM_USER_HAPPINESS_METRICS); 386 DCHECK_LT(metric, NUM_USER_HAPPINESS_METRICS);
388
389 UMA_HISTOGRAM_ENUMERATION("Autofill.UserHappiness", metric, 387 UMA_HISTOGRAM_ENUMERATION("Autofill.UserHappiness", metric,
390 NUM_USER_HAPPINESS_METRICS); 388 NUM_USER_HAPPINESS_METRICS);
391 } 389 }
392 390
393 void AutofillMetrics::LogFormFillDurationFromLoadWithAutofill( 391 void AutofillMetrics::LogFormFillDurationFromLoadWithAutofill(
394 const base::TimeDelta& duration) const { 392 const base::TimeDelta& duration) const {
395 UMA_HISTOGRAM_CUSTOM_TIMES("Autofill.FillDuration.FromLoad.WithAutofill", 393 UMA_HISTOGRAM_CUSTOM_TIMES("Autofill.FillDuration.FromLoad.WithAutofill",
396 duration, 394 duration,
397 base::TimeDelta::FromMilliseconds(100), 395 base::TimeDelta::FromMilliseconds(100),
398 base::TimeDelta::FromMinutes(10), 396 base::TimeDelta::FromMinutes(10),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 436
439 void AutofillMetrics::LogStoredProfileCount(size_t num_profiles) const { 437 void AutofillMetrics::LogStoredProfileCount(size_t num_profiles) const {
440 UMA_HISTOGRAM_COUNTS("Autofill.StoredProfileCount", num_profiles); 438 UMA_HISTOGRAM_COUNTS("Autofill.StoredProfileCount", num_profiles);
441 } 439 }
442 440
443 void AutofillMetrics::LogAddressSuggestionsCount(size_t num_suggestions) const { 441 void AutofillMetrics::LogAddressSuggestionsCount(size_t num_suggestions) const {
444 UMA_HISTOGRAM_COUNTS("Autofill.AddressSuggestionsCount", num_suggestions); 442 UMA_HISTOGRAM_COUNTS("Autofill.AddressSuggestionsCount", num_suggestions);
445 } 443 }
446 444
447 } // namespace autofill 445 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/core/browser/autofill_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698