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

Unified Diff: components/user_manager/user_manager_base.cc

Issue 1463753002: ChromeOS: This CL fixes bug in UserManager::GetKnownUserAccountId . (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 5 years, 1 month 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
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 f51d9b14f18f5538ce0b4bc0a4c265610a32b278..69006eee7532d903819ff028d28822fcb4b6019d 100644
--- a/components/user_manager/user_manager_base.cc
+++ b/components/user_manager/user_manager_base.cc
@@ -595,19 +595,7 @@ void UserManagerBase::ParseUserList(const base::ListValue& users_list,
continue;
}
- const AccountId partial_account_id = AccountId::FromUserEmail(email);
- AccountId account_id = EmptyAccountId();
-
- const bool lookup_result =
- GetKnownUserAccountId(partial_account_id, &account_id);
- // TODO(alemate):
- // DCHECK(lookup_result) << "KnownUser lookup falied for '" << email << "'";
- // (tests do not initialize KnownUserData)
-
- if (!lookup_result) {
- account_id = partial_account_id;
- LOG(WARNING) << "KnownUser lookup falied for '" << email << "'";
- }
+ const AccountId account_id = GetKnownUserAccountId(email, std::string());
if (existing_users.find(account_id) != existing_users.end() ||
!users_set->insert(account_id).second) {
@@ -1042,6 +1030,7 @@ bool UserManagerBase::FindKnownUserPrefs(
// Local State may not be initialized in tests.
if (!local_state)
return false;
+
if (IsUserNonCryptohomeDataEphemeral(account_id))
return false;
@@ -1163,29 +1152,33 @@ void UserManagerBase::SetKnownUserIntegerPref(const AccountId& account_id,
UpdateKnownUserPrefs(account_id, dict, false);
}
-bool UserManagerBase::GetKnownUserAccountId(
- const AccountId& authenticated_account_id,
- AccountId* out_account_id) {
- if (!authenticated_account_id.GetGaiaId().empty()) {
- std::string canonical_email;
- if (!GetKnownUserStringPref(
- AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()),
- kCanonicalEmail, &canonical_email)) {
- return false;
- }
+AccountId UserManagerBase::GetKnownUserAccountIdImpl(
+ const std::string& user_email,
+ const std::string& gaia_id) {
+ DCHECK(!(user_email.empty() && gaia_id.empty()));
- *out_account_id = AccountId::FromUserEmailGaiaId(
- canonical_email, authenticated_account_id.GetGaiaId());
- return true;
+ // We can have several users with the same gaia_id but different e-mails.
+ // The opposite case is not possible.
achuithb 2015/11/20 18:46:51 I think we need more comments for the various case
+ std::string old_gaia_id;
+ const std::string sanitized_email =
+ gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email));
+ if (!user_email.empty() &&
achuithb 2015/11/20 18:46:51 !sanitized_email.empty() would be clearer
Alexander Alekseev 2015/11/21 01:06:29 Done.
+ GetKnownUserStringPref(AccountId::FromUserEmail(sanitized_email),
+ kGAIAIdKey, &old_gaia_id)) {
+ if (!gaia_id.empty() && gaia_id != old_gaia_id)
+ LOG(ERROR) << "User gaia id has changed. Sync will not work.";
+
+ return AccountId::FromUserEmailGaiaId(sanitized_email, old_gaia_id);
achuithb 2015/11/20 18:46:51 Why is this right? SHouldn't we use the new gaia_i
}
- DCHECK(!authenticated_account_id.GetUserEmail().empty());
- std::string gaia_id;
- if (!GetKnownUserStringPref(authenticated_account_id, kGAIAIdKey, &gaia_id))
- return false;
- *out_account_id = AccountId::FromUserEmailGaiaId(
- authenticated_account_id.GetUserEmail(), gaia_id);
- return true;
+ std::string canonical_email;
achuithb 2015/11/20 18:46:51 maybe stored_email?
Alexander Alekseev 2015/11/21 01:06:29 Done.
+ if (!gaia_id.empty() &&
+ GetKnownUserStringPref(AccountId::FromGaiaId(gaia_id), kCanonicalEmail,
+ &canonical_email)) {
+ return AccountId::FromUserEmailGaiaId(canonical_email, gaia_id);
+ }
+
+ return AccountId::FromUserEmailGaiaId(sanitized_email, gaia_id);
}
void UserManagerBase::UpdateGaiaID(const AccountId& account_id,

Powered by Google App Engine
This is Rietveld 408576698