| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 DCHECK(active_user_); | 235 DCHECK(active_user_); |
| 236 active_user_->set_is_active(false); | 236 active_user_->set_is_active(false); |
| 237 user->set_is_active(true); | 237 user->set_is_active(true); |
| 238 active_user_ = user; | 238 active_user_ = user; |
| 239 | 239 |
| 240 // Move the user to the front. | 240 // Move the user to the front. |
| 241 SetLRUUser(active_user_); | 241 SetLRUUser(active_user_); |
| 242 | 242 |
| 243 NotifyActiveUserHashChanged(active_user_->username_hash()); | 243 NotifyActiveUserHashChanged(active_user_->username_hash()); |
| 244 NotifyActiveUserChanged(active_user_); | 244 NotifyActiveUserChanged(active_user_); |
| 245 CallUpdateLoginState(); |
| 245 } | 246 } |
| 246 | 247 |
| 247 void UserManagerBase::SwitchToLastActiveUser() { | 248 void UserManagerBase::SwitchToLastActiveUser() { |
| 248 if (!last_session_active_account_id_.is_valid()) | 249 if (!last_session_active_account_id_.is_valid()) |
| 249 return; | 250 return; |
| 250 | 251 |
| 251 if (AccountId::FromUserEmail( | 252 if (AccountId::FromUserEmail( |
| 252 GetActiveUser()->GetAccountId().GetUserEmail()) != | 253 GetActiveUser()->GetAccountId().GetUserEmail()) != |
| 253 last_session_active_account_id_) | 254 last_session_active_account_id_) |
| 254 SwitchActiveUser(last_session_active_account_id_); | 255 SwitchActiveUser(last_session_active_account_id_); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 !users_set->insert(account_id).second) { | 512 !users_set->insert(account_id).second) { |
| 512 LOG(ERROR) << "Duplicate user: " << email; | 513 LOG(ERROR) << "Duplicate user: " << email; |
| 513 continue; | 514 continue; |
| 514 } | 515 } |
| 515 users_vector->push_back(account_id); | 516 users_vector->push_back(account_id); |
| 516 } | 517 } |
| 517 } | 518 } |
| 518 | 519 |
| 519 bool UserManagerBase::IsCurrentUserOwner() const { | 520 bool UserManagerBase::IsCurrentUserOwner() const { |
| 520 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 521 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 521 base::AutoLock lk(is_current_user_owner_lock_); | 522 return !owner_account_id_.empty() && active_user_ && |
| 522 return is_current_user_owner_; | 523 active_user_->GetAccountId() == owner_account_id_; |
| 523 } | |
| 524 | |
| 525 void UserManagerBase::SetCurrentUserIsOwner(bool is_current_user_owner) { | |
| 526 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | |
| 527 { | |
| 528 base::AutoLock lk(is_current_user_owner_lock_); | |
| 529 is_current_user_owner_ = is_current_user_owner; | |
| 530 } | |
| 531 CallUpdateLoginState(); | |
| 532 } | 524 } |
| 533 | 525 |
| 534 bool UserManagerBase::IsCurrentUserNew() const { | 526 bool UserManagerBase::IsCurrentUserNew() const { |
| 535 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 527 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 536 return is_current_user_new_; | 528 return is_current_user_new_; |
| 537 } | 529 } |
| 538 | 530 |
| 539 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { | 531 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { |
| 540 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 532 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 541 return IsUserLoggedIn() && | 533 return IsUserLoggedIn() && |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 void UserManagerBase::SetIsCurrentUserNew(bool is_new) { | 734 void UserManagerBase::SetIsCurrentUserNew(bool is_new) { |
| 743 is_current_user_new_ = is_new; | 735 is_current_user_new_ = is_new; |
| 744 } | 736 } |
| 745 | 737 |
| 746 bool UserManagerBase::HasPendingBootstrap(const AccountId& account_id) const { | 738 bool UserManagerBase::HasPendingBootstrap(const AccountId& account_id) const { |
| 747 return false; | 739 return false; |
| 748 } | 740 } |
| 749 | 741 |
| 750 void UserManagerBase::SetOwnerId(const AccountId& owner_account_id) { | 742 void UserManagerBase::SetOwnerId(const AccountId& owner_account_id) { |
| 751 owner_account_id_ = owner_account_id; | 743 owner_account_id_ = owner_account_id; |
| 744 CallUpdateLoginState(); |
| 752 } | 745 } |
| 753 | 746 |
| 754 const AccountId& UserManagerBase::GetPendingUserSwitchID() const { | 747 const AccountId& UserManagerBase::GetPendingUserSwitchID() const { |
| 755 return pending_user_switch_; | 748 return pending_user_switch_; |
| 756 } | 749 } |
| 757 | 750 |
| 758 void UserManagerBase::SetPendingUserSwitchId(const AccountId& account_id) { | 751 void UserManagerBase::SetPendingUserSwitchId(const AccountId& account_id) { |
| 759 pending_user_switch_ = account_id; | 752 pending_user_switch_ = account_id; |
| 760 } | 753 } |
| 761 | 754 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 for (auto& observer : session_state_observer_list_) | 1027 for (auto& observer : session_state_observer_list_) |
| 1035 observer.UserChangedChildStatus(user); | 1028 observer.UserChangedChildStatus(user); |
| 1036 } | 1029 } |
| 1037 | 1030 |
| 1038 void UserManagerBase::Initialize() { | 1031 void UserManagerBase::Initialize() { |
| 1039 UserManager::Initialize(); | 1032 UserManager::Initialize(); |
| 1040 CallUpdateLoginState(); | 1033 CallUpdateLoginState(); |
| 1041 } | 1034 } |
| 1042 | 1035 |
| 1043 void UserManagerBase::CallUpdateLoginState() { | 1036 void UserManagerBase::CallUpdateLoginState() { |
| 1044 UpdateLoginState(active_user_, primary_user_, is_current_user_owner_); | 1037 UpdateLoginState(active_user_, primary_user_, IsCurrentUserOwner()); |
| 1045 } | 1038 } |
| 1046 | 1039 |
| 1047 void UserManagerBase::SetLRUUser(User* user) { | 1040 void UserManagerBase::SetLRUUser(User* user) { |
| 1048 GetLocalState()->SetString(kLastActiveUser, | 1041 GetLocalState()->SetString(kLastActiveUser, |
| 1049 user->GetAccountId().GetUserEmail()); | 1042 user->GetAccountId().GetUserEmail()); |
| 1050 GetLocalState()->CommitPendingWrite(); | 1043 GetLocalState()->CommitPendingWrite(); |
| 1051 | 1044 |
| 1052 UserList::iterator it = | 1045 UserList::iterator it = |
| 1053 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); | 1046 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); |
| 1054 if (it != lru_logged_in_users_.end()) | 1047 if (it != lru_logged_in_users_.end()) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 } | 1095 } |
| 1103 | 1096 |
| 1104 void UserManagerBase::DeleteUser(User* user) { | 1097 void UserManagerBase::DeleteUser(User* user) { |
| 1105 const bool is_active_user = (user == active_user_); | 1098 const bool is_active_user = (user == active_user_); |
| 1106 delete user; | 1099 delete user; |
| 1107 if (is_active_user) | 1100 if (is_active_user) |
| 1108 active_user_ = nullptr; | 1101 active_user_ = nullptr; |
| 1109 } | 1102 } |
| 1110 | 1103 |
| 1111 } // namespace user_manager | 1104 } // namespace user_manager |
| OLD | NEW |