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

Unified Diff: components/user_manager/user_manager_base.cc

Issue 1412813003: This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Rebased. Created 5 years, 2 months 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/user_manager/user_manager_base.cc
diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc
index 3bcb61c23916808a9bcee2b29a79b2531b75c363..b0e3e20dbca1cb9f930c3f61abca0614322c7c03 100644
--- a/components/user_manager/user_manager_base.cc
+++ b/components/user_manager/user_manager_base.cc
@@ -116,24 +116,24 @@ void ResolveLocale(const std::string& raw_locale,
}
// Checks if values in |dict| correspond with |user_id| identity.
-bool UserMatches(const UserID& user_id, const base::DictionaryValue& dict) {
+bool UserMatches(const AccountId& user_id, const base::DictionaryValue& dict) {
std::string value;
bool has_email = dict.GetString(kCanonicalEmail, &value);
- if (has_email && user_id == value)
+ if (has_email && user_id.GetUserEmail() == 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 && user_id == value)
+ if (has_gaia_id && user_id.GetUserEmail() == value)
return true;
return false;
}
// Fills relevant |dict| values based on |user_id|.
-void UpdateIdentity(const UserID& user_id, base::DictionaryValue& dict) {
- dict.SetString(kCanonicalEmail, user_id);
+void UpdateIdentity(const AccountId& user_id, base::DictionaryValue& dict) {
+ dict.SetString(kCanonicalEmail, user_id.GetUserEmail());
}
} // namespace
@@ -163,7 +163,10 @@ UserManagerBase::UserManagerBase(
is_current_user_new_(false),
is_current_user_ephemeral_regular_user_(false),
ephemeral_users_enabled_(false),
+ owner_id_(EmptyAccountId()),
manager_creation_time_(base::TimeTicks::Now()),
+ pending_user_switch_(EmptyAccountId()),
+ last_session_active_user_(EmptyAccountId()),
last_session_active_user_initialized_(false),
task_runner_(task_runner),
blocking_task_runner_(blocking_task_runner),
@@ -201,17 +204,18 @@ const UserList& UserManagerBase::GetLRULoggedInUsers() const {
return lru_logged_in_users_;
}
-const std::string& UserManagerBase::GetOwnerEmail() const {
- return owner_email_;
+const AccountId& UserManagerBase::GetOwnerId() const {
achuithb 2015/10/23 00:08:52 GetOwnerAccountID?
Alexander Alekseev 2015/10/23 09:11:25 Done.
+ return owner_id_;
}
-void UserManagerBase::UserLoggedIn(const std::string& user_id,
+void UserManagerBase::UserLoggedIn(const AccountId& user_id,
const std::string& username_hash,
bool browser_restart) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
if (!last_session_active_user_initialized_) {
- last_session_active_user_ = GetLocalState()->GetString(kLastActiveUser);
+ last_session_active_user_ =
+ AccountId::FromUserEmail(GetLocalState()->GetString(kLastActiveUser));
last_session_active_user_initialized_ = true;
}
@@ -229,7 +233,7 @@ void UserManagerBase::UserLoggedIn(const std::string& user_id,
return;
}
- if (user_id == chromeos::login::kGuestUserName) {
+ if (user_id == chromeos::login::GuestAccountId()) {
GuestUserLoggedIn();
} else if (IsKioskApp(user_id)) {
KioskAppLoggedIn(user_id);
@@ -242,12 +246,12 @@ void UserManagerBase::UserLoggedIn(const std::string& user_id,
PublicAccountUserLoggedIn(user);
} else if ((user && user->GetType() == USER_TYPE_SUPERVISED) ||
(!user &&
- gaia::ExtractDomainName(user_id) ==
+ gaia::ExtractDomainName(user_id.GetUserEmail()) ==
chromeos::login::kSupervisedUserDomain)) {
SupervisedUserLoggedIn(user_id);
} else if (browser_restart && IsPublicAccountMarkedForRemoval(user_id)) {
PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id));
- } else if (user_id != GetOwnerEmail() && !user &&
+ } else if (user_id != GetOwnerId() && !user &&
(AreEphemeralUsersEnabled() || browser_restart)) {
RegularUserLoggedInAsEphemeral(user_id);
} else {
@@ -274,13 +278,14 @@ void UserManagerBase::UserLoggedIn(const std::string& user_id,
"UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES);
GetLocalState()->SetString(
- kLastLoggedInGaiaUser, active_user_->HasGaiaAccount() ? user_id : "");
+ kLastLoggedInGaiaUser,
+ active_user_->HasGaiaAccount() ? user_id.GetUserEmail() : "");
NotifyOnLogin();
PerformPostUserLoggedInActions(browser_restart);
}
-void UserManagerBase::SwitchActiveUser(const std::string& user_id) {
+void UserManagerBase::SwitchActiveUser(const AccountId& user_id) {
User* user = FindUserAndModify(user_id);
if (!user) {
NOTREACHED() << "Switching to a non-existing user";
@@ -320,7 +325,8 @@ void UserManagerBase::SwitchToLastActiveUser() {
if (last_session_active_user_.empty())
return;
- if (GetActiveUser()->email() != last_session_active_user_)
+ if (AccountId::FromUserEmail(GetActiveUser()->email()) !=
+ last_session_active_user_)
SwitchActiveUser(last_session_active_user_);
// Make sure that this function gets run only once.
@@ -341,7 +347,7 @@ void UserManagerBase::SessionStarted() {
}
}
-void UserManagerBase::RemoveUser(const std::string& user_id,
+void UserManagerBase::RemoveUser(const AccountId& user_id,
RemoveUserDelegate* delegate) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
@@ -351,36 +357,37 @@ void UserManagerBase::RemoveUser(const std::string& user_id,
RemoveUserInternal(user_id, delegate);
}
-void UserManagerBase::RemoveUserInternal(const std::string& user_email,
+void UserManagerBase::RemoveUserInternal(const AccountId& user_id,
RemoveUserDelegate* delegate) {
- RemoveNonOwnerUserInternal(user_email, delegate);
+ RemoveNonOwnerUserInternal(user_id, delegate);
}
-void UserManagerBase::RemoveNonOwnerUserInternal(const std::string& user_email,
+void UserManagerBase::RemoveNonOwnerUserInternal(const AccountId& user_id,
RemoveUserDelegate* delegate) {
if (delegate)
- delegate->OnBeforeUserRemoved(user_email);
- RemoveUserFromList(user_email);
+ delegate->OnBeforeUserRemoved(user_id.GetUserEmail());
+ RemoveUserFromList(user_id);
cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove(
- user_email, base::Bind(&OnRemoveUserComplete, user_email));
+ user_id.GetUserEmail(),
+ base::Bind(&OnRemoveUserComplete, user_id.GetUserEmail()));
if (delegate)
- delegate->OnUserRemoved(user_email);
+ delegate->OnUserRemoved(user_id.GetUserEmail());
}
-void UserManagerBase::RemoveUserFromList(const std::string& user_id) {
+void UserManagerBase::RemoveUserFromList(const AccountId& user_id) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
RemoveNonCryptohomeData(user_id);
if (user_loading_stage_ == STAGE_LOADED) {
DeleteUser(RemoveRegularOrSupervisedUserFromList(user_id));
} else if (user_loading_stage_ == STAGE_LOADING) {
- DCHECK(gaia::ExtractDomainName(user_id) ==
+ DCHECK(gaia::ExtractDomainName(user_id.GetUserEmail()) ==
chromeos::login::kSupervisedUserDomain ||
HasPendingBootstrap(user_id));
// Special case, removing partially-constructed supervised user or
// boostrapping user during user list loading.
ListPrefUpdate users_update(GetLocalState(), kRegularUsers);
- users_update->Remove(base::StringValue(user_id), NULL);
+ users_update->Remove(base::StringValue(user_id.GetUserEmail()), NULL);
OnUserRemoved(user_id);
} else {
NOTREACHED() << "Users are not loaded yet.";
@@ -391,20 +398,20 @@ void UserManagerBase::RemoveUserFromList(const std::string& user_id) {
GetLocalState()->CommitPendingWrite();
}
-bool UserManagerBase::IsKnownUser(const std::string& user_id) const {
+bool UserManagerBase::IsKnownUser(const AccountId& user_id) const {
return FindUser(user_id) != NULL;
}
-const User* UserManagerBase::FindUser(const std::string& user_id) const {
+const User* UserManagerBase::FindUser(const AccountId& user_id) const {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
- if (active_user_ && active_user_->email() == user_id)
+ if (active_user_ && active_user_->GetUserID() == user_id)
return active_user_;
return FindUserInList(user_id);
}
-User* UserManagerBase::FindUserAndModify(const std::string& user_id) {
+User* UserManagerBase::FindUserAndModify(const AccountId& user_id) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
- if (active_user_ && active_user_->email() == user_id)
+ if (active_user_ && active_user_->GetUserID() == user_id)
return active_user_;
return FindUserInListAndModify(user_id);
}
@@ -435,7 +442,7 @@ const User* UserManagerBase::GetPrimaryUser() const {
}
void UserManagerBase::SaveUserOAuthStatus(
- const std::string& user_id,
+ const AccountId& user_id,
User::OAuthTokenStatus oauth_token_status) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
@@ -452,11 +459,11 @@ void UserManagerBase::SaveUserOAuthStatus(
DictionaryPrefUpdate oauth_status_update(GetLocalState(),
kUserOAuthTokenStatus);
oauth_status_update->SetWithoutPathExpansion(
- user_id,
+ user_id.GetUserEmail(),
new base::FundamentalValue(static_cast<int>(oauth_token_status)));
}
-void UserManagerBase::SaveForceOnlineSignin(const std::string& user_id,
+void UserManagerBase::SaveForceOnlineSignin(const AccountId& user_id,
bool force_online_signin) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
@@ -467,11 +474,11 @@ void UserManagerBase::SaveForceOnlineSignin(const std::string& user_id,
DictionaryPrefUpdate force_online_update(GetLocalState(),
kUserForceOnlineSignin);
- force_online_update->SetBooleanWithoutPathExpansion(user_id,
+ force_online_update->SetBooleanWithoutPathExpansion(user_id.GetUserEmail(),
force_online_signin);
}
-void UserManagerBase::SaveUserDisplayName(const std::string& user_id,
+void UserManagerBase::SaveUserDisplayName(const AccountId& user_id,
const base::string16& display_name) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
@@ -484,24 +491,24 @@ void UserManagerBase::SaveUserDisplayName(const std::string& user_id,
DictionaryPrefUpdate display_name_update(GetLocalState(),
kUserDisplayName);
display_name_update->SetWithoutPathExpansion(
- user_id, new base::StringValue(display_name));
+ user_id.GetUserEmail(), new base::StringValue(display_name));
}
}
}
base::string16 UserManagerBase::GetUserDisplayName(
- const std::string& user_id) const {
+ const AccountId& user_id) const {
const User* user = FindUser(user_id);
return user ? user->display_name() : base::string16();
}
-void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id,
+void UserManagerBase::SaveUserDisplayEmail(const AccountId& user_id,
const std::string& display_email) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
User* user = FindUserAndModify(user_id);
if (!user) {
- LOG(ERROR) << "User not found: " << user_id;
+ LOG(ERROR) << "User not found: " << user_id.GetUserEmail();
return; // Ignore if there is no such user.
}
@@ -514,22 +521,22 @@ void UserManagerBase::SaveUserDisplayEmail(const std::string& user_id,
DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail);
display_email_update->SetWithoutPathExpansion(
- user_id, new base::StringValue(display_email));
+ user_id.GetUserEmail(), new base::StringValue(display_email));
}
std::string UserManagerBase::GetUserDisplayEmail(
- const std::string& user_id) const {
+ const AccountId& user_id) const {
const User* user = FindUser(user_id);
- return user ? user->display_email() : user_id;
+ return user ? user->display_email() : user_id.GetUserEmail();
}
-void UserManagerBase::SaveUserType(const std::string& user_id,
+void UserManagerBase::SaveUserType(const AccountId& user_id,
const UserType& user_type) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
User* user = FindUserAndModify(user_id);
if (!user) {
- LOG(ERROR) << "User not found: " << user_id;
+ LOG(ERROR) << "User not found: " << user_id.GetUserEmail();
return; // Ignore if there is no such user.
}
@@ -540,34 +547,35 @@ void UserManagerBase::SaveUserType(const std::string& user_id,
DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType);
user_type_update->SetWithoutPathExpansion(
- user_id, new base::FundamentalValue(static_cast<int>(user_type)));
+ user_id.GetUserEmail(),
+ new base::FundamentalValue(static_cast<int>(user_type)));
GetLocalState()->CommitPendingWrite();
}
-void UserManagerBase::UpdateUsingSAML(const std::string& user_id,
+void UserManagerBase::UpdateUsingSAML(const AccountId& user_id,
const bool using_saml) {
SetKnownUserBooleanPref(user_id, kUsingSAMLKey, using_saml);
}
-bool UserManagerBase::FindUsingSAML(const std::string& user_id) {
+bool UserManagerBase::FindUsingSAML(const AccountId& user_id) {
bool using_saml;
if (GetKnownUserBooleanPref(user_id, kUsingSAMLKey, &using_saml))
return using_saml;
return false;
}
-void UserManagerBase::UpdateReauthReason(const std::string& user_id,
+void UserManagerBase::UpdateReauthReason(const AccountId& user_id,
const int reauth_reason) {
SetKnownUserIntegerPref(user_id, kReauthReasonKey, reauth_reason);
}
-bool UserManagerBase::FindReauthReason(const std::string& user_id,
+bool UserManagerBase::FindReauthReason(const AccountId& user_id,
int* out_value) {
return GetKnownUserIntegerPref(user_id, kReauthReasonKey, out_value);
}
void UserManagerBase::UpdateUserAccountData(
- const std::string& user_id,
+ const AccountId& user_id,
const UserAccountData& account_data) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
@@ -579,7 +587,7 @@ void UserManagerBase::UpdateUserAccountData(
if (!IsUserNonCryptohomeDataEphemeral(user_id)) {
DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName);
given_name_update->SetWithoutPathExpansion(
- user_id, new base::StringValue(given_name));
+ user_id.GetUserEmail(), new base::StringValue(given_name));
}
}
@@ -588,9 +596,9 @@ void UserManagerBase::UpdateUserAccountData(
// static
void UserManagerBase::ParseUserList(const base::ListValue& users_list,
- const std::set<std::string>& existing_users,
- std::vector<std::string>* users_vector,
- std::set<std::string>* users_set) {
+ const std::set<AccountId>& existing_users,
+ std::vector<AccountId>* users_vector,
+ std::set<AccountId>* users_set) {
users_vector->clear();
users_set->clear();
for (size_t i = 0; i < users_list.GetSize(); ++i) {
@@ -599,12 +607,13 @@ void UserManagerBase::ParseUserList(const base::ListValue& users_list,
LOG(ERROR) << "Corrupt entry in user list at index " << i << ".";
continue;
}
- if (existing_users.find(email) != existing_users.end() ||
- !users_set->insert(email).second) {
+ const AccountId account_id(AccountId::FromUserEmail(email));
+ if (existing_users.find(account_id) != existing_users.end() ||
+ !users_set->insert(account_id).second) {
LOG(ERROR) << "Duplicate user: " << email;
continue;
}
- users_vector->push_back(email);
+ users_vector->push_back(account_id);
}
}
@@ -631,7 +640,7 @@ bool UserManagerBase::IsCurrentUserNew() const {
bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
return IsUserLoggedIn() &&
- IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->email());
+ IsUserNonCryptohomeDataEphemeral(GetLoggedInUser()->GetUserID());
}
bool UserManagerBase::CanCurrentUserLock() const {
@@ -687,16 +696,16 @@ bool UserManagerBase::IsSessionStarted() const {
}
bool UserManagerBase::IsUserNonCryptohomeDataEphemeral(
- const std::string& user_id) const {
+ const AccountId& user_id) const {
// Data belonging to the guest and stub users is always ephemeral.
- if (user_id == chromeos::login::kGuestUserName ||
- user_id == chromeos::login::kStubUser) {
+ if (user_id == chromeos::login::GuestAccountId() ||
+ user_id == chromeos::login::StubAccountId()) {
return true;
}
// Data belonging to the owner, anyone found on the user list and obsolete
// public accounts whose data has not been removed yet is not ephemeral.
- if (user_id == GetOwnerEmail() || UserExistsInList(user_id) ||
+ if (user_id == GetOwnerId() || UserExistsInList(user_id) ||
IsPublicAccountMarkedForRemoval(user_id)) {
return false;
}
@@ -706,7 +715,7 @@ bool UserManagerBase::IsUserNonCryptohomeDataEphemeral(
// policy was enabled.
// - or -
// b) The user logged into any other account type.
- if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->email()) &&
+ if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->GetUserID()) &&
(is_current_user_ephemeral_regular_user_ ||
!IsLoggedInAsUserWithGaiaAccount())) {
return true;
@@ -786,19 +795,19 @@ void UserManagerBase::SetIsCurrentUserNew(bool is_new) {
is_current_user_new_ = is_new;
}
-bool UserManagerBase::HasPendingBootstrap(const std::string& user_id) const {
+bool UserManagerBase::HasPendingBootstrap(const AccountId& user_id) const {
return false;
}
-void UserManagerBase::SetOwnerEmail(const std::string& owner_user_id) {
- owner_email_ = owner_user_id;
+void UserManagerBase::SetOwnerId(const AccountId& owner_user_id) {
+ owner_id_ = owner_user_id;
}
-const std::string& UserManagerBase::GetPendingUserSwitchID() const {
+const AccountId& UserManagerBase::GetPendingUserSwitchID() const {
return pending_user_switch_;
}
-void UserManagerBase::SetPendingUserSwitchID(const std::string& user_id) {
+void UserManagerBase::SetPendingUserSwitchId(const AccountId& user_id) {
pending_user_switch_ = user_id;
}
@@ -827,27 +836,27 @@ void UserManagerBase::EnsureUsersLoaded() {
local_state->GetDictionary(kUserType);
// Load public sessions first.
- std::set<std::string> public_sessions_set;
+ std::set<AccountId> public_sessions_set;
LoadPublicAccounts(&public_sessions_set);
// Load regular users and supervised users.
- std::vector<std::string> regular_users;
- std::set<std::string> regular_users_set;
+ std::vector<AccountId> regular_users;
+ std::set<AccountId> regular_users_set;
ParseUserList(*prefs_regular_users,
public_sessions_set,
&regular_users,
&regular_users_set);
- for (std::vector<std::string>::const_iterator it = regular_users.begin();
- it != regular_users.end();
- ++it) {
+ for (std::vector<AccountId>::const_iterator it = regular_users.begin();
+ it != regular_users.end(); ++it) {
User* user = NULL;
- const std::string domain = gaia::ExtractDomainName(*it);
+ const std::string domain = gaia::ExtractDomainName(it->GetUserEmail());
if (domain == chromeos::login::kSupervisedUserDomain) {
user = User::CreateSupervisedUser(*it);
} else {
user = User::CreateRegularUser(*it);
int user_type;
- if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) &&
+ if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(),
+ &user_type) &&
user_type == USER_TYPE_CHILD) {
ChangeUserChildStatus(user, true /* is child */);
}
@@ -858,18 +867,19 @@ void UserManagerBase::EnsureUsersLoaded() {
users_.push_back(user);
base::string16 display_name;
- if (prefs_display_names->GetStringWithoutPathExpansion(*it,
+ if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(),
&display_name)) {
user->set_display_name(display_name);
}
base::string16 given_name;
- if (prefs_given_names->GetStringWithoutPathExpansion(*it, &given_name)) {
+ if (prefs_given_names->GetStringWithoutPathExpansion(it->GetUserEmail(),
+ &given_name)) {
user->set_given_name(given_name);
}
std::string display_email;
- if (prefs_display_emails->GetStringWithoutPathExpansion(*it,
+ if (prefs_display_emails->GetStringWithoutPathExpansion(it->GetUserEmail(),
&display_email)) {
user->set_display_email(display_email);
}
@@ -885,29 +895,29 @@ UserList& UserManagerBase::GetUsersAndModify() {
return users_;
}
-const User* UserManagerBase::FindUserInList(const std::string& user_id) const {
+const User* UserManagerBase::FindUserInList(const AccountId& user_id) const {
const UserList& users = GetUsers();
for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) {
- if ((*it)->email() == user_id)
+ if ((*it)->GetUserID() == user_id)
return *it;
}
return NULL;
}
-bool UserManagerBase::UserExistsInList(const std::string& user_id) const {
+bool UserManagerBase::UserExistsInList(const AccountId& user_id) const {
const base::ListValue* user_list = GetLocalState()->GetList(kRegularUsers);
for (size_t i = 0; i < user_list->GetSize(); ++i) {
std::string email;
- if (user_list->GetString(i, &email) && (user_id == email))
+ if (user_list->GetString(i, &email) && (user_id.GetUserEmail() == email))
return true;
}
return false;
}
-User* UserManagerBase::FindUserInListAndModify(const std::string& user_id) {
+User* UserManagerBase::FindUserInListAndModify(const AccountId& user_id) {
UserList& users = GetUsersAndModify();
for (UserList::iterator it = users.begin(); it != users.end(); ++it) {
- if ((*it)->email() == user_id)
+ if ((*it)->GetUserID() == user_id)
return *it;
}
return NULL;
@@ -925,7 +935,7 @@ void UserManagerBase::AddUserRecord(User* user) {
users_.insert(users_.begin(), user);
}
-void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) {
+void UserManagerBase::RegularUserLoggedIn(const AccountId& user_id) {
// Remove the user from the user list.
active_user_ = RemoveRegularOrSupervisedUserFromList(user_id);
@@ -934,7 +944,7 @@ void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) {
if (IsCurrentUserNew()) {
active_user_ = User::CreateRegularUser(user_id);
active_user_->set_oauth_token_status(LoadUserOAuthStatus(user_id));
- SaveUserDisplayName(active_user_->email(),
+ SaveUserDisplayName(active_user_->GetUserID(),
base::UTF8ToUTF16(active_user_->GetAccountName(true)));
}
@@ -944,8 +954,7 @@ void UserManagerBase::RegularUserLoggedIn(const std::string& user_id) {
GetLocalState()->CommitPendingWrite();
}
-void UserManagerBase::RegularUserLoggedInAsEphemeral(
- const std::string& user_id) {
+void UserManagerBase::RegularUserLoggedInAsEphemeral(const AccountId& user_id) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
SetIsCurrentUserNew(true);
is_current_user_ephemeral_regular_user_ = true;
@@ -961,14 +970,14 @@ void UserManagerBase::NotifyOnLogin() {
}
User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus(
- const std::string& user_id) const {
+ const AccountId& user_id) const {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
const base::DictionaryValue* prefs_oauth_status =
GetLocalState()->GetDictionary(kUserOAuthTokenStatus);
int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN;
if (prefs_oauth_status &&
- prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id,
+ prefs_oauth_status->GetIntegerWithoutPathExpansion(user_id.GetUserEmail(),
&oauth_token_status)) {
User::OAuthTokenStatus status =
static_cast<User::OAuthTokenStatus>(oauth_token_status);
@@ -979,45 +988,50 @@ User::OAuthTokenStatus UserManagerBase::LoadUserOAuthStatus(
return User::OAUTH_TOKEN_STATUS_UNKNOWN;
}
-bool UserManagerBase::LoadForceOnlineSignin(const std::string& user_id) const {
+bool UserManagerBase::LoadForceOnlineSignin(const AccountId& user_id) const {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
const base::DictionaryValue* prefs_force_online =
GetLocalState()->GetDictionary(kUserForceOnlineSignin);
bool force_online_signin = false;
if (prefs_force_online) {
- prefs_force_online->GetBooleanWithoutPathExpansion(user_id,
+ prefs_force_online->GetBooleanWithoutPathExpansion(user_id.GetUserEmail(),
&force_online_signin);
}
return force_online_signin;
}
-void UserManagerBase::RemoveNonCryptohomeData(const std::string& user_id) {
+void UserManagerBase::RemoveNonCryptohomeData(const AccountId& user_id) {
PrefService* prefs = GetLocalState();
DictionaryPrefUpdate prefs_display_name_update(prefs, kUserDisplayName);
- prefs_display_name_update->RemoveWithoutPathExpansion(user_id, NULL);
+ prefs_display_name_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(),
+ NULL);
DictionaryPrefUpdate prefs_given_name_update(prefs, kUserGivenName);
- prefs_given_name_update->RemoveWithoutPathExpansion(user_id, NULL);
+ prefs_given_name_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(),
+ NULL);
DictionaryPrefUpdate prefs_display_email_update(prefs, kUserDisplayEmail);
- prefs_display_email_update->RemoveWithoutPathExpansion(user_id, NULL);
+ prefs_display_email_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(),
+ NULL);
DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus);
- prefs_oauth_update->RemoveWithoutPathExpansion(user_id, NULL);
+ prefs_oauth_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(), NULL);
DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin);
- prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL);
+ prefs_force_online_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(),
+ NULL);
RemoveKnownUserPrefs(user_id);
- std::string last_active_user = GetLocalState()->GetString(kLastActiveUser);
+ AccountId last_active_user =
achuithb 2015/10/23 00:08:52 const AccountId last_active_account_id =
Alexander Alekseev 2015/10/23 09:11:25 Done.
+ AccountId::FromUserEmail(GetLocalState()->GetString(kLastActiveUser));
if (user_id == last_active_user)
GetLocalState()->SetString(kLastActiveUser, std::string());
}
bool UserManagerBase::FindKnownUserPrefs(
- const UserID& user_id,
+ const AccountId& user_id,
const base::DictionaryValue** out_value) {
PrefService* local_state = GetLocalState();
@@ -1040,7 +1054,7 @@ bool UserManagerBase::FindKnownUserPrefs(
return false;
}
-void UserManagerBase::UpdateKnownUserPrefs(const UserID& user_id,
+void UserManagerBase::UpdateKnownUserPrefs(const AccountId& user_id,
const base::DictionaryValue& values,
bool clear) {
PrefService* local_state = GetLocalState();
@@ -1071,7 +1085,7 @@ void UserManagerBase::UpdateKnownUserPrefs(const UserID& user_id,
update->Append(new_value.release());
}
-bool UserManagerBase::GetKnownUserStringPref(const UserID& user_id,
+bool UserManagerBase::GetKnownUserStringPref(const AccountId& user_id,
const std::string& path,
std::string* out_value) {
const base::DictionaryValue* user_pref_dict = nullptr;
@@ -1081,7 +1095,7 @@ bool UserManagerBase::GetKnownUserStringPref(const UserID& user_id,
return user_pref_dict->GetString(path, out_value);
}
-void UserManagerBase::SetKnownUserStringPref(const UserID& user_id,
+void UserManagerBase::SetKnownUserStringPref(const AccountId& user_id,
const std::string& path,
const std::string& in_value) {
PrefService* local_state = GetLocalState();
@@ -1096,7 +1110,7 @@ void UserManagerBase::SetKnownUserStringPref(const UserID& user_id,
UpdateKnownUserPrefs(user_id, dict, false);
}
-bool UserManagerBase::GetKnownUserBooleanPref(const UserID& user_id,
+bool UserManagerBase::GetKnownUserBooleanPref(const AccountId& user_id,
const std::string& path,
bool* out_value) {
const base::DictionaryValue* user_pref_dict = nullptr;
@@ -1106,7 +1120,7 @@ bool UserManagerBase::GetKnownUserBooleanPref(const UserID& user_id,
return user_pref_dict->GetBoolean(path, out_value);
}
-void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id,
+void UserManagerBase::SetKnownUserBooleanPref(const AccountId& user_id,
const std::string& path,
const bool in_value) {
PrefService* local_state = GetLocalState();
@@ -1121,7 +1135,7 @@ void UserManagerBase::SetKnownUserBooleanPref(const UserID& user_id,
UpdateKnownUserPrefs(user_id, dict, false);
}
-bool UserManagerBase::GetKnownUserIntegerPref(const UserID& user_id,
+bool UserManagerBase::GetKnownUserIntegerPref(const AccountId& user_id,
const std::string& path,
int* out_value) {
const base::DictionaryValue* user_pref_dict = nullptr;
@@ -1130,7 +1144,7 @@ bool UserManagerBase::GetKnownUserIntegerPref(const UserID& user_id,
return user_pref_dict->GetInteger(path, out_value);
}
-void UserManagerBase::SetKnownUserIntegerPref(const UserID& user_id,
+void UserManagerBase::SetKnownUserIntegerPref(const AccountId& user_id,
const std::string& path,
const int in_value) {
PrefService* local_state = GetLocalState();
@@ -1145,22 +1159,31 @@ void UserManagerBase::SetKnownUserIntegerPref(const UserID& user_id,
UpdateKnownUserPrefs(user_id, dict, false);
}
-bool UserManagerBase::GetKnownUserCanonicalEmail(const UserID& user_id,
- std::string* out_email) {
- return GetKnownUserStringPref(user_id, kCanonicalEmail, out_email);
+bool UserManagerBase::GetKnownUserAccountId(const AccountId& authenticated_id,
+ AccountId* out_id) {
+ DCHECK(!authenticated_id.GetGaiaId().empty());
+ std::string canonical_email;
+ if (!GetKnownUserStringPref(
+ AccountId::FromGaiaId(authenticated_id.GetGaiaId()), kCanonicalEmail,
+ &canonical_email))
+ return false;
+
+ *out_id = authenticated_id;
+ out_id->SetUserEmail(canonical_email);
+ return true;
}
-void UserManagerBase::UpdateGaiaID(const UserID& user_id,
+void UserManagerBase::UpdateGaiaID(const AccountId& user_id,
const std::string& gaia_id) {
SetKnownUserStringPref(user_id, kGAIAIdKey, gaia_id);
}
-bool UserManagerBase::FindGaiaID(const UserID& user_id,
+bool UserManagerBase::FindGaiaID(const AccountId& user_id,
std::string* out_value) {
return GetKnownUserStringPref(user_id, kGAIAIdKey, out_value);
}
-void UserManagerBase::SetKnownUserDeviceId(const UserID& user_id,
+void UserManagerBase::SetKnownUserDeviceId(const AccountId& user_id,
const std::string& device_id) {
const std::string known_device_id = GetKnownUserDeviceId(user_id);
if (!known_device_id.empty() && device_id != known_device_id) {
@@ -1169,7 +1192,7 @@ void UserManagerBase::SetKnownUserDeviceId(const UserID& user_id,
SetKnownUserStringPref(user_id, kDeviceId, device_id);
}
-std::string UserManagerBase::GetKnownUserDeviceId(const UserID& user_id) {
+std::string UserManagerBase::GetKnownUserDeviceId(const AccountId& user_id) {
std::string device_id;
if (GetKnownUserStringPref(user_id, kDeviceId, &device_id)) {
return device_id;
@@ -1177,12 +1200,12 @@ std::string UserManagerBase::GetKnownUserDeviceId(const UserID& user_id) {
return std::string();
}
-void UserManagerBase::SetKnownUserGAPSCookie(const UserID& user_id,
+void UserManagerBase::SetKnownUserGAPSCookie(const AccountId& user_id,
const std::string& gaps_cookie) {
SetKnownUserStringPref(user_id, kGAPSCookie, gaps_cookie);
}
-std::string UserManagerBase::GetKnownUserGAPSCookie(const UserID& user_id) {
+std::string UserManagerBase::GetKnownUserGAPSCookie(const AccountId& user_id) {
std::string gaps_cookie;
if (GetKnownUserStringPref(user_id, kGAPSCookie, &gaps_cookie)) {
return gaps_cookie;
@@ -1191,18 +1214,19 @@ std::string UserManagerBase::GetKnownUserGAPSCookie(const UserID& user_id) {
}
User* UserManagerBase::RemoveRegularOrSupervisedUserFromList(
- const std::string& user_id) {
+ const AccountId& user_id) {
ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers);
prefs_users_update->Clear();
User* user = NULL;
for (UserList::iterator it = users_.begin(); it != users_.end();) {
- const std::string user_email = (*it)->email();
- if (user_email == user_id) {
+ if ((*it)->GetUserID() == user_id) {
user = *it;
it = users_.erase(it);
} else {
- if ((*it)->HasGaiaAccount() || (*it)->IsSupervised())
+ if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) {
+ const std::string user_email = (*it)->email();
prefs_users_update->Append(new base::StringValue(user_email));
+ }
++it;
}
}
@@ -1210,7 +1234,7 @@ User* UserManagerBase::RemoveRegularOrSupervisedUserFromList(
return user;
}
-void UserManagerBase::RemoveKnownUserPrefs(const UserID& user_id) {
+void UserManagerBase::RemoveKnownUserPrefs(const AccountId& user_id) {
ListPrefUpdate update(GetLocalState(), kKnownUsers);
for (size_t i = 0; i < update->GetSize(); ++i) {
base::DictionaryValue* element = nullptr;
@@ -1250,8 +1274,8 @@ void UserManagerBase::ChangeUserChildStatus(User* user, bool is_child) {
if (user->IsSupervised() == is_child)
return;
user->SetIsChild(is_child);
- SaveUserType(user->email(), is_child ? user_manager::USER_TYPE_CHILD
- : user_manager::USER_TYPE_REGULAR);
+ SaveUserType(user->GetUserID(), is_child ? user_manager::USER_TYPE_CHILD
+ : user_manager::USER_TYPE_REGULAR);
FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver,
session_state_observer_list_,
UserChangedChildStatus(user));
@@ -1301,7 +1325,7 @@ void UserManagerBase::SetLRUUser(User* user) {
lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user);
}
-void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) {
+void UserManagerBase::SendGaiaUserLoginMetrics(const AccountId& user_id) {
// If this isn't the first time Chrome was run after the system booted,
// assume that Chrome was restarted because a previous session ended.
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
@@ -1310,7 +1334,8 @@ void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) {
GetLocalState()->GetString(kLastLoggedInGaiaUser);
const base::TimeDelta time_to_login =
base::TimeTicks::Now() - manager_creation_time_;
- if (!last_email.empty() && user_id != last_email &&
+ if (!last_email.empty() &&
+ user_id != AccountId::FromUserEmail(last_email) &&
time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) {
UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay",
time_to_login.InSeconds(),
@@ -1321,7 +1346,7 @@ void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) {
}
}
-void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id,
+void UserManagerBase::UpdateUserAccountLocale(const AccountId& user_id,
const std::string& locale) {
scoped_ptr<std::string> resolved_locale(new std::string());
if (!locale.empty() && locale != GetApplicationLocale()) {
@@ -1343,7 +1368,7 @@ void UserManagerBase::UpdateUserAccountLocale(const std::string& user_id,
}
void UserManagerBase::DoUpdateAccountLocale(
- const std::string& user_id,
+ const AccountId& user_id,
scoped_ptr<std::string> resolved_locale) {
User* user = FindUserAndModify(user_id);
if (user && resolved_locale)

Powered by Google App Engine
This is Rietveld 408576698