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

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

Issue 1440583002: This CL replaces e-mail with AccountId on user selection screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build. 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
123 bool has_email = dict.GetString(kCanonicalEmail, &value); 128 bool has_email = dict.GetString(kCanonicalEmail, &value);
124 if (has_email && account_id.GetUserEmail() == value) 129 if (has_email && account_id.GetUserEmail() == value)
125 return true; 130 return true;
126 131
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
586 void UserManagerBase::ParseUserList(const base::ListValue& users_list, 585 void UserManagerBase::ParseUserList(const base::ListValue& users_list,
587 const std::set<AccountId>& existing_users, 586 const std::set<AccountId>& existing_users,
588 std::vector<AccountId>* users_vector, 587 std::vector<AccountId>* users_vector,
589 std::set<AccountId>* users_set) { 588 std::set<AccountId>* users_set) {
590 users_vector->clear(); 589 users_vector->clear();
591 users_set->clear(); 590 users_set->clear();
592 for (size_t i = 0; i < users_list.GetSize(); ++i) { 591 for (size_t i = 0; i < users_list.GetSize(); ++i) {
593 std::string email; 592 std::string email;
594 if (!users_list.GetString(i, &email) || email.empty()) { 593 if (!users_list.GetString(i, &email) || email.empty()) {
595 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; 594 LOG(ERROR) << "Corrupt entry in user list at index " << i << ".";
596 continue; 595 continue;
597 } 596 }
598 const AccountId account_id(AccountId::FromUserEmail(email)); 597
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
599 if (existing_users.find(account_id) != existing_users.end() || 612 if (existing_users.find(account_id) != existing_users.end() ||
600 !users_set->insert(account_id).second) { 613 !users_set->insert(account_id).second) {
601 LOG(ERROR) << "Duplicate user: " << email; 614 LOG(ERROR) << "Duplicate user: " << email;
602 continue; 615 continue;
603 } 616 }
604 users_vector->push_back(account_id); 617 users_vector->push_back(account_id);
605 } 618 }
606 } 619 }
607 620
608 bool UserManagerBase::IsCurrentUserOwner() const { 621 bool UserManagerBase::IsCurrentUserOwner() const {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 user = User::CreateSupervisedUser(*it); 855 user = User::CreateSupervisedUser(*it);
843 } else { 856 } else {
844 user = User::CreateRegularUser(*it); 857 user = User::CreateRegularUser(*it);
845 int user_type; 858 int user_type;
846 if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(), 859 if (prefs_user_types->GetIntegerWithoutPathExpansion(it->GetUserEmail(),
847 &user_type) && 860 &user_type) &&
848 user_type == USER_TYPE_CHILD) { 861 user_type == USER_TYPE_CHILD) {
849 ChangeUserChildStatus(user, true /* is child */); 862 ChangeUserChildStatus(user, true /* is child */);
850 } 863 }
851 } 864 }
865 const AccountId account_id = user->GetAccountId();
852 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); 866 user->set_oauth_token_status(LoadUserOAuthStatus(*it));
853 user->set_force_online_signin(LoadForceOnlineSignin(*it)); 867 user->set_force_online_signin(LoadForceOnlineSignin(*it));
854 user->set_using_saml(FindUsingSAML(*it)); 868 user->set_using_saml(FindUsingSAML(*it));
855 users_.push_back(user); 869 users_.push_back(user);
856 870
857 base::string16 display_name; 871 base::string16 display_name;
858 if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(), 872 if (prefs_display_names->GetStringWithoutPathExpansion(it->GetUserEmail(),
859 &display_name)) { 873 &display_name)) {
860 user->set_display_name(display_name); 874 user->set_display_name(display_name);
861 } 875 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 1159
1146 ListPrefUpdate update(local_state, kKnownUsers); 1160 ListPrefUpdate update(local_state, kKnownUsers);
1147 base::DictionaryValue dict; 1161 base::DictionaryValue dict;
1148 dict.SetInteger(path, in_value); 1162 dict.SetInteger(path, in_value);
1149 UpdateKnownUserPrefs(account_id, dict, false); 1163 UpdateKnownUserPrefs(account_id, dict, false);
1150 } 1164 }
1151 1165
1152 bool UserManagerBase::GetKnownUserAccountId( 1166 bool UserManagerBase::GetKnownUserAccountId(
1153 const AccountId& authenticated_account_id, 1167 const AccountId& authenticated_account_id,
1154 AccountId* out_account_id) { 1168 AccountId* out_account_id) {
1155 DCHECK(!authenticated_account_id.GetGaiaId().empty()); 1169 if (!authenticated_account_id.GetGaiaId().empty()) {
1156 std::string canonical_email; 1170 std::string canonical_email;
1157 if (!GetKnownUserStringPref( 1171 if (!GetKnownUserStringPref(
1158 AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()), 1172 AccountId::FromGaiaId(authenticated_account_id.GetGaiaId()),
1159 kCanonicalEmail, &canonical_email)) 1173 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))
1160 return false; 1184 return false;
1161 1185
1162 *out_account_id = authenticated_account_id; 1186 *out_account_id = AccountId::FromUserEmailGaiaId(
1163 out_account_id->SetUserEmail(canonical_email); 1187 authenticated_account_id.GetUserEmail(), gaia_id);
1164 return true; 1188 return true;
1165 } 1189 }
1166 1190
1167 void UserManagerBase::UpdateGaiaID(const AccountId& account_id, 1191 void UserManagerBase::UpdateGaiaID(const AccountId& account_id,
1168 const std::string& gaia_id) { 1192 const std::string& gaia_id) {
1169 SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id); 1193 SetKnownUserStringPref(account_id, kGAIAIdKey, gaia_id);
1170 } 1194 }
1171 1195
1172 bool UserManagerBase::FindGaiaID(const AccountId& account_id, 1196 bool UserManagerBase::FindGaiaID(const AccountId& account_id,
1173 std::string* out_value) { 1197 std::string* out_value) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 } 1391 }
1368 1392
1369 void UserManagerBase::DeleteUser(User* user) { 1393 void UserManagerBase::DeleteUser(User* user) {
1370 const bool is_active_user = (user == active_user_); 1394 const bool is_active_user = (user == active_user_);
1371 delete user; 1395 delete user;
1372 if (is_active_user) 1396 if (is_active_user)
1373 active_user_ = nullptr; 1397 active_user_ = nullptr;
1374 } 1398 }
1375 1399
1376 } // namespace user_manager 1400 } // 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