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

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

Issue 2798343003: Merge "cros: Fix flaky owner detection" (Closed)
Patch Set: Created 3 years, 8 months 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
« no previous file with comments | « components/user_manager/user_manager_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 !users_set->insert(account_id).second) { 502 !users_set->insert(account_id).second) {
502 LOG(ERROR) << "Duplicate user: " << email; 503 LOG(ERROR) << "Duplicate user: " << email;
503 continue; 504 continue;
504 } 505 }
505 users_vector->push_back(account_id); 506 users_vector->push_back(account_id);
506 } 507 }
507 } 508 }
508 509
509 bool UserManagerBase::IsCurrentUserOwner() const { 510 bool UserManagerBase::IsCurrentUserOwner() const {
510 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 511 DCHECK(task_runner_->RunsTasksOnCurrentThread());
511 base::AutoLock lk(is_current_user_owner_lock_); 512 return !owner_account_id_.empty() && active_user_ &&
512 return is_current_user_owner_; 513 active_user_->GetAccountId() == owner_account_id_;
513 }
514
515 void UserManagerBase::SetCurrentUserIsOwner(bool is_current_user_owner) {
516 DCHECK(task_runner_->RunsTasksOnCurrentThread());
517 {
518 base::AutoLock lk(is_current_user_owner_lock_);
519 is_current_user_owner_ = is_current_user_owner;
520 }
521 CallUpdateLoginState();
522 } 514 }
523 515
524 bool UserManagerBase::IsCurrentUserNew() const { 516 bool UserManagerBase::IsCurrentUserNew() const {
525 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 517 DCHECK(task_runner_->RunsTasksOnCurrentThread());
526 return is_current_user_new_; 518 return is_current_user_new_;
527 } 519 }
528 520
529 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const { 521 bool UserManagerBase::IsCurrentUserNonCryptohomeDataEphemeral() const {
530 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 522 DCHECK(task_runner_->RunsTasksOnCurrentThread());
531 return IsUserLoggedIn() && 523 return IsUserLoggedIn() &&
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 void UserManagerBase::SetIsCurrentUserNew(bool is_new) { 724 void UserManagerBase::SetIsCurrentUserNew(bool is_new) {
733 is_current_user_new_ = is_new; 725 is_current_user_new_ = is_new;
734 } 726 }
735 727
736 bool UserManagerBase::HasPendingBootstrap(const AccountId& account_id) const { 728 bool UserManagerBase::HasPendingBootstrap(const AccountId& account_id) const {
737 return false; 729 return false;
738 } 730 }
739 731
740 void UserManagerBase::SetOwnerId(const AccountId& owner_account_id) { 732 void UserManagerBase::SetOwnerId(const AccountId& owner_account_id) {
741 owner_account_id_ = owner_account_id; 733 owner_account_id_ = owner_account_id;
734 CallUpdateLoginState();
742 } 735 }
743 736
744 const AccountId& UserManagerBase::GetPendingUserSwitchID() const { 737 const AccountId& UserManagerBase::GetPendingUserSwitchID() const {
745 return pending_user_switch_; 738 return pending_user_switch_;
746 } 739 }
747 740
748 void UserManagerBase::SetPendingUserSwitchId(const AccountId& account_id) { 741 void UserManagerBase::SetPendingUserSwitchId(const AccountId& account_id) {
749 pending_user_switch_ = account_id; 742 pending_user_switch_ = account_id;
750 } 743 }
751 744
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 for (auto& observer : session_state_observer_list_) 1014 for (auto& observer : session_state_observer_list_)
1022 observer.UserChangedChildStatus(user); 1015 observer.UserChangedChildStatus(user);
1023 } 1016 }
1024 1017
1025 void UserManagerBase::Initialize() { 1018 void UserManagerBase::Initialize() {
1026 UserManager::Initialize(); 1019 UserManager::Initialize();
1027 CallUpdateLoginState(); 1020 CallUpdateLoginState();
1028 } 1021 }
1029 1022
1030 void UserManagerBase::CallUpdateLoginState() { 1023 void UserManagerBase::CallUpdateLoginState() {
1031 UpdateLoginState(active_user_, primary_user_, is_current_user_owner_); 1024 UpdateLoginState(active_user_, primary_user_, IsCurrentUserOwner());
1032 } 1025 }
1033 1026
1034 void UserManagerBase::SetLRUUser(User* user) { 1027 void UserManagerBase::SetLRUUser(User* user) {
1035 GetLocalState()->SetString(kLastActiveUser, 1028 GetLocalState()->SetString(kLastActiveUser,
1036 user->GetAccountId().GetUserEmail()); 1029 user->GetAccountId().GetUserEmail());
1037 GetLocalState()->CommitPendingWrite(); 1030 GetLocalState()->CommitPendingWrite();
1038 1031
1039 UserList::iterator it = 1032 UserList::iterator it =
1040 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user); 1033 std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user);
1041 if (it != lru_logged_in_users_.end()) 1034 if (it != lru_logged_in_users_.end())
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 } 1082 }
1090 1083
1091 void UserManagerBase::DeleteUser(User* user) { 1084 void UserManagerBase::DeleteUser(User* user) {
1092 const bool is_active_user = (user == active_user_); 1085 const bool is_active_user = (user == active_user_);
1093 delete user; 1086 delete user;
1094 if (is_active_user) 1087 if (is_active_user)
1095 active_user_ = nullptr; 1088 active_user_ = nullptr;
1096 } 1089 }
1097 1090
1098 } // namespace user_manager 1091 } // namespace user_manager
OLDNEW
« no previous file with comments | « components/user_manager/user_manager_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698