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

Unified Diff: components/user_manager/known_user.cc

Issue 2529103002: Add account_type into AccountId (Closed)
Patch Set: Created 4 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/known_user.cc
diff --git a/components/user_manager/known_user.cc b/components/user_manager/known_user.cc
index 8ad90614b9f3444673b46fb8a9fdb69ee8a2a7a8..66f6452e883e299ff8e58e1086fb44ddb1bade68 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,16 @@ PrefService* GetLocalState() {
bool UserMatches(const AccountId& account_id,
const base::DictionaryValue& dict) {
std::string value;
+ std::string account_type;
+ if (!dict.GetString(kAccountTypeKey, &account_type))
+ account_type = AccountId::kGoogle;
// 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)
@@ -78,6 +86,9 @@ void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) {
if (!account_id.GetGaiaId().empty())
dict.SetString(kGAIAIdKey, account_id.GetGaiaId());
+
+ if (!account_id.GetAccountType().empty())
+ dict.SetString(kAccountTypeKey, account_id.GetAccountType());
}
} // namespace
@@ -216,7 +227,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 std::string& account_type) {
+ // Account type shouldn't be passed w/o gaia_id.
+ DCHECK(account_type.empty() || !gaia_id.empty());
// In tests empty accounts are possible.
if (user_email.empty() && gaia_id.empty())
return EmptyAccountId();
@@ -236,6 +250,14 @@ AccountId GetAccountId(const std::string& user_email,
user_email.empty()
? std::string()
: gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email));
+ std::string stored_account_type;
+ const bool has_stored_account_type =
+ GetStringPref(AccountId::FromUserEmail(sanitized_email), kAccountTypeKey,
+ &stored_account_type);
+ if (has_stored_account_type && !account_type.empty() &&
+ account_type != stored_account_type) {
+ LOG(FATAL) << "Account type has changed";
+ }
if (!sanitized_email.empty() &&
GetStringPref(AccountId::FromUserEmail(sanitized_email), kGAIAIdKey,
@@ -243,21 +265,36 @@ 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.empty()
+ ? 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.empty()) {
+ return AccountId::FromUserEmailGaiaIdAccountType(user_email, gaia_id,
+ account_type);
+ } else {
+ return (gaia_id.empty()
Alexander Alekseev 2016/11/27 08:41:54 nit: no else
Roman Sorokin (ftl) 2016/12/02 11:13:11 Done.
+ ? AccountId::FromUserEmail(user_email)
+ : AccountId::FromUserEmailGaiaId(user_email, gaia_id));
+ }
}
std::vector<AccountId> GetKnownAccountIds() {
@@ -274,10 +311,14 @@ std::vector<AccountId> GetKnownAccountIds() {
if (known_users->GetDictionary(i, &element)) {
std::string email;
std::string gaia_id;
+ std::string account_type = AccountId::kGoogle;
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));
+ element->GetString(kAccountTypeKey, &account_type);
+ if (has_email || has_gaia_id) {
+ result.push_back(AccountId::FromUserEmailGaiaIdAccountType(
+ email, gaia_id, account_type));
+ }
}
}
return result;
@@ -306,6 +347,10 @@ 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, 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