state.cc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2020 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. #include "components/profile_metrics/state.h"
  5. #include "base/metrics/histogram_functions.h"
  6. namespace profile_metrics {
  7. namespace {
  8. std::string GetStateSuffix(StateSuffix suffix) {
  9. switch (suffix) {
  10. case StateSuffix::kAll:
  11. return "_All";
  12. case StateSuffix::kActiveMultiProfile:
  13. return "_ActiveMultiProfile";
  14. case StateSuffix::kLatentMultiProfile:
  15. return "_LatentMultiProfile";
  16. case StateSuffix::kLatentMultiProfileActive:
  17. return "_LatentMultiProfileActive";
  18. case StateSuffix::kLatentMultiProfileOthers:
  19. return "_LatentMultiProfileOthers";
  20. case StateSuffix::kSingleProfile:
  21. return "_SingleProfile";
  22. case StateSuffix::kUponDeletion:
  23. return "_UponDeletion";
  24. }
  25. }
  26. // Context for profile deletion.
  27. // These values are persisted to logs. Entries should not be renumbered and
  28. // numeric values should never be reused.
  29. enum class DeleteProfileContext {
  30. kWithoutBrowserLastProfile = 0,
  31. kWithoutBrowserAdditionalProfile = 1,
  32. kWithBrowserLastProfile = 2,
  33. kWithBrowserAdditionalProfile = 3,
  34. kMaxValue = kWithBrowserAdditionalProfile
  35. };
  36. } // namespace
  37. void LogProfileAvatar(AvatarState avatar_state, StateSuffix suffix) {
  38. base::UmaHistogramEnumeration("Profile.State.Avatar" + GetStateSuffix(suffix),
  39. avatar_state);
  40. }
  41. void LogProfileName(NameState name_state, StateSuffix suffix) {
  42. base::UmaHistogramEnumeration("Profile.State.Name" + GetStateSuffix(suffix),
  43. name_state);
  44. }
  45. void LogProfileAccountType(UnconsentedPrimaryAccountType account_type,
  46. StateSuffix suffix) {
  47. base::UmaHistogramEnumeration(
  48. "Profile.State.UnconsentedPrimaryAccountType" + GetStateSuffix(suffix),
  49. account_type);
  50. }
  51. void LogProfileSyncEnabled(bool sync_enabled, StateSuffix suffix) {
  52. base::UmaHistogramBoolean(
  53. "Profile.State.SyncEnabled" + GetStateSuffix(suffix), sync_enabled);
  54. }
  55. void LogProfileDaysSinceLastUse(int days_since_last_use, StateSuffix suffix) {
  56. base::UmaHistogramCounts1000(
  57. "Profile.State.LastUsed" + GetStateSuffix(suffix), days_since_last_use);
  58. }
  59. void LogProfileDeletionContext(bool is_last_profile, bool no_browser_windows) {
  60. DeleteProfileContext context;
  61. if (no_browser_windows) {
  62. if (is_last_profile) {
  63. context = DeleteProfileContext::kWithoutBrowserLastProfile;
  64. } else {
  65. context = DeleteProfileContext::kWithoutBrowserAdditionalProfile;
  66. }
  67. } else {
  68. if (is_last_profile) {
  69. context = DeleteProfileContext::kWithBrowserLastProfile;
  70. } else {
  71. context = DeleteProfileContext::kWithBrowserAdditionalProfile;
  72. }
  73. }
  74. base::UmaHistogramEnumeration("Profile.DeleteProfileContext", context);
  75. }
  76. void LogProfileAllAccountsNames(AllAccountsNames names) {
  77. base::UmaHistogramEnumeration("Profile.AllAccounts.Names", names);
  78. }
  79. void LogProfileAllAccountsCategories(AllAccountsCategories categories) {
  80. base::UmaHistogramEnumeration("Profile.AllAccounts.Categories", categories);
  81. }
  82. } // namespace profile_metrics