trusted_vault_histograms.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2021 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/sync/driver/trusted_vault_histograms.h"
  5. #include <string>
  6. #include "base/metrics/histogram_functions.h"
  7. #include "base/strings/strcat.h"
  8. namespace syncer {
  9. namespace {
  10. std::string GetReasonSuffix(TrustedVaultURLFetchReasonForUMA reason) {
  11. switch (reason) {
  12. case TrustedVaultURLFetchReasonForUMA::kUnspecified:
  13. return std::string();
  14. case TrustedVaultURLFetchReasonForUMA::kRegisterDevice:
  15. return "RegisterDevice";
  16. case TrustedVaultURLFetchReasonForUMA::
  17. kRegisterUnspecifiedAuthenticationFactor:
  18. return "RegisterUnspecifiedAuthenticationFactor";
  19. case TrustedVaultURLFetchReasonForUMA::kDownloadKeys:
  20. return "DownloadKeys";
  21. case TrustedVaultURLFetchReasonForUMA::kDownloadIsRecoverabilityDegraded:
  22. return "DownloadIsRecoverabilityDegraded";
  23. }
  24. }
  25. } // namespace
  26. void RecordTrustedVaultDeviceRegistrationState(
  27. TrustedVaultDeviceRegistrationStateForUMA registration_state) {
  28. base::UmaHistogramEnumeration("Sync.TrustedVaultDeviceRegistrationState",
  29. registration_state);
  30. }
  31. void RecordTrustedVaultURLFetchResponse(
  32. int http_response_code,
  33. int net_error,
  34. TrustedVaultURLFetchReasonForUMA reason) {
  35. DCHECK_LE(net_error, 0);
  36. DCHECK_GE(http_response_code, 0);
  37. const int value = http_response_code == 0 ? net_error : http_response_code;
  38. const std::string suffix = GetReasonSuffix(reason);
  39. base::UmaHistogramSparse("Sync.TrustedVaultURLFetchResponse", value);
  40. if (!suffix.empty()) {
  41. base::UmaHistogramSparse(
  42. base::StrCat({"Sync.TrustedVaultURLFetchResponse", ".", suffix}),
  43. value);
  44. }
  45. }
  46. void RecordTrustedVaultDownloadKeysStatus(
  47. TrustedVaultDownloadKeysStatusForUMA status) {
  48. base::UmaHistogramEnumeration("Sync.TrustedVaultDownloadKeysStatus", status);
  49. }
  50. } // namespace syncer