summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authoralemate <alemate@chromium.org>2015-11-18 02:46:19 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-18 10:47:09 +0000
commit1e24fe57a4ca921355bb1506f5a79627647a8c16 (patch)
tree3b0c77c133379b2bd54a4a42a21f777c92a32015 /components
parenta370ef52788ea0f6c410b05ec40a74ee9bf3a647 (diff)
downloadchromium_src-1e24fe57a4ca921355bb1506f5a79627647a8c16.zip
chromium_src-1e24fe57a4ca921355bb1506f5a79627647a8c16.tar.gz
chromium_src-1e24fe57a4ca921355bb1506f5a79627647a8c16.tar.bz2
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 Review URL: https://codereview.chromium.org/1440583002 Cr-Commit-Position: refs/heads/master@{#360319}
Diffstat (limited to 'components')
-rw-r--r--components/login.gypi1
-rw-r--r--components/login/BUILD.gn1
-rw-r--r--components/login/DEPS1
-rw-r--r--components/login/base_screen_handler_utils.cc23
-rw-r--r--components/login/base_screen_handler_utils.h20
-rw-r--r--components/signin/core/account_id/account_id.cc48
-rw-r--r--components/signin/core/account_id/account_id.h9
-rw-r--r--components/user_manager/empty_user_info.cc2
-rw-r--r--components/user_manager/empty_user_info.h2
-rw-r--r--components/user_manager/user.cc5
-rw-r--r--components/user_manager/user.h2
-rw-r--r--components/user_manager/user_info.h2
-rw-r--r--components/user_manager/user_info_impl.cc10
-rw-r--r--components/user_manager/user_info_impl.h4
-rw-r--r--components/user_manager/user_manager_base.cc52
-rw-r--r--components/user_manager/user_manager_base.h10
16 files changed, 155 insertions, 37 deletions
diff --git a/components/login.gypi b/components/login.gypi
index e8a6bb1..ac66212 100644
--- a/components/login.gypi
+++ b/components/login.gypi
@@ -8,6 +8,7 @@
'type': '<(component)',
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
+ '<(DEPTH)/components/components.gyp:signin_core_account_id',
'<(DEPTH)/ui/base/ui_base.gyp:ui_base',
],
'export_dependent_settings': [
diff --git a/components/login/BUILD.gn b/components/login/BUILD.gn
index 26a2868..8d20888 100644
--- a/components/login/BUILD.gn
+++ b/components/login/BUILD.gn
@@ -16,6 +16,7 @@ component("login") {
deps = [
"//ui/base",
+ "//components/signin/core/account_id",
]
public_deps = [
diff --git a/components/login/DEPS b/components/login/DEPS
index 6df15b8..da38c4d 100644
--- a/components/login/DEPS
+++ b/components/login/DEPS
@@ -1,3 +1,4 @@
include_rules = [
+ "+components/signin/core/account_id/account_id.h",
"+ui/base/l10n"
]
diff --git a/components/login/base_screen_handler_utils.cc b/components/login/base_screen_handler_utils.cc
index 6454cdf..fd977a3 100644
--- a/components/login/base_screen_handler_utils.cc
+++ b/components/login/base_screen_handler_utils.cc
@@ -4,6 +4,8 @@
#include "components/login/base_screen_handler_utils.h"
+#include "components/signin/core/account_id/account_id.h"
+
namespace login {
namespace {
@@ -56,6 +58,20 @@ bool ParseValue(const base::Value* value, String16List* out_value) {
return ParseStringList(value, out_value);
}
+bool ParseValue(const base::Value* value, AccountId* out_value) {
+ std::string serialized;
+ const bool has_string = value->GetAsString(&serialized);
+ if (!has_string)
+ return false;
+
+ if (AccountId::Deserialize(serialized, out_value))
+ return true;
+
+ LOG(ERROR) << "Failed to deserialize '" << serialized << "'";
+ *out_value = AccountId::FromUserEmail(serialized);
+ return true;
+}
+
base::FundamentalValue MakeValue(bool v) {
return base::FundamentalValue(v);
}
@@ -76,4 +92,11 @@ base::StringValue MakeValue(const base::string16& v) {
return base::StringValue(v);
}
+base::StringValue MakeValue(const AccountId& v) {
+ return base::StringValue(v.Serialize());
+}
+
+ParsedValueContainer<AccountId>::ParsedValueContainer() {
+}
+
} // namespace login
diff --git a/components/login/base_screen_handler_utils.h b/components/login/base_screen_handler_utils.h
index 71d2e7f..7d884d2 100644
--- a/components/login/base_screen_handler_utils.h
+++ b/components/login/base_screen_handler_utils.h
@@ -14,6 +14,7 @@
#include "base/tuple.h"
#include "base/values.h"
#include "components/login/login_export.h"
+#include "components/signin/core/account_id/account_id.h"
namespace login {
@@ -40,6 +41,7 @@ bool LOGIN_EXPORT ParseValue(const base::Value* value,
const base::DictionaryValue** out_value);
bool LOGIN_EXPORT ParseValue(const base::Value* value, StringList* out_value);
bool LOGIN_EXPORT ParseValue(const base::Value* value, String16List* out_value);
+bool LOGIN_EXPORT ParseValue(const base::Value* value, AccountId* out_value);
template <typename T>
inline bool GetArg(const base::ListValue* args, size_t index, T* out_value) {
@@ -54,17 +56,29 @@ base::FundamentalValue LOGIN_EXPORT MakeValue(int v);
base::FundamentalValue LOGIN_EXPORT MakeValue(double v);
base::StringValue LOGIN_EXPORT MakeValue(const std::string& v);
base::StringValue LOGIN_EXPORT MakeValue(const base::string16& v);
+base::StringValue LOGIN_EXPORT MakeValue(const AccountId& v);
template <typename T>
inline const T& MakeValue(const T& v) {
return v;
}
+template <typename T>
+struct ParsedValueContainer {
+ T value;
+};
+
+template <>
+struct LOGIN_EXPORT ParsedValueContainer<AccountId> {
+ ParsedValueContainer();
+ AccountId value = EmptyAccountId();
+};
+
template <typename Arg, size_t index>
typename UnwrapConstRef<Arg>::Type ParseArg(const base::ListValue* args) {
- typename UnwrapConstRef<Arg>::Type parsed;
- CHECK(GetArg(args, index, &parsed));
- return parsed;
+ ParsedValueContainer<typename UnwrapConstRef<Arg>::Type> parsed;
+ CHECK(GetArg(args, index, &parsed.value));
+ return parsed.value;
}
template <typename... Args, size_t... Ns>
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();
diff --git a/components/user_manager/empty_user_info.cc b/components/user_manager/empty_user_info.cc
index 08d4a19..07b4087 100644
--- a/components/user_manager/empty_user_info.cc
+++ b/components/user_manager/empty_user_info.cc
@@ -31,7 +31,7 @@ std::string EmptyUserInfo::GetEmail() const {
return std::string();
}
-AccountId EmptyUserInfo::GetAccountId() const {
+const AccountId& EmptyUserInfo::GetAccountId() const {
NOTIMPLEMENTED();
return EmptyAccountId();
}
diff --git a/components/user_manager/empty_user_info.h b/components/user_manager/empty_user_info.h
index 76c0d16..5fb41c9 100644
--- a/components/user_manager/empty_user_info.h
+++ b/components/user_manager/empty_user_info.h
@@ -25,7 +25,7 @@ class USER_MANAGER_EXPORT EmptyUserInfo : public UserInfo {
base::string16 GetDisplayName() const override;
base::string16 GetGivenName() const override;
std::string GetEmail() const override;
- AccountId GetAccountId() const override;
+ const AccountId& GetAccountId() const override;
const gfx::ImageSkia& GetImage() const override;
private:
diff --git a/components/user_manager/user.cc b/components/user_manager/user.cc
index 39ef430..3ead416 100644
--- a/components/user_manager/user.cc
+++ b/components/user_manager/user.cc
@@ -123,9 +123,8 @@ const gfx::ImageSkia& User::GetImage() const {
return user_image_.image();
}
-AccountId User::GetAccountId() const {
- return AccountId::FromUserEmail(
- gaia::CanonicalizeEmail(gaia::SanitizeEmail(email())));
+const AccountId& User::GetAccountId() const {
+ return account_id_;
}
void User::SetIsChild(bool is_child) {
diff --git a/components/user_manager/user.h b/components/user_manager/user.h
index fe0899e..71d7016 100644
--- a/components/user_manager/user.h
+++ b/components/user_manager/user.h
@@ -97,7 +97,7 @@ class USER_MANAGER_EXPORT User : public UserInfo {
base::string16 GetDisplayName() const override;
base::string16 GetGivenName() const override;
const gfx::ImageSkia& GetImage() const override;
- AccountId GetAccountId() const override;
+ const AccountId& GetAccountId() const override;
// Allows managing child status of the user. Used for RegularUser.
virtual void SetIsChild(bool is_child);
diff --git a/components/user_manager/user_info.h b/components/user_manager/user_info.h
index 2f0cf19..6a692d6 100644
--- a/components/user_manager/user_info.h
+++ b/components/user_manager/user_info.h
@@ -36,7 +36,7 @@ class USER_MANAGER_EXPORT UserInfo {
virtual std::string GetEmail() const = 0;
// Returns AccountId for the user.
- virtual AccountId GetAccountId() const = 0;
+ virtual const AccountId& GetAccountId() const = 0;
// Gets the avatar image for the user.
virtual const gfx::ImageSkia& GetImage() const = 0;
diff --git a/components/user_manager/user_info_impl.cc b/components/user_manager/user_info_impl.cc
index cf6d2ad..afb2e9d 100644
--- a/components/user_manager/user_info_impl.cc
+++ b/components/user_manager/user_info_impl.cc
@@ -10,8 +10,8 @@
namespace user_manager {
-UserInfoImpl::UserInfoImpl() {
-}
+UserInfoImpl::UserInfoImpl()
+ : account_id_(AccountId::FromUserEmail("stub-user@domain.com")) {}
UserInfoImpl::~UserInfoImpl() {
}
@@ -25,11 +25,11 @@ base::string16 UserInfoImpl::GetGivenName() const {
}
std::string UserInfoImpl::GetEmail() const {
- return "stub-user@domain.com";
+ return account_id_.GetUserEmail();
}
-AccountId UserInfoImpl::GetAccountId() const {
- return AccountId::FromUserEmail(GetEmail());
+const AccountId& UserInfoImpl::GetAccountId() const {
+ return account_id_;
}
const gfx::ImageSkia& UserInfoImpl::GetImage() const {
diff --git a/components/user_manager/user_info_impl.h b/components/user_manager/user_info_impl.h
index 4922e36..d2733eb 100644
--- a/components/user_manager/user_info_impl.h
+++ b/components/user_manager/user_info_impl.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/strings/string16.h"
+#include "components/signin/core/account_id/account_id.h"
#include "components/user_manager/user_info.h"
#include "components/user_manager/user_manager_export.h"
#include "ui/gfx/image/image_skia.h"
@@ -24,10 +25,11 @@ class USER_MANAGER_EXPORT UserInfoImpl : public UserInfo {
base::string16 GetDisplayName() const override;
base::string16 GetGivenName() const override;
std::string GetEmail() const override;
- AccountId GetAccountId() const override;
+ const AccountId& GetAccountId() const override;
const gfx::ImageSkia& GetImage() const override;
private:
+ const AccountId account_id_;
gfx::ImageSkia user_image_;
DISALLOW_COPY_AND_ASSIGN(UserInfoImpl);
diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc
index 81a68ff..f51d9b1 100644
--- a/components/user_manager/user_manager_base.cc
+++ b/components/user_manager/user_manager_base.cc
@@ -120,13 +120,13 @@ bool UserMatches(const AccountId& account_id,
const base::DictionaryValue& dict) {
std::string value;
- bool has_email = dict.GetString(kCanonicalEmail, &value);
- if (has_email && account_id.GetUserEmail() == value)
+ // TODO(alemate): update code once user id is really a struct.
+ bool has_gaia_id = dict.GetString(kGAIAIdKey, &value);
+ if (has_gaia_id && account_id.GetGaiaId() == value)
return true;
- // TODO(antrim): update code once user id is really a struct.
- bool has_gaia_id = dict.GetString(kGAIAIdKey, &value);
- if (has_gaia_id && account_id.GetUserEmail() == value)
+ bool has_email = dict.GetString(kCanonicalEmail, &value);
+ if (has_email && account_id.GetUserEmail() == value)
return true;
return false;
@@ -582,7 +582,6 @@ void UserManagerBase::UpdateUserAccountData(
UpdateUserAccountLocale(account_id, account_data.locale());
}
-// static
void UserManagerBase::ParseUserList(const base::ListValue& users_list,
const std::set<AccountId>& existing_users,
std::vector<AccountId>* users_vector,
@@ -595,7 +594,21 @@ void UserManagerBase::ParseUserList(const base::ListValue& users_list,
LOG(ERROR) << "Corrupt entry in user list at index " << i << ".";
continue;
}
- const AccountId account_id(AccountId::FromUserEmail(email));
+
+ const AccountId partial_account_id = AccountId::FromUserEmail(email);
+ AccountId account_id = EmptyAccountId();
+
+ const bool lookup_result =
+ GetKnownUserAccountId(partial_account_id, &account_id);
+ // TODO(alemate):
+ // DCHECK(lookup_result) << "KnownUser lookup falied for '" << email << "'";
+ // (tests do not initialize KnownUserData)
+
+ if (!lookup_result) {
+ account_id = partial_account_id;
+ LOG(WARNING) << "KnownUser lookup falied for '" << email << "'";
+ }
+
if (existing_users.find(account_id) != existing_users.end() ||
!users_set->insert(account_id).second) {
LOG(ERROR) << "Duplicate user: " << email;
@@ -849,6 +862,7 @@ void UserManagerBase::EnsureUsersLoaded() {
ChangeUserChildStatus(user, true /* is child */);
}
}
+ const AccountId account_id = user->GetAccountId();
user->set_oauth_token_status(LoadUserOAuthStatus(*it));
user->set_force_online_signin(LoadForceOnlineSignin(*it));
user->set_using_saml(FindUsingSAML(*it));
@@ -1152,15 +1166,25 @@ void UserManagerBase::SetKnownUserIntegerPref(const AccountId& account_id,
bool UserManagerBase::GetKnownUserAccountId(
const AccountId& authenticated_account_id,
AccountId* out_account_id) {
- DCHECK(!authenticated_account_id.GetGaiaId().empty());
- std::string canonical_email;
- if (!GetKnownUserStringPref(
- AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()),
- kCanonicalEmail, &canonical_email))
+ if (!authenticated_account_id.GetGaiaId().empty()) {
+ std::string canonical_email;
+ if (!GetKnownUserStringPref(
+ AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()),
+ kCanonicalEmail, &canonical_email)) {
+ return false;
+ }
+
+ *out_account_id = AccountId::FromUserEmailGaiaId(
+ canonical_email, authenticated_account_id.GetGaiaId());
+ return true;
+ }
+ DCHECK(!authenticated_account_id.GetUserEmail().empty());
+ std::string gaia_id;
+ if (!GetKnownUserStringPref(authenticated_account_id, kGAIAIdKey, &gaia_id))
return false;
- *out_account_id = authenticated_account_id;
- out_account_id->SetUserEmail(canonical_email);
+ *out_account_id = AccountId::FromUserEmailGaiaId(
+ authenticated_account_id.GetUserEmail(), gaia_id);
return true;
}
diff --git a/components/user_manager/user_manager_base.h b/components/user_manager/user_manager_base.h
index ead7d44..dd46c5d 100644
--- a/components/user_manager/user_manager_base.h
+++ b/components/user_manager/user_manager_base.h
@@ -154,13 +154,13 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
// TODO(xiyuan): Figure out a better way to expose this info.
virtual bool HasPendingBootstrap(const AccountId& account_id) const;
- // Helper function that copies users from |users_list| to |users_vector| and
+ // Helper function that converts users from |users_list| to |users_vector| and
// |users_set|. Duplicates and users already present in |existing_users| are
// skipped.
- static void ParseUserList(const base::ListValue& users_list,
- const std::set<AccountId>& existing_users,
- std::vector<AccountId>* users_vector,
- std::set<AccountId>* users_set);
+ void ParseUserList(const base::ListValue& users_list,
+ const std::set<AccountId>& existing_users,
+ std::vector<AccountId>* users_vector,
+ std::set<AccountId>* users_set);
// Returns true if trusted device policies have successfully been retrieved
// and ephemeral users are enabled.