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

Unified Diff: chrome/browser/chromeos/login/users/multi_profile_user_controller.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/multi_profile_user_controller.cc
diff --git a/chrome/browser/chromeos/login/users/multi_profile_user_controller.cc b/chrome/browser/chromeos/login/users/multi_profile_user_controller.cc
index e1733004c33b8498b9b61207681b6c05dfd0f717..8b01f34d21dbfa3643d4d7cf11ddcacc962e9a41 100644
--- a/chrome/browser/chromeos/login/users/multi_profile_user_controller.cc
+++ b/chrome/browser/chromeos/login/users/multi_profile_user_controller.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/user_manager/user.h"
+#include "components/user_manager/user_id.h"
#include "components/user_manager/user_manager.h"
#include "google_apis/gaia/gaia_auth_util.h"
@@ -96,7 +97,7 @@ MultiProfileUserController::GetPrimaryUserPolicy() {
return ALLOWED;
// Don't allow any secondary profiles if the primary profile is tainted.
- if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user->email())) {
+ if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user->GetUserID())) {
// Check directly in local_state before checking if the primary user has
// a PolicyCertService. His profile may have been tainted previously though
// he didn't get a PolicyCertService created for this session.
@@ -125,24 +126,24 @@ MultiProfileUserController::GetPrimaryUserPolicy() {
}
bool MultiProfileUserController::IsUserAllowedInSession(
- const std::string& user_email,
+ const user_manager::UserID& user_id,
MultiProfileUserController::UserAllowedInSessionReason* reason) const {
user_manager::UserManager* user_manager = user_manager::UserManager::Get();
CHECK(user_manager);
const user_manager::User* primary_user = user_manager->GetPrimaryUser();
- std::string primary_user_email;
+ user_manager::UserID primary_user_id = user_manager::UserID(std::string(), std::string());
Denis Kuznetsov (DE-MUC) 2015/06/10 16:50:45 EmptyGaiaID() ?
if (primary_user)
- primary_user_email = primary_user->email();
+ primary_user_id = primary_user->GetUserID();
// Always allow if there is no primary user or user being checked is the
// primary user.
- if (primary_user_email.empty() || primary_user_email == user_email)
+ if (primary_user_id.empty() || primary_user_id == user_id)
return SetUserAllowedReason(reason, ALLOWED);
// Don't allow profiles potentially tainted by data fetched with policy-pushed
// certificates to join a multiprofile session.
- if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user_email))
+ if (policy::PolicyCertServiceFactory::UsedPolicyCertificates(user_id))
return SetUserAllowedReason(reason, NOT_ALLOWED_POLICY_CERT_TAINTED);
UserAllowedInSessionReason primary_user_policy = GetPrimaryUserPolicy();
@@ -150,7 +151,7 @@ bool MultiProfileUserController::IsUserAllowedInSession(
return SetUserAllowedReason(reason, primary_user_policy);
// The user must have 'unrestricted' policy to be a secondary user.
- const std::string behavior = GetCachedValue(user_email);
+ const std::string behavior = GetCachedValue(user_id);
return SetUserAllowedReason(
reason,
behavior == kBehaviorUnrestricted ? ALLOWED : NOT_ALLOWED_POLICY_FORBIDS);
@@ -174,30 +175,30 @@ void MultiProfileUserController::StartObserving(Profile* user_profile) {
}
void MultiProfileUserController::RemoveCachedValues(
- const std::string& user_email) {
+ const user_manager::UserID& user_id) {
DictionaryPrefUpdate update(local_state_,
prefs::kCachedMultiProfileUserBehavior);
- update->RemoveWithoutPathExpansion(user_email, NULL);
- policy::PolicyCertServiceFactory::ClearUsedPolicyCertificates(user_email);
+ update->RemoveWithoutPathExpansion(user_id.GetUserEmail(), NULL);
+ policy::PolicyCertServiceFactory::ClearUsedPolicyCertificates(user_id);
}
std::string MultiProfileUserController::GetCachedValue(
- const std::string& user_email) const {
+ const user_manager::UserID& user_id) const {
const base::DictionaryValue* dict =
local_state_->GetDictionary(prefs::kCachedMultiProfileUserBehavior);
std::string value;
- if (dict && dict->GetStringWithoutPathExpansion(user_email, &value))
+ if (dict && dict->GetStringWithoutPathExpansion(user_id.GetUserEmail(), &value))
return SanitizeBehaviorValue(value);
return std::string(kBehaviorUnrestricted);
}
void MultiProfileUserController::SetCachedValue(
- const std::string& user_email,
+ const user_manager::UserID& user_id,
const std::string& behavior) {
DictionaryPrefUpdate update(local_state_,
prefs::kCachedMultiProfileUserBehavior);
- update->SetStringWithoutPathExpansion(user_email,
+ update->SetStringWithoutPathExpansion(user_id.GetUserEmail(),
SanitizeBehaviorValue(behavior));
}
@@ -207,8 +208,8 @@ void MultiProfileUserController::CheckSessionUsers() {
for (user_manager::UserList::const_iterator it = users.begin();
it != users.end();
++it) {
- if (!IsUserAllowedInSession((*it)->email(), NULL)) {
- delegate_->OnUserNotAllowed((*it)->email());
+ if (!IsUserAllowedInSession((*it)->GetUserID(), NULL)) {
+ delegate_->OnUserNotAllowed((*it)->GetUserID());
return;
}
}
@@ -219,6 +220,7 @@ void MultiProfileUserController::OnUserPrefChanged(
std::string user_email = user_profile->GetProfileUserName();
CHECK(!user_email.empty());
user_email = gaia::CanonicalizeEmail(user_email);
+ const user_manager::UserID user_id(std::string() /* gaia_id */, user_email);
Denis Kuznetsov (DE-MUC) 2015/06/10 16:50:45 FromUserEmail()
PrefService* prefs = user_profile->GetPrefs();
if (prefs->FindPreference(prefs::kMultiProfileUserBehavior)
@@ -227,11 +229,11 @@ void MultiProfileUserController::OnUserPrefChanged(
// TODO(xiyuan): Remove this after M35.
DictionaryPrefUpdate update(local_state_,
prefs::kCachedMultiProfileUserBehavior);
- update->RemoveWithoutPathExpansion(user_email, NULL);
+ update->RemoveWithoutPathExpansion(user_id.GetUserEmail(), NULL);
} else {
const std::string behavior =
prefs->GetString(prefs::kMultiProfileUserBehavior);
- SetCachedValue(user_email, behavior);
+ SetCachedValue(user_id, behavior);
}
CheckSessionUsers();

Powered by Google App Engine
This is Rietveld 408576698