Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: components/user_manager/user_manager_base.cc

Issue 1132523002: UMA to track the reason for re-auth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: initialize local state Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/user_manager/user_manager_base.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/user_manager/user_manager_base.cc
diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc
index 2cee60b6d7984a004b968ea063f727709d524539..8b1feae462c471bda2f6f5243b6947349dce7510 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);
« no previous file with comments | « components/user_manager/user_manager_base.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698