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

Unified Diff: components/user_manager/known_user.cc

Issue 2529103002: Add account_type into AccountId (Closed)
Patch Set: Fix MultiUserWindowManagerChromeOSTest.* Created 4 years 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/known_user.cc
diff --git a/components/user_manager/known_user.cc b/components/user_manager/known_user.cc
index 8ad90614b9f3444673b46fb8a9fdb69ee8a2a7a8..3a2e97f8dc3a66832eafaec9c989f317d6596ddd 100644
--- a/components/user_manager/known_user.cc
+++ b/components/user_manager/known_user.cc
@@ -32,6 +32,9 @@ const char kCanonicalEmail[] = "email";
// Key of obfuscated GAIA id value.
const char kGAIAIdKey[] = "gaia_id";
+// Key of account type.
+const char kAccountTypeKey[] = "account_type";
+
// Key of whether this user ID refers to a SAML user.
const char kUsingSAMLKey[] = "using_saml";
@@ -58,11 +61,19 @@ PrefService* GetLocalState() {
bool UserMatches(const AccountId& account_id,
const base::DictionaryValue& dict) {
std::string value;
+ AccountType account_type(AccountType::GOOGLE);
+ {
+ std::string account_type_string;
+ if (dict.GetString(kAccountTypeKey, &account_type_string))
+ account_type = AccountId::StringToAccountType(account_type_string);
+ }
// TODO(alemate): update code once user id is really a struct.
bool has_gaia_id = dict.GetString(kGAIAIdKey, &value);
- if (has_gaia_id && account_id.GetGaiaId() == value)
+ if (has_gaia_id && account_id.GetGaiaId() == value) {
+ DCHECK(account_id.GetAccountType() == account_type);
return true;
+ }
bool has_email = dict.GetString(kCanonicalEmail, &value);
if (has_email && account_id.GetUserEmail() == value)
@@ -76,8 +87,11 @@ void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) {
if (!account_id.GetUserEmail().empty())
dict.SetString(kCanonicalEmail, account_id.GetUserEmail());
- if (!account_id.GetGaiaId().empty())
+ if (!account_id.GetGaiaId().empty()) {
dict.SetString(kGAIAIdKey, account_id.GetGaiaId());
+ dict.SetString(kAccountTypeKey,
+ AccountId::AccountTypeToString(account_id.GetAccountType()));
+ }
}
} // namespace
@@ -216,7 +230,10 @@ void SetIntegerPref(const AccountId& account_id,
}
AccountId GetAccountId(const std::string& user_email,
- const std::string& gaia_id) {
+ const std::string& gaia_id,
+ const AccountType& account_type) {
+ // Account type shouldn't be passed w/o gaia_id.
+ DCHECK(account_type == AccountType::UNKNOWN || !gaia_id.empty());
// In tests empty accounts are possible.
if (user_email.empty() && gaia_id.empty())
return EmptyAccountId();
@@ -236,6 +253,19 @@ AccountId GetAccountId(const std::string& user_email,
user_email.empty()
? std::string()
: gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email));
+ std::string stored_account_type_string;
+ const bool has_stored_account_type =
+ GetStringPref(AccountId::FromUserEmail(sanitized_email), kAccountTypeKey,
+ &stored_account_type_string);
+ const AccountType stored_account_type =
+ has_stored_account_type
+ ? AccountId::StringToAccountType(stored_account_type_string)
+ : AccountType::UNKNOWN;
+
+ if (has_stored_account_type && account_type != AccountType::UNKNOWN &&
+ account_type != stored_account_type) {
+ LOG(FATAL) << "Account type has changed";
+ }
if (!sanitized_email.empty() &&
GetStringPref(AccountId::FromUserEmail(sanitized_email), kGAIAIdKey,
@@ -243,21 +273,35 @@ AccountId GetAccountId(const std::string& user_email,
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);
+ return has_stored_account_type
+ ? AccountId::FromUserEmailGaiaIdAccountType(
+ sanitized_email, stored_gaia_id, stored_account_type)
+ : AccountId::FromUserEmailGaiaId(sanitized_email,
+ stored_gaia_id);
}
+ DCHECK(!has_stored_account_type);
std::string stored_email;
// GetStringPref() returns the first user record that matches
// given ID. So we will get the first one if there are multiples.
- if (!gaia_id.empty() && GetStringPref(AccountId::FromGaiaId(gaia_id),
- kCanonicalEmail, &stored_email)) {
- return AccountId::FromUserEmailGaiaId(stored_email, gaia_id);
+ if (!gaia_id.empty()) {
+ const AccountId account_id(
+ account_type == AccountType::UNKNOWN
+ ? AccountId::FromGaiaId(gaia_id)
+ : AccountId::FromGaiaIdAccountType(gaia_id, account_type));
+ if (GetStringPref(account_id, kCanonicalEmail, &stored_email)) {
+ return AccountId::FromUserEmailGaiaIdAccountType(
+ stored_email, gaia_id, account_id.GetAccountType());
+ }
}
- return (gaia_id.empty()
- ? AccountId::FromUserEmail(user_email)
- : AccountId::FromUserEmailGaiaId(user_email, gaia_id));
+ if (account_type == AccountType::UNKNOWN) {
+ return gaia_id.empty()
+ ? AccountId::FromUserEmail(user_email)
+ : AccountId::FromUserEmailGaiaId(user_email, gaia_id);
+ }
+ return AccountId::FromUserEmailGaiaIdAccountType(user_email, gaia_id,
+ account_type);
}
std::vector<AccountId> GetKnownAccountIds() {
@@ -274,10 +318,17 @@ std::vector<AccountId> GetKnownAccountIds() {
if (known_users->GetDictionary(i, &element)) {
std::string email;
std::string gaia_id;
+ AccountType account_type = AccountType::GOOGLE;
const bool has_email = element->GetString(kCanonicalEmail, &email);
const bool has_gaia_id = element->GetString(kGAIAIdKey, &gaia_id);
- if (has_email || has_gaia_id)
- result.push_back(AccountId::FromUserEmailGaiaId(email, gaia_id));
+ std::string account_type_string;
+ if (element->GetString(kAccountTypeKey, &account_type_string)) {
+ account_type = AccountId::StringToAccountType(account_type_string);
+ }
+ if (has_email || has_gaia_id) {
+ result.push_back(AccountId::FromUserEmailGaiaIdAccountType(
+ email, gaia_id, account_type));
+ }
}
}
return result;
@@ -306,6 +357,11 @@ void UpdateGaiaID(const AccountId& account_id, const std::string& gaia_id) {
SetStringPref(account_id, kGAIAIdKey, gaia_id);
}
+void UpdateAccountType(const AccountId& account_id) {
+ SetStringPref(account_id, kAccountTypeKey,
+ AccountId::AccountTypeToString(account_id.GetAccountType()));
+}
+
bool FindGaiaID(const AccountId& account_id, std::string* out_value) {
return GetStringPref(account_id, kGAIAIdKey, out_value);
}

Powered by Google App Engine
This is Rietveld 408576698