diff options
Diffstat (limited to 'components/user_manager')
-rw-r--r-- | components/user_manager/user_manager.cc | 25 | ||||
-rw-r--r-- | components/user_manager/user_manager.h | 14 | ||||
-rw-r--r-- | components/user_manager/user_manager_base.cc | 64 | ||||
-rw-r--r-- | components/user_manager/user_manager_base.h | 4 |
4 files changed, 68 insertions, 39 deletions
diff --git a/components/user_manager/user_manager.cc b/components/user_manager/user_manager.cc index 3cf3f267..869b366 100644 --- a/components/user_manager/user_manager.cc +++ b/components/user_manager/user_manager.cc @@ -5,6 +5,8 @@ #include "components/user_manager/user_manager.h" #include "base/logging.h" +#include "chromeos/login/user_names.h" +#include "components/signin/core/account_id/account_id.h" namespace user_manager { @@ -85,4 +87,27 @@ UserManager* UserManager::SetForTesting(UserManager* user_manager) { return previous_instance; } +// static +AccountId UserManager::GetKnownUserAccountId(const std::string& user_email, + const std::string& gaia_id) { + // In tests empty accounts are possible. + if (user_email.empty() && gaia_id.empty()) + return EmptyAccountId(); + + if (user_email == chromeos::login::kStubUser) + return chromeos::login::StubAccountId(); + + if (user_email == chromeos::login::kGuestUserName) + return chromeos::login::GuestAccountId(); + + UserManager* user_manager = Get(); + if (user_manager) + return user_manager->GetKnownUserAccountIdImpl(user_email, gaia_id); + + // This is fallback for tests. + return (gaia_id.empty() + ? AccountId::FromUserEmail(user_email) + : AccountId::FromUserEmailGaiaId(user_email, gaia_id)); +} + } // namespace user_manager diff --git a/components/user_manager/user_manager.h b/components/user_manager/user_manager.h index 03a08d7..59cbbd9 100644 --- a/components/user_manager/user_manager.h +++ b/components/user_manager/user_manager.h @@ -363,10 +363,16 @@ class USER_MANAGER_EXPORT UserManager { const std::string& path, const int in_value) = 0; - // Returns true if user's AccountId was found. - // Returns it in |out_account_id|. - virtual bool GetKnownUserAccountId(const AccountId& authenticated_account_id, - AccountId* out_account_id) = 0; + // This call forms full account id of a known user by email and (optionally) + // gaia_id. + // This is a temporary call while migrating to AccountId. + virtual AccountId GetKnownUserAccountIdImpl(const std::string& user_email, + const std::string& gaia_id) = 0; + + // The same as above, but doesn't crash in unit_tests when Usermanager + // doesn't exist. + static AccountId GetKnownUserAccountId(const std::string& user_email, + const std::string& gaia_id); // Updates |gaia_id| for user with |account_id|. // TODO(alemate): Update this once AccountId contains GAIA ID diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc index f51d9b1..cdfcb72 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,38 @@ 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())); + + // We can have several users with the same gaia_id but different e-mails. + // The opposite case is not possible. + std::string stored_gaia_id; + const std::string sanitized_email = + user_email.empty() + ? std::string() + : gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email)); + if (!sanitized_email.empty() && + GetKnownUserStringPref(AccountId::FromUserEmail(sanitized_email), + kGAIAIdKey, &stored_gaia_id)) { + if (!gaia_id.empty() && gaia_id != stored_gaia_id) + LOG(ERROR) << "User gaia id has changed. Sync will not work."; + + // gaia_id is associated with cryptohome. + return AccountId::FromUserEmailGaiaId(sanitized_email, stored_gaia_id); + } - *out_account_id = AccountId::FromUserEmailGaiaId( - canonical_email, authenticated_account_id.GetGaiaId()); - return true; + std::string stored_email; + // GetKnownUserStringPref() returns the first user record that matches + // given ID. So we will get the first one if there are multiples. + if (!gaia_id.empty() && + GetKnownUserStringPref(AccountId::FromGaiaId(gaia_id), kCanonicalEmail, + &stored_email)) { + return AccountId::FromUserEmailGaiaId(stored_email, gaia_id); } - 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; + return AccountId::FromUserEmailGaiaId(sanitized_email, gaia_id); } void UserManagerBase::UpdateGaiaID(const AccountId& account_id, diff --git a/components/user_manager/user_manager_base.h b/components/user_manager/user_manager_base.h index dd46c5d..138faf0 100644 --- a/components/user_manager/user_manager_base.h +++ b/components/user_manager/user_manager_base.h @@ -129,8 +129,8 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager { void SetKnownUserIntegerPref(const AccountId& account_id, const std::string& path, int in_value) override; - bool GetKnownUserAccountId(const AccountId& authenticated_account_id, - AccountId* out_account_id) override; + AccountId GetKnownUserAccountIdImpl(const std::string& user_email, + const std::string& gaia_id) override; void UpdateGaiaID(const AccountId& account_id, const std::string& gaia_id) override; bool FindGaiaID(const AccountId& account_id, std::string* out_value) override; |