summaryrefslogtreecommitdiff
path: root/chromium/components/password_manager/core/browser/password_manager_metrics_util.cc
blob: 81d9945a7938ce56016d21b32b5daa690d53f05d (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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// 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/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "components/autofill/core/common/password_generation_util.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"

using autofill::password_generation::PasswordGenerationType;

namespace ukm::builders {
class PasswordManager_LeakWarningDialog;
}  // namespace ukm::builders

namespace password_manager::metrics_util {

std::string GetPasswordAccountStorageUserStateHistogramSuffix(
    PasswordAccountStorageUserState user_state) {
  switch (user_state) {
    case PasswordAccountStorageUserState::kSignedOutUser:
      return "SignedOutUser";
    case PasswordAccountStorageUserState::kSignedOutAccountStoreUser:
      return "SignedOutAccountStoreUser";
    case PasswordAccountStorageUserState::kSignedInUser:
      return "SignedInUser";
    case PasswordAccountStorageUserState::kSignedInUserSavingLocally:
      return "SignedInUserSavingLocally";
    case PasswordAccountStorageUserState::kSignedInAccountStoreUser:
      return "SignedInAccountStoreUser";
    case PasswordAccountStorageUserState::
        kSignedInAccountStoreUserSavingLocally:
      return "SignedInAccountStoreUserSavingLocally";
    case PasswordAccountStorageUserState::kSyncUser:
      return "SyncUser";
  }
  NOTREACHED();
  return std::string();
}

std::string GetPasswordAccountStorageUsageLevelHistogramSuffix(
    PasswordAccountStorageUsageLevel usage_level) {
  switch (usage_level) {
    case PasswordAccountStorageUsageLevel::kNotUsingAccountStorage:
      return "NotUsingAccountStorage";
    case PasswordAccountStorageUsageLevel::kUsingAccountStorage:
      return "UsingAccountStorage";
    case PasswordAccountStorageUsageLevel::kSyncing:
      return "Syncing";
  }
  NOTREACHED();
  return std::string();
}

LeakDialogMetricsRecorder::LeakDialogMetricsRecorder(ukm::SourceId source_id,
                                                     LeakDialogType type)
    : source_id_(source_id), type_(type) {}

void LeakDialogMetricsRecorder::LogLeakDialogTypeAndDismissalReason(
    LeakDialogDismissalReason reason) {
  // Always record UMA.
  base::UmaHistogramEnumeration(kHistogram, reason);
  base::UmaHistogramEnumeration(base::StrCat({kHistogram, ".", GetUMASuffix()}),
                                reason);

  // For UKM, sample the recorded events.
  if (base::RandDouble() > ukm_sampling_rate_)
    return;

  // The entire event is made up of these two fields, so we can build and
  // record it in one step.
  ukm ::builders::PasswordManager_LeakWarningDialog ukm_builder(source_id_);
  ukm_builder.SetPasswordLeakDetectionDialogType(static_cast<int64_t>(type_));
  ukm_builder.SetPasswordLeakDetectionDialogDismissalReason(
      static_cast<int64_t>(reason));
  ukm_builder.Record(ukm::UkmRecorder::Get());
}

const char* LeakDialogMetricsRecorder::GetUMASuffix() const {
  switch (type_) {
    case LeakDialogType::kCheckup:
      return "Checkup";
    case LeakDialogType::kChange:
      return "Change";
    case LeakDialogType::kCheckupAndChange:
      return "CheckupAndChange";
    case LeakDialogType::kChangeAutomatically:
      return "ChangeAutomatically";
  }
}

void LogGeneralUIDismissalReason(UIDismissalReason reason) {
  base::UmaHistogramEnumeration("PasswordManager.UIDismissalReason", reason,
                                NUM_UI_RESPONSES);
}

void LogSaveUIDismissalReason(
    UIDismissalReason reason,
    autofill::mojom::SubmissionIndicatorEvent submission_event,
    absl::optional<PasswordAccountStorageUserState> user_state) {
  base::UmaHistogramEnumeration("PasswordManager.SaveUIDismissalReason", reason,
                                NUM_UI_RESPONSES);

  if (user_state.has_value()) {
    std::string suffix =
        GetPasswordAccountStorageUserStateHistogramSuffix(user_state.value());
    base::UmaHistogramEnumeration(
        "PasswordManager.SaveUIDismissalReason." + suffix, reason,
        NUM_UI_RESPONSES);
  }

  if (submission_event ==
      autofill::mojom::SubmissionIndicatorEvent::CHANGE_PASSWORD_FORM_CLEARED) {
    base::UmaHistogramEnumeration(
        "PasswordManager.SaveUIOnClearedPasswordChangeFormDismissalReason",
        reason, NUM_UI_RESPONSES);
  }
}

void LogSaveUIDismissalReasonAfterUnblocklisting(UIDismissalReason reason) {
  base::UmaHistogramEnumeration(
      "PasswordManager.SaveUIDismissalReasonAfterUnblacklisting", reason,
      NUM_UI_RESPONSES);
}

void LogUpdateUIDismissalReason(
    UIDismissalReason reason,
    autofill::mojom::SubmissionIndicatorEvent submission_event) {
  base::UmaHistogramEnumeration("PasswordManager.UpdateUIDismissalReason",
                                reason, NUM_UI_RESPONSES);

  if (submission_event ==
      autofill::mojom::SubmissionIndicatorEvent::CHANGE_PASSWORD_FORM_CLEARED) {
    base::UmaHistogramEnumeration(
        "PasswordManager.UpdateUIOnClearedPasswordChangeFormDismissalReason",
        reason, NUM_UI_RESPONSES);
  }
}

void LogMoveUIDismissalReason(UIDismissalReason reason,
                              PasswordAccountStorageUserState user_state) {
  base::UmaHistogramEnumeration("PasswordManager.MoveUIDismissalReason", reason,
                                NUM_UI_RESPONSES);

  std::string suffix =
      GetPasswordAccountStorageUserStateHistogramSuffix(user_state);
  base::UmaHistogramEnumeration(
      "PasswordManager.MoveUIDismissalReason." + suffix, reason,
      NUM_UI_RESPONSES);
}

void LogUIDisplayDisposition(UIDisplayDisposition disposition) {
  base::UmaHistogramEnumeration("PasswordBubble.DisplayDisposition",
                                disposition, NUM_DISPLAY_DISPOSITIONS);
}

void LogFormDataDeserializationStatus(FormDeserializationStatus status) {
  base::UmaHistogramEnumeration("PasswordManager.FormDataDeserializationStatus",
                                status, NUM_DESERIALIZATION_STATUSES);
}

void LogFilledCredentialIsFromAndroidApp(bool from_android) {
  base::UmaHistogramBoolean("PasswordManager.FilledCredentialWasFromAndroidApp",
                            from_android);
}

void LogPasswordSyncState(PasswordSyncState state) {
  base::UmaHistogramEnumeration("PasswordManager.PasswordSyncState2", state);
}

void LogApplySyncChangesState(ApplySyncChangesState state) {
  base::UmaHistogramEnumeration("PasswordManager.ApplySyncChangesState", state);
}

void LogPasswordGenerationSubmissionEvent(PasswordSubmissionEvent event) {
  base::UmaHistogramEnumeration("PasswordGeneration.SubmissionEvent", event,
                                SUBMISSION_EVENT_ENUM_COUNT);
}

void LogPasswordGenerationAvailableSubmissionEvent(
    PasswordSubmissionEvent event) {
  base::UmaHistogramEnumeration("PasswordGeneration.SubmissionAvailableEvent",
                                event, SUBMISSION_EVENT_ENUM_COUNT);
}

void LogAutoSigninPromoUserAction(AutoSigninPromoUserAction action) {
  base::UmaHistogramEnumeration("PasswordManager.AutoSigninFirstRunDialog",
                                action, AUTO_SIGNIN_PROMO_ACTION_COUNT);
}

void LogAccountChooserUserActionOneAccount(AccountChooserUserAction action) {
  base::UmaHistogramEnumeration(
      "PasswordManager.AccountChooserDialogOneAccount", action,
      ACCOUNT_CHOOSER_ACTION_COUNT);
}

void LogAccountChooserUserActionManyAccounts(AccountChooserUserAction action) {
  base::UmaHistogramEnumeration(
      "PasswordManager.AccountChooserDialogMultipleAccounts", action,
      ACCOUNT_CHOOSER_ACTION_COUNT);
}

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

void LogPasswordReuse(int saved_passwords,
                      int number_matches,
                      bool password_field_detected,
                      PasswordType reused_password_type) {
  base::UmaHistogramCounts1000("PasswordManager.PasswordReuse.TotalPasswords",
                               saved_passwords);
  base::UmaHistogramCounts1000("PasswordManager.PasswordReuse.NumberOfMatches",
                               number_matches);
  base::UmaHistogramEnumeration(
      "PasswordManager.PasswordReuse.PasswordFieldDetected",
      password_field_detected ? HAS_PASSWORD_FIELD : NO_PASSWORD_FIELD,
      PASSWORD_REUSE_PASSWORD_FIELD_DETECTED_COUNT);
  base::UmaHistogramEnumeration("PasswordManager.ReusedPasswordType",
                                reused_password_type,
                                PasswordType::PASSWORD_TYPE_COUNT);
}

void LogPasswordDropdownShown(PasswordDropdownState state,
                              bool off_the_record) {
  base::UmaHistogramEnumeration("PasswordManager.PasswordDropdownShown", state);

  base::UmaHistogramBoolean("PasswordManager.DropdownShown.OffTheRecord",
                            off_the_record);
}

void LogPasswordDropdownItemSelected(PasswordDropdownSelectedOption type,
                                     bool off_the_record) {
  base::UmaHistogramEnumeration("PasswordManager.PasswordDropdownItemSelected",
                                type);
  base::UmaHistogramBoolean("PasswordManager.ItemSelected.OffTheRecord",
                            off_the_record);
}

void LogPasswordSuccessfulSubmissionIndicatorEvent(
    autofill::mojom::SubmissionIndicatorEvent event) {
  base::UmaHistogramEnumeration(
      "PasswordManager.SuccessfulSubmissionIndicatorEvent", event);
}

void LogPasswordAcceptedSaveUpdateSubmissionIndicatorEvent(
    autofill::mojom::SubmissionIndicatorEvent event) {
  base::UmaHistogramEnumeration(
      "PasswordManager.AcceptedSaveUpdateSubmissionIndicatorEvent", event);
}

void LogPasswordsCountFromAccountStoreAfterUnlock(
    int account_store_passwords_count) {
  base::UmaHistogramCounts100(
      "PasswordManager.CredentialsCountFromAccountStoreAfterUnlock",
      account_store_passwords_count);
}

void LogDownloadedPasswordsCountFromAccountStoreAfterUnlock(
    int account_store_passwords_count) {
  base::UmaHistogramCounts100(
      "PasswordManager.AccountStoreCredentialsAfterOptIn",
      account_store_passwords_count);
}

void LogDownloadedBlocklistedEntriesCountFromAccountStoreAfterUnlock(
    int blocklist_entries_count) {
  base::UmaHistogramCounts100(
      "PasswordManager.AccountStoreBlocklistedEntriesAfterOptIn",
      blocklist_entries_count);
}

void LogPasswordSettingsReauthResult(ReauthResult result) {
  base::UmaHistogramEnumeration(
      "PasswordManager.ReauthToAccessPasswordInSettings", result);
}

void LogDeleteUndecryptableLoginsReturnValue(
    DeleteCorruptedPasswordsResult result) {
  base::UmaHistogramEnumeration(
      "PasswordManager.DeleteUndecryptableLoginsReturnValue", result);
}

void LogNewlySavedPasswordMetrics(
    bool is_generated_password,
    bool is_username_empty,
    PasswordAccountStorageUsageLevel account_storage_usage_level) {
  base::UmaHistogramBoolean("PasswordManager.NewlySavedPasswordIsGenerated",
                            is_generated_password);
  std::string suffix = GetPasswordAccountStorageUsageLevelHistogramSuffix(
      account_storage_usage_level);
  base::UmaHistogramBoolean(
      "PasswordManager.NewlySavedPasswordIsGenerated." + suffix,
      is_generated_password);

  base::UmaHistogramBoolean(
      "PasswordManager.NewlySavedPasswordHasEmptyUsername.Overall",
      is_username_empty);
  base::UmaHistogramBoolean(
      base::StrCat({"PasswordManager.NewlySavedPasswordHasEmptyUsername.",
                    is_generated_password ? "AutoGenerated" : "UserCreated"}),
      is_username_empty);
}

void LogGenerationDialogChoice(GenerationDialogChoice choice,
                               PasswordGenerationType type) {
  switch (type) {
    case PasswordGenerationType::kAutomatic:
      base::UmaHistogramEnumeration(
          "KeyboardAccessory.GenerationDialogChoice.Automatic", choice);
      break;
    case PasswordGenerationType::kManual:
      base::UmaHistogramEnumeration(
          "KeyboardAccessory.GenerationDialogChoice.Manual", choice);
      break;
  };
}  // namespace metrics_util

void LogGaiaPasswordHashChange(GaiaPasswordHashChange event,
                               bool is_sync_password) {
  if (is_sync_password) {
    base::UmaHistogramEnumeration("PasswordManager.SyncPasswordHashChange",
                                  event);
  } else {
    base::UmaHistogramEnumeration("PasswordManager.NonSyncPasswordHashChange",
                                  event);
  }
}

void LogIsSyncPasswordHashSaved(IsSyncPasswordHashSaved state,
                                bool is_under_advanced_protection) {
  base::UmaHistogramEnumeration("PasswordManager.IsSyncPasswordHashSaved",
                                state);
  if (is_under_advanced_protection) {
    base::UmaHistogramEnumeration(
        "PasswordManager.IsSyncPasswordHashSavedForAdvancedProtectionUser",
        state);
  }
}

void LogProtectedPasswordHashCounts(size_t gaia_hash_count,
                                    bool does_primary_account_exists,
                                    bool is_signed_in) {
  base::UmaHistogramCounts100("PasswordManager.SavedGaiaPasswordHashCount",
                              static_cast<int>(gaia_hash_count));

  // Log parallel metrics for sync and signed-in non-sync accounts in addition
  // to above to be able to tell what fraction of signed-in non-sync users we
  // are protecting compared to syncing users.
  if (does_primary_account_exists) {
    base::UmaHistogramCounts100(
        "PasswordManager.SavedGaiaPasswordHashCount.Sync",
        static_cast<int>(gaia_hash_count));
  } else if (is_signed_in) {
    base::UmaHistogramCounts100(
        "PasswordManager.SavedGaiaPasswordHashCount.SignedInNonSync",
        static_cast<int>(gaia_hash_count));
  }
}

void LogProtectedPasswordReuse(PasswordType reused_password_type) {}

void LogPasswordEditResult(IsUsernameChanged username_changed,
                           IsPasswordChanged password_changed) {
  PasswordEditUpdatedValues values;
  if (username_changed && password_changed) {
    values = PasswordEditUpdatedValues::kBoth;
  } else if (username_changed) {
    values = PasswordEditUpdatedValues::kUsername;
  } else if (password_changed) {
    values = PasswordEditUpdatedValues::kPassword;
  } else {
    values = PasswordEditUpdatedValues::kNone;
  }
  base::UmaHistogramEnumeration("PasswordManager.PasswordEditUpdatedValues",
                                values);
}

void LogUserInteractionsWhenAddingCredentialFromSettings(
    AddCredentialFromSettingsUserInteractions
        add_credential_from_settings_user_interaction) {
  base::UmaHistogramEnumeration(
      "PasswordManager.AddCredentialFromSettings.UserAction",
      add_credential_from_settings_user_interaction);
}

void LogPasswordNoteActionInSettings(PasswordNoteAction action) {
  base::UmaHistogramEnumeration("PasswordManager.PasswordNoteActionInSettings",
                                action);
}

}  // namespace password_manager::metrics_util