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

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

Issue 1440583002: This CL replaces e-mail with AccountId on user selection screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. Created 5 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
« no previous file with comments | « components/signin/core/account_id/account_id.h ('k') | components/user_manager/empty_user_info.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 65b237fa2758b5c19d604db08dc0259f9b0338c2..e933f4b571b0839b9b40fc2ad8b58b36db4cf93f 100644
--- a/components/signin/core/account_id/account_id.cc
+++ b/components/signin/core/account_id/account_id.cc
@@ -6,7 +6,10 @@
#include <functional>
+#include "base/json/json_reader.h"
+#include "base/json/json_writer.h"
#include "base/memory/singleton.h"
+#include "base/values.h"
#include "google_apis/gaia/gaia_auth_util.h"
namespace {
@@ -14,6 +17,10 @@ namespace {
// Known account types.
const char kGoogle[] = "google";
+// Serialization keys
+const char kGaiaIdKey[] = "gaia_id";
+const char kEmailKey[] = "email";
+
struct GoogleStringSingleton {
GoogleStringSingleton() : google(kGoogle) {}
@@ -115,6 +122,47 @@ AccountId AccountId::FromUserEmailGaiaId(const std::string& email,
return AccountId(gaia_id, email);
}
+std::string AccountId::Serialize() const {
+ base::DictionaryValue value;
+ value.SetString(kGaiaIdKey, gaia_id_);
+ value.SetString(kEmailKey, user_email_);
+
+ std::string serialized;
+ base::JSONWriter::Write(value, &serialized);
+ return serialized;
+}
+
+// static
+bool AccountId::Deserialize(const std::string& serialized,
+ AccountId* account_id) {
+ base::JSONReader reader;
+ scoped_ptr<const base::Value> value(reader.Read(serialized));
+ const base::DictionaryValue* dictionary_value = NULL;
+
+ if (!value || !value->GetAsDictionary(&dictionary_value))
+ return false;
+
+ std::string gaia_id;
+ std::string user_email;
+
+ const bool found_gaia_id = dictionary_value->GetString(kGaiaIdKey, &gaia_id);
+ const bool found_user_email =
+ dictionary_value->GetString(kEmailKey, &user_email);
+
+ 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_gaia_id && !found_user_email)
+ return false;
+
+ *account_id = FromUserEmailGaiaId(user_email, gaia_id);
+
+ return true;
+}
+
const AccountId& EmptyAccountId() {
return AccountId::EmptyAccountId::GetInstance()->user_id;
}
« no previous file with comments | « components/signin/core/account_id/account_id.h ('k') | components/user_manager/empty_user_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698