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

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

Issue 1454153002: Revert of This CL replaces e-mail with AccountId on user selection screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« 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 <cstddef> 7 #include <cstddef>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 void ResolveLocale(const std::string& raw_locale, 113 void ResolveLocale(const std::string& raw_locale,
114 std::string* resolved_locale) { 114 std::string* resolved_locale) {
115 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale)); 115 ignore_result(l10n_util::CheckAndResolveLocale(raw_locale, resolved_locale));
116 } 116 }
117 117
118 // Checks if values in |dict| correspond with |account_id| identity. 118 // Checks if values in |dict| correspond with |account_id| identity.
119 bool UserMatches(const AccountId& account_id, 119 bool UserMatches(const AccountId& account_id,
120 const base::DictionaryValue& dict) { 120 const base::DictionaryValue& dict) {
121 std::string value; 121 std::string value;
122 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); 123 bool has_email = dict.GetString(kCanonicalEmail, &value);
129 if (has_email && account_id.GetUserEmail() == value) 124 if (has_email && account_id.GetUserEmail() == value)
130 return true; 125 return true;
131 126
127 // TODO(antrim): update code once user id is really a struct.
128 bool has_gaia_id = dict.GetString(kGAIAIdKey, &value);
129 if (has_gaia_id && account_id.GetUserEmail() == value)
130 return true;
131
132 return false; 132 return false;
133 } 133 }
134 134
135 // Fills relevant |dict| values based on |account_id|. 135 // Fills relevant |dict| values based on |account_id|.
136 void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) { 136 void UpdateIdentity(const AccountId& account_id, base::DictionaryValue& dict) {
137 dict.SetString(kCanonicalEmail, account_id.GetUserEmail()); 137 dict.SetString(kCanonicalEmail, account_id.GetUserEmail());
138 } 138 }
139 139
140 } // namespace 140 } // namespace
141 141
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 if (!IsUserNonCryptohomeDataEphemeral(account_id)) { 575 if (!IsUserNonCryptohomeDataEphemeral(account_id)) {
576 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName); 576 DictionaryPrefUpdate given_name_update(GetLocalState(), kUserGivenName);
577 given_name_update->SetWithoutPathExpansion( 577 given_name_update->SetWithoutPathExpansion(
578 account_id.GetUserEmail(), new base::StringValue(given_name)); 578 account_id.GetUserEmail(), new base::StringValue(given_name));
579 } 579 }
580 } 580 }
581 581
582 UpdateUserAccountLocale(account_id, account_data.locale()); 582 UpdateUserAccountLocale(account_id, account_data.locale());
583 } 583 }
584 584
585 // static
585 void UserManagerBase::ParseUserList(const base::ListValue& users_list, 586 void UserManagerBase::ParseUserList(const base::ListValue& users_list,
586 const std::set<AccountId>& existing_users, 587 const std::set<AccountId>& existing_users,
587 std::vector<AccountId>* users_vector, 588 std::vector<AccountId>* users_vector,
588 std::set<AccountId>* users_set) { 589 std::set<AccountId>* users_set) {
589 users_vector->clear(); 590 users_vector->clear();
590 users_set->clear(); 591 users_set->clear();
591 for (size_t i = 0; i < users_list.GetSize(); ++i) { 592 for (size_t i = 0; i < users_list.GetSize(); ++i) {
592 std::string email; 593 std::string email;
593 if (!users_list.GetString(i, &email) || email.empty()) { 594 if (!users_list.GetString(i, &email) || email.empty()) {
594 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; 595 LOG(ERROR) << "Corrupt entry in user list at index " << i << ".";
595 continue; 596 continue;
596 } 597 }
597 598 const AccountId account_id(AccountId::FromUserEmail(email));
598 const AccountId partial_account_id = AccountId::FromUserEmail(email);
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
612 if (existing_users.find(account_id) != existing_users.end() || 599 if (existing_users.find(account_id) != existing_users.end() ||
613 !users_set->insert(account_id).second) { 600 !users_set->insert(account_id).second) {
614 LOG(ERROR) << "Duplicate user: " << email; 601 LOG(ERROR) << "Duplicate user: " << email;
615 continue; 602 continue;
616 } 603 }
617 users_vector->push_back(account_id); 604 users_vector->push_back(account_id);
618 } 605 }
619 } 606 }
620 607
621 bool UserManagerBase::IsCurrentUserOwner() const { 608 bool UserManagerBase::IsCurrentUserOwner() const {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 user = User::CreateSupervisedUser(*it); 842 user = User::CreateSupervisedUser(*it);
856 } else { 843 } else {
857 user = User::CreateRegularUser(*it); 844 user = User::CreateRegularUser(*it);
858 int user_type; 845 int user_type;
859 if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(), 846 if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(),
860 &user_type) && 847 &user_type) &&
861 user_type == USER_TYPE_CHILD) { 848 user_type == USER_TYPE_CHILD) {
862 ChangeUserChildStatus(user, true /* is child */); 849 ChangeUserChildStatus(user, true /* is child */);
863 } 850 }
864 } 851 }
865 const AccountId account_id = user->GetAccountId();
866 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); 852 user->set_oauth_token_status(LoadUserOAuthStatus(*it));
867 user->set_force_online_signin(LoadForceOnlineSignin(*it)); 853 user->set_force_online_signin(LoadForceOnlineSignin(*it));
868 user->set_using_saml(FindUsingSAML(*it)); 854 user->set_using_saml(FindUsingSAML(*it));
869 users_.push_back(user); 855 users_.push_back(user);
870 856
871 base::string16 display_name; 857 base::string16 display_name;
872 if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(), 858 if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(),
873 &display_name)) { 859 &display_name)) {
874 user->set_display_name(display_name); 860 user->set_display_name(display_name);
875 } 861 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 1145
1160 ListPrefUpdate update(local_state, kKnownUsers); 1146 ListPrefUpdate update(local_state, kKnownUsers);
1161 base::DictionaryValue dict; 1147 base::DictionaryValue dict;
1162 dict.SetInteger(path, in_value); 1148 dict.SetInteger(path, in_value);
1163 UpdateKnownUserPrefs(account_id, dict, false); 1149 UpdateKnownUserPrefs(account_id, dict, false);
1164 } 1150 }
1165 1151
1166 bool UserManagerBase::GetKnownUserAccountId( 1152 bool UserManagerBase::GetKnownUserAccountId(
1167 const AccountId& authenticated_account_id, 1153 const AccountId& authenticated_account_id,
1168 AccountId* out_account_id) { 1154 AccountId* out_account_id) {
1169 if (!authenticated_account_id.GetGaiaId().empty()) { 1155 DCHECK(!authenticated_account_id.GetGaiaId().empty());
1170 std::string canonical_email; 1156 std::string canonical_email;
1171 if (!GetKnownUserStringPref( 1157 if (!GetKnownUserStringPref(
1172 AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()), 1158 AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()),
1173 kCanonicalEmail, &canonical_email)) { 1159 kCanonicalEmail, &canonical_email))
1174 return false;
1175 }
1176
1177 *out_account_id = AccountId::FromUserEmailGaiaId(
1178 canonical_email, authenticated_account_id.GetGaiaId());
1179 return true;
1180 }
1181 DCHECK(!authenticated_account_id.GetUserEmail().empty());
1182 std::string gaia_id;
1183 if (!GetKnownUserStringPref(authenticated_account_id, kGAIAIdKey, &gaia_id))
1184 return false; 1160 return false;
1185 1161
1186 *out_account_id = AccountId::FromUserEmailGaiaId( 1162 *out_account_id = authenticated_account_id;
1187 authenticated_account_id.GetUserEmail(), gaia_id); 1163 out_account_id->SetUserEmail(canonical_email);
1188 return true; 1164 return true;
1189 } 1165 }
1190 1166
1191 void UserManagerBase::UpdateGaiaID(const AccountId& account_id, 1167 void UserManagerBase::UpdateGaiaID(const AccountId& account_id,
1192 const std::string& gaia_id) { 1168 const std::string& gaia_id) {
1193 SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id); 1169 SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id);
1194 } 1170 }
1195 1171
1196 bool UserManagerBase::FindGaiaID(const AccountId& account_id, 1172 bool UserManagerBase::FindGaiaID(const AccountId& account_id,
1197 std::string* out_value) { 1173 std::string* out_value) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 } 1367 }
1392 1368
1393 void UserManagerBase::DeleteUser(User* user) { 1369 void UserManagerBase::DeleteUser(User* user) {
1394 const bool is_active_user = (user == active_user_); 1370 const bool is_active_user = (user == active_user_);
1395 delete user; 1371 delete user;
1396 if (is_active_user) 1372 if (is_active_user)
1397 active_user_ = nullptr; 1373 active_user_ = nullptr;
1398 } 1374 }
1399 1375
1400 } // namespace user_manager 1376 } // 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