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 11 matching lines...) Expand all Loading... |
22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
25 #include "base/task_runner.h" | 25 #include "base/task_runner.h" |
26 #include "base/values.h" | 26 #include "base/values.h" |
27 #include "chromeos/chromeos_switches.h" | 27 #include "chromeos/chromeos_switches.h" |
28 #include "chromeos/cryptohome/async_method_caller.h" | 28 #include "chromeos/cryptohome/async_method_caller.h" |
29 #include "chromeos/login/login_state.h" | 29 #include "chromeos/login/login_state.h" |
30 #include "chromeos/login/user_names.h" | 30 #include "chromeos/login/user_names.h" |
31 #include "components/session_manager/core/session_manager.h" | 31 #include "components/session_manager/core/session_manager.h" |
| 32 #include "components/user_manager/known_user.h" |
32 #include "components/user_manager/remove_user_delegate.h" | 33 #include "components/user_manager/remove_user_delegate.h" |
33 #include "components/user_manager/user_type.h" | 34 #include "components/user_manager/user_type.h" |
34 #include "google_apis/gaia/gaia_auth_util.h" | 35 #include "google_apis/gaia/gaia_auth_util.h" |
35 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
36 | 37 |
37 namespace user_manager { | 38 namespace user_manager { |
38 namespace { | 39 namespace { |
39 | 40 |
40 // A vector pref of the the regular users known on this device, arranged in LRU | 41 // A vector pref of the the regular users known on this device, arranged in LRU |
41 // order. | 42 // order. |
(...skipping 21 matching lines...) Expand all Loading... |
63 // A string pref containing the ID of the last user who logged in if it was | 64 // A string pref containing the ID of the last user who logged in if it was |
64 // a user with gaia account (regular) or an empty string if it was another type | 65 // a user with gaia account (regular) or an empty string if it was another type |
65 // of user (guest, kiosk, public account, etc.). | 66 // of user (guest, kiosk, public account, etc.). |
66 const char kLastLoggedInGaiaUser[] = "LastLoggedInRegularUser"; | 67 const char kLastLoggedInGaiaUser[] = "LastLoggedInRegularUser"; |
67 | 68 |
68 // A string pref containing the ID of the last active user. | 69 // A string pref containing the ID of the last active user. |
69 // In case of browser crash, this pref will be used to set active user after | 70 // In case of browser crash, this pref will be used to set active user after |
70 // session restore. | 71 // session restore. |
71 const char kLastActiveUser[] = "LastActiveUser"; | 72 const char kLastActiveUser[] = "LastActiveUser"; |
72 | 73 |
73 // A vector pref of preferences of known users. All new preferences should be | |
74 // placed in this list. | |
75 const char kKnownUsers[] = "KnownUsers"; | |
76 | |
77 // Known user preferences keys (stored in Local State). | |
78 | |
79 // Key of canonical e-mail value. | |
80 const char kCanonicalEmail[] = "email"; | |
81 | |
82 // Key of obfuscated GAIA id value. | |
83 const char kGAIAIdKey[] = "gaia_id"; | |
84 | |
85 // Key of whether this user ID refers to a SAML user. | |
86 const char kUsingSAMLKey[] = "using_saml"; | |
87 | |
88 // Key of Device Id. | |
89 const char kDeviceId[] = "device_id"; | |
90 | |
91 // Key of GAPS cookie. | |
92 const char kGAPSCookie[] = "gaps_cookie"; | |
93 | |
94 // Key of the reason for re-auth. | |
95 const char kReauthReasonKey[] = "reauth_reason"; | |
96 | |
97 // Upper bound for a histogram metric reporting the amount of time between | 74 // Upper bound for a histogram metric reporting the amount of time between |
98 // one regular user logging out and a different regular user logging in. | 75 // one regular user logging out and a different regular user logging in. |
99 const int kLogoutToLoginDelayMaxSec = 1800; | 76 const int kLogoutToLoginDelayMaxSec = 1800; |
100 | 77 |
101 // Callback that is called after user removal is complete. | 78 // Callback that is called after user removal is complete. |
102 void OnRemoveUserComplete(const AccountId& account_id, | 79 void OnRemoveUserComplete(const AccountId& account_id, |
103 bool success, | 80 bool success, |
104 cryptohome::MountError return_code) { | 81 cryptohome::MountError return_code) { |
105 // Log the error, but there's not much we can do. | 82 // Log the error, but there's not much we can do. |
106 if (!success) { | 83 if (!success) { |
107 LOG(ERROR) << "Removal of cryptohome for " << account_id.Serialize() | 84 LOG(ERROR) << "Removal of cryptohome for " << account_id.Serialize() |
108 << " failed, return code: " << return_code; | 85 << " failed, return code: " << return_code; |
109 } | 86 } |
110 } | 87 } |
111 | 88 |
112 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread. | 89 // Runs on SequencedWorkerPool thread. Passes resolved locale to UI thread. |
113 void ResolveLocale(const std::string& raw_locale, | 90 void ResolveLocale(const std::string& raw_locale, |
114 std::string* resolved_locale) { | 91 std::string* resolved_locale) { |
115 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); | 92 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); |
116 } | 93 } |
117 | 94 |
118 // Checks if values in |dict| correspond with |account_id| identity. | |
119 bool UserMatches(const AccountId& account_id, | |
120 const base::DictionaryValue& dict) { | |
121 std::string value; | |
122 | |
123 // TODO(alemate): update code once user id is really a struct. | |
124 bool has_gaia_id = dict.GetString(kGAIAIdKey, &value); | |
125 if (has_gaia_id && account_id.GetGaiaId() == value) | |
126 return true; | |
127 | |
128 bool has_email = dict.GetString(kCanonicalEmail, &value); | |
129 if (has_email && account_id.GetUserEmail() == value) | |
130 return true; | |
131 | |
132 return false; | |
133 } | |
134 | |
135 // Fills relevant |dict| values based on |account_id|. | |
136 void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) { | |
137 dict.SetString(kCanonicalEmail, account_id.GetUserEmail()); | |
138 } | |
139 | |
140 } // namespace | 95 } // namespace |
141 | 96 |
142 // static | 97 // static |
143 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { | 98 void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) { |
144 registry->RegisterListPref(kRegularUsers); | 99 registry->RegisterListPref(kRegularUsers); |
145 registry->RegisterListPref(kKnownUsers); | |
146 registry->RegisterStringPref(kLastLoggedInGaiaUser, std::string()); | 100 registry->RegisterStringPref(kLastLoggedInGaiaUser, std::string()); |
147 registry->RegisterDictionaryPref(kUserDisplayName); | 101 registry->RegisterDictionaryPref(kUserDisplayName); |
148 registry->RegisterDictionaryPref(kUserGivenName); | 102 registry->RegisterDictionaryPref(kUserGivenName); |
149 registry->RegisterDictionaryPref(kUserDisplayEmail); | 103 registry->RegisterDictionaryPref(kUserDisplayEmail); |
150 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); | 104 registry->RegisterDictionaryPref(kUserOAuthTokenStatus); |
151 registry->RegisterDictionaryPref(kUserForceOnlineSignin); | 105 registry->RegisterDictionaryPref(kUserForceOnlineSignin); |
152 registry->RegisterDictionaryPref(kUserType); | 106 registry->RegisterDictionaryPref(kUserType); |
153 registry->RegisterStringPref(kLastActiveUser, std::string()); | 107 registry->RegisterStringPref(kLastActiveUser, std::string()); |
| 108 |
| 109 known_user::RegisterPrefs(registry); |
154 } | 110 } |
155 | 111 |
156 UserManagerBase::UserManagerBase( | 112 UserManagerBase::UserManagerBase( |
157 scoped_refptr<base::TaskRunner> task_runner, | 113 scoped_refptr<base::TaskRunner> task_runner, |
158 scoped_refptr<base::TaskRunner> blocking_task_runner) | 114 scoped_refptr<base::TaskRunner> blocking_task_runner) |
159 : task_runner_(task_runner), | 115 : task_runner_(task_runner), |
160 blocking_task_runner_(blocking_task_runner), | 116 blocking_task_runner_(blocking_task_runner), |
161 weak_factory_(this) { | 117 weak_factory_(this) { |
162 UpdateLoginState(); | 118 UpdateLoginState(); |
163 } | 119 } |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 if (IsUserNonCryptohomeDataEphemeral(account_id)) | 488 if (IsUserNonCryptohomeDataEphemeral(account_id)) |
533 return; | 489 return; |
534 | 490 |
535 DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType); | 491 DictionaryPrefUpdate user_type_update(GetLocalState(), kUserType); |
536 user_type_update->SetWithoutPathExpansion( | 492 user_type_update->SetWithoutPathExpansion( |
537 account_id.GetUserEmail(), | 493 account_id.GetUserEmail(), |
538 new base::FundamentalValue(static_cast<int>(user_type))); | 494 new base::FundamentalValue(static_cast<int>(user_type))); |
539 GetLocalState()->CommitPendingWrite(); | 495 GetLocalState()->CommitPendingWrite(); |
540 } | 496 } |
541 | 497 |
542 void UserManagerBase::UpdateUsingSAML(const AccountId& account_id, | |
543 const bool using_saml) { | |
544 SetKnownUserBooleanPref(account_id, kUsingSAMLKey, using_saml); | |
545 } | |
546 | |
547 bool UserManagerBase::FindUsingSAML(const AccountId& account_id) { | |
548 bool using_saml; | |
549 if (GetKnownUserBooleanPref(account_id, kUsingSAMLKey, &using_saml)) | |
550 return using_saml; | |
551 return false; | |
552 } | |
553 | |
554 void UserManagerBase::UpdateReauthReason(const AccountId& account_id, | |
555 const int reauth_reason) { | |
556 SetKnownUserIntegerPref(account_id, kReauthReasonKey, reauth_reason); | |
557 } | |
558 | |
559 bool UserManagerBase::FindReauthReason(const AccountId& account_id, | |
560 int* out_value) { | |
561 return GetKnownUserIntegerPref(account_id, kReauthReasonKey, out_value); | |
562 } | |
563 | |
564 void UserManagerBase::UpdateUserAccountData( | 498 void UserManagerBase::UpdateUserAccountData( |
565 const AccountId& account_id, | 499 const AccountId& account_id, |
566 const UserAccountData& account_data) { | 500 const UserAccountData& account_data) { |
567 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 501 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
568 | 502 |
569 SaveUserDisplayName(account_id, account_data.display_name()); | 503 SaveUserDisplayName(account_id, account_data.display_name()); |
570 | 504 |
571 if (User* user = FindUserAndModify(account_id)) { | 505 if (User* user = FindUserAndModify(account_id)) { |
572 base::string16 given_name = account_data.given_name(); | 506 base::string16 given_name = account_data.given_name(); |
573 user->set_given_name(given_name); | 507 user->set_given_name(given_name); |
(...skipping 13 matching lines...) Expand all Loading... |
587 std::set<AccountId>* users_set) { | 521 std::set<AccountId>* users_set) { |
588 users_vector->clear(); | 522 users_vector->clear(); |
589 users_set->clear(); | 523 users_set->clear(); |
590 for (size_t i = 0; i < users_list.GetSize(); ++i) { | 524 for (size_t i = 0; i < users_list.GetSize(); ++i) { |
591 std::string email; | 525 std::string email; |
592 if (!users_list.GetString(i, &email) || email.empty()) { | 526 if (!users_list.GetString(i, &email) || email.empty()) { |
593 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; | 527 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; |
594 continue; | 528 continue; |
595 } | 529 } |
596 | 530 |
597 const AccountId account_id = GetKnownUserAccountId(email, std::string()); | 531 const AccountId account_id = known_user::GetAccountId(email, std::string()); |
598 | 532 |
599 if (existing_users.find(account_id) != existing_users.end() || | 533 if (existing_users.find(account_id) != existing_users.end() || |
600 !users_set->insert(account_id).second) { | 534 !users_set->insert(account_id).second) { |
601 LOG(ERROR) << "Duplicate user: " << email; | 535 LOG(ERROR) << "Duplicate user: " << email; |
602 continue; | 536 continue; |
603 } | 537 } |
604 users_vector->push_back(account_id); | 538 users_vector->push_back(account_id); |
605 } | 539 } |
606 } | 540 } |
607 | 541 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 int user_type; | 779 int user_type; |
846 if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(), | 780 if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(), |
847 &user_type) && | 781 &user_type) && |
848 user_type == USER_TYPE_CHILD) { | 782 user_type == USER_TYPE_CHILD) { |
849 ChangeUserChildStatus(user, true /* is child */); | 783 ChangeUserChildStatus(user, true /* is child */); |
850 } | 784 } |
851 } | 785 } |
852 const AccountId account_id = user->GetAccountId(); | 786 const AccountId account_id = user->GetAccountId(); |
853 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); | 787 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); |
854 user->set_force_online_signin(LoadForceOnlineSignin(*it)); | 788 user->set_force_online_signin(LoadForceOnlineSignin(*it)); |
855 user->set_using_saml(FindUsingSAML(*it)); | 789 user->set_using_saml(known_user::IsUsingSAML(*it)); |
856 users_.push_back(user); | 790 users_.push_back(user); |
857 | 791 |
858 base::string16 display_name; | 792 base::string16 display_name; |
859 if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(), | 793 if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(), |
860 &display_name)) { | 794 &display_name)) { |
861 user->set_display_name(display_name); | 795 user->set_display_name(display_name); |
862 } | 796 } |
863 | 797 |
864 base::string16 given_name; | 798 base::string16 given_name; |
865 if (prefs_given_names->GetStringWithoutPathExpansion(it->GetUserEmail(), | 799 if (prefs_given_names->GetStringWithoutPathExpansion(it->GetUserEmail(), |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 account_id.GetUserEmail(), nullptr); | 940 account_id.GetUserEmail(), nullptr); |
1007 | 941 |
1008 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); | 942 DictionaryPrefUpdate prefs_oauth_update(prefs, kUserOAuthTokenStatus); |
1009 prefs_oauth_update->RemoveWithoutPathExpansion(account_id.GetUserEmail(), | 943 prefs_oauth_update->RemoveWithoutPathExpansion(account_id.GetUserEmail(), |
1010 nullptr); | 944 nullptr); |
1011 | 945 |
1012 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); | 946 DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin); |
1013 prefs_force_online_update->RemoveWithoutPathExpansion( | 947 prefs_force_online_update->RemoveWithoutPathExpansion( |
1014 account_id.GetUserEmail(), nullptr); | 948 account_id.GetUserEmail(), nullptr); |
1015 | 949 |
1016 RemoveKnownUserPrefs(account_id); | 950 known_user::RemovePrefs(account_id); |
1017 | 951 |
1018 const AccountId last_active_user = | 952 const AccountId last_active_user = |
1019 AccountId::FromUserEmail(GetLocalState()->GetString(kLastActiveUser)); | 953 AccountId::FromUserEmail(GetLocalState()->GetString(kLastActiveUser)); |
1020 if (account_id == last_active_user) | 954 if (account_id == last_active_user) |
1021 GetLocalState()->SetString(kLastActiveUser, std::string()); | 955 GetLocalState()->SetString(kLastActiveUser, std::string()); |
1022 } | 956 } |
1023 | 957 |
1024 bool UserManagerBase::FindKnownUserPrefs( | |
1025 const AccountId& account_id, | |
1026 const base::DictionaryValue** out_value) { | |
1027 PrefService* local_state = GetLocalState(); | |
1028 | |
1029 // Local State may not be initialized in tests. | |
1030 if (!local_state) | |
1031 return false; | |
1032 | |
1033 if (IsUserNonCryptohomeDataEphemeral(account_id)) | |
1034 return false; | |
1035 | |
1036 const base::ListValue* known_users = local_state->GetList(kKnownUsers); | |
1037 for (size_t i = 0; i < known_users->GetSize(); ++i) { | |
1038 const base::DictionaryValue* element = nullptr; | |
1039 if (known_users->GetDictionary(i, &element)) { | |
1040 if (UserMatches(account_id, *element)) { | |
1041 known_users->GetDictionary(i, out_value); | |
1042 return true; | |
1043 } | |
1044 } | |
1045 } | |
1046 return false; | |
1047 } | |
1048 | |
1049 void UserManagerBase::UpdateKnownUserPrefs(const AccountId& account_id, | |
1050 const base::DictionaryValue& values, | |
1051 bool clear) { | |
1052 PrefService* local_state = GetLocalState(); | |
1053 | |
1054 // Local State may not be initialized in tests. | |
1055 if (!local_state) | |
1056 return; | |
1057 | |
1058 if (IsUserNonCryptohomeDataEphemeral(account_id)) | |
1059 return; | |
1060 | |
1061 ListPrefUpdate update(local_state, kKnownUsers); | |
1062 for (size_t i = 0; i < update->GetSize(); ++i) { | |
1063 base::DictionaryValue* element = nullptr; | |
1064 if (update->GetDictionary(i, &element)) { | |
1065 if (UserMatches(account_id, *element)) { | |
1066 if (clear) | |
1067 element->Clear(); | |
1068 element->MergeDictionary(&values); | |
1069 UpdateIdentity(account_id, *element); | |
1070 return; | |
1071 } | |
1072 } | |
1073 } | |
1074 scoped_ptr<base::DictionaryValue> new_value(new base::DictionaryValue()); | |
1075 new_value->MergeDictionary(&values); | |
1076 UpdateIdentity(account_id, *new_value); | |
1077 update->Append(new_value.release()); | |
1078 } | |
1079 | |
1080 bool UserManagerBase::GetKnownUserStringPref(const AccountId& account_id, | |
1081 const std::string& path, | |
1082 std::string* out_value) { | |
1083 const base::DictionaryValue* user_pref_dict = nullptr; | |
1084 if (!FindKnownUserPrefs(account_id, &user_pref_dict)) | |
1085 return false; | |
1086 | |
1087 return user_pref_dict->GetString(path, out_value); | |
1088 } | |
1089 | |
1090 void UserManagerBase::SetKnownUserStringPref(const AccountId& account_id, | |
1091 const std::string& path, | |
1092 const std::string& in_value) { | |
1093 PrefService* local_state = GetLocalState(); | |
1094 | |
1095 // Local State may not be initialized in tests. | |
1096 if (!local_state) | |
1097 return; | |
1098 | |
1099 ListPrefUpdate update(local_state, kKnownUsers); | |
1100 base::DictionaryValue dict; | |
1101 dict.SetString(path, in_value); | |
1102 UpdateKnownUserPrefs(account_id, dict, false); | |
1103 } | |
1104 | |
1105 bool UserManagerBase::GetKnownUserBooleanPref(const AccountId& account_id, | |
1106 const std::string& path, | |
1107 bool* out_value) { | |
1108 const base::DictionaryValue* user_pref_dict = nullptr; | |
1109 if (!FindKnownUserPrefs(account_id, &user_pref_dict)) | |
1110 return false; | |
1111 | |
1112 return user_pref_dict->GetBoolean(path, out_value); | |
1113 } | |
1114 | |
1115 void UserManagerBase::SetKnownUserBooleanPref(const AccountId& account_id, | |
1116 const std::string& path, | |
1117 const bool in_value) { | |
1118 PrefService* local_state = GetLocalState(); | |
1119 | |
1120 // Local State may not be initialized in tests. | |
1121 if (!local_state) | |
1122 return; | |
1123 | |
1124 ListPrefUpdate update(local_state, kKnownUsers); | |
1125 base::DictionaryValue dict; | |
1126 dict.SetBoolean(path, in_value); | |
1127 UpdateKnownUserPrefs(account_id, dict, false); | |
1128 } | |
1129 | |
1130 bool UserManagerBase::GetKnownUserIntegerPref(const AccountId& account_id, | |
1131 const std::string& path, | |
1132 int* out_value) { | |
1133 const base::DictionaryValue* user_pref_dict = nullptr; | |
1134 if (!FindKnownUserPrefs(account_id, &user_pref_dict)) | |
1135 return false; | |
1136 return user_pref_dict->GetInteger(path, out_value); | |
1137 } | |
1138 | |
1139 void UserManagerBase::SetKnownUserIntegerPref(const AccountId& account_id, | |
1140 const std::string& path, | |
1141 const int in_value) { | |
1142 PrefService* local_state = GetLocalState(); | |
1143 | |
1144 // Local State may not be initialized in tests. | |
1145 if (!local_state) | |
1146 return; | |
1147 | |
1148 ListPrefUpdate update(local_state, kKnownUsers); | |
1149 base::DictionaryValue dict; | |
1150 dict.SetInteger(path, in_value); | |
1151 UpdateKnownUserPrefs(account_id, dict, false); | |
1152 } | |
1153 | |
1154 AccountId UserManagerBase::GetKnownUserAccountIdImpl( | |
1155 const std::string& user_email, | |
1156 const std::string& gaia_id) { | |
1157 DCHECK(!(user_email.empty() && gaia_id.empty())); | |
1158 | |
1159 // We can have several users with the same gaia_id but different e-mails. | |
1160 // The opposite case is not possible. | |
1161 std::string stored_gaia_id; | |
1162 const std::string sanitized_email = | |
1163 user_email.empty() | |
1164 ? std::string() | |
1165 : gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email)); | |
1166 if (!sanitized_email.empty() && | |
1167 GetKnownUserStringPref(AccountId::FromUserEmail(sanitized_email), | |
1168 kGAIAIdKey, &stored_gaia_id)) { | |
1169 if (!gaia_id.empty() && gaia_id != stored_gaia_id) | |
1170 LOG(ERROR) << "User gaia id has changed. Sync will not work."; | |
1171 | |
1172 // gaia_id is associated with cryptohome. | |
1173 return AccountId::FromUserEmailGaiaId(sanitized_email, stored_gaia_id); | |
1174 } | |
1175 | |
1176 std::string stored_email; | |
1177 // GetKnownUserStringPref() returns the first user record that matches | |
1178 // given ID. So we will get the first one if there are multiples. | |
1179 if (!gaia_id.empty() && | |
1180 GetKnownUserStringPref(AccountId::FromGaiaId(gaia_id), kCanonicalEmail, | |
1181 &stored_email)) { | |
1182 return AccountId::FromUserEmailGaiaId(stored_email, gaia_id); | |
1183 } | |
1184 | |
1185 return AccountId::FromUserEmailGaiaId(sanitized_email, gaia_id); | |
1186 } | |
1187 | |
1188 void UserManagerBase::UpdateGaiaID(const AccountId& account_id, | |
1189 const std::string& gaia_id) { | |
1190 SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id); | |
1191 } | |
1192 | |
1193 bool UserManagerBase::FindGaiaID(const AccountId& account_id, | |
1194 std::string* out_value) { | |
1195 return GetKnownUserStringPref(account_id, kGAIAIdKey, out_value); | |
1196 } | |
1197 | |
1198 void UserManagerBase::SetKnownUserDeviceId(const AccountId& account_id, | |
1199 const std::string& device_id) { | |
1200 const std::string known_device_id = GetKnownUserDeviceId(account_id); | |
1201 if (!known_device_id.empty() && device_id != known_device_id) { | |
1202 NOTREACHED() << "Trying to change device ID for known user."; | |
1203 } | |
1204 SetKnownUserStringPref(account_id, kDeviceId, device_id); | |
1205 } | |
1206 | |
1207 std::string UserManagerBase::GetKnownUserDeviceId(const AccountId& account_id) { | |
1208 std::string device_id; | |
1209 if (GetKnownUserStringPref(account_id, kDeviceId, &device_id)) { | |
1210 return device_id; | |
1211 } | |
1212 return std::string(); | |
1213 } | |
1214 | |
1215 void UserManagerBase::SetKnownUserGAPSCookie(const AccountId& account_id, | |
1216 const std::string& gaps_cookie) { | |
1217 SetKnownUserStringPref(account_id, kGAPSCookie, gaps_cookie); | |
1218 } | |
1219 | |
1220 std::string UserManagerBase::GetKnownUserGAPSCookie( | |
1221 const AccountId& account_id) { | |
1222 std::string gaps_cookie; | |
1223 if (GetKnownUserStringPref(account_id, kGAPSCookie, &gaps_cookie)) { | |
1224 return gaps_cookie; | |
1225 } | |
1226 return std::string(); | |
1227 } | |
1228 | |
1229 User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( | 958 User* UserManagerBase::RemoveRegularOrSupervisedUserFromList( |
1230 const AccountId& account_id) { | 959 const AccountId& account_id) { |
1231 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); | 960 ListPrefUpdate prefs_users_update(GetLocalState(), kRegularUsers); |
1232 prefs_users_update->Clear(); | 961 prefs_users_update->Clear(); |
1233 User* user = nullptr; | 962 User* user = nullptr; |
1234 for (UserList::iterator it = users_.begin(); it != users_.end();) { | 963 for (UserList::iterator it = users_.begin(); it != users_.end();) { |
1235 if ((*it)->GetAccountId() == account_id) { | 964 if ((*it)->GetAccountId() == account_id) { |
1236 user = *it; | 965 user = *it; |
1237 it = users_.erase(it); | 966 it = users_.erase(it); |
1238 } else { | 967 } else { |
1239 if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) { | 968 if ((*it)->HasGaiaAccount() || (*it)->IsSupervised()) { |
1240 const std::string user_email = (*it)->email(); | 969 const std::string user_email = (*it)->email(); |
1241 prefs_users_update->Append(new base::StringValue(user_email)); | 970 prefs_users_update->Append(new base::StringValue(user_email)); |
1242 } | 971 } |
1243 ++it; | 972 ++it; |
1244 } | 973 } |
1245 } | 974 } |
1246 OnUserRemoved(account_id); | 975 OnUserRemoved(account_id); |
1247 return user; | 976 return user; |
1248 } | 977 } |
1249 | 978 |
1250 void UserManagerBase::RemoveKnownUserPrefs(const AccountId& account_id) { | |
1251 ListPrefUpdate update(GetLocalState(), kKnownUsers); | |
1252 for (size_t i = 0; i < update->GetSize(); ++i) { | |
1253 base::DictionaryValue* element = nullptr; | |
1254 if (update->GetDictionary(i, &element)) { | |
1255 if (UserMatches(account_id, *element)) { | |
1256 update->Remove(i, nullptr); | |
1257 break; | |
1258 } | |
1259 } | |
1260 } | |
1261 } | |
1262 | |
1263 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { | 979 void UserManagerBase::NotifyActiveUserChanged(const User* active_user) { |
1264 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 980 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
1265 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, | 981 FOR_EACH_OBSERVER(UserManager::UserSessionStateObserver, |
1266 session_state_observer_list_, | 982 session_state_observer_list_, |
1267 ActiveUserChanged(active_user)); | 983 ActiveUserChanged(active_user)); |
1268 } | 984 } |
1269 | 985 |
1270 void UserManagerBase::NotifyUserAddedToSession(const User* added_user, | 986 void UserManagerBase::NotifyUserAddedToSession(const User* added_user, |
1271 bool user_switch_pending) { | 987 bool user_switch_pending) { |
1272 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 988 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 } | 1104 } |
1389 | 1105 |
1390 void UserManagerBase::DeleteUser(User* user) { | 1106 void UserManagerBase::DeleteUser(User* user) { |
1391 const bool is_active_user = (user == active_user_); | 1107 const bool is_active_user = (user == active_user_); |
1392 delete user; | 1108 delete user; |
1393 if (is_active_user) | 1109 if (is_active_user) |
1394 active_user_ = nullptr; | 1110 active_user_ = nullptr; |
1395 } | 1111 } |
1396 | 1112 |
1397 } // namespace user_manager | 1113 } // namespace user_manager |
OLD | NEW |