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

Side by Side Diff: components/user_manager/user_manager_base.cc

Issue 718673002: New user type introduced. Combines regular and supervised features. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Logical expression fixed. 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 string pref containing the ID of the last user who logged in if it was 60 // 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, 61 // a user with gaia account (regular) or an empty string if it was another type
bartfab (slow) 2014/11/27 12:51:51 Nit: As before, I am not sure "regular" is actuall
62 // kiosk, public account, etc.). 62 // of user (guest, kiosk, public account, etc.).
63 const char kLastLoggedInRegularUser[] = "LastLoggedInRegularUser"; 63 const char kLastLoggedInGaiaUser[] = "LastLoggedInRegularUser";
64 64
65 // A string pref containing the ID of the last active user. 65 // 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 66 // In case of browser crash, this pref will be used to set active user after
67 // session restore. 67 // session restore.
68 const char kLastActiveUser[] = "LastActiveUser"; 68 const char kLastActiveUser[] = "LastActiveUser";
69 69
70 // Upper bound for a histogram metric reporting the amount of time between 70 // Upper bound for a histogram metric reporting the amount of time between
71 // one regular user logging out and a different regular user logging in. 71 // one regular user logging out and a different regular user logging in.
72 const int kLogoutToLoginDelayMaxSec = 1800; 72 const int kLogoutToLoginDelayMaxSec = 1800;
73 73
(...skipping 12 matching lines...) Expand all
86 void ResolveLocale(const std::string& raw_locale, 86 void ResolveLocale(const std::string& raw_locale,
87 std::string* resolved_locale) { 87 std::string* resolved_locale) {
88 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); 88 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale));
89 } 89 }
90 90
91 } // namespace 91 } // namespace
92 92
93 // static 93 // static
94 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { 94 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) {
95 registry->RegisterListPref(kRegularUsers); 95 registry->RegisterListPref(kRegularUsers);
96 registry->RegisterStringPref(kLastLoggedInRegularUser, std::string()); 96 registry->RegisterStringPref(kLastLoggedInGaiaUser, std::string());
97 registry->RegisterDictionaryPref(kUserDisplayName); 97 registry->RegisterDictionaryPref(kUserDisplayName);
98 registry->RegisterDictionaryPref(kUserGivenName); 98 registry->RegisterDictionaryPref(kUserGivenName);
99 registry->RegisterDictionaryPref(kUserDisplayEmail); 99 registry->RegisterDictionaryPref(kUserDisplayEmail);
100 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); 100 registry->RegisterDictionaryPref(kUserOAuthTokenStatus);
101 registry->RegisterDictionaryPref(kUserForceOnlineSignin); 101 registry->RegisterDictionaryPref(kUserForceOnlineSignin);
102 registry->RegisterStringPref(kLastActiveUser, std::string()); 102 registry->RegisterStringPref(kLastActiveUser, std::string());
103 } 103 }
104 104
105 UserManagerBase::UserManagerBase( 105 UserManagerBase::UserManagerBase(
106 scoped_refptr<base::TaskRunner> task_runner, 106 scoped_refptr<base::TaskRunner> task_runner,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 active_user_->set_is_logged_in(true); 211 active_user_->set_is_logged_in(true);
212 active_user_->set_is_active(true); 212 active_user_->set_is_active(true);
213 active_user_->set_username_hash(username_hash); 213 active_user_->set_username_hash(username_hash);
214 214
215 // Place user who just signed in to the top of the logged in users. 215 // Place user who just signed in to the top of the logged in users.
216 logged_in_users_.insert(logged_in_users_.begin(), active_user_); 216 logged_in_users_.insert(logged_in_users_.begin(), active_user_);
217 SetLRUUser(active_user_); 217 SetLRUUser(active_user_);
218 218
219 if (!primary_user_) { 219 if (!primary_user_) {
220 primary_user_ = active_user_; 220 primary_user_ = active_user_;
221 if (primary_user_->GetType() == USER_TYPE_REGULAR) 221 if (primary_user_->HasGaiaAccount())
222 SendRegularUserLoginMetrics(user_id); 222 SendGaiaUserLoginMetrics(user_id);
223 } 223 }
224 224
225 UMA_HISTOGRAM_ENUMERATION( 225 UMA_HISTOGRAM_ENUMERATION(
226 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES); 226 "UserManager.LoginUserType", active_user_->GetType(), NUM_USER_TYPES);
227 227
228 GetLocalState()->SetString( 228 GetLocalState()->SetString(
229 kLastLoggedInRegularUser, 229 kLastLoggedInGaiaUser, active_user_->HasGaiaAccount() ? user_id : "");
230 (active_user_->GetType() == USER_TYPE_REGULAR) ? user_id : "");
231 230
232 NotifyOnLogin(); 231 NotifyOnLogin();
233 PerformPostUserLoggedInActions(browser_restart); 232 PerformPostUserLoggedInActions(browser_restart);
234 } 233 }
235 234
236 void UserManagerBase::SwitchActiveUser(const std::string& user_id) { 235 void UserManagerBase::SwitchActiveUser(const std::string& user_id) {
237 User* user = FindUserAndModify(user_id); 236 User* user = FindUserAndModify(user_id);
238 if (!user) { 237 if (!user) {
239 NOTREACHED() << "Switching to a non-existing user"; 238 NOTREACHED() << "Switching to a non-existing user";
240 return; 239 return;
241 } 240 }
242 if (user == active_user_) { 241 if (user == active_user_) {
243 NOTREACHED() << "Switching to a user who is already active"; 242 NOTREACHED() << "Switching to a user who is already active";
244 return; 243 return;
245 } 244 }
246 if (!user->is_logged_in()) { 245 if (!user->is_logged_in()) {
247 NOTREACHED() << "Switching to a user that is not logged in"; 246 NOTREACHED() << "Switching to a user that is not logged in";
248 return; 247 return;
249 } 248 }
250 if (user->GetType() != USER_TYPE_REGULAR) { 249 if (!user->HasGaiaAccount()) {
251 NOTREACHED() << "Switching to a non-regular user"; 250 NOTREACHED() <<
251 "Switching to a user without gaia account (non-regular one)";
bartfab (slow) 2014/11/27 12:51:51 Nit: As before, "non-regular one" is not really he
252 return; 252 return;
253 } 253 }
254 if (user->username_hash().empty()) { 254 if (user->username_hash().empty()) {
255 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; 255 NOTREACHED() << "Switching to a user that doesn't have username_hash set";
256 return; 256 return;
257 } 257 }
258 258
259 DCHECK(active_user_); 259 DCHECK(active_user_);
260 active_user_->set_is_active(false); 260 active_user_->set_is_active(false);
261 user->set_is_active(true); 261 user->set_is_active(true);
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 bool UserManagerBase::CanCurrentUserLock() const { 544 bool UserManagerBase::CanCurrentUserLock() const {
545 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 545 DCHECK(task_runner_->RunsTasksOnCurrentThread());
546 return IsUserLoggedIn() && active_user_->can_lock(); 546 return IsUserLoggedIn() && active_user_->can_lock();
547 } 547 }
548 548
549 bool UserManagerBase::IsUserLoggedIn() const { 549 bool UserManagerBase::IsUserLoggedIn() const {
550 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 550 DCHECK(task_runner_->RunsTasksOnCurrentThread());
551 return active_user_; 551 return active_user_;
552 } 552 }
553 553
554 bool UserManagerBase::IsLoggedInAsRegularUser() const { 554 bool UserManagerBase::IsLoggedInAsUserWithGaiaAccount() const {
555 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 555 DCHECK(task_runner_->RunsTasksOnCurrentThread());
556 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_REGULAR; 556 return IsUserLoggedIn() && active_user_->HasGaiaAccount();
557 }
558
559 bool UserManagerBase::IsLoggedInAsRegularSupervisedUser() const {
560 DCHECK(task_runner_->RunsTasksOnCurrentThread());
561 return IsUserLoggedIn() && active_user_->GetType() ==
562 USER_TYPE_REGULAR_SUPERVISED;
557 } 563 }
558 564
559 bool UserManagerBase::IsLoggedInAsDemoUser() const { 565 bool UserManagerBase::IsLoggedInAsDemoUser() const {
560 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 566 DCHECK(task_runner_->RunsTasksOnCurrentThread());
561 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_RETAIL_MODE; 567 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_RETAIL_MODE;
562 } 568 }
563 569
564 bool UserManagerBase::IsLoggedInAsPublicAccount() const { 570 bool UserManagerBase::IsLoggedInAsPublicAccount() const {
565 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 571 DCHECK(task_runner_->RunsTasksOnCurrentThread());
566 return IsUserLoggedIn() && 572 return IsUserLoggedIn() &&
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 610 }
605 611
606 // Data belonging to the owner, anyone found on the user list and obsolete 612 // Data belonging to the owner, anyone found on the user list and obsolete
607 // public accounts whose data has not been removed yet is not ephemeral. 613 // public accounts whose data has not been removed yet is not ephemeral.
608 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) || 614 if (user_id == GetOwnerEmail() || UserExistsInList(user_id) ||
609 IsPublicAccountMarkedForRemoval(user_id)) { 615 IsPublicAccountMarkedForRemoval(user_id)) {
610 return false; 616 return false;
611 } 617 }
612 618
613 // Data belonging to the currently logged-in user is ephemeral when: 619 // Data belonging to the currently logged-in user is ephemeral when:
614 // a) The user logged into a regular account while the ephemeral users policy 620 // a) The user logged into a regular gaia account while the ephemeral users
bartfab (slow) 2014/11/27 12:51:51 Nit: s/into a regular/in with a/ (there is not suc
615 // was enabled. 621 // policy was enabled.
616 // - or - 622 // - or -
617 // b) The user logged into any other account type. 623 // b) The user logged into any other account type.
618 if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->email()) && 624 if (IsUserLoggedIn() && (user_id == GetLoggedInUser()->email()) &&
619 (is_current_user_ephemeral_regular_user_ || !IsLoggedInAsRegularUser())) { 625 (is_current_user_ephemeral_regular_user_ ||
626 !IsLoggedInAsUserWithGaiaAccount())) {
620 return true; 627 return true;
621 } 628 }
622 629
623 // Data belonging to any other user is ephemeral when: 630 // Data belonging to any other user is ephemeral when:
624 // a) Going through the regular login flow and the ephemeral users policy is 631 // a) Going through the regular login flow and the ephemeral users policy is
625 // enabled. 632 // enabled.
626 // - or - 633 // - or -
627 // b) The browser is restarting after a crash. 634 // b) The browser is restarting after a crash.
628 return AreEphemeralUsersEnabled() || 635 return AreEphemeralUsersEnabled() ||
629 session_manager::SessionManager::HasBrowserRestarted(); 636 session_manager::SessionManager::HasBrowserRestarted();
(...skipping 21 matching lines...) Expand all
651 session_state_observer_list_.RemoveObserver(obs); 658 session_state_observer_list_.RemoveObserver(obs);
652 } 659 }
653 660
654 void UserManagerBase::NotifyLocalStateChanged() { 661 void UserManagerBase::NotifyLocalStateChanged() {
655 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 662 DCHECK(task_runner_->RunsTasksOnCurrentThread());
656 FOR_EACH_OBSERVER( 663 FOR_EACH_OBSERVER(
657 UserManager::Observer, observer_list_, LocalStateChanged(this)); 664 UserManager::Observer, observer_list_, LocalStateChanged(this));
658 } 665 }
659 666
660 bool UserManagerBase::CanUserBeRemoved(const User* user) const { 667 bool UserManagerBase::CanUserBeRemoved(const User* user) const {
661 // Only regular and supervised users are allowed to be manually removed. 668 // Only regular and supervised users are allowed to be manually removed.
bartfab (slow) 2014/11/27 12:51:51 Nit: "regular" and "supervised" overlap now that w
662 if (!user || (user->GetType() != USER_TYPE_REGULAR && 669 if (!user || !(user->HasGaiaAccount() || user->IsSupervised()))
663 user->GetType() != USER_TYPE_SUPERVISED)) {
664 return false; 670 return false;
665 }
666 671
667 // Sanity check: we must not remove single user unless it's an enterprise 672 // Sanity check: we must not remove single user unless it's an enterprise
668 // device. This check may seem redundant at a first sight because 673 // device. This check may seem redundant at a first sight because
669 // this single user must be an owner and we perform special check later 674 // this single user must be an owner and we perform special check later
670 // in order not to remove an owner. However due to non-instant nature of 675 // in order not to remove an owner. However due to non-instant nature of
671 // ownership assignment this later check may sometimes fail. 676 // ownership assignment this later check may sometimes fail.
672 // See http://crosbug.com/12723 677 // See http://crosbug.com/12723
673 if (users_.size() < 2 && !IsEnterpriseManaged()) 678 if (users_.size() < 2 && !IsEnterpriseManaged())
674 return false; 679 return false;
675 680
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 const std::string& user_id) { 920 const std::string& user_id) {
916 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); 921 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers);
917 prefs_users_update->Clear(); 922 prefs_users_update->Clear();
918 User* user = NULL; 923 User* user = NULL;
919 for (UserList::iterator it = users_.begin(); it != users_.end();) { 924 for (UserList::iterator it = users_.begin(); it != users_.end();) {
920 const std::string user_email = (*it)->email(); 925 const std::string user_email = (*it)->email();
921 if (user_email == user_id) { 926 if (user_email == user_id) {
922 user = *it; 927 user = *it;
923 it = users_.erase(it); 928 it = users_.erase(it);
924 } else { 929 } else {
925 if ((*it)->GetType() == USER_TYPE_REGULAR || 930 if ((*it)->HasGaiaAccount() || (*it)->IsSupervised())
926 (*it)->GetType() == USER_TYPE_SUPERVISED) {
927 prefs_users_update->Append(new base::StringValue(user_email)); 931 prefs_users_update->Append(new base::StringValue(user_email));
928 }
929 ++it; 932 ++it;
930 } 933 }
931 } 934 }
932 return user; 935 return user;
933 } 936 }
934 937
935 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { 938 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) {
936 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 939 DCHECK(task_runner_->RunsTasksOnCurrentThread());
937 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, 940 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver,
938 session_state_observer_list_, 941 session_state_observer_list_,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 GetLocalState()->SetString(kLastActiveUser, user->email()); 1005 GetLocalState()->SetString(kLastActiveUser, user->email());
1003 GetLocalState()->CommitPendingWrite(); 1006 GetLocalState()->CommitPendingWrite();
1004 1007
1005 UserList::iterator it = 1008 UserList::iterator it =
1006 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); 1009 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user);
1007 if (it != lru_logged_in_users_.end()) 1010 if (it != lru_logged_in_users_.end())
1008 lru_logged_in_users_.erase(it); 1011 lru_logged_in_users_.erase(it);
1009 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user); 1012 lru_logged_in_users_.insert(lru_logged_in_users_.begin(), user);
1010 } 1013 }
1011 1014
1012 void UserManagerBase::SendRegularUserLoginMetrics(const std::string& user_id) { 1015 void UserManagerBase::SendGaiaUserLoginMetrics(const std::string& user_id) {
1013 // If this isn't the first time Chrome was run after the system booted, 1016 // If this isn't the first time Chrome was run after the system booted,
1014 // assume that Chrome was restarted because a previous session ended. 1017 // assume that Chrome was restarted because a previous session ended.
1015 if (!CommandLine::ForCurrentProcess()->HasSwitch( 1018 if (!CommandLine::ForCurrentProcess()->HasSwitch(
1016 chromeos::switches::kFirstExecAfterBoot)) { 1019 chromeos::switches::kFirstExecAfterBoot)) {
1017 const std::string last_email = 1020 const std::string last_email =
1018 GetLocalState()->GetString(kLastLoggedInRegularUser); 1021 GetLocalState()->GetString(kLastLoggedInGaiaUser);
1019 const base::TimeDelta time_to_login = 1022 const base::TimeDelta time_to_login =
1020 base::TimeTicks::Now() - manager_creation_time_; 1023 base::TimeTicks::Now() - manager_creation_time_;
1021 if (!last_email.empty() && user_id != last_email && 1024 if (!last_email.empty() && user_id != last_email &&
1022 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) { 1025 time_to_login.InSeconds() <= kLogoutToLoginDelayMaxSec) {
1023 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay", 1026 UMA_HISTOGRAM_CUSTOM_COUNTS("UserManager.LogoutToLoginDelay",
1024 time_to_login.InSeconds(), 1027 time_to_login.InSeconds(),
1025 0, 1028 0,
1026 kLogoutToLoginDelayMaxSec, 1029 kLogoutToLoginDelayMaxSec,
1027 50); 1030 50);
1028 } 1031 }
(...skipping 30 matching lines...) Expand all
1059 } 1062 }
1060 1063
1061 void UserManagerBase::DeleteUser(User* user) { 1064 void UserManagerBase::DeleteUser(User* user) {
1062 const bool is_active_user = (user == active_user_); 1065 const bool is_active_user = (user == active_user_);
1063 delete user; 1066 delete user;
1064 if (is_active_user) 1067 if (is_active_user)
1065 active_user_ = NULL; 1068 active_user_ = NULL;
1066 } 1069 }
1067 1070
1068 } // namespace user_manager 1071 } // namespace user_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698