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

Unified Diff: components/user_manager/user_manager_base.cc

Issue 720723002: Creating supervised users restricted for regular users if they are supervised. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unicornUserTypePublic
Patch Set: Unused headers removed Created 6 years, 1 month 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 06b702660f515332b24748a485f96092708640c0..93f72450ed8bd0210a8e7b16b3a6fdcdabb2498f 100644
--- a/components/user_manager/user_manager_base.cc
+++ b/components/user_manager/user_manager_base.cc
@@ -57,6 +57,9 @@ const char kUserOAuthTokenStatus[] = "OAuthTokenStatus";
// authentication against GAIA should be enforced during the next sign-in.
const char kUserForceOnlineSignin[] = "UserForceOnlineSignin";
+// A dictionary that maps user ID to the user type.
+const char kUserType[] = "UserType";
+
// A string pref containing the ID of the last user who logged in if it was
// a regular user or an empty string if it was another type of user (guest,
// kiosk, public account, etc.).
@@ -99,6 +102,7 @@ void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(kUserDisplayEmail);
registry->RegisterDictionaryPref(kUserOAuthTokenStatus);
registry->RegisterDictionaryPref(kUserForceOnlineSignin);
+ registry->RegisterDictionaryPref(kUserType);
registry->RegisterStringPref(kLastActiveUser, std::string());
}
@@ -472,6 +476,27 @@ std::string UserManagerBase::GetUserDisplayEmail(
return user ? user->display_email() : user_id;
}
+void UserManagerBase::SaveUserType(const std::string& user_id,
+ const UserType& user_type) {
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
+
+ User* user = FindUserAndModify(user_id);
+ if (!user) {
+ LOG(ERROR) << "User not found: " << user_id;
+ return; // Ignore if there is no such user.
+ }
+
+ // Do not update local state if data stored or cached outside the user's
+ // cryptohome is to be treated as ephemeral.
+ if (IsUserNonCryptohomeDataEphemeral(user_id))
+ return;
+
+ DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType);
+ user_type_update->SetWithoutPathExpansion(
+ user_id, new base::FundamentalValue(static_cast<int>(user_type)));
+ GetLocalState()->CommitPendingWrite();
+}
+
void UserManagerBase::UpdateUserAccountData(
const std::string& user_id,
const UserAccountData& account_data) {
@@ -732,6 +757,8 @@ void UserManagerBase::EnsureUsersLoaded() {
local_state->GetDictionary(kUserGivenName);
const base::DictionaryValue* prefs_display_emails =
local_state->GetDictionary(kUserDisplayEmail);
+ const base::DictionaryValue* prefs_user_types =
+ local_state->GetDictionary(kUserType);
// Load public sessions first.
std::set<std::string> public_sessions_set;
@@ -749,10 +776,17 @@ void UserManagerBase::EnsureUsersLoaded() {
++it) {
User* user = NULL;
const std::string domain = gaia::ExtractDomainName(*it);
- if (domain == chromeos::login::kSupervisedUserDomain)
+ if (domain == chromeos::login::kSupervisedUserDomain) {
user = User::CreateSupervisedUser(*it);
- else
+ } else {
user = User::CreateRegularUser(*it);
+ int user_type;
+ prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type);
Nikita (slow) 2014/11/12 11:09:09 nit: Drop this line.
merkulova 2014/11/12 13:19:51 Done.
+ if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) &&
+ user_type == USER_TYPE_REGULAR_SUPERVISED) {
+ ChangeUserSupervisedStatus(user, true /* is supervised */);
+ }
+ }
user->set_oauth_token_status(LoadUserOAuthStatus(*it));
user->set_force_online_signin(LoadForceOnlineSignin(*it));
users_.push_back(user);
@@ -959,6 +993,9 @@ void UserManagerBase::ChangeUserSupervisedStatus(User* user,
bool is_supervised) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
user->SetIsSupervised(is_supervised);
+ SaveUserType(user->email(), is_supervised ?
Nikita (slow) 2014/11/12 11:09:09 nit: run git cl format on your patch.
+ user_manager::USER_TYPE_REGULAR_SUPERVISED :
+ user_manager::USER_TYPE_REGULAR);
FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver,
session_state_observer_list_,
UserChangedSupervisedStatus(user));
@@ -966,7 +1003,7 @@ void UserManagerBase::ChangeUserSupervisedStatus(User* user,
void UserManagerBase::UpdateLoginState() {
if (!chromeos::LoginState::IsInitialized())
- return; // LoginState may not be intialized in tests.
+ return; // LoginState may not be initialized in tests.
chromeos::LoginState::LoggedInState logged_in_state;
logged_in_state = active_user_ ? chromeos::LoginState::LOGGED_IN_ACTIVE

Powered by Google App Engine
This is Rietveld 408576698