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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 294 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
295 RemoveNonCryptohomeData(account_id); | 295 RemoveNonCryptohomeData(account_id); |
296 if (user_loading_stage_ == STAGE_LOADED) { | 296 if (user_loading_stage_ == STAGE_LOADED) { |
297 DeleteUser(RemoveRegularOrSupervisedUserFromList(account_id)); | 297 DeleteUser(RemoveRegularOrSupervisedUserFromList(account_id)); |
298 } else if (user_loading_stage_ == STAGE_LOADING) { | 298 } else if (user_loading_stage_ == STAGE_LOADING) { |
299 DCHECK(IsSupervisedAccountId(account_id) || | 299 DCHECK(IsSupervisedAccountId(account_id) || |
300 HasPendingBootstrap(account_id)); | 300 HasPendingBootstrap(account_id)); |
301 // Special case, removing partially-constructed supervised user or | 301 // Special case, removing partially-constructed supervised user or |
302 // boostrapping user during user list loading. | 302 // boostrapping user during user list loading. |
303 ListPrefUpdate users_update(GetLocalState(), kRegularUsers); | 303 ListPrefUpdate users_update(GetLocalState(), kRegularUsers); |
304 users_update->Remove(base::StringValue(account_id.GetUserEmail()), nullptr); | 304 users_update->Remove(base::Value(account_id.GetUserEmail()), nullptr); |
305 OnUserRemoved(account_id); | 305 OnUserRemoved(account_id); |
306 } else { | 306 } else { |
307 NOTREACHED() << "Users are not loaded yet."; | 307 NOTREACHED() << "Users are not loaded yet."; |
308 return; | 308 return; |
309 } | 309 } |
310 | 310 |
311 // Make sure that new data is persisted to Local State. | 311 // Make sure that new data is persisted to Local State. |
312 GetLocalState()->CommitPendingWrite(); | 312 GetLocalState()->CommitPendingWrite(); |
313 } | 313 } |
314 | 314 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 | 394 |
395 if (User* user = FindUserAndModify(account_id)) { | 395 if (User* user = FindUserAndModify(account_id)) { |
396 user->set_display_name(display_name); | 396 user->set_display_name(display_name); |
397 | 397 |
398 // Do not update local state if data stored or cached outside the user's | 398 // Do not update local state if data stored or cached outside the user's |
399 // cryptohome is to be treated as ephemeral. | 399 // cryptohome is to be treated as ephemeral. |
400 if (!IsUserNonCryptohomeDataEphemeral(account_id)) { | 400 if (!IsUserNonCryptohomeDataEphemeral(account_id)) { |
401 DictionaryPrefUpdate display_name_update(GetLocalState(), | 401 DictionaryPrefUpdate display_name_update(GetLocalState(), |
402 kUserDisplayName); | 402 kUserDisplayName); |
403 display_name_update->SetWithoutPathExpansion( | 403 display_name_update->SetWithoutPathExpansion( |
404 account_id.GetUserEmail(), new base::StringValue(display_name)); | 404 account_id.GetUserEmail(), new base::Value(display_name)); |
405 } | 405 } |
406 } | 406 } |
407 } | 407 } |
408 | 408 |
409 base::string16 UserManagerBase::GetUserDisplayName( | 409 base::string16 UserManagerBase::GetUserDisplayName( |
410 const AccountId& account_id) const { | 410 const AccountId& account_id) const { |
411 const User* user = FindUser(account_id); | 411 const User* user = FindUser(account_id); |
412 return user ? user->display_name() : base::string16(); | 412 return user ? user->display_name() : base::string16(); |
413 } | 413 } |
414 | 414 |
415 void UserManagerBase::SaveUserDisplayEmail(const AccountId& account_id, | 415 void UserManagerBase::SaveUserDisplayEmail(const AccountId& account_id, |
416 const std::string& display_email) { | 416 const std::string& display_email) { |
417 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 417 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
418 | 418 |
419 User* user = FindUserAndModify(account_id); | 419 User* user = FindUserAndModify(account_id); |
420 if (!user) { | 420 if (!user) { |
421 LOG(ERROR) << "User not found: " << account_id.GetUserEmail(); | 421 LOG(ERROR) << "User not found: " << account_id.GetUserEmail(); |
422 return; // Ignore if there is no such user. | 422 return; // Ignore if there is no such user. |
423 } | 423 } |
424 | 424 |
425 user->set_display_email(display_email); | 425 user->set_display_email(display_email); |
426 | 426 |
427 // Do not update local state if data stored or cached outside the user's | 427 // Do not update local state if data stored or cached outside the user's |
428 // cryptohome is to be treated as ephemeral. | 428 // cryptohome is to be treated as ephemeral. |
429 if (IsUserNonCryptohomeDataEphemeral(account_id)) | 429 if (IsUserNonCryptohomeDataEphemeral(account_id)) |
430 return; | 430 return; |
431 | 431 |
432 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); | 432 DictionaryPrefUpdate display_email_update(GetLocalState(), kUserDisplayEmail); |
433 display_email_update->SetWithoutPathExpansion( | 433 display_email_update->SetWithoutPathExpansion(account_id.GetUserEmail(), |
434 account_id.GetUserEmail(), new base::StringValue(display_email)); | 434 new base::Value(display_email)); |
435 } | 435 } |
436 | 436 |
437 std::string UserManagerBase::GetUserDisplayEmail( | 437 std::string UserManagerBase::GetUserDisplayEmail( |
438 const AccountId& account_id) const { | 438 const AccountId& account_id) const { |
439 const User* user = FindUser(account_id); | 439 const User* user = FindUser(account_id); |
440 return user ? user->display_email() : account_id.GetUserEmail(); | 440 return user ? user->display_email() : account_id.GetUserEmail(); |
441 } | 441 } |
442 | 442 |
443 void UserManagerBase::SaveUserType(const AccountId& account_id, | 443 void UserManagerBase::SaveUserType(const AccountId& account_id, |
444 const UserType& user_type) { | 444 const UserType& user_type) { |
(...skipping 21 matching lines...) Expand all Loading... |
466 const UserAccountData& account_data) { | 466 const UserAccountData& account_data) { |
467 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 467 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
468 | 468 |
469 SaveUserDisplayName(account_id, account_data.display_name()); | 469 SaveUserDisplayName(account_id, account_data.display_name()); |
470 | 470 |
471 if (User* user = FindUserAndModify(account_id)) { | 471 if (User* user = FindUserAndModify(account_id)) { |
472 base::string16 given_name = account_data.given_name(); | 472 base::string16 given_name = account_data.given_name(); |
473 user->set_given_name(given_name); | 473 user->set_given_name(given_name); |
474 if (!IsUserNonCryptohomeDataEphemeral(account_id)) { | 474 if (!IsUserNonCryptohomeDataEphemeral(account_id)) { |
475 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); | 475 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); |
476 given_name_update->SetWithoutPathExpansion( | 476 given_name_update->SetWithoutPathExpansion(account_id.GetUserEmail(), |
477 account_id.GetUserEmail(), new base::StringValue(given_name)); | 477 new base::Value(given_name)); |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
481 UpdateUserAccountLocale(account_id, account_data.locale()); | 481 UpdateUserAccountLocale(account_id, account_data.locale()); |
482 } | 482 } |
483 | 483 |
484 void UserManagerBase::ParseUserList(const base::ListValue& users_list, | 484 void UserManagerBase::ParseUserList(const base::ListValue& users_list, |
485 const std::set<AccountId>& existing_users, | 485 const std::set<AccountId>& existing_users, |
486 std::vector<AccountId>* users_vector, | 486 std::vector<AccountId>* users_vector, |
487 std::set<AccountId>* users_set) { | 487 std::set<AccountId>* users_set) { |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 } | 860 } |
861 | 861 |
862 void UserManagerBase::GuestUserLoggedIn() { | 862 void UserManagerBase::GuestUserLoggedIn() { |
863 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 863 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
864 active_user_ = User::CreateGuestUser(GetGuestAccountId()); | 864 active_user_ = User::CreateGuestUser(GetGuestAccountId()); |
865 } | 865 } |
866 | 866 |
867 void UserManagerBase::AddUserRecord(User* user) { | 867 void UserManagerBase::AddUserRecord(User* user) { |
868 // Add the user to the front of the user list. | 868 // Add the user to the front of the user list. |
869 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 869 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
870 prefs_users_update->Insert(0, base::MakeUnique<base::StringValue>( | 870 prefs_users_update->Insert( |
871 user->GetAccountId().GetUserEmail())); | 871 0, base::MakeUnique<base::Value>(user->GetAccountId().GetUserEmail())); |
872 users_.insert(users_.begin(), user); | 872 users_.insert(users_.begin(), user); |
873 } | 873 } |
874 | 874 |
875 void UserManagerBase::RegularUserLoggedIn(const AccountId& account_id) { | 875 void UserManagerBase::RegularUserLoggedIn(const AccountId& account_id) { |
876 // Remove the user from the user list. | 876 // Remove the user from the user list. |
877 active_user_ = RemoveRegularOrSupervisedUserFromList(account_id); | 877 active_user_ = RemoveRegularOrSupervisedUserFromList(account_id); |
878 | 878 |
879 // If the user was not found on the user list, create a new user. | 879 // If the user was not found on the user list, create a new user. |
880 SetIsCurrentUserNew(!active_user_); | 880 SetIsCurrentUserNew(!active_user_); |
881 if (IsCurrentUserNew()) { | 881 if (IsCurrentUserNew()) { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 } | 1089 } |
1090 | 1090 |
1091 void UserManagerBase::DeleteUser(User* user) { | 1091 void UserManagerBase::DeleteUser(User* user) { |
1092 const bool is_active_user = (user == active_user_); | 1092 const bool is_active_user = (user == active_user_); |
1093 delete user; | 1093 delete user; |
1094 if (is_active_user) | 1094 if (is_active_user) |
1095 active_user_ = nullptr; | 1095 active_user_ = nullptr; |
1096 } | 1096 } |
1097 | 1097 |
1098 } // namespace user_manager | 1098 } // namespace user_manager |
OLD | NEW |