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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/user_manager/user_manager_base.h" 5 #include "components/user_manager/user_manager_base.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 // A dictionary that maps user IDs to the displayed (non-canonical) emails. 50 // A dictionary that maps user IDs to the displayed (non-canonical) emails.
51 const char kUserDisplayEmail[] = "UserDisplayEmail"; 51 const char kUserDisplayEmail[] = "UserDisplayEmail";
52 52
53 // A dictionary that maps user IDs to OAuth token presence flag. 53 // A dictionary that maps user IDs to OAuth token presence flag.
54 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus"; 54 const char kUserOAuthTokenStatus[] = "OAuthTokenStatus";
55 55
56 // A dictionary that maps user IDs to a flag indicating whether online 56 // A dictionary that maps user IDs to a flag indicating whether online
57 // authentication against GAIA should be enforced during the next sign-in. 57 // authentication against GAIA should be enforced during the next sign-in.
58 const char kUserForceOnlineSignin[] = "UserForceOnlineSignin"; 58 const char kUserForceOnlineSignin[] = "UserForceOnlineSignin";
59 59
60 // A dictionary that maps user ID to the user type.
61 const char kUserType[] = "UserType";
62
60 // A string pref containing the ID of the last user who logged in if it was 63 // A string pref containing the ID of the last user who logged in if it was
61 // a regular user or an empty string if it was another type of user (guest, 64 // a regular user or an empty string if it was another type of user (guest,
62 // kiosk, public account, etc.). 65 // kiosk, public account, etc.).
63 const char kLastLoggedInRegularUser[] = "LastLoggedInRegularUser"; 66 const char kLastLoggedInRegularUser[] = "LastLoggedInRegularUser";
64 67
65 // A string pref containing the ID of the last active user. 68 // A string pref containing the ID of the last active user.
66 // In case of browser crash, this pref will be used to set active user after 69 // In case of browser crash, this pref will be used to set active user after
67 // session restore. 70 // session restore.
68 const char kLastActiveUser[] = "LastActiveUser"; 71 const char kLastActiveUser[] = "LastActiveUser";
69 72
(...skipping 22 matching lines...) Expand all
92 95
93 // static 96 // static
94 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { 97 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) {
95 registry->RegisterListPref(kRegularUsers); 98 registry->RegisterListPref(kRegularUsers);
96 registry->RegisterStringPref(kLastLoggedInRegularUser, std::string()); 99 registry->RegisterStringPref(kLastLoggedInRegularUser, std::string());
97 registry->RegisterDictionaryPref(kUserDisplayName); 100 registry->RegisterDictionaryPref(kUserDisplayName);
98 registry->RegisterDictionaryPref(kUserGivenName); 101 registry->RegisterDictionaryPref(kUserGivenName);
99 registry->RegisterDictionaryPref(kUserDisplayEmail); 102 registry->RegisterDictionaryPref(kUserDisplayEmail);
100 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); 103 registry->RegisterDictionaryPref(kUserOAuthTokenStatus);
101 registry->RegisterDictionaryPref(kUserForceOnlineSignin); 104 registry->RegisterDictionaryPref(kUserForceOnlineSignin);
105 registry->RegisterDictionaryPref(kUserType);
102 registry->RegisterStringPref(kLastActiveUser, std::string()); 106 registry->RegisterStringPref(kLastActiveUser, std::string());
103 } 107 }
104 108
105 UserManagerBase::UserManagerBase( 109 UserManagerBase::UserManagerBase(
106 scoped_refptr<base::TaskRunner> task_runner, 110 scoped_refptr<base::TaskRunner> task_runner,
107 scoped_refptr<base::TaskRunner> blocking_task_runner) 111 scoped_refptr<base::TaskRunner> blocking_task_runner)
108 : active_user_(NULL), 112 : active_user_(NULL),
109 primary_user_(NULL), 113 primary_user_(NULL),
110 user_loading_stage_(STAGE_NOT_LOADED), 114 user_loading_stage_(STAGE_NOT_LOADED),
111 session_started_(false), 115 session_started_(false),
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 display_email_update->SetWithoutPathExpansion( 469 display_email_update->SetWithoutPathExpansion(
466 user_id, new base::StringValue(display_email)); 470 user_id, new base::StringValue(display_email));
467 } 471 }
468 472
469 std::string UserManagerBase::GetUserDisplayEmail( 473 std::string UserManagerBase::GetUserDisplayEmail(
470 const std::string& user_id) const { 474 const std::string& user_id) const {
471 const User* user = FindUser(user_id); 475 const User* user = FindUser(user_id);
472 return user ? user->display_email() : user_id; 476 return user ? user->display_email() : user_id;
473 } 477 }
474 478
479 void UserManagerBase::SaveUserType(const std::string& user_id,
480 const UserType& user_type) {
481 DCHECK(task_runner_->RunsTasksOnCurrentThread());
482
483 User* user = FindUserAndModify(user_id);
484 if (!user) {
485 LOG(ERROR) << "User not found: " << user_id;
486 return; // Ignore if there is no such user.
487 }
488
489 // Do not update local state if data stored or cached outside the user's
490 // cryptohome is to be treated as ephemeral.
491 if (IsUserNonCryptohomeDataEphemeral(user_id))
492 return;
493
494 DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType);
495 user_type_update->SetWithoutPathExpansion(
496 user_id, new base::FundamentalValue(static_cast<int>(user_type)));
497 GetLocalState()->CommitPendingWrite();
498 }
499
475 void UserManagerBase::UpdateUserAccountData( 500 void UserManagerBase::UpdateUserAccountData(
476 const std::string& user_id, 501 const std::string& user_id,
477 const UserAccountData& account_data) { 502 const UserAccountData& account_data) {
478 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 503 DCHECK(task_runner_->RunsTasksOnCurrentThread());
479 504
480 SaveUserDisplayName(user_id, account_data.display_name()); 505 SaveUserDisplayName(user_id, account_data.display_name());
481 506
482 if (User* user = FindUserAndModify(user_id)) { 507 if (User* user = FindUserAndModify(user_id)) {
483 base::string16 given_name = account_data.given_name(); 508 base::string16 given_name = account_data.given_name();
484 user->set_given_name(given_name); 509 user->set_given_name(given_name);
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 PrefService* local_state = GetLocalState(); 750 PrefService* local_state = GetLocalState();
726 const base::ListValue* prefs_regular_users = 751 const base::ListValue* prefs_regular_users =
727 local_state->GetList(kRegularUsers); 752 local_state->GetList(kRegularUsers);
728 753
729 const base::DictionaryValue* prefs_display_names = 754 const base::DictionaryValue* prefs_display_names =
730 local_state->GetDictionary(kUserDisplayName); 755 local_state->GetDictionary(kUserDisplayName);
731 const base::DictionaryValue* prefs_given_names = 756 const base::DictionaryValue* prefs_given_names =
732 local_state->GetDictionary(kUserGivenName); 757 local_state->GetDictionary(kUserGivenName);
733 const base::DictionaryValue* prefs_display_emails = 758 const base::DictionaryValue* prefs_display_emails =
734 local_state->GetDictionary(kUserDisplayEmail); 759 local_state->GetDictionary(kUserDisplayEmail);
760 const base::DictionaryValue* prefs_user_types =
761 local_state->GetDictionary(kUserType);
735 762
736 // Load public sessions first. 763 // Load public sessions first.
737 std::set<std::string> public_sessions_set; 764 std::set<std::string> public_sessions_set;
738 LoadPublicAccounts(&public_sessions_set); 765 LoadPublicAccounts(&public_sessions_set);
739 766
740 // Load regular users and supervised users. 767 // Load regular users and supervised users.
741 std::vector<std::string> regular_users; 768 std::vector<std::string> regular_users;
742 std::set<std::string> regular_users_set; 769 std::set<std::string> regular_users_set;
743 ParseUserList(*prefs_regular_users, 770 ParseUserList(*prefs_regular_users,
744 public_sessions_set, 771 public_sessions_set,
745 &regular_users, 772 &regular_users,
746 &regular_users_set); 773 &regular_users_set);
747 for (std::vector<std::string>::const_iterator it = regular_users.begin(); 774 for (std::vector<std::string>::const_iterator it = regular_users.begin();
748 it != regular_users.end(); 775 it != regular_users.end();
749 ++it) { 776 ++it) {
750 User* user = NULL; 777 User* user = NULL;
751 const std::string domain = gaia::ExtractDomainName(*it); 778 const std::string domain = gaia::ExtractDomainName(*it);
752 if (domain == chromeos::login::kSupervisedUserDomain) 779 if (domain == chromeos::login::kSupervisedUserDomain) {
753 user = User::CreateSupervisedUser(*it); 780 user = User::CreateSupervisedUser(*it);
754 else 781 } else {
755 user = User::CreateRegularUser(*it); 782 user = User::CreateRegularUser(*it);
783 int user_type;
784 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.
785 if (prefs_user_types->GetIntegerWithoutPathExpansion(*it, &user_type) &&
786 user_type == USER_TYPE_REGULAR_SUPERVISED) {
787 ChangeUserSupervisedStatus(user, true /* is supervised */);
788 }
789 }
756 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); 790 user->set_oauth_token_status(LoadUserOAuthStatus(*it));
757 user->set_force_online_signin(LoadForceOnlineSignin(*it)); 791 user->set_force_online_signin(LoadForceOnlineSignin(*it));
758 users_.push_back(user); 792 users_.push_back(user);
759 793
760 base::string16 display_name; 794 base::string16 display_name;
761 if (prefs_display_names->GetStringWithoutPathExpansion(*it, 795 if (prefs_display_names->GetStringWithoutPathExpansion(*it,
762 &display_name)) { 796 &display_name)) {
763 user->set_display_name(display_name); 797 user->set_display_name(display_name);
764 } 798 }
765 799
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 986 DCHECK(task_runner_->RunsTasksOnCurrentThread());
953 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, 987 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver,
954 session_state_observer_list_, 988 session_state_observer_list_,
955 ActiveUserHashChanged(hash)); 989 ActiveUserHashChanged(hash));
956 } 990 }
957 991
958 void UserManagerBase::ChangeUserSupervisedStatus(User* user, 992 void UserManagerBase::ChangeUserSupervisedStatus(User* user,
959 bool is_supervised) { 993 bool is_supervised) {
960 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 994 DCHECK(task_runner_->RunsTasksOnCurrentThread());
961 user->SetIsSupervised(is_supervised); 995 user->SetIsSupervised(is_supervised);
996 SaveUserType(user->email(), is_supervised ?
Nikita (slow) 2014/11/12 11:09:09 nit: run git cl format on your patch.
997 user_manager::USER_TYPE_REGULAR_SUPERVISED :
998 user_manager::USER_TYPE_REGULAR);
962 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, 999 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver,
963 session_state_observer_list_, 1000 session_state_observer_list_,
964 UserChangedSupervisedStatus(user)); 1001 UserChangedSupervisedStatus(user));
965 } 1002 }
966 1003
967 void UserManagerBase::UpdateLoginState() { 1004 void UserManagerBase::UpdateLoginState() {
968 if (!chromeos::LoginState::IsInitialized()) 1005 if (!chromeos::LoginState::IsInitialized())
969 return; // LoginState may not be intialized in tests. 1006 return; // LoginState may not be initialized in tests.
970 1007
971 chromeos::LoginState::LoggedInState logged_in_state; 1008 chromeos::LoginState::LoggedInState logged_in_state;
972 logged_in_state = active_user_ ? chromeos::LoginState::LOGGED_IN_ACTIVE 1009 logged_in_state = active_user_ ? chromeos::LoginState::LOGGED_IN_ACTIVE
973 : chromeos::LoginState::LOGGED_IN_NONE; 1010 : chromeos::LoginState::LOGGED_IN_NONE;
974 1011
975 chromeos::LoginState::LoggedInUserType login_user_type; 1012 chromeos::LoginState::LoggedInUserType login_user_type;
976 if (logged_in_state == chromeos::LoginState::LOGGED_IN_NONE) 1013 if (logged_in_state == chromeos::LoginState::LOGGED_IN_NONE)
977 login_user_type = chromeos::LoginState::LOGGED_IN_USER_NONE; 1014 login_user_type = chromeos::LoginState::LOGGED_IN_USER_NONE;
978 else if (is_current_user_owner_) 1015 else if (is_current_user_owner_)
979 login_user_type = chromeos::LoginState::LOGGED_IN_USER_OWNER; 1016 login_user_type = chromeos::LoginState::LOGGED_IN_USER_OWNER;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 } 1097 }
1061 1098
1062 void UserManagerBase::DeleteUser(User* user) { 1099 void UserManagerBase::DeleteUser(User* user) {
1063 const bool is_active_user = (user == active_user_); 1100 const bool is_active_user = (user == active_user_);
1064 delete user; 1101 delete user;
1065 if (is_active_user) 1102 if (is_active_user)
1066 active_user_ = NULL; 1103 active_user_ = NULL;
1067 } 1104 }
1068 1105
1069 } // namespace user_manager 1106 } // namespace user_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698