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

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

Issue 1463753002: ChromeOS: This CL fixes bug in UserManager::GetKnownUserAccountId . (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests. Created 5 years, 1 month 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
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 <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 std::set<AccountId>* users_set) { 588 std::set<AccountId>* users_set) {
589 users_vector->clear(); 589 users_vector->clear();
590 users_set->clear(); 590 users_set->clear();
591 for (size_t i = 0; i < users_list.GetSize(); ++i) { 591 for (size_t i = 0; i < users_list.GetSize(); ++i) {
592 std::string email; 592 std::string email;
593 if (!users_list.GetString(i, &email) || email.empty()) { 593 if (!users_list.GetString(i, &email) || email.empty()) {
594 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; 594 LOG(ERROR) << "Corrupt entry in user list at index " << i << ".";
595 continue; 595 continue;
596 } 596 }
597 597
598 const AccountId partial_account_id = AccountId::FromUserEmail(email); 598 const AccountId account_id = GetKnownUserAccountId(email, std::string());
599 AccountId account_id = EmptyAccountId();
600
601 const bool lookup_result =
602 GetKnownUserAccountId(partial_account_id, &account_id);
603 // TODO(alemate):
604 // DCHECK(lookup_result) << "KnownUser lookup falied for '" << email << "'";
605 // (tests do not initialize KnownUserData)
606
607 if (!lookup_result) {
608 account_id = partial_account_id;
609 LOG(WARNING) << "KnownUser lookup falied for '" << email << "'";
610 }
611 599
612 if (existing_users.find(account_id) != existing_users.end() || 600 if (existing_users.find(account_id) != existing_users.end() ||
613 !users_set->insert(account_id).second) { 601 !users_set->insert(account_id).second) {
614 LOG(ERROR) << "Duplicate user: " << email; 602 LOG(ERROR) << "Duplicate user: " << email;
615 continue; 603 continue;
616 } 604 }
617 users_vector->push_back(account_id); 605 users_vector->push_back(account_id);
618 } 606 }
619 } 607 }
620 608
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 } 1023 }
1036 1024
1037 bool UserManagerBase::FindKnownUserPrefs( 1025 bool UserManagerBase::FindKnownUserPrefs(
1038 const AccountId& account_id, 1026 const AccountId& account_id,
1039 const base::DictionaryValue** out_value) { 1027 const base::DictionaryValue** out_value) {
1040 PrefService* local_state = GetLocalState(); 1028 PrefService* local_state = GetLocalState();
1041 1029
1042 // Local State may not be initialized in tests. 1030 // Local State may not be initialized in tests.
1043 if (!local_state) 1031 if (!local_state)
1044 return false; 1032 return false;
1033
1045 if (IsUserNonCryptohomeDataEphemeral(account_id)) 1034 if (IsUserNonCryptohomeDataEphemeral(account_id))
1046 return false; 1035 return false;
1047 1036
1048 const base::ListValue* known_users = local_state->GetList(kKnownUsers); 1037 const base::ListValue* known_users = local_state->GetList(kKnownUsers);
1049 for (size_t i = 0; i < known_users->GetSize(); ++i) { 1038 for (size_t i = 0; i < known_users->GetSize(); ++i) {
1050 const base::DictionaryValue* element = nullptr; 1039 const base::DictionaryValue* element = nullptr;
1051 if (known_users->GetDictionary(i, &element)) { 1040 if (known_users->GetDictionary(i, &element)) {
1052 if (UserMatches(account_id, *element)) { 1041 if (UserMatches(account_id, *element)) {
1053 known_users->GetDictionary(i, out_value); 1042 known_users->GetDictionary(i, out_value);
1054 return true; 1043 return true;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 // Local State may not be initialized in tests. 1145 // Local State may not be initialized in tests.
1157 if (!local_state) 1146 if (!local_state)
1158 return; 1147 return;
1159 1148
1160 ListPrefUpdate update(local_state, kKnownUsers); 1149 ListPrefUpdate update(local_state, kKnownUsers);
1161 base::DictionaryValue dict; 1150 base::DictionaryValue dict;
1162 dict.SetInteger(path, in_value); 1151 dict.SetInteger(path, in_value);
1163 UpdateKnownUserPrefs(account_id, dict, false); 1152 UpdateKnownUserPrefs(account_id, dict, false);
1164 } 1153 }
1165 1154
1166 bool UserManagerBase::GetKnownUserAccountId( 1155 AccountId UserManagerBase::GetKnownUserAccountIdImpl(
1167 const AccountId& authenticated_account_id, 1156 const std::string& user_email,
1168 AccountId* out_account_id) { 1157 const std::string& gaia_id) {
1169 if (!authenticated_account_id.GetGaiaId().empty()) { 1158 DCHECK(!(user_email.empty() && gaia_id.empty()));
1170 std::string canonical_email;
1171 if (!GetKnownUserStringPref(
1172 AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()),
1173 kCanonicalEmail, &canonical_email)) {
1174 return false;
1175 }
1176 1159
1177 *out_account_id = AccountId::FromUserEmailGaiaId( 1160 // We can have several users with the same gaia_id but different e-mails.
1178 canonical_email, authenticated_account_id.GetGaiaId()); 1161 // The opposite case is not possible.
achuithb 2015/11/20 18:46:51 I think we need more comments for the various case
1179 return true; 1162 std::string old_gaia_id;
1163 const std::string sanitized_email =
1164 gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_email));
1165 if (!user_email.empty() &&
achuithb 2015/11/20 18:46:51 !sanitized_email.empty() would be clearer
Alexander Alekseev 2015/11/21 01:06:29 Done.
1166 GetKnownUserStringPref(AccountId::FromUserEmail(sanitized_email),
1167 kGAIAIdKey, &old_gaia_id)) {
1168 if (!gaia_id.empty() && gaia_id != old_gaia_id)
1169 LOG(ERROR) << "User gaia id has changed. Sync will not work.";
1170
1171 return AccountId::FromUserEmailGaiaId(sanitized_email, old_gaia_id);
achuithb 2015/11/20 18:46:51 Why is this right? SHouldn't we use the new gaia_i
1180 } 1172 }
1181 DCHECK(!authenticated_account_id.GetUserEmail().empty());
1182 std::string gaia_id;
1183 if (!GetKnownUserStringPref(authenticated_account_id, kGAIAIdKey, &gaia_id))
1184 return false;
1185 1173
1186 *out_account_id = AccountId::FromUserEmailGaiaId( 1174 std::string canonical_email;
achuithb 2015/11/20 18:46:51 maybe stored_email?
Alexander Alekseev 2015/11/21 01:06:29 Done.
1187 authenticated_account_id.GetUserEmail(), gaia_id); 1175 if (!gaia_id.empty() &&
1188 return true; 1176 GetKnownUserStringPref(AccountId::FromGaiaId(gaia_id), kCanonicalEmail,
1177 &canonical_email)) {
1178 return AccountId::FromUserEmailGaiaId(canonical_email, gaia_id);
1179 }
1180
1181 return AccountId::FromUserEmailGaiaId(sanitized_email, gaia_id);
1189 } 1182 }
1190 1183
1191 void UserManagerBase::UpdateGaiaID(const AccountId& account_id, 1184 void UserManagerBase::UpdateGaiaID(const AccountId& account_id,
1192 const std::string& gaia_id) { 1185 const std::string& gaia_id) {
1193 SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id); 1186 SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id);
1194 } 1187 }
1195 1188
1196 bool UserManagerBase::FindGaiaID(const AccountId& account_id, 1189 bool UserManagerBase::FindGaiaID(const AccountId& account_id,
1197 std::string* out_value) { 1190 std::string* out_value) {
1198 return GetKnownUserStringPref(account_id, kGAIAIdKey, out_value); 1191 return GetKnownUserStringPref(account_id, kGAIAIdKey, out_value);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 } 1384 }
1392 1385
1393 void UserManagerBase::DeleteUser(User* user) { 1386 void UserManagerBase::DeleteUser(User* user) {
1394 const bool is_active_user = (user == active_user_); 1387 const bool is_active_user = (user == active_user_);
1395 delete user; 1388 delete user;
1396 if (is_active_user) 1389 if (is_active_user)
1397 active_user_ = nullptr; 1390 active_user_ = nullptr;
1398 } 1391 }
1399 1392
1400 } // namespace user_manager 1393 } // namespace user_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698