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

Unified Diff: components/user_manager/known_user.cc

Issue 2593133002: Revert of Add account_type into AccountId (Closed)
Patch Set: 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
« no previous file with comments | « components/user_manager/known_user.h ('k') | components/user_manager/user_manager_base.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/user_manager/known_user.cc
diff --git a/components/user_manager/known_user.cc b/components/user_manager/known_user.cc
index 815d105e187f75d648fc1543cf7d0e0a184a6a7d..8ad90614b9f3444673b46fb8a9fdb69ee8a2a7a8 100644
--- a/components/user_manager/known_user.cc
+++ b/components/user_manager/known_user.cc
@@ -32,12 +32,6 @@
// Key of obfuscated GAIA id value.
const char kGAIAIdKey[] = "gaia_id";
-// Key of obfuscated object guid value for Active Directory accounts.
-const char kObjGuidKey[] = "obj_guid";
-
-// 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";
@@ -64,29 +58,11 @@
bool UserMatches(const AccountId& account_id,
const base::DictionaryValue& dict) {
std::string value;
- if (account_id.GetAccountType() != AccountType::UNKNOWN &&
- dict.GetString(kAccountTypeKey, &value) &&
- account_id.GetAccountType() != AccountId::StringToAccountType(value)) {
- return false;
- }
// TODO(alemate): update code once user id is really a struct.
- switch (account_id.GetAccountType()) {
- case AccountType::GOOGLE: {
- bool has_gaia_id = dict.GetString(kGAIAIdKey, &value);
- if (has_gaia_id && account_id.GetGaiaId() == value)
- return true;
- break;
- }
- case AccountType::ACTIVE_DIRECTORY: {
- bool has_obj_guid = dict.GetString(kObjGuidKey, &value);
- if (has_obj_guid && account_id.GetObjGuid() == value)
- return true;
- break;
- }
- case AccountType::UNKNOWN: {
- }
- }
+ bool has_gaia_id = dict.GetString(kGAIAIdKey, &value);
+ if (has_gaia_id && account_id.GetGaiaId() == value)
+ return true;
bool has_email = dict.GetString(kCanonicalEmail, &value);
if (has_email && account_id.GetUserEmail() == value)
@@ -100,20 +76,8 @@
if (!account_id.GetUserEmail().empty())
dict.SetString(kCanonicalEmail, account_id.GetUserEmail());
- switch (account_id.GetAccountType()) {
- case AccountType::GOOGLE:
- if (!account_id.GetGaiaId().empty())
- dict.SetString(kGAIAIdKey, account_id.GetGaiaId());
- break;
- case AccountType::ACTIVE_DIRECTORY:
- if (!account_id.GetObjGuid().empty())
- dict.SetString(kObjGuidKey, account_id.GetObjGuid());
- break;
- case AccountType::UNKNOWN:
- return;
- }
- dict.SetString(kAccountTypeKey,
- AccountId::AccountTypeToString(account_id.GetAccountType()));
+ if (!account_id.GetGaiaId().empty())
+ dict.SetString(kGAIAIdKey, account_id.GetGaiaId());
}
} // namespace
@@ -252,76 +216,48 @@
}
AccountId GetAccountId(const std::string& user_email,
- const std::string& id,
- const AccountType& account_type) {
- DCHECK((id.empty() && account_type == AccountType::UNKNOWN) ||
- (!id.empty() && account_type != AccountType::UNKNOWN));
+ const std::string& gaia_id) {
// In tests empty accounts are possible.
- if (user_email.empty() && id.empty() &&
- account_type == AccountType::UNKNOWN) {
+ if (user_email.empty() && gaia_id.empty())
return EmptyAccountId();
- }
AccountId result(EmptyAccountId());
// UserManager is usually NULL in unit tests.
- if (account_type == AccountType::UNKNOWN && UserManager::IsInitialized() &&
- UserManager::Get()->GetPlatformKnownUserId(user_email, id, &result)) {
+ if (UserManager::IsInitialized() &&
+ UserManager::Get()->GetPlatformKnownUserId(user_email, gaia_id,
+ &result)) {
return result;
}
+ // 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;
- std::string stored_obj_guid;
const std::string sanitized_email =
user_email.empty()
? std::string()
: gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email));
- if (!sanitized_email.empty()) {
- if (GetStringPref(AccountId::FromUserEmail(sanitized_email), kGAIAIdKey,
- &stored_gaia_id)) {
- if (!id.empty()) {
- DCHECK(account_type == AccountType::GOOGLE);
- if (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);
- }
-
- if (GetStringPref(AccountId::FromUserEmail(sanitized_email), kObjGuidKey,
- &stored_obj_guid)) {
- if (!id.empty()) {
- DCHECK(account_type == AccountType::ACTIVE_DIRECTORY);
- if (id != stored_obj_guid)
- LOG(ERROR) << "User object guid has changed. Sync will not work.";
- }
-
- // obj_guid is associated with cryptohome.
- return AccountId::AdFromUserEmailObjGuid(sanitized_email,
- stored_obj_guid);
- }
+ if (!sanitized_email.empty() &&
+ GetStringPref(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);
}
std::string stored_email;
- switch (account_type) {
- case AccountType::GOOGLE:
- if (GetStringPref(AccountId::FromGaiaId(id), kCanonicalEmail,
- &stored_email)) {
- return AccountId::FromUserEmailGaiaId(stored_email, id);
- }
- return AccountId::FromUserEmailGaiaId(sanitized_email, id);
- case AccountType::ACTIVE_DIRECTORY:
- if (GetStringPref(AccountId::AdFromObjGuid(id), kCanonicalEmail,
- &stored_email)) {
- return AccountId::AdFromUserEmailObjGuid(stored_email, id);
- }
- return AccountId::AdFromUserEmailObjGuid(sanitized_email, id);
- case AccountType::UNKNOWN:
- return AccountId::FromUserEmail(sanitized_email);
- }
- NOTREACHED();
- return EmptyAccountId();
+ // 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);
+ }
+
+ return (gaia_id.empty()
+ ? AccountId::FromUserEmail(user_email)
+ : AccountId::FromUserEmailGaiaId(user_email, gaia_id));
}
std::vector<AccountId> GetKnownAccountIds() {
@@ -338,30 +274,10 @@
if (known_users->GetDictionary(i, &element)) {
std::string email;
std::string gaia_id;
- std::string obj_guid;
const bool has_email = element->GetString(kCanonicalEmail, &email);
const bool has_gaia_id = element->GetString(kGAIAIdKey, &gaia_id);
- const bool has_obj_guid = element->GetString(kObjGuidKey, &obj_guid);
- AccountType account_type = AccountType::GOOGLE;
- std::string account_type_string;
- if (element->GetString(kAccountTypeKey, &account_type_string)) {
- account_type = AccountId::StringToAccountType(account_type_string);
- }
- switch (account_type) {
- case AccountType::GOOGLE:
- if (has_email || has_gaia_id) {
- result.push_back(AccountId::FromUserEmailGaiaId(email, gaia_id));
- }
- break;
- case AccountType::ACTIVE_DIRECTORY:
- if (has_email && has_obj_guid) {
- result.push_back(
- AccountId::AdFromUserEmailObjGuid(email, obj_guid));
- }
- break;
- default:
- NOTREACHED() << "Unknown account type";
- }
+ if (has_email || has_gaia_id)
+ result.push_back(AccountId::FromUserEmailGaiaId(email, gaia_id));
}
}
return result;
@@ -388,23 +304,6 @@
void UpdateGaiaID(const AccountId& account_id, const std::string& gaia_id) {
SetStringPref(account_id, kGAIAIdKey, gaia_id);
- SetStringPref(account_id, kAccountTypeKey,
- AccountId::AccountTypeToString(AccountType::GOOGLE));
-}
-
-void UpdateId(const AccountId& account_id) {
- switch (account_id.GetAccountType()) {
- case AccountType::GOOGLE:
- SetStringPref(account_id, kGAIAIdKey, account_id.GetGaiaId());
- break;
- case AccountType::ACTIVE_DIRECTORY:
- SetStringPref(account_id, kObjGuidKey, account_id.GetObjGuid());
- break;
- case AccountType::UNKNOWN:
- return;
- }
- SetStringPref(account_id, kAccountTypeKey,
- AccountId::AccountTypeToString(account_id.GetAccountType()));
}
bool FindGaiaID(const AccountId& account_id, std::string* out_value) {
« no previous file with comments | « components/user_manager/known_user.h ('k') | components/user_manager/user_manager_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698