summaryrefslogtreecommitdiffstats
path: root/components/signin
diff options
context:
space:
mode:
authorhcarmona <hcarmona@chromium.org>2015-11-18 13:52:58 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-18 21:53:40 +0000
commitb1723ed336199cc11039ca4a2746e20a7ebc3e9a (patch)
tree5d43b68625f109e871af91d89621c284db0ddb2f /components/signin
parenta962c414a493e21c092c1d8a9a649048c6f028eb (diff)
downloadchromium_src-b1723ed336199cc11039ca4a2746e20a7ebc3e9a.zip
chromium_src-b1723ed336199cc11039ca4a2746e20a7ebc3e9a.tar.gz
chromium_src-b1723ed336199cc11039ca4a2746e20a7ebc3e9a.tar.bz2
Reland of This CL replaces e-mail with AccountId on user selection screen. (patchset #1 id:1 of https://codereview.chromium.org/1454153002/ )
Reason for revert: This did not fix issues, reverting the revert. Original issue's description: > Revert of This CL replaces e-mail with AccountId on user selection screen. (patchset #12 id:220001 of https://codereview.chromium.org/1440583002/ ) > > Reason for revert: > Suspecting this CL for introducing failures on Mac 10.10 Release (ATI) > > First failure: https://build.chromium.org/p/chromium.gpu/builders/Mac%2010.10%20Release%20%28ATI%29/builds/8148 > > Failing tests: > CastStreamingApiTestWithPixelOutput.EndToEnd > TabCaptureApiPixelTest.EndToEndThroughWebRTC > TabCaptureApiPixelTest.EndToEndWithoutRemoting > > Please update tests. > > Original issue's description: > > This CL replaces e-mail with AccountId on user selection screen. > > > > This CL replaces e-mail with serialized AccountId on user selection screen. > > It also adds simple AccountId Serialize/Deserialize methods suitable for > > passing AccountId to JS code. > > > > This is part of transition to AccountId. > > > > BUG=462823, 552034 > > TEST=manual > > > > Committed: https://crrev.com/1e24fe57a4ca921355bb1506f5a79627647a8c16 > > Cr-Commit-Position: refs/heads/master@{#360319} > > TBR=dzhioev@chromium.org,rogerta@chromium.org,stevenjb@chromium.org,oshima@chromium.org,alemate@chromium.org > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=462823, 552034 > > Committed: https://crrev.com/dede4c3836de2dddda5a484f098bba7152a6779b > Cr-Commit-Position: refs/heads/master@{#360369} TBR=dzhioev@chromium.org,rogerta@chromium.org,stevenjb@chromium.org,oshima@chromium.org,alemate@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=462823, 552034 Review URL: https://codereview.chromium.org/1455263002 Cr-Commit-Position: refs/heads/master@{#360423}
Diffstat (limited to 'components/signin')
-rw-r--r--components/signin/core/account_id/account_id.cc48
-rw-r--r--components/signin/core/account_id/account_id.h9
2 files changed, 55 insertions, 2 deletions
diff --git a/components/signin/core/account_id/account_id.cc b/components/signin/core/account_id/account_id.cc
index 65b237f..e933f4b 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;
}
diff --git a/components/signin/core/account_id/account_id.h b/components/signin/core/account_id/account_id.h
index 73be450..9f72030 100644
--- a/components/signin/core/account_id/account_id.h
+++ b/components/signin/core/account_id/account_id.h
@@ -45,8 +45,13 @@ class AccountId {
static AccountId FromUserEmailGaiaId(const std::string& user_email,
const std::string& gaia_id);
- // std::string Serialize() const;
- // static AccountId Deserialize(const std::string& serialized);
+ // These are (for now) unstable and cannot be used to store serialized data to
+ // persistent storage. Only in-memory storage is safe.
+ // Serialize() returns JSON dictionary,
+ // Deserialize() restores AccountId after serialization.
+ std::string Serialize() const;
+ static bool Deserialize(const std::string& serialized,
+ AccountId* out_account_id);
private:
AccountId();