OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/chromeos/login/user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/user_manager_impl.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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // Log the error, but there's not much we can do. | 109 // Log the error, but there's not much we can do. |
110 if (!success) { | 110 if (!success) { |
111 LOG(ERROR) << "Removal of cryptohome for " << user_email | 111 LOG(ERROR) << "Removal of cryptohome for " << user_email |
112 << " failed, return code: " << return_code; | 112 << " failed, return code: " << return_code; |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 // Helper function that copies users from |users_list| to |users_vector| and | 116 // Helper function that copies users from |users_list| to |users_vector| and |
117 // |users_set|. Duplicates and users already present in |existing_users| are | 117 // |users_set|. Duplicates and users already present in |existing_users| are |
118 // skipped. | 118 // skipped. |
119 void ParseUserList(const ListValue& users_list, | 119 void ParseUserList(const base::ListValue& users_list, |
120 const std::set<std::string>& existing_users, | 120 const std::set<std::string>& existing_users, |
121 std::vector<std::string>* users_vector, | 121 std::vector<std::string>* users_vector, |
122 std::set<std::string>* users_set) { | 122 std::set<std::string>* users_set) { |
123 users_vector->clear(); | 123 users_vector->clear(); |
124 users_set->clear(); | 124 users_set->clear(); |
125 for (size_t i = 0; i < users_list.GetSize(); ++i) { | 125 for (size_t i = 0; i < users_list.GetSize(); ++i) { |
126 std::string email; | 126 std::string email; |
127 if (!users_list.GetString(i, &email) || email.empty()) { | 127 if (!users_list.GetString(i, &email) || email.empty()) { |
128 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; | 128 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; |
129 continue; | 129 continue; |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); | 618 DictionaryPrefUpdate oauth_status_update(local_state, kUserOAuthTokenStatus); |
619 oauth_status_update->SetWithoutPathExpansion(user_id, | 619 oauth_status_update->SetWithoutPathExpansion(user_id, |
620 new base::FundamentalValue(static_cast<int>(oauth_token_status))); | 620 new base::FundamentalValue(static_cast<int>(oauth_token_status))); |
621 } | 621 } |
622 | 622 |
623 User::OAuthTokenStatus UserManagerImpl::LoadUserOAuthStatus( | 623 User::OAuthTokenStatus UserManagerImpl::LoadUserOAuthStatus( |
624 const std::string& user_id) const { | 624 const std::string& user_id) const { |
625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
626 | 626 |
627 PrefService* local_state = g_browser_process->local_state(); | 627 PrefService* local_state = g_browser_process->local_state(); |
628 const DictionaryValue* prefs_oauth_status = | 628 const base::DictionaryValue* prefs_oauth_status = |
629 local_state->GetDictionary(kUserOAuthTokenStatus); | 629 local_state->GetDictionary(kUserOAuthTokenStatus); |
630 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; | 630 int oauth_token_status = User::OAUTH_TOKEN_STATUS_UNKNOWN; |
631 if (prefs_oauth_status && | 631 if (prefs_oauth_status && |
632 prefs_oauth_status->GetIntegerWithoutPathExpansion( | 632 prefs_oauth_status->GetIntegerWithoutPathExpansion( |
633 user_id, &oauth_token_status)) { | 633 user_id, &oauth_token_status)) { |
634 User::OAuthTokenStatus result = | 634 User::OAuthTokenStatus result = |
635 static_cast<User::OAuthTokenStatus>(oauth_token_status); | 635 static_cast<User::OAuthTokenStatus>(oauth_token_status); |
636 if (result == User::OAUTH2_TOKEN_STATUS_INVALID) | 636 if (result == User::OAUTH2_TOKEN_STATUS_INVALID) |
637 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(result); | 637 GetUserFlow(user_id)->HandleOAuthTokenStatusChange(result); |
638 return result; | 638 return result; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 if (user_loading_stage_ != STAGE_NOT_LOADED) | 1019 if (user_loading_stage_ != STAGE_NOT_LOADED) |
1020 return; | 1020 return; |
1021 user_loading_stage_ = STAGE_LOADING; | 1021 user_loading_stage_ = STAGE_LOADING; |
1022 // Clean up user list first. All code down the path should be synchronous, | 1022 // Clean up user list first. All code down the path should be synchronous, |
1023 // so that local state after transaction rollback is in consistent state. | 1023 // so that local state after transaction rollback is in consistent state. |
1024 // This process also should not trigger EnsureUsersLoaded again. | 1024 // This process also should not trigger EnsureUsersLoaded again. |
1025 if (supervised_user_manager_->HasFailedUserCreationTransaction()) | 1025 if (supervised_user_manager_->HasFailedUserCreationTransaction()) |
1026 supervised_user_manager_->RollbackUserCreationTransaction(); | 1026 supervised_user_manager_->RollbackUserCreationTransaction(); |
1027 | 1027 |
1028 PrefService* local_state = g_browser_process->local_state(); | 1028 PrefService* local_state = g_browser_process->local_state(); |
1029 const ListValue* prefs_regular_users = local_state->GetList(kRegularUsers); | 1029 const base::ListValue* prefs_regular_users = |
1030 const ListValue* prefs_public_accounts = | 1030 local_state->GetList(kRegularUsers); |
| 1031 const base::ListValue* prefs_public_accounts = |
1031 local_state->GetList(kPublicAccounts); | 1032 local_state->GetList(kPublicAccounts); |
1032 const DictionaryValue* prefs_display_names = | 1033 const base::DictionaryValue* prefs_display_names = |
1033 local_state->GetDictionary(kUserDisplayName); | 1034 local_state->GetDictionary(kUserDisplayName); |
1034 const DictionaryValue* prefs_given_names = | 1035 const base::DictionaryValue* prefs_given_names = |
1035 local_state->GetDictionary(kUserGivenName); | 1036 local_state->GetDictionary(kUserGivenName); |
1036 const DictionaryValue* prefs_display_emails = | 1037 const base::DictionaryValue* prefs_display_emails = |
1037 local_state->GetDictionary(kUserDisplayEmail); | 1038 local_state->GetDictionary(kUserDisplayEmail); |
1038 | 1039 |
1039 // Load regular users and locally managed users. | 1040 // Load regular users and locally managed users. |
1040 std::vector<std::string> regular_users; | 1041 std::vector<std::string> regular_users; |
1041 std::set<std::string> regular_users_set; | 1042 std::set<std::string> regular_users_set; |
1042 ParseUserList(*prefs_regular_users, std::set<std::string>(), | 1043 ParseUserList(*prefs_regular_users, std::set<std::string>(), |
1043 ®ular_users, ®ular_users_set); | 1044 ®ular_users, ®ular_users_set); |
1044 for (std::vector<std::string>::const_iterator it = regular_users.begin(); | 1045 for (std::vector<std::string>::const_iterator it = regular_users.begin(); |
1045 it != regular_users.end(); ++it) { | 1046 it != regular_users.end(); ++it) { |
1046 User* user = NULL; | 1047 User* user = NULL; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 const UserList& users = GetUsers(); | 1147 const UserList& users = GetUsers(); |
1147 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { | 1148 for (UserList::const_iterator it = users.begin(); it != users.end(); ++it) { |
1148 if ((*it)->email() == user_id) | 1149 if ((*it)->email() == user_id) |
1149 return *it; | 1150 return *it; |
1150 } | 1151 } |
1151 return NULL; | 1152 return NULL; |
1152 } | 1153 } |
1153 | 1154 |
1154 const bool UserManagerImpl::UserExistsInList(const std::string& user_id) const { | 1155 const bool UserManagerImpl::UserExistsInList(const std::string& user_id) const { |
1155 PrefService* local_state = g_browser_process->local_state(); | 1156 PrefService* local_state = g_browser_process->local_state(); |
1156 const ListValue* user_list = local_state->GetList(kRegularUsers); | 1157 const base::ListValue* user_list = local_state->GetList(kRegularUsers); |
1157 for (size_t i = 0; i < user_list->GetSize(); ++i) { | 1158 for (size_t i = 0; i < user_list->GetSize(); ++i) { |
1158 std::string email; | 1159 std::string email; |
1159 if (user_list->GetString(i, &email) && (user_id == email)) | 1160 if (user_list->GetString(i, &email) && (user_id == email)) |
1160 return true; | 1161 return true; |
1161 } | 1162 } |
1162 return false; | 1163 return false; |
1163 } | 1164 } |
1164 | 1165 |
1165 User* UserManagerImpl::FindUserInListAndModify(const std::string& user_id) { | 1166 User* UserManagerImpl::FindUserInListAndModify(const std::string& user_id) { |
1166 UserList& users = GetUsersAndModify(); | 1167 UserList& users = GetUsersAndModify(); |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1815 | 1816 |
1816 void UserManagerImpl::DoUpdateAccountLocale( | 1817 void UserManagerImpl::DoUpdateAccountLocale( |
1817 const std::string& user_id, | 1818 const std::string& user_id, |
1818 const std::string& resolved_locale) { | 1819 const std::string& resolved_locale) { |
1819 if (User* user = FindUserAndModify(user_id)) | 1820 if (User* user = FindUserAndModify(user_id)) |
1820 user->SetAccountLocale(resolved_locale); | 1821 user->SetAccountLocale(resolved_locale); |
1821 } | 1822 } |
1822 | 1823 |
1823 | 1824 |
1824 } // namespace chromeos | 1825 } // namespace chromeos |
OLD | NEW |