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
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/trusted_vault/trusted_vault_histograms.h"
#include <string>
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "components/trusted_vault/local_recovery_factor.h"
#include "components/trusted_vault/trusted_vault_server_constants.h"
namespace trusted_vault {
namespace {
std::string GetTrustedVaultURLFetchReasonSuffix(
TrustedVaultURLFetchReasonForUMA reason) {
switch (reason) {
case TrustedVaultURLFetchReasonForUMA::kUnspecified:
return std::string();
case TrustedVaultURLFetchReasonForUMA::kRegisterDevice:
return "RegisterDevice";
case TrustedVaultURLFetchReasonForUMA::kRegisterLockScreenKnowledgeFactor:
return "RegisterLockScreenKnowledgeFactor";
case TrustedVaultURLFetchReasonForUMA::kRegisterGpmPin:
return "RegisterGooglePasswordManagerPIN";
case TrustedVaultURLFetchReasonForUMA::
kRegisterUnspecifiedAuthenticationFactor:
return "RegisterUnspecifiedAuthenticationFactor";
case TrustedVaultURLFetchReasonForUMA::kDownloadKeys:
return "DownloadKeys";
case TrustedVaultURLFetchReasonForUMA::kDownloadIsRecoverabilityDegraded:
return "DownloadIsRecoverabilityDegraded";
case TrustedVaultURLFetchReasonForUMA::
kDownloadAuthenticationFactorsRegistrationState:
return "DownloadAuthenticationFactorsRegistrationState";
case TrustedVaultURLFetchReasonForUMA::kRegisterICloudKeychain:
return "RegisterICloudKeychain";
}
NOTREACHED();
}
std::string GetRecoveryKeyStoreURLFetchReasonSuffix(
RecoveryKeyStoreURLFetchReasonForUMA reason) {
switch (reason) {
case RecoveryKeyStoreURLFetchReasonForUMA::kUpdateRecoveryKeyStore:
return "UpdateRecoveryKeyStore";
case RecoveryKeyStoreURLFetchReasonForUMA::kListRecoveryKeyStores:
return "ListRecoveryKeyStores";
}
NOTREACHED();
}
} // namespace
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SecurityDomainIdOrInvalidForUma {
kInvalid = 0,
kChromeSync = 1,
kPasskeys = 2,
kMaxValue = kPasskeys,
};
SecurityDomainIdOrInvalidForUma GetSecurityDomainIdOrInvalidForUma(
std::optional<SecurityDomainId> security_domain) {
if (!security_domain) {
return SecurityDomainIdOrInvalidForUma::kInvalid;
}
switch (*security_domain) {
case SecurityDomainId::kChromeSync:
return SecurityDomainIdOrInvalidForUma::kChromeSync;
case SecurityDomainId::kPasskeys:
return SecurityDomainIdOrInvalidForUma::kPasskeys;
}
NOTREACHED();
}
void RecordTrustedVaultHintDegradedRecoverabilityChangedReason(
TrustedVaultHintDegradedRecoverabilityChangedReasonForUMA
hint_degraded_recoverability_changed_reason) {
base::UmaHistogramEnumeration(
"TrustedVault.TrustedVaultHintDegradedRecoverabilityChangedReason",
hint_degraded_recoverability_changed_reason);
}
void RecordTrustedVaultDeviceRegistrationState(
TrustedVaultDeviceRegistrationStateForUMA registration_state) {
RecordTrustedVaultRecoveryFactorRegistrationState(
LocalRecoveryFactorType::kPhysicalDevice, SecurityDomainId::kChromeSync,
registration_state);
}
void RecordTrustedVaultRecoveryFactorRegistrationState(
LocalRecoveryFactorType local_recovery_factor_type,
SecurityDomainId security_domain_id,
TrustedVaultRecoveryFactorRegistrationStateForUMA registration_state) {
base::UmaHistogramEnumeration(
base::StrCat(
{"TrustedVault.RecoveryFactorRegistrationState.",
GetLocalRecoveryFactorNameForUma(local_recovery_factor_type), ".",
GetSecurityDomainNameForUma(security_domain_id)}),
registration_state);
}
void RecordTrustedVaultRecoveryFactorRegistrationOutcome(
LocalRecoveryFactorType local_recovery_factor_type,
SecurityDomainId security_domain_id,
TrustedVaultRecoveryFactorRegistrationOutcomeForUMA registration_outcome) {
base::UmaHistogramEnumeration(
base::StrCat(
{"TrustedVault.RecoveryFactorRegistrationOutcome.",
GetLocalRecoveryFactorNameForUma(local_recovery_factor_type), ".",
GetSecurityDomainNameForUma(security_domain_id)}),
registration_outcome);
}
void RecordTrustedVaultURLFetchResponse(SecurityDomainId security_domain_id,
TrustedVaultURLFetchReasonForUMA reason,
int http_response_code,
int net_error) {
CHECK_LE(net_error, 0);
CHECK_GE(http_response_code, 0);
const int value = http_response_code == 0 ? net_error : http_response_code;
const std::string reason_suffix = GetTrustedVaultURLFetchReasonSuffix(reason);
const std::string security_domain_name =
GetSecurityDomainNameForUma(security_domain_id);
base::UmaHistogramSparse("TrustedVault.SecurityDomainServiceURLFetchResponse",
value);
base::UmaHistogramSparse(
base::StrCat({"TrustedVault.SecurityDomainServiceURLFetchResponse", ".",
security_domain_name}),
value);
if (!reason_suffix.empty()) {
base::UmaHistogramSparse(
base::StrCat({"TrustedVault.SecurityDomainServiceURLFetchResponse", ".",
reason_suffix}),
value);
base::UmaHistogramSparse(
base::StrCat({"TrustedVault.SecurityDomainServiceURLFetchResponse", ".",
reason_suffix, ".", security_domain_name}),
value);
}
}
void RecordRecoveryKeyStoreURLFetchResponse(
RecoveryKeyStoreURLFetchReasonForUMA reason,
int http_response_code,
int net_error) {
CHECK_LE(net_error, 0);
CHECK_GE(http_response_code, 0);
const int value = http_response_code == 0 ? net_error : http_response_code;
const std::string reason_suffix =
GetRecoveryKeyStoreURLFetchReasonSuffix(reason);
base::UmaHistogramSparse("TrustedVault.RecoveryKeyStoreURLFetchResponse",
value);
base::UmaHistogramSparse(
base::StrCat({"TrustedVault.RecoveryKeyStoreURLFetchResponse", ".",
reason_suffix}),
value);
}
void RecordTrustedVaultDownloadKeysStatus(
LocalRecoveryFactorType local_recovery_factor_type,
SecurityDomainId security_domain_id,
TrustedVaultDownloadKeysStatusForUMA status) {
base::UmaHistogramEnumeration(
base::StrCat(
{"TrustedVault.DownloadKeysStatus.",
GetLocalRecoveryFactorNameForUma(local_recovery_factor_type), ".",
GetSecurityDomainNameForUma(security_domain_id)}),
status);
}
void RecordTrustedVaultDownloadKeysStatus(
TrustedVaultDownloadKeysStatusForUMA status) {
RecordTrustedVaultDownloadKeysStatus(LocalRecoveryFactorType::kPhysicalDevice,
SecurityDomainId::kChromeSync, status);
}
void RecordTrustedVaultRecoverKeysOutcome(
SecurityDomainId security_domain_id,
TrustedVaultRecoverKeysOutcomeForUMA status) {
base::UmaHistogramEnumeration(
base::StrCat({"TrustedVault.RecoverKeysOutcome.",
GetSecurityDomainNameForUma(security_domain_id)}),
status);
}
void RecordTrustedVaultFileReadStatus(SecurityDomainId security_domain_id,
TrustedVaultFileReadStatusForUMA status) {
base::UmaHistogramEnumeration(
"TrustedVault.FileReadStatus." +
GetSecurityDomainNameForUma(security_domain_id),
status);
}
void RecordTrustedVaultSetEncryptionKeysForSecurityDomain(
std::optional<SecurityDomainId> security_domain,
IsOffTheRecord is_off_the_record) {
SecurityDomainIdOrInvalidForUma domain_for_uma =
GetSecurityDomainIdOrInvalidForUma(security_domain);
base::UmaHistogramEnumeration(
"TrustedVault.SetEncryptionKeysForSecurityDomain."
"AllProfiles",
domain_for_uma);
if (is_off_the_record == IsOffTheRecord::kYes) {
base::UmaHistogramEnumeration(
"TrustedVault.SetEncryptionKeysForSecurityDomain.OffTheRecordOnly",
domain_for_uma);
}
}
void RecordCallToJsSetClientEncryptionKeysWithSecurityDomainToUma(
std::optional<SecurityDomainId> security_domain) {
SecurityDomainIdOrInvalidForUma domain_for_uma =
GetSecurityDomainIdOrInvalidForUma(security_domain);
base::UmaHistogramEnumeration(
"TrustedVault.JavascriptSetClientEncryptionKeysForSecurityDomain",
domain_for_uma);
}
void RecordTrustedVaultListSecurityDomainMembersPinStatus(
SecurityDomainId security_domain_id,
TrustedVaultListSecurityDomainMembersPinStatus status) {
base::UmaHistogramEnumeration(
"TrustedVault.ListSecurityDomainMembersPinStatus." +
GetSecurityDomainNameForUma(security_domain_id),
status);
}
std::string GetLocalRecoveryFactorNameForUma(
LocalRecoveryFactorType local_recovery_factor_type) {
// These strings get embedded in histogram names and so should not be
// changed.
switch (local_recovery_factor_type) {
case LocalRecoveryFactorType::kPhysicalDevice:
return "PhysicalDevice";
#if BUILDFLAG(IS_MAC)
case LocalRecoveryFactorType::kICloudKeychain:
return "ICloudKeychain";
#endif
// If adding a new value, also update the variants for
// LocalRecoveryFactorType in
// tools/metrics/histograms/metadata/trusted_vault/histograms.xml.
}
}
std::string GetSecurityDomainNameForUma(SecurityDomainId domain) {
switch (domain) {
// These strings get embedded in histogram names and so should not be
// changed.
case SecurityDomainId::kChromeSync:
return "ChromeSync";
case SecurityDomainId::kPasskeys:
return "HwProtected";
// If adding a new value, also update the variants for SecurityDomainId
// in tools/metrics/histograms/metadata/trusted_vault/histograms.xml.
}
}
} // namespace trusted_vault
|