diff options
author | nkostylev <nkostylev@chromium.org> | 2015-05-07 15:23:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-07 22:23:46 +0000 |
commit | eb9ce0de55f3746e59ea805ca954a1be849b3815 (patch) | |
tree | 938df7ec3e385d8c8052914b624009964ce820c1 /components/user_manager | |
parent | 179b32c0a35ad3070b9b28ce05ac986677b7c521 (diff) | |
download | chromium_src-eb9ce0de55f3746e59ea805ca954a1be849b3815.zip chromium_src-eb9ce0de55f3746e59ea805ca954a1be849b3815.tar.gz chromium_src-eb9ce0de55f3746e59ea805ca954a1be849b3815.tar.bz2 |
UMA to track the reason for re-auth
Landing https://codereview.chromium.org/1114543002/
BUG=469992
TBR=isherman@chromium.org
Review URL: https://codereview.chromium.org/1132523002
Cr-Commit-Position: refs/heads/master@{#328858}
Diffstat (limited to 'components/user_manager')
-rw-r--r-- | components/user_manager/user_manager.h | 20 | ||||
-rw-r--r-- | components/user_manager/user_manager_base.cc | 67 | ||||
-rw-r--r-- | components/user_manager/user_manager_base.h | 9 |
3 files changed, 93 insertions, 3 deletions
diff --git a/components/user_manager/user_manager.h b/components/user_manager/user_manager.h index 9038c94..5d9268e 100644 --- a/components/user_manager/user_manager.h +++ b/components/user_manager/user_manager.h @@ -348,6 +348,17 @@ class USER_MANAGER_EXPORT UserManager { const std::string& path, const bool in_value) = 0; + // Returns true if |user_id| preference by |path| does exist, + // fills in |out_value|. Otherwise returns false. + virtual bool GetKnownUserIntegerPref(const UserID& user_id, + const std::string& path, + int* out_value) = 0; + + // Updates user's identified by |user_id| integer preference |path|. + virtual void SetKnownUserIntegerPref(const UserID& user_id, + const std::string& path, + const int in_value) = 0; + // Updates |gaia_id| for user with |user_id|. // TODO(antrim): Update this once UserID contains GAIA ID. virtual void UpdateGaiaID(const UserID& user_id, @@ -372,6 +383,15 @@ class USER_MANAGER_EXPORT UserManager { const std::string& device_id) = 0; virtual std::string GetKnownUserDeviceId(const UserID& user_id) = 0; + // Saves why the user has to go through re-auth flow. + virtual void UpdateReauthReason(const UserID& user_id, + const int reauth_reason) = 0; + + // Returns the reason why the user with |user_id| has to go through the + // re-auth flow. Returns true if such a reason was recorded or false + // otherwise. + virtual bool FindReauthReason(const UserID& user_id, int* out_value) = 0; + protected: // Sets UserManager instance. static void SetInstance(UserManager* user_manager); diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc index 2cee60b..8b1feae 100644 --- a/components/user_manager/user_manager_base.cc +++ b/components/user_manager/user_manager_base.cc @@ -88,6 +88,9 @@ const char kUsingSAMLKey[] = "using_saml"; // Key of Device Id. const char kDeviceId[] = "device_id"; +// Key of the reason for re-auth. +const char kReauthReasonKey[] = "reauth_reason"; + // Upper bound for a histogram metric reporting the amount of time between // one regular user logging out and a different regular user logging in. const int kLogoutToLoginDelayMaxSec = 1800; @@ -549,6 +552,16 @@ bool UserManagerBase::FindUsingSAML(const std::string& user_id) { return false; } +void UserManagerBase::UpdateReauthReason(const std::string& user_id, + const int reauth_reason) { + SetKnownUserIntegerPref(user_id, kReauthReasonKey, reauth_reason); +} + +bool UserManagerBase::FindReauthReason(const std::string& user_id, + int* out_value) { + return GetKnownUserIntegerPref(user_id, kReauthReasonKey, out_value); +} + void UserManagerBase::UpdateUserAccountData( const std::string& user_id, const UserAccountData& account_data) { @@ -837,6 +850,7 @@ void UserManagerBase::EnsureUsersLoaded() { } user->set_oauth_token_status(LoadUserOAuthStatus(*it)); user->set_force_online_signin(LoadForceOnlineSignin(*it)); + user->set_using_saml(FindUsingSAML(*it)); users_.push_back(user); base::string16 display_name; @@ -1002,6 +1016,11 @@ bool UserManagerBase::FindKnownUserPrefs( const UserID& user_id, const base::DictionaryValue** out_value) { PrefService* local_state = GetLocalState(); + + // Local State may not be initialized in tests. + if (!local_state) + return false; + const base::ListValue* known_users = local_state->GetList(kKnownUsers); for (size_t i = 0; i < known_users->GetSize(); ++i) { const base::DictionaryValue* element = nullptr; @@ -1018,7 +1037,13 @@ bool UserManagerBase::FindKnownUserPrefs( void UserManagerBase::UpdateKnownUserPrefs(const UserID& user_id, const base::DictionaryValue& values, bool clear) { - ListPrefUpdate update(GetLocalState(), kKnownUsers); + PrefService* local_state = GetLocalState(); + + // Local State may not be initialized in tests. + if (!local_state) + return; + + ListPrefUpdate update(local_state, kKnownUsers); for (size_t i = 0; i < update->GetSize(); ++i) { base::DictionaryValue* element = nullptr; if (update->GetDictionary(i, &element)) { @@ -1050,7 +1075,13 @@ bool UserManagerBase::GetKnownUserStringPref(const UserID& user_id, void UserManagerBase::SetKnownUserStringPref(const UserID& user_id, const std::string& path, const std::string& in_value) { - ListPrefUpdate update(GetLocalState(), kKnownUsers); + PrefService* local_state = GetLocalState(); + + // Local State may not be initialized in tests. + if (!local_state) + return; + + ListPrefUpdate update(local_state, kKnownUsers); base::DictionaryValue dict; dict.SetString(path, in_value); UpdateKnownUserPrefs(user_id, dict, false); @@ -1069,12 +1100,42 @@ bool UserManagerBase::GetKnownUserBooleanPref(const UserID& user_id, void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id, const std::string& path, const bool in_value) { - ListPrefUpdate update(GetLocalState(), kKnownUsers); + PrefService* local_state = GetLocalState(); + + // Local State may not be initialized in tests. + if (!local_state) + return; + + ListPrefUpdate update(local_state, kKnownUsers); base::DictionaryValue dict; dict.SetBoolean(path, in_value); UpdateKnownUserPrefs(user_id, dict, false); } +bool UserManagerBase::GetKnownUserIntegerPref(const UserID& user_id, + const std::string& path, + int* out_value) { + const base::DictionaryValue* user_pref_dict = nullptr; + if (!FindKnownUserPrefs(user_id, &user_pref_dict)) + return false; + return user_pref_dict->GetInteger(path, out_value); +} + +void UserManagerBase::SetKnownUserIntegerPref(const UserID& user_id, + const std::string& path, + const int in_value) { + PrefService* local_state = GetLocalState(); + + // Local State may not be initialized in tests. + if (!local_state) + return; + + ListPrefUpdate update(local_state, kKnownUsers); + base::DictionaryValue dict; + dict.SetInteger(path, in_value); + UpdateKnownUserPrefs(user_id, dict, false); +} + void UserManagerBase::UpdateGaiaID(const UserID& user_id, const std::string& gaia_id) { SetKnownUserStringPref(user_id, kGAIAIdKey, gaia_id); diff --git a/components/user_manager/user_manager_base.h b/components/user_manager/user_manager_base.h index d61f8fb..d8454efa 100644 --- a/components/user_manager/user_manager_base.h +++ b/components/user_manager/user_manager_base.h @@ -123,6 +123,12 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { void SetKnownUserBooleanPref(const UserID& user_id, const std::string& path, const bool in_value) override; + bool GetKnownUserIntegerPref(const UserID& user_id, + const std::string& path, + int* out_value) override; + void SetKnownUserIntegerPref(const UserID& user_id, + const std::string& path, + const int in_value) override; void UpdateGaiaID(const UserID& user_id, const std::string& gaia_id) override; bool FindGaiaID(const UserID& user_id, std::string* out_value) override; void UpdateUsingSAML(const std::string& user_id, @@ -131,6 +137,9 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { void SetKnownUserDeviceId(const UserID& user_id, const std::string& device_id) override; std::string GetKnownUserDeviceId(const UserID& user_id) override; + void UpdateReauthReason(const std::string& user_id, + const int reauth_reason) override; + bool FindReauthReason(const std::string& user_id, int* out_value) override; virtual void SetIsCurrentUserNew(bool is_new); |