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

Unified Diff: components/signin/core/account_id/account_id.cc

Issue 2519823006: Chromad: Add authentication flow (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/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 00ceb2e2f52bf9f5225ca76c4af50f99e0f58105..8cc61611e6950fa840b88db3c3fa36cc4966fd29 100644
--- a/components/signin/core/account_id/account_id.cc
+++ b/components/signin/core/account_id/account_id.cc
@@ -16,28 +16,21 @@
namespace {
-// Known account types.
-const char kGoogle[] = "google";
-
// Serialization keys
const char kGaiaIdKey[] = "gaia_id";
const char kEmailKey[] = "email";
+const char kAccountTypeKey[] = "account_type";
// Prefix for GetAccountIdKey().
const char kKeyGaiaIdPrefix[] = "g-";
-
-struct GoogleStringSingleton {
- GoogleStringSingleton() : google(kGoogle) {}
-
- static GoogleStringSingleton* GetInstance() {
- return base::Singleton<GoogleStringSingleton>::get();
- }
-
- const std::string google;
-};
+const char kKeyAdIdPrefix[] = "a-";
} // anonymous namespace
+const std::string AccountId::kGoogle = "google";
+// TODO(rsorokin): Fix account id after migration. (see crbug.com/668130).
+const std::string AccountId::kAd = "ad";
+
struct AccountId::EmptyAccountId {
EmptyAccountId() : user_id() {}
const AccountId user_id;
@@ -62,7 +55,9 @@ AccountId::AccountId(const std::string& gaia_id, const std::string& user_email)
}
AccountId::AccountId(const AccountId& other)
- : gaia_id_(other.gaia_id_), user_email_(other.user_email_) {}
+ : gaia_id_(other.gaia_id_),
+ user_email_(other.user_email_),
+ account_type_(other.account_type_) {}
bool AccountId::operator==(const AccountId& other) const {
return (this == &other) ||
@@ -94,7 +89,7 @@ void AccountId::clear() {
}
const std::string& AccountId::GetAccountType() const {
- return GoogleStringSingleton::GetInstance()->google;
+ return account_type_;
}
const std::string& AccountId::GetGaiaId() const {
@@ -114,7 +109,13 @@ const std::string AccountId::GetAccountIdKey() const {
CHECK(!gaia_id_.empty());
#endif
- return std::string(kKeyGaiaIdPrefix) + gaia_id_;
+ if (GetAccountType() == kGoogle)
+ return std::string(kKeyGaiaIdPrefix) + gaia_id_;
+ else if (GetAccountType() == kAd)
+ return std::string(kKeyAdIdPrefix) + gaia_id_;
+ else
+ LOG(FATAL) << "Unknown account type " << GetAccountType();
+ return std::string();
}
void AccountId::SetGaiaId(const std::string& gaia_id) {
@@ -127,6 +128,11 @@ void AccountId::SetUserEmail(const std::string& email) {
user_email_ = email;
}
+void AccountId::SetAccountType(const std::string& account_type) {
+ DCHECK(account_type == kAd || account_type == kGoogle);
+ account_type_ = account_type;
+}
+
// static
AccountId AccountId::FromUserEmail(const std::string& email) {
// TODO(alemate): DCHECK(!email.empty());
@@ -149,6 +155,7 @@ std::string AccountId::Serialize() const {
base::DictionaryValue value;
value.SetString(kGaiaIdKey, gaia_id_);
value.SetString(kEmailKey, user_email_);
+ value.SetString(kAccountTypeKey, account_type_);
std::string serialized;
base::JSONWriter::Write(value, &serialized);
@@ -167,6 +174,7 @@ bool AccountId::Deserialize(const std::string& serialized,
std::string gaia_id;
std::string user_email;
+ std::string account_type = kGoogle;
const bool found_gaia_id = dictionary_value->GetString(kGaiaIdKey, &gaia_id);
const bool found_user_email =
@@ -182,6 +190,8 @@ bool AccountId::Deserialize(const std::string& serialized,
return false;
*account_id = FromUserEmailGaiaId(user_email, gaia_id);
Alexander Alekseev 2016/11/24 07:12:40 Could you just add function "FromAccountTypeUserEm
Roman Sorokin (ftl) 2016/12/02 12:35:12 Done.
+ if (dictionary_value->GetString(kAccountTypeKey, &account_type))
+ account_id->SetAccountType(account_type);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698