| OLD | NEW |
| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_->IsRegular()) |
| 222 SendRegularUserLoginMetrics(user_id); | 222 SendRegularUserLoginMetrics(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 kLastLoggedInRegularUser, active_user_->IsRegular() ? 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->IsRegular()) { |
| 251 NOTREACHED() << "Switching to a non-regular user"; | 250 NOTREACHED() << "Switching to a non-regular user"; |
| 252 return; | 251 return; |
| 253 } | 252 } |
| 254 if (user->username_hash().empty()) { | 253 if (user->username_hash().empty()) { |
| 255 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; | 254 NOTREACHED() << "Switching to a user that doesn't have username_hash set"; |
| 256 return; | 255 return; |
| 257 } | 256 } |
| 258 | 257 |
| 259 DCHECK(active_user_); | 258 DCHECK(active_user_); |
| 260 active_user_->set_is_active(false); | 259 active_user_->set_is_active(false); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 return IsUserLoggedIn() && active_user_->can_lock(); | 545 return IsUserLoggedIn() && active_user_->can_lock(); |
| 547 } | 546 } |
| 548 | 547 |
| 549 bool UserManagerBase::IsUserLoggedIn() const { | 548 bool UserManagerBase::IsUserLoggedIn() const { |
| 550 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 549 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 551 return active_user_; | 550 return active_user_; |
| 552 } | 551 } |
| 553 | 552 |
| 554 bool UserManagerBase::IsLoggedInAsRegularUser() const { | 553 bool UserManagerBase::IsLoggedInAsRegularUser() const { |
| 555 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 554 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 556 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_REGULAR; | 555 return IsUserLoggedIn() && active_user_->IsRegular(); |
| 556 } |
| 557 |
| 558 bool UserManagerBase::IsLoggedInAsRegularSupervisedUser() const { |
| 559 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 560 return IsUserLoggedIn() && active_user_->GetType() == |
| 561 USER_TYPE_REGULAR_SUPERVISED; |
| 557 } | 562 } |
| 558 | 563 |
| 559 bool UserManagerBase::IsLoggedInAsDemoUser() const { | 564 bool UserManagerBase::IsLoggedInAsDemoUser() const { |
| 560 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 565 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 561 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_RETAIL_MODE; | 566 return IsUserLoggedIn() && active_user_->GetType() == USER_TYPE_RETAIL_MODE; |
| 562 } | 567 } |
| 563 | 568 |
| 564 bool UserManagerBase::IsLoggedInAsPublicAccount() const { | 569 bool UserManagerBase::IsLoggedInAsPublicAccount() const { |
| 565 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 570 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 566 return IsUserLoggedIn() && | 571 return IsUserLoggedIn() && |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 } | 657 } |
| 653 | 658 |
| 654 void UserManagerBase::NotifyLocalStateChanged() { | 659 void UserManagerBase::NotifyLocalStateChanged() { |
| 655 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 660 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 656 FOR_EACH_OBSERVER( | 661 FOR_EACH_OBSERVER( |
| 657 UserManager::Observer, observer_list_, LocalStateChanged(this)); | 662 UserManager::Observer, observer_list_, LocalStateChanged(this)); |
| 658 } | 663 } |
| 659 | 664 |
| 660 bool UserManagerBase::CanUserBeRemoved(const User* user) const { | 665 bool UserManagerBase::CanUserBeRemoved(const User* user) const { |
| 661 // Only regular and supervised users are allowed to be manually removed. | 666 // Only regular and supervised users are allowed to be manually removed. |
| 662 if (!user || (user->GetType() != USER_TYPE_REGULAR && | 667 if (!user || (!user->IsRegular() && !user->IsSupervised())) |
| 663 user->GetType() != USER_TYPE_SUPERVISED)) { | |
| 664 return false; | 668 return false; |
| 665 } | |
| 666 | 669 |
| 667 // Sanity check: we must not remove single user unless it's an enterprise | 670 // 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 | 671 // 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 | 672 // 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 | 673 // in order not to remove an owner. However due to non-instant nature of |
| 671 // ownership assignment this later check may sometimes fail. | 674 // ownership assignment this later check may sometimes fail. |
| 672 // See http://crosbug.com/12723 | 675 // See http://crosbug.com/12723 |
| 673 if (users_.size() < 2 && !IsEnterpriseManaged()) | 676 if (users_.size() < 2 && !IsEnterpriseManaged()) |
| 674 return false; | 677 return false; |
| 675 | 678 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 const std::string& user_id) { | 918 const std::string& user_id) { |
| 916 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 919 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
| 917 prefs_users_update->Clear(); | 920 prefs_users_update->Clear(); |
| 918 User* user = NULL; | 921 User* user = NULL; |
| 919 for (UserList::iterator it = users_.begin(); it != users_.end();) { | 922 for (UserList::iterator it = users_.begin(); it != users_.end();) { |
| 920 const std::string user_email = (*it)->email(); | 923 const std::string user_email = (*it)->email(); |
| 921 if (user_email == user_id) { | 924 if (user_email == user_id) { |
| 922 user = *it; | 925 user = *it; |
| 923 it = users_.erase(it); | 926 it = users_.erase(it); |
| 924 } else { | 927 } else { |
| 925 if ((*it)->GetType() == USER_TYPE_REGULAR || | 928 if ((*it)->IsRegular() || (*it)->IsSupervised()) |
| 926 (*it)->GetType() == USER_TYPE_SUPERVISED) { | |
| 927 prefs_users_update->Append(new base::StringValue(user_email)); | 929 prefs_users_update->Append(new base::StringValue(user_email)); |
| 928 } | |
| 929 ++it; | 930 ++it; |
| 930 } | 931 } |
| 931 } | 932 } |
| 932 return user; | 933 return user; |
| 933 } | 934 } |
| 934 | 935 |
| 935 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { | 936 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { |
| 936 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 937 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 937 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 938 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
| 938 session_state_observer_list_, | 939 session_state_observer_list_, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 } | 1060 } |
| 1060 | 1061 |
| 1061 void UserManagerBase::DeleteUser(User* user) { | 1062 void UserManagerBase::DeleteUser(User* user) { |
| 1062 const bool is_active_user = (user == active_user_); | 1063 const bool is_active_user = (user == active_user_); |
| 1063 delete user; | 1064 delete user; |
| 1064 if (is_active_user) | 1065 if (is_active_user) |
| 1065 active_user_ = NULL; | 1066 active_user_ = NULL; |
| 1066 } | 1067 } |
| 1067 | 1068 |
| 1068 } // namespace user_manager | 1069 } // namespace user_manager |
| OLD | NEW |