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

Unified Diff: components/signin/core/account_id/account_id.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/signin/core/account_id/account_id.h ('k') | components/user_manager/known_user.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/signin/core/account_id/account_id.cc
diff --git a/components/signin/core/account_id/account_id.cc b/components/signin/core/account_id/account_id.cc
index a7959763eb96aab74b808e3ee5b5d55861bf8b26..00ceb2e2f52bf9f5225ca76c4af50f99e0f58105 100644
--- a/components/signin/core/account_id/account_id.cc
+++ b/components/signin/core/account_id/account_id.cc
@@ -16,19 +16,25 @@
namespace {
+// Known account types.
+const char kGoogle[] = "google";
+
// Serialization keys
const char kGaiaIdKey[] = "gaia_id";
const char kEmailKey[] = "email";
-const char kObjGuid[] = "obj_guid";
-const char kAccountTypeKey[] = "account_type";
-
-// Serialization values for account type.
-const std::string kGoogle = "google";
-const std::string kAd = "ad";
// Prefix for GetAccountIdKey().
const char kKeyGaiaIdPrefix[] = "g-";
-const char kKeyAdIdPrefix[] = "a-";
+
+struct GoogleStringSingleton {
+ GoogleStringSingleton() : google(kGoogle) {}
+
+ static GoogleStringSingleton* GetInstance() {
+ return base::Singleton<GoogleStringSingleton>::get();
+ }
+
+ const std::string google;
+};
} // anonymous namespace
@@ -43,46 +49,26 @@
AccountId::AccountId() {}
-AccountId::AccountId(const std::string& id,
- const std::string& user_email,
- const AccountType& account_type)
- : id_(id), user_email_(user_email), account_type_(account_type) {
- DCHECK(account_type != AccountType::UNKNOWN || id.empty());
- DCHECK(account_type != AccountType::ACTIVE_DIRECTORY || !id.empty());
+AccountId::AccountId(const std::string& gaia_id, const std::string& user_email)
+ : gaia_id_(gaia_id), user_email_(user_email) {
// Fail if e-mail looks similar to GaiaIdKey.
LOG_ASSERT(!base::StartsWith(user_email, kKeyGaiaIdPrefix,
base::CompareCase::SENSITIVE) ||
user_email.find('@') != std::string::npos)
- << "Bad e-mail: '" << user_email << "' with gaia_id='" << id << "'";
+ << "Bad e-mail: '" << user_email << "' with gaia_id='" << gaia_id << "'";
// TODO(alemate): DCHECK(!email.empty());
// TODO(alemate): check gaia_id is not empty once it is required.
}
AccountId::AccountId(const AccountId& other)
- : id_(other.id_),
- user_email_(other.user_email_),
- account_type_(other.account_type_) {}
+ : gaia_id_(other.gaia_id_), user_email_(other.user_email_) {}
bool AccountId::operator==(const AccountId& other) const {
- if (this == &other)
- return true;
- if (account_type_ == AccountType::UNKNOWN ||
- other.account_type_ == AccountType::UNKNOWN)
- return user_email_ == other.user_email_;
- if (account_type_ != other.account_type_)
- return false;
- switch (account_type_) {
- case AccountType::GOOGLE:
- return (id_ == other.id_ && user_email_ == other.user_email_) ||
- (!id_.empty() && id_ == other.id_) ||
- (!user_email_.empty() && user_email_ == other.user_email_);
- case AccountType::ACTIVE_DIRECTORY:
- return id_ == other.id_ && user_email_ == other.user_email_;
- default:
- NOTREACHED() << "Unknown account type";
- }
- return false;
+ return (this == &other) ||
+ (gaia_id_ == other.gaia_id_ && user_email_ == other.user_email_) ||
+ (!gaia_id_.empty() && gaia_id_ == other.gaia_id_) ||
+ (!user_email_.empty() && user_email_ == other.user_email_);
}
bool AccountId::operator!=(const AccountId& other) const {
@@ -95,70 +81,45 @@
}
bool AccountId::empty() const {
- return id_.empty() && user_email_.empty() &&
- account_type_ == AccountType::UNKNOWN;
+ return gaia_id_.empty() && user_email_.empty();
}
bool AccountId::is_valid() const {
- switch (account_type_) {
- case AccountType::GOOGLE:
- return /* !id_.empty() && */ !user_email_.empty();
- case AccountType::ACTIVE_DIRECTORY:
- return !id_.empty() && !user_email_.empty();
- case AccountType::UNKNOWN:
- return id_.empty() && !user_email_.empty();
- }
- NOTREACHED();
- return false;
+ return /* !gaia_id_.empty() && */ !user_email_.empty();
}
void AccountId::clear() {
- id_.clear();
+ gaia_id_.clear();
user_email_.clear();
- account_type_ = AccountType::UNKNOWN;
}
-AccountType AccountId::GetAccountType() const {
- return account_type_;
+const std::string& AccountId::GetAccountType() const {
+ return GoogleStringSingleton::GetInstance()->google;
}
const std::string& AccountId::GetGaiaId() const {
- if (account_type_ != AccountType::GOOGLE)
- NOTIMPLEMENTED() << "Failed to get gaia_id for non-Google account.";
- return id_;
-}
-
-const std::string& AccountId::GetObjGuid() const {
- if (account_type_ != AccountType::ACTIVE_DIRECTORY)
- NOTIMPLEMENTED()
- << "Failed to get obj_guid for non-Active Directory account.";
- return id_;
+ return gaia_id_;
}
const std::string& AccountId::GetUserEmail() const {
return user_email_;
}
-bool AccountId::HasAccountIdKey() const {
- return account_type_ != AccountType::UNKNOWN && !id_.empty();
+const std::string AccountId::GetAccountIdKey() const {
+#ifdef NDEBUG
+ if (gaia_id_.empty())
+ LOG(FATAL) << "GetAccountIdKey(): no gaia id for " << Serialize();
+
+#else
+ CHECK(!gaia_id_.empty());
+#endif
+
+ return std::string(kKeyGaiaIdPrefix) + gaia_id_;
}
-const std::string AccountId::GetAccountIdKey() const {
-#ifdef NDEBUG
- if (id_.empty())
- LOG(FATAL) << "GetAccountIdKey(): no id for " << Serialize();
-#else
- CHECK(!id_.empty());
-#endif
- switch (GetAccountType()) {
- case AccountType::GOOGLE:
- return std::string(kKeyGaiaIdPrefix) + id_;
- case AccountType::ACTIVE_DIRECTORY:
- return std::string(kKeyAdIdPrefix) + id_;
- default:
- NOTREACHED() << "Unknown account type";
- }
- return std::string();
+void AccountId::SetGaiaId(const std::string& gaia_id) {
+ DCHECK(!gaia_id.empty());
+ gaia_id_ = gaia_id;
}
void AccountId::SetUserEmail(const std::string& email) {
@@ -169,74 +130,24 @@
// static
AccountId AccountId::FromUserEmail(const std::string& email) {
// TODO(alemate): DCHECK(!email.empty());
- return AccountId(std::string() /* id */, email, AccountType::UNKNOWN);
+ return AccountId(std::string() /* gaia_id */, email);
}
-// static
AccountId AccountId::FromGaiaId(const std::string& gaia_id) {
DCHECK(!gaia_id.empty());
- return AccountId(gaia_id, std::string() /* email */, AccountType::GOOGLE);
+ return AccountId(gaia_id, std::string() /* email */);
}
// static
AccountId AccountId::FromUserEmailGaiaId(const std::string& email,
const std::string& gaia_id) {
DCHECK(!(email.empty() && gaia_id.empty()));
- return AccountId(gaia_id, email, AccountType::GOOGLE);
-}
-
-// static
-AccountId AccountId::AdFromUserEmailObjGuid(const std::string& email,
- const std::string& obj_guid) {
- DCHECK(!email.empty() && !obj_guid.empty());
- return AccountId(obj_guid, email, AccountType::ACTIVE_DIRECTORY);
-}
-
-// static
-AccountId AccountId::AdFromObjGuid(const std::string& obj_guid) {
- DCHECK(!obj_guid.empty());
- return AccountId(obj_guid, std::string() /* email */,
- AccountType::ACTIVE_DIRECTORY);
-}
-
-// static
-AccountType AccountId::StringToAccountType(
- const std::string& account_type_string) {
- if (account_type_string == kGoogle)
- return AccountType::GOOGLE;
- if (account_type_string == kAd)
- return AccountType::ACTIVE_DIRECTORY;
- NOTREACHED() << "Unknown account type " << account_type_string;
- return AccountType::UNKNOWN;
-}
-
-// static
-std::string AccountId::AccountTypeToString(const AccountType& account_type) {
- switch (account_type) {
- case AccountType::GOOGLE:
- return kGoogle;
- case AccountType::ACTIVE_DIRECTORY:
- return kAd;
- default:
- NOTREACHED() << "Unknown account type";
- }
- return std::string();
+ return AccountId(gaia_id, email);
}
std::string AccountId::Serialize() const {
base::DictionaryValue value;
- switch (GetAccountType()) {
- case AccountType::UNKNOWN:
- case AccountType::GOOGLE:
- value.SetString(kGaiaIdKey, id_);
- value.SetString(kAccountTypeKey,
- AccountTypeToString(AccountType::GOOGLE));
- break;
- case AccountType::ACTIVE_DIRECTORY:
- value.SetString(kObjGuid, id_);
- value.SetString(kAccountTypeKey, AccountTypeToString(GetAccountType()));
- break;
- }
+ value.SetString(kGaiaIdKey, gaia_id_);
value.SetString(kEmailKey, user_email_);
std::string serialized;
@@ -256,62 +167,23 @@
std::string gaia_id;
std::string user_email;
- std::string obj_guid;
- std::string account_type_string;
- AccountType account_type = AccountType::GOOGLE;
const bool found_gaia_id = dictionary_value->GetString(kGaiaIdKey, &gaia_id);
const bool found_user_email =
dictionary_value->GetString(kEmailKey, &user_email);
- const bool found_obj_guid = dictionary_value->GetString(kObjGuid, &obj_guid);
- const bool found_account_type =
- dictionary_value->GetString(kAccountTypeKey, &account_type_string);
- if (found_account_type)
- account_type = StringToAccountType(account_type_string);
- switch (account_type) {
- case AccountType::GOOGLE:
- if (found_obj_guid)
- LOG(ERROR) << "AccountType is 'google' but obj_guid is found in '"
- << serialized << "'";
+ if (!found_gaia_id)
+ LOG(ERROR) << "gaia_id is not found in '" << serialized << "'";
- if (!found_gaia_id)
- LOG(ERROR) << "gaia_id is not found in '" << serialized << "'";
+ if (!found_user_email)
+ LOG(ERROR) << "user_email is not found in '" << serialized << "'";
- if (!found_user_email)
- LOG(ERROR) << "user_email is not found in '" << serialized << "'";
+ if (!found_gaia_id && !found_user_email)
+ return false;
- if (!found_gaia_id && !found_user_email)
- return false;
+ *account_id = FromUserEmailGaiaId(user_email, gaia_id);
- *account_id = FromUserEmailGaiaId(user_email, gaia_id);
- return true;
-
- case AccountType::ACTIVE_DIRECTORY:
- if (found_gaia_id)
- LOG(ERROR)
- << "AccountType is 'active directory' but gaia_id is found in '"
- << serialized << "'";
-
- if (!found_obj_guid) {
- LOG(ERROR) << "obj_guid is not found in '" << serialized << "'";
- return false;
- }
-
- if (!found_user_email) {
- LOG(ERROR) << "user_email is not found in '" << serialized << "'";
- }
-
- if (!found_obj_guid || !found_user_email)
- return false;
-
- *account_id = AdFromUserEmailObjGuid(user_email, obj_guid);
- return true;
-
- default:
- NOTREACHED() << "Unknown account type";
- return false;
- }
+ return true;
}
const AccountId& EmptyAccountId() {
« no previous file with comments | « components/signin/core/account_id/account_id.h ('k') | components/user_manager/known_user.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698