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: chrome/browser/chromeos/login/users/supervised_user_manager_impl.cc

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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: chrome/browser/chromeos/login/users/supervised_user_manager_impl.cc
diff --git a/chrome/browser/chromeos/login/users/supervised_user_manager_impl.cc b/chrome/browser/chromeos/login/users/supervised_user_manager_impl.cc
index 066846564f6db4530cfe15b60f9b36a6bf1e20d9..16f99453632cd1b55b5e9ae9c75b0ef1b6bccae5 100644
--- a/chrome/browser/chromeos/login/users/supervised_user_manager_impl.cc
+++ b/chrome/browser/chromeos/login/users/supervised_user_manager_impl.cc
@@ -23,6 +23,7 @@
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chromeos/login/user_names.h"
#include "chromeos/settings/cros_settings_names.h"
+#include "components/user_manager/user_id.h"
#include "components/user_manager/user_type.h"
#include "content/public/browser/browser_thread.h"
#include "google_apis/gaia/gaia_auth_util.h"
@@ -140,19 +141,20 @@ SupervisedUserManagerImpl::SupervisedUserManagerImpl(
SupervisedUserManagerImpl::~SupervisedUserManagerImpl() {
}
-std::string SupervisedUserManagerImpl::GenerateUserId() {
+user_manager::UserID SupervisedUserManagerImpl::GenerateUserId() {
int counter = g_browser_process->local_state()->
GetInteger(kSupervisedUsersNextId);
- std::string id;
+ user_manager::UserID user_id = user_manager::UserID(std::string(), std::string());
Denis Kuznetsov (DE-MUC) 2015/06/10 16:50:47 EmptyGaiaID() ?
bool user_exists;
do {
- id = base::StringPrintf(
+ const std::string email = base::StringPrintf(
"%d@%s", counter, chromeos::login::kSupervisedUserDomain);
counter++;
- user_exists = (NULL != owner_->FindUser(id));
+ user_id = user_manager::UserID::FromUserEmail(email);
+ user_exists = (NULL != owner_->FindUser(user_id));
DCHECK(!user_exists);
if (user_exists) {
- LOG(ERROR) << "Supervised user with id " << id << " already exists.";
+ LOG(ERROR) << "Supervised user with email " << email << " already exists.";
}
} while (user_exists);
@@ -160,17 +162,17 @@ std::string SupervisedUserManagerImpl::GenerateUserId() {
SetInteger(kSupervisedUsersNextId, counter);
g_browser_process->local_state()->CommitPendingWrite();
- return id;
+ return user_id;
}
bool SupervisedUserManagerImpl::HasSupervisedUsers(
- const std::string& manager_id) const {
+ const user_manager::UserID& manager_id) const {
const user_manager::UserList& users = owner_->GetUsers();
for (user_manager::UserList::const_iterator it = users.begin();
it != users.end();
++it) {
if ((*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) {
- if (manager_id == GetManagerUserId((*it)->email()))
+ if (manager_id == GetManagerUserId((*it)->GetUserID()))
return true;
}
}
@@ -178,8 +180,8 @@ bool SupervisedUserManagerImpl::HasSupervisedUsers(
}
const user_manager::User* SupervisedUserManagerImpl::CreateUserRecord(
- const std::string& manager_id,
- const std::string& local_user_id,
+ const user_manager::UserID& manager_id,
+ const user_manager::UserID& local_user_id,
const std::string& sync_user_id,
const base::string16& display_name) {
const user_manager::User* user = FindByDisplayName(display_name);
@@ -206,15 +208,15 @@ const user_manager::User* SupervisedUserManagerImpl::CreateUserRecord(
local_state,
kSupervisedUserManagerDisplayEmails);
- prefs_new_users_update->Insert(0, new base::StringValue(local_user_id));
+ prefs_new_users_update->Insert(0, new base::StringValue(local_user_id.GetUserEmail()));
- sync_id_update->SetWithoutPathExpansion(local_user_id,
+ sync_id_update->SetWithoutPathExpansion(local_user_id.GetUserEmail(),
new base::StringValue(sync_user_id));
- manager_update->SetWithoutPathExpansion(local_user_id,
- new base::StringValue(manager->email()));
- manager_name_update->SetWithoutPathExpansion(local_user_id,
+ manager_update->SetWithoutPathExpansion(local_user_id.GetUserEmail(),
+ new base::StringValue(manager->GetUserID().GetUserEmail()));
+ manager_name_update->SetWithoutPathExpansion(local_user_id.GetUserEmail(),
new base::StringValue(manager->GetDisplayName()));
- manager_email_update->SetWithoutPathExpansion(local_user_id,
+ manager_email_update->SetWithoutPathExpansion(local_user_id.GetUserEmail(),
new base::StringValue(manager->display_email()));
owner_->SaveUserDisplayName(local_user_id, display_name);
@@ -223,7 +225,7 @@ const user_manager::User* SupervisedUserManagerImpl::CreateUserRecord(
return new_user;
}
-std::string SupervisedUserManagerImpl::GetUserSyncId(const std::string& user_id)
+std::string SupervisedUserManagerImpl::GetUserSyncId(const user_manager::UserID& user_id)
const {
std::string result;
GetUserStringValue(user_id, kSupervisedUserSyncId, &result);
@@ -231,37 +233,37 @@ std::string SupervisedUserManagerImpl::GetUserSyncId(const std::string& user_id)
}
base::string16 SupervisedUserManagerImpl::GetManagerDisplayName(
- const std::string& user_id) const {
+ const user_manager::UserID& user_id) const {
PrefService* local_state = g_browser_process->local_state();
const base::DictionaryValue* manager_names =
local_state->GetDictionary(kSupervisedUserManagerNames);
base::string16 result;
- if (manager_names->GetStringWithoutPathExpansion(user_id, &result) &&
+ if (manager_names->GetStringWithoutPathExpansion(user_id.GetUserEmail(), &result) &&
!result.empty())
return result;
return base::UTF8ToUTF16(GetManagerDisplayEmail(user_id));
}
-std::string SupervisedUserManagerImpl::GetManagerUserId(
- const std::string& user_id) const {
+user_manager::UserID SupervisedUserManagerImpl::GetManagerUserId(
+ const user_manager::UserID& user_id) const {
std::string result;
GetUserStringValue(user_id, kSupervisedUserManagers, &result);
- return result;
+ return user_manager::UserID::FromUserEmail(result);
}
std::string SupervisedUserManagerImpl::GetManagerDisplayEmail(
- const std::string& user_id) const {
+ const user_manager::UserID& user_id) const {
std::string result;
if (GetUserStringValue(user_id,
kSupervisedUserManagerDisplayEmails,
&result) &&
!result.empty())
return result;
- return GetManagerUserId(user_id);
+ return GetManagerUserId(user_id).GetUserEmail();
}
void SupervisedUserManagerImpl::GetPasswordInformation(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
base::DictionaryValue* result) {
int value;
if (GetUserIntegerValue(user_id, kSupervisedUserPasswordSchema, &value))
@@ -281,7 +283,7 @@ void SupervisedUserManagerImpl::GetPasswordInformation(
}
void SupervisedUserManagerImpl::SetPasswordInformation(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const base::DictionaryValue* password_info) {
int value;
if (password_info->GetIntegerWithoutPathExpansion(kSchemaVersion, &value))
@@ -304,55 +306,55 @@ void SupervisedUserManagerImpl::SetPasswordInformation(
}
bool SupervisedUserManagerImpl::GetUserStringValue(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const char* key,
std::string* out_value) const {
PrefService* local_state = g_browser_process->local_state();
const base::DictionaryValue* dictionary = local_state->GetDictionary(key);
- return dictionary->GetStringWithoutPathExpansion(user_id, out_value);
+ return dictionary->GetStringWithoutPathExpansion(user_id.GetUserEmail(), out_value);
}
bool SupervisedUserManagerImpl::GetUserIntegerValue(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const char* key,
int* out_value) const {
PrefService* local_state = g_browser_process->local_state();
const base::DictionaryValue* dictionary = local_state->GetDictionary(key);
- return dictionary->GetIntegerWithoutPathExpansion(user_id, out_value);
+ return dictionary->GetIntegerWithoutPathExpansion(user_id.GetUserEmail(), out_value);
}
-bool SupervisedUserManagerImpl::GetUserBooleanValue(const std::string& user_id,
+bool SupervisedUserManagerImpl::GetUserBooleanValue(const user_manager::UserID& user_id,
const char* key,
bool* out_value) const {
PrefService* local_state = g_browser_process->local_state();
const base::DictionaryValue* dictionary = local_state->GetDictionary(key);
- return dictionary->GetBooleanWithoutPathExpansion(user_id, out_value);
+ return dictionary->GetBooleanWithoutPathExpansion(user_id.GetUserEmail(), out_value);
}
void SupervisedUserManagerImpl::SetUserStringValue(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const char* key,
const std::string& value) {
PrefService* local_state = g_browser_process->local_state();
DictionaryPrefUpdate update(local_state, key);
- update->SetStringWithoutPathExpansion(user_id, value);
+ update->SetStringWithoutPathExpansion(user_id.GetUserEmail(), value);
}
void SupervisedUserManagerImpl::SetUserIntegerValue(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const char* key,
const int value) {
PrefService* local_state = g_browser_process->local_state();
DictionaryPrefUpdate update(local_state, key);
- update->SetIntegerWithoutPathExpansion(user_id, value);
+ update->SetIntegerWithoutPathExpansion(user_id.GetUserEmail(), value);
}
-void SupervisedUserManagerImpl::SetUserBooleanValue(const std::string& user_id,
+void SupervisedUserManagerImpl::SetUserBooleanValue(const user_manager::UserID& user_id,
const char* key,
const bool value) {
PrefService* local_state = g_browser_process->local_state();
DictionaryPrefUpdate update(local_state, key);
- update->SetBooleanWithoutPathExpansion(user_id, value);
+ update->SetBooleanWithoutPathExpansion(user_id.GetUserEmail(), value);
}
const user_manager::User* SupervisedUserManagerImpl::FindByDisplayName(
@@ -378,7 +380,7 @@ const user_manager::User* SupervisedUserManagerImpl::FindBySyncId(
it != users.end();
++it) {
if (((*it)->GetType() == user_manager::USER_TYPE_SUPERVISED) &&
- (GetUserSyncId((*it)->email()) == sync_id)) {
+ (GetUserSyncId((*it)->GetUserID()) == sync_id)) {
return *it;
}
}
@@ -394,10 +396,10 @@ void SupervisedUserManagerImpl::StartCreationTransaction(
}
void SupervisedUserManagerImpl::SetCreationTransactionUserId(
- const std::string& email) {
+ const user_manager::UserID& user_id) {
g_browser_process->local_state()->
SetString(kSupervisedUserCreationTransactionUserId,
- email);
+ user_id.GetUserEmail());
g_browser_process->local_state()->CommitPendingWrite();
}
@@ -420,11 +422,11 @@ void SupervisedUserManagerImpl::RollbackUserCreationTransaction() {
std::string display_name = prefs->
GetString(kSupervisedUserCreationTransactionDisplayName);
- std::string user_id = prefs->
- GetString(kSupervisedUserCreationTransactionUserId);
+ user_manager::UserID user_id(user_manager::UserID::FromUserEmail(prefs->
+ GetString(kSupervisedUserCreationTransactionUserId)));
LOG(WARNING) << "Cleaning up transaction for "
- << display_name << "/" << user_id;
+ << display_name << "/" << user_id.GetUserEmail();
if (user_id.empty()) {
// Not much to do - just remove transaction.
@@ -433,10 +435,10 @@ void SupervisedUserManagerImpl::RollbackUserCreationTransaction() {
return;
}
- if (gaia::ExtractDomainName(user_id) !=
+ if (gaia::ExtractDomainName(user_id.GetUserEmail()) !=
chromeos::login::kSupervisedUserDomain) {
LOG(WARNING) << "Clean up transaction for non-supervised user found :"
- << user_id << ", will not remove data";
+ << user_id.GetUserEmail() << ", will not remove data";
prefs->ClearPref(kSupervisedUserCreationTransactionDisplayName);
prefs->ClearPref(kSupervisedUserCreationTransactionUserId);
prefs->CommitPendingWrite();
@@ -450,10 +452,10 @@ void SupervisedUserManagerImpl::RollbackUserCreationTransaction() {
}
void SupervisedUserManagerImpl::RemoveNonCryptohomeData(
- const std::string& user_id) {
+ const user_manager::UserID& user_id) {
PrefService* prefs = g_browser_process->local_state();
ListPrefUpdate prefs_new_users_update(prefs, kSupervisedUsersFirstRun);
- prefs_new_users_update->Remove(base::StringValue(user_id), NULL);
+ prefs_new_users_update->Remove(base::StringValue(user_id.GetUserEmail()), NULL);
CleanPref(user_id, kSupervisedUserSyncId);
CleanPref(user_id, kSupervisedUserManagers);
@@ -466,20 +468,20 @@ void SupervisedUserManagerImpl::RemoveNonCryptohomeData(
CleanPref(user_id, kSupervisedUserIncompleteKey);
}
-void SupervisedUserManagerImpl::CleanPref(const std::string& user_id,
+void SupervisedUserManagerImpl::CleanPref(const user_manager::UserID& user_id,
const char* key) {
PrefService* prefs = g_browser_process->local_state();
DictionaryPrefUpdate dict_update(prefs, key);
- dict_update->RemoveWithoutPathExpansion(user_id, NULL);
+ dict_update->RemoveWithoutPathExpansion(user_id.GetUserEmail(), NULL);
}
-bool SupervisedUserManagerImpl::CheckForFirstRun(const std::string& user_id) {
+bool SupervisedUserManagerImpl::CheckForFirstRun(const user_manager::UserID& user_id) {
ListPrefUpdate prefs_new_users_update(g_browser_process->local_state(),
kSupervisedUsersFirstRun);
- return prefs_new_users_update->Remove(base::StringValue(user_id), NULL);
+ return prefs_new_users_update->Remove(base::StringValue(user_id.GetUserEmail()), NULL);
}
-void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id,
+void SupervisedUserManagerImpl::UpdateManagerName(const user_manager::UserID& manager_id,
const base::string16& new_display_name) {
PrefService* local_state = g_browser_process->local_state();
@@ -490,10 +492,10 @@ void SupervisedUserManagerImpl::UpdateManagerName(const std::string& manager_id,
kSupervisedUserManagerNames);
for (base::DictionaryValue::Iterator it(*manager_ids); !it.IsAtEnd();
it.Advance()) {
- std::string user_id;
- bool has_manager_id = it.value().GetAsString(&user_id);
+ std::string user_email;
+ bool has_manager_id = it.value().GetAsString(&user_email);
DCHECK(has_manager_id);
- if (user_id == manager_id) {
+ if (user_manager::UserID::FromUserEmail(user_email) == manager_id) {
manager_name_update->SetWithoutPathExpansion(
it.key(),
new base::StringValue(new_display_name));

Powered by Google App Engine
This is Rietveld 408576698