Commit ac49c006 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Explicit values for UMA enums in LoginAuthRecorder

1. Provide explicit values for those enums in the LoginAuthRecorder
   class that are logged as UMA metric values.
   This makes it more clear that those values shouldn't be renumbered,
   and makes it easier to find and verify the correspondence between
   the enum values in the C++ code and the <enum> values in enums.xml.

2. Use new-style UMA utils that deduct the enum size automatically
   based on the "kMaxValue" item.

Bug: none
Change-Id: I853e5cae5eaeb39765d02b4256af59b2d2c2eb93
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1724087
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682919}
parent 91715dde
...@@ -15,7 +15,7 @@ using AuthMethodSwitchType = LoginAuthRecorder::AuthMethodSwitchType; ...@@ -15,7 +15,7 @@ using AuthMethodSwitchType = LoginAuthRecorder::AuthMethodSwitchType;
namespace { namespace {
AuthMethodSwitchType SwitchFromPasswordTo(AuthMethod current) { base::Optional<AuthMethodSwitchType> SwitchFromPasswordTo(AuthMethod current) {
DCHECK_NE(AuthMethod::kPassword, current); DCHECK_NE(AuthMethod::kPassword, current);
switch (current) { switch (current) {
case AuthMethod::kPin: case AuthMethod::kPin:
...@@ -27,13 +27,12 @@ AuthMethodSwitchType SwitchFromPasswordTo(AuthMethod current) { ...@@ -27,13 +27,12 @@ AuthMethodSwitchType SwitchFromPasswordTo(AuthMethod current) {
case AuthMethod::kChallengeResponse: case AuthMethod::kChallengeResponse:
return AuthMethodSwitchType::kPasswordToChallengeResponse; return AuthMethodSwitchType::kPasswordToChallengeResponse;
case AuthMethod::kPassword: case AuthMethod::kPassword:
case AuthMethod::kMethodCount:
NOTREACHED(); NOTREACHED();
return AuthMethodSwitchType::kSwitchTypeCount; return base::nullopt;
} }
} }
AuthMethodSwitchType SwitchFromPinTo(AuthMethod current) { base::Optional<AuthMethodSwitchType> SwitchFromPinTo(AuthMethod current) {
DCHECK_NE(AuthMethod::kPin, current); DCHECK_NE(AuthMethod::kPin, current);
switch (current) { switch (current) {
case AuthMethod::kPassword: case AuthMethod::kPassword:
...@@ -44,13 +43,12 @@ AuthMethodSwitchType SwitchFromPinTo(AuthMethod current) { ...@@ -44,13 +43,12 @@ AuthMethodSwitchType SwitchFromPinTo(AuthMethod current) {
return AuthMethodSwitchType::kPinToFingerprint; return AuthMethodSwitchType::kPinToFingerprint;
case AuthMethod::kPin: case AuthMethod::kPin:
case AuthMethod::kChallengeResponse: case AuthMethod::kChallengeResponse:
case AuthMethod::kMethodCount:
NOTREACHED(); NOTREACHED();
return AuthMethodSwitchType::kSwitchTypeCount; return base::nullopt;
} }
} }
AuthMethodSwitchType SwitchFromSmartlockTo(AuthMethod current) { base::Optional<AuthMethodSwitchType> SwitchFromSmartlockTo(AuthMethod current) {
DCHECK_NE(AuthMethod::kSmartlock, current); DCHECK_NE(AuthMethod::kSmartlock, current);
switch (current) { switch (current) {
case AuthMethod::kPassword: case AuthMethod::kPassword:
...@@ -61,13 +59,13 @@ AuthMethodSwitchType SwitchFromSmartlockTo(AuthMethod current) { ...@@ -61,13 +59,13 @@ AuthMethodSwitchType SwitchFromSmartlockTo(AuthMethod current) {
return AuthMethodSwitchType::kSmartlockToFingerprint; return AuthMethodSwitchType::kSmartlockToFingerprint;
case AuthMethod::kSmartlock: case AuthMethod::kSmartlock:
case AuthMethod::kChallengeResponse: case AuthMethod::kChallengeResponse:
case AuthMethod::kMethodCount:
NOTREACHED(); NOTREACHED();
return AuthMethodSwitchType::kSwitchTypeCount; return base::nullopt;
} }
} }
AuthMethodSwitchType SwitchFromFingerprintTo(AuthMethod current) { base::Optional<AuthMethodSwitchType> SwitchFromFingerprintTo(
AuthMethod current) {
DCHECK_NE(AuthMethod::kFingerprint, current); DCHECK_NE(AuthMethod::kFingerprint, current);
switch (current) { switch (current) {
case AuthMethod::kPassword: case AuthMethod::kPassword:
...@@ -78,13 +76,13 @@ AuthMethodSwitchType SwitchFromFingerprintTo(AuthMethod current) { ...@@ -78,13 +76,13 @@ AuthMethodSwitchType SwitchFromFingerprintTo(AuthMethod current) {
return AuthMethodSwitchType::kFingerprintToPin; return AuthMethodSwitchType::kFingerprintToPin;
case AuthMethod::kFingerprint: case AuthMethod::kFingerprint:
case AuthMethod::kChallengeResponse: case AuthMethod::kChallengeResponse:
case AuthMethod::kMethodCount:
NOTREACHED(); NOTREACHED();
return AuthMethodSwitchType::kSwitchTypeCount; return base::nullopt;
} }
} }
AuthMethodSwitchType FindSwitchType(AuthMethod previous, AuthMethod current) { base::Optional<AuthMethodSwitchType> FindSwitchType(AuthMethod previous,
AuthMethod current) {
DCHECK_NE(previous, current); DCHECK_NE(previous, current);
switch (previous) { switch (previous) {
case AuthMethod::kPassword: case AuthMethod::kPassword:
...@@ -96,9 +94,8 @@ AuthMethodSwitchType FindSwitchType(AuthMethod previous, AuthMethod current) { ...@@ -96,9 +94,8 @@ AuthMethodSwitchType FindSwitchType(AuthMethod previous, AuthMethod current) {
case AuthMethod::kFingerprint: case AuthMethod::kFingerprint:
return SwitchFromFingerprintTo(current); return SwitchFromFingerprintTo(current);
case AuthMethod::kChallengeResponse: case AuthMethod::kChallengeResponse:
case AuthMethod::kMethodCount:
NOTREACHED(); NOTREACHED();
return AuthMethodSwitchType::kSwitchTypeCount; return base::nullopt;
} }
} }
...@@ -113,7 +110,6 @@ LoginAuthRecorder::~LoginAuthRecorder() { ...@@ -113,7 +110,6 @@ LoginAuthRecorder::~LoginAuthRecorder() {
} }
void LoginAuthRecorder::RecordAuthMethod(AuthMethod method) { void LoginAuthRecorder::RecordAuthMethod(AuthMethod method) {
DCHECK_NE(method, AuthMethod::kMethodCount);
if (session_manager::SessionManager::Get()->session_state() != if (session_manager::SessionManager::Get()->session_state() !=
session_manager::SessionState::LOCKED) { session_manager::SessionState::LOCKED) {
return; return;
...@@ -123,17 +119,20 @@ void LoginAuthRecorder::RecordAuthMethod(AuthMethod method) { ...@@ -123,17 +119,20 @@ void LoginAuthRecorder::RecordAuthMethod(AuthMethod method) {
const bool is_tablet_mode = TabletModeClient::Get()->tablet_mode_enabled(); const bool is_tablet_mode = TabletModeClient::Get()->tablet_mode_enabled();
if (is_tablet_mode) { if (is_tablet_mode) {
UMA_HISTOGRAM_ENUMERATION("Ash.Login.Lock.AuthMethod.Used.TabletMode", UMA_HISTOGRAM_ENUMERATION("Ash.Login.Lock.AuthMethod.Used.TabletMode",
method, AuthMethod::kMethodCount); method);
} else { } else {
UMA_HISTOGRAM_ENUMERATION("Ash.Login.Lock.AuthMethod.Used.ClamShellMode", UMA_HISTOGRAM_ENUMERATION("Ash.Login.Lock.AuthMethod.Used.ClamShellMode",
method, AuthMethod::kMethodCount); method);
} }
if (last_auth_method_ != method) { if (last_auth_method_ != method) {
// Record switching between unlock methods. // Record switching between unlock methods.
UMA_HISTOGRAM_ENUMERATION("Ash.Login.Lock.AuthMethod.Switched", const base::Optional<AuthMethodSwitchType> switch_type =
FindSwitchType(last_auth_method_, method), FindSwitchType(last_auth_method_, method);
AuthMethodSwitchType::kSwitchTypeCount); if (switch_type) {
UMA_HISTOGRAM_ENUMERATION("Ash.Login.Lock.AuthMethod.Switched",
*switch_type);
}
last_auth_method_ = method; last_auth_method_ = method;
} }
......
...@@ -19,34 +19,34 @@ class LoginAuthRecorder : public session_manager::SessionManagerObserver { ...@@ -19,34 +19,34 @@ class LoginAuthRecorder : public session_manager::SessionManagerObserver {
public: public:
// Authentication method to unlock the screen. This enum is used to back an // Authentication method to unlock the screen. This enum is used to back an
// UMA histogram and new values should be inserted immediately above // UMA histogram and new values should be inserted immediately above
// kMethodCount. // kMaxValue.
enum class AuthMethod { enum class AuthMethod {
kPassword = 0, kPassword = 0,
kPin, kPin = 1,
kSmartlock, kSmartlock = 2,
kFingerprint, kFingerprint = 3,
kChallengeResponse, kChallengeResponse = 4,
kMethodCount, kMaxValue = kChallengeResponse,
}; };
// The type of switching between auth methods. This enum is used to back an // The type of switching between auth methods. This enum is used to back an
// UMA histogram and new values should be inserted immediately above // UMA histogram and new values should be inserted immediately above
// kSwitchTypeCount. // kMaxValue.
enum class AuthMethodSwitchType { enum class AuthMethodSwitchType {
kPasswordToPin = 0, kPasswordToPin = 0,
kPasswordToSmartlock, kPasswordToSmartlock = 1,
kPinToPassword, kPinToPassword = 2,
kPinToSmartlock, kPinToSmartlock = 3,
kSmartlockToPassword, kSmartlockToPassword = 4,
kSmartlockToPin, kSmartlockToPin = 5,
kPasswordToFingerprint, kPasswordToFingerprint = 6,
kPinToFingerprint, kPinToFingerprint = 7,
kSmartlockToFingerprint, kSmartlockToFingerprint = 8,
kFingerprintToPassword, kFingerprintToPassword = 9,
kFingerprintToPin, kFingerprintToPin = 10,
kFingerprintToSmartlock, kFingerprintToSmartlock = 11,
kPasswordToChallengeResponse, kPasswordToChallengeResponse = 12,
kSwitchTypeCount, kMaxValue = kPasswordToChallengeResponse,
}; };
LoginAuthRecorder(); LoginAuthRecorder();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment