summaryrefslogtreecommitdiff
path: root/chromium/components/password_manager/core/browser/password_manager_metrics_util.cc
blob: a6e6827c0718ec33c6acf2a841da056cb66fe5a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/password_manager/core/browser/password_manager_metrics_util.h"

#include "base/macros.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "url/gurl.h"

using base::ListValue;
using base::Value;

namespace password_manager {

namespace metrics_util {

void LogUMAHistogramBoolean(const std::string& name, bool sample) {
  // Note: This leaks memory, which is expected behavior.
  base::HistogramBase* histogram = base::BooleanHistogram::FactoryGet(
      name, base::Histogram::kUmaTargetedHistogramFlag);
  histogram->AddBoolean(sample);
}

void LogGeneralUIDismissalReason(UIDismissalReason reason) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.UIDismissalReason",
                            reason,
                            NUM_UI_RESPONSES);
}

void LogSaveUIDismissalReason(UIDismissalReason reason) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.SaveUIDismissalReason", reason,
                            NUM_UI_RESPONSES);
}

void LogUpdateUIDismissalReason(UIDismissalReason reason) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.UpdateUIDismissalReason", reason,
                            NUM_UI_RESPONSES);
}

void LogUIDisplayDisposition(UIDisplayDisposition disposition) {
  UMA_HISTOGRAM_ENUMERATION("PasswordBubble.DisplayDisposition",
                            disposition,
                            NUM_DISPLAY_DISPOSITIONS);
}

void LogFormDataDeserializationStatus(FormDeserializationStatus status) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.FormDataDeserializationStatus",
                            status, NUM_DESERIALIZATION_STATUSES);
}

void LogFilledCredentialIsFromAndroidApp(bool from_android) {
  UMA_HISTOGRAM_BOOLEAN(
      "PasswordManager.FilledCredentialWasFromAndroidApp",
      from_android);
}

void LogPasswordSyncState(PasswordSyncState state) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.PasswordSyncState", state,
                            NUM_SYNC_STATES);
}

void LogPasswordGenerationSubmissionEvent(PasswordSubmissionEvent event) {
  UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.SubmissionEvent", event,
                            SUBMISSION_EVENT_ENUM_COUNT);
}

void LogPasswordGenerationAvailableSubmissionEvent(
    PasswordSubmissionEvent event) {
  UMA_HISTOGRAM_ENUMERATION("PasswordGeneration.SubmissionAvailableEvent",
                            event, SUBMISSION_EVENT_ENUM_COUNT);
}

void LogAutoSigninPromoUserAction(AutoSigninPromoUserAction action) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.AutoSigninFirstRunDialog", action,
                            AUTO_SIGNIN_PROMO_ACTION_COUNT);
}

void LogAccountChooserUserActionOneAccount(AccountChooserUserAction action) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.AccountChooserDialogOneAccount",
                            action, ACCOUNT_CHOOSER_ACTION_COUNT);
}

void LogAccountChooserUserActionManyAccounts(AccountChooserUserAction action) {
  UMA_HISTOGRAM_ENUMERATION(
      "PasswordManager.AccountChooserDialogMultipleAccounts", action,
      ACCOUNT_CHOOSER_ACTION_COUNT);
}

void LogSyncSigninPromoUserAction(SyncSignInUserAction action) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.SignInPromo", action,
                            CHROME_SIGNIN_ACTION_COUNT);
}

void LogShouldBlockPasswordForSameOriginButDifferentScheme(bool should_block) {
  UMA_HISTOGRAM_BOOLEAN(
      "PasswordManager.ShouldBlockPasswordForSameOriginButDifferentScheme",
      should_block);
}

void LogCountHttpMigratedPasswords(int count) {
  UMA_HISTOGRAM_COUNTS_100("PasswordManager.HttpPasswordMigrationCount", count);
}

void LogHttpPasswordMigrationMode(HttpPasswordMigrationMode mode) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.HttpPasswordMigrationMode", mode,
                            HTTP_PASSWORD_MIGRATION_MODE_COUNT);
}

void LogAccountChooserUsability(AccountChooserUsabilityMetric usability,
                                int count_empty_icons,
                                int count_accounts) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.AccountChooserDialogUsability",
                            usability, ACCOUNT_CHOOSER_USABILITY_COUNT);
  UMA_HISTOGRAM_COUNTS_100("PasswordManager.AccountChooserDialogEmptyAvatars",
                           count_empty_icons);
  UMA_HISTOGRAM_COUNTS_100("PasswordManager.AccountChooserDialogAccounts",
                           count_accounts);
}

void LogCredentialManagerGetResult(CredentialManagerGetResult result,
                                   CredentialMediationRequirement mediation) {
  switch (mediation) {
    case CredentialMediationRequirement::kSilent:
      UMA_HISTOGRAM_ENUMERATION("PasswordManager.MediationSilent", result,
                                CREDENTIAL_MANAGER_GET_COUNT);
      break;
    case CredentialMediationRequirement::kOptional:
      UMA_HISTOGRAM_ENUMERATION("PasswordManager.MediationOptional", result,
                                CREDENTIAL_MANAGER_GET_COUNT);
      break;
    case CredentialMediationRequirement::kRequired:
      UMA_HISTOGRAM_ENUMERATION("PasswordManager.MediationRequired", result,
                                CREDENTIAL_MANAGER_GET_COUNT);
      break;
  }
}

void LogPasswordReuse(int password_length,
                      int saved_passwords,
                      int number_matches,
                      bool password_field_detected) {
  UMA_HISTOGRAM_COUNTS_100("PasswordManager.PasswordReuse.PasswordLength",
                           password_length);
  UMA_HISTOGRAM_COUNTS_1000("PasswordManager.PasswordReuse.TotalPasswords",
                            saved_passwords);
  UMA_HISTOGRAM_COUNTS_1000("PasswordManager.PasswordReuse.NumberOfMatches",
                            number_matches);
  UMA_HISTOGRAM_ENUMERATION(
      "PasswordManager.PasswordReuse.PasswordFieldDetected",
      password_field_detected ? HAS_PASSWORD_FIELD : NO_PASSWORD_FIELD,
      PASSWORD_REUSE_PASSWORD_FIELD_DETECTED_COUNT);
}

void LogContextOfShowAllSavedPasswordsShown(
    ShowAllSavedPasswordsContext context) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.ShowAllSavedPasswordsShownContext",
                            context, SHOW_ALL_SAVED_PASSWORDS_CONTEXT_COUNT);
}

void LogContextOfShowAllSavedPasswordsAccepted(
    ShowAllSavedPasswordsContext context) {
  UMA_HISTOGRAM_ENUMERATION(
      "PasswordManager.ShowAllSavedPasswordsAcceptedContext", context,
      SHOW_ALL_SAVED_PASSWORDS_CONTEXT_COUNT);
}

void LogPasswordSuccessfulSubmissionIndicatorEvent(
    autofill::PasswordForm::SubmissionIndicatorEvent event) {
  UMA_HISTOGRAM_ENUMERATION(
      "PasswordManager.SuccessfulSubmissionIndicatorEvent", event,
      autofill::PasswordForm::SubmissionIndicatorEvent::
          SUBMISSION_INDICATOR_EVENT_COUNT);
}

void LogPasswordAcceptedSaveUpdateSubmissionIndicatorEvent(
    autofill::PasswordForm::SubmissionIndicatorEvent event) {
  UMA_HISTOGRAM_ENUMERATION(
      "PasswordManager.AcceptedSaveUpdateSubmissionIndicatorEvent", event,
      autofill::PasswordForm::SubmissionIndicatorEvent::
          SUBMISSION_INDICATOR_EVENT_COUNT);
}

void LogSubmittedFormFrame(SubmittedFormFrame frame) {
  UMA_HISTOGRAM_ENUMERATION("PasswordManager.SubmittedFormFrame", frame,
                            SubmittedFormFrame::SUBMITTED_FORM_FRAME_COUNT);
}

#if defined(SYNC_PASSWORD_REUSE_DETECTION_ENABLED)
void LogSyncPasswordHashChange(SyncPasswordHashChange event) {
  UMA_HISTOGRAM_ENUMERATION(
      "PasswordManager.SyncPasswordHashChange", event,
      SyncPasswordHashChange::SAVED_SYNC_PASSWORD_CHANGE_COUNT);
}

void LogIsSyncPasswordHashSaved(IsSyncPasswordHashSaved state) {
  UMA_HISTOGRAM_ENUMERATION(
      "PasswordManager.IsSyncPasswordHashSaved", state,
      IsSyncPasswordHashSaved::IS_SYNC_PASSWORD_HASH_SAVED_COUNT);
}
#endif

}  // namespace metrics_util

}  // namespace password_manager