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

Side by Side Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 15198005: Remove data belonging to a public account when the account is removed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.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 (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 #include <vector>
10 9
11 #include "ash/shell.h" 10 #include "ash/shell.h"
12 #include "base/bind.h" 11 #include "base/bind.h"
13 #include "base/chromeos/chromeos_version.h" 12 #include "base/chromeos/chromeos_version.h"
14 #include "base/command_line.h" 13 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
16 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
17 #include "base/logging.h" 16 #include "base/logging.h"
18 #include "base/prefs/pref_registry_simple.h" 17 #include "base/prefs/pref_registry_simple.h"
19 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 chromeos::UserManager::Get()->RemoveUserFromList(user_email); 130 chromeos::UserManager::Get()->RemoveUserFromList(user_email);
132 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( 131 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove(
133 user_email, base::Bind(&OnRemoveUserComplete, user_email)); 132 user_email, base::Bind(&OnRemoveUserComplete, user_email));
134 133
135 if (delegate) 134 if (delegate)
136 delegate->OnUserRemoved(user_email); 135 delegate->OnUserRemoved(user_email);
137 } 136 }
138 137
139 // Helper function that copies users from |users_list| to |users_vector| and 138 // Helper function that copies users from |users_list| to |users_vector| and
140 // |users_set|. Duplicates and users already present in |existing_users| are 139 // |users_set|. Duplicates and users already present in |existing_users| are
141 // skipped. The |logged_in_user| is also skipped and the return value 140 // skipped.
142 // indicates whether that user was found in |users_list|. 141 void ParseUserList(const ListValue& users_list,
143 bool ParseUserList(const ListValue& users_list,
144 const std::set<std::string>& existing_users, 142 const std::set<std::string>& existing_users,
145 const std::string& logged_in_user,
146 std::vector<std::string>* users_vector, 143 std::vector<std::string>* users_vector,
147 std::set<std::string>* users_set) { 144 std::set<std::string>* users_set) {
148 users_vector->clear(); 145 users_vector->clear();
149 users_set->clear(); 146 users_set->clear();
150 bool logged_in_user_on_list = false;
151 for (size_t i = 0; i < users_list.GetSize(); ++i) { 147 for (size_t i = 0; i < users_list.GetSize(); ++i) {
152 std::string email; 148 std::string email;
153 if (!users_list.GetString(i, &email) || email.empty()) { 149 if (!users_list.GetString(i, &email) || email.empty()) {
154 LOG(ERROR) << "Corrupt entry in user list at index " << i << "."; 150 LOG(ERROR) << "Corrupt entry in user list at index " << i << ".";
155 continue; 151 continue;
156 } 152 }
157 if (existing_users.find(email) != existing_users.end() || 153 if (existing_users.find(email) != existing_users.end() ||
158 !users_set->insert(email).second) { 154 !users_set->insert(email).second) {
159 LOG(ERROR) << "Duplicate user: " << email; 155 LOG(ERROR) << "Duplicate user: " << email;
160 continue; 156 continue;
161 } 157 }
162 if (email == logged_in_user) {
163 logged_in_user_on_list = true;
164 continue;
165 }
166 users_vector->push_back(email); 158 users_vector->push_back(email);
167 } 159 }
168 users_set->erase(logged_in_user);
169 return logged_in_user_on_list;
170 } 160 }
171 161
172 } // namespace 162 } // namespace
173 163
174 // static 164 // static
175 void UserManager::RegisterPrefs(PrefRegistrySimple* registry) { 165 void UserManager::RegisterPrefs(PrefRegistrySimple* registry) {
176 registry->RegisterListPref(kRegularUsers); 166 registry->RegisterListPref(kRegularUsers);
177 registry->RegisterListPref(kPublicAccounts); 167 registry->RegisterListPref(kPublicAccounts);
178 registry->RegisterListPref(kLocallyManagedUsersFirstRun); 168 registry->RegisterListPref(kLocallyManagedUsersFirstRun);
179 registry->RegisterIntegerPref(kLocallyManagedUsersNextId, 0); 169 registry->RegisterIntegerPref(kLocallyManagedUsersNextId, 0);
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 const ListValue* prefs_public_accounts = 836 const ListValue* prefs_public_accounts =
847 local_state->GetList(kPublicAccounts); 837 local_state->GetList(kPublicAccounts);
848 const DictionaryValue* prefs_display_names = 838 const DictionaryValue* prefs_display_names =
849 local_state->GetDictionary(kUserDisplayName); 839 local_state->GetDictionary(kUserDisplayName);
850 const DictionaryValue* prefs_display_emails = 840 const DictionaryValue* prefs_display_emails =
851 local_state->GetDictionary(kUserDisplayEmail); 841 local_state->GetDictionary(kUserDisplayEmail);
852 842
853 // Load regular users and locally managed users. 843 // Load regular users and locally managed users.
854 std::vector<std::string> regular_users; 844 std::vector<std::string> regular_users;
855 std::set<std::string> regular_users_set; 845 std::set<std::string> regular_users_set;
856 ParseUserList(*prefs_regular_users, std::set<std::string>(), "", 846 ParseUserList(*prefs_regular_users, std::set<std::string>(),
857 &regular_users, &regular_users_set); 847 &regular_users, &regular_users_set);
858 for (std::vector<std::string>::const_iterator it = regular_users.begin(); 848 for (std::vector<std::string>::const_iterator it = regular_users.begin();
859 it != regular_users.end(); ++it) { 849 it != regular_users.end(); ++it) {
860 User* user = NULL; 850 User* user = NULL;
861 const std::string domain = gaia::ExtractDomainName(*it); 851 const std::string domain = gaia::ExtractDomainName(*it);
862 if (domain == UserManager::kLocallyManagedUserDomain) { 852 if (domain == UserManager::kLocallyManagedUserDomain) {
863 user = User::CreateLocallyManagedUser(*it); 853 user = User::CreateLocallyManagedUser(*it);
864 } else { 854 } else {
865 user = User::CreateRegularUser(*it); 855 user = User::CreateRegularUser(*it);
866 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); 856 user->set_oauth_token_status(LoadUserOAuthStatus(*it));
867 } 857 }
868 users_.push_back(user); 858 users_.push_back(user);
869 859
870 string16 display_name; 860 string16 display_name;
871 if (prefs_display_names->GetStringWithoutPathExpansion(*it, 861 if (prefs_display_names->GetStringWithoutPathExpansion(*it,
872 &display_name)) { 862 &display_name)) {
873 user->set_display_name(display_name); 863 user->set_display_name(display_name);
874 } 864 }
875 865
876 std::string display_email; 866 std::string display_email;
877 if (prefs_display_emails->GetStringWithoutPathExpansion(*it, 867 if (prefs_display_emails->GetStringWithoutPathExpansion(*it,
878 &display_email)) { 868 &display_email)) {
879 user->set_display_email(display_email); 869 user->set_display_email(display_email);
880 } 870 }
881 } 871 }
882 872
883 // Load public accounts. 873 // Load public accounts.
884 std::vector<std::string> public_accounts; 874 std::vector<std::string> public_accounts;
885 std::set<std::string> public_accounts_set; 875 std::set<std::string> public_accounts_set;
886 ParseUserList(*prefs_public_accounts, regular_users_set, "", 876 ParseUserList(*prefs_public_accounts, regular_users_set,
887 &public_accounts, &public_accounts_set); 877 &public_accounts, &public_accounts_set);
888 for (std::vector<std::string>::const_iterator it = public_accounts.begin(); 878 for (std::vector<std::string>::const_iterator it = public_accounts.begin();
889 it != public_accounts.end(); ++it) { 879 it != public_accounts.end(); ++it) {
890 users_.push_back(User::CreatePublicAccountUser(*it)); 880 users_.push_back(User::CreatePublicAccountUser(*it));
891 UpdatePublicAccountDisplayName(*it); 881 UpdatePublicAccountDisplayName(*it);
892 } 882 }
893 883
894 user_image_manager_->LoadUserImages(users_); 884 user_image_manager_->LoadUserImages(users_);
895 } 885 }
896 886
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 if ((*it)->GetType() == User::USER_TYPE_REGULAR || 1165 if ((*it)->GetType() == User::USER_TYPE_REGULAR ||
1176 (*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { 1166 (*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) {
1177 prefs_users_update->Append(new base::StringValue(user_email)); 1167 prefs_users_update->Append(new base::StringValue(user_email));
1178 } 1168 }
1179 ++it; 1169 ++it;
1180 } 1170 }
1181 } 1171 }
1182 return user; 1172 return user;
1183 } 1173 }
1184 1174
1175 void UserManagerImpl::CleanUpPublicAccountNonCryptohomeData(
1176 const std::vector<std::string>& old_public_accounts) {
1177 std::set<std::string> users;
1178 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it)
1179 users.insert((*it)->email());
1180
1181 // If the user is logged into a public account that has been removed from the
1182 // user list, mark the account's data as pending removal after logout.
1183 if (IsLoggedInAsPublicAccount()) {
1184 const std::string active_user_id = GetActiveUser()->email();
1185 if (users.find(active_user_id) == users.end()) {
1186 g_browser_process->local_state()->SetString(
1187 kPublicAccountPendingDataRemoval, active_user_id);
1188 users.insert(active_user_id);
1189 }
1190 }
1191
1192 // Remove the data belonging to any other public accounts that are no longer
1193 // found on the user list.
1194 for (std::vector<std::string>::const_iterator
1195 it = old_public_accounts.begin();
1196 it != old_public_accounts.end(); ++it) {
1197 if (users.find(*it) == users.end())
1198 RemoveNonCryptohomeData(*it);
1199 }
1200 }
1201
1185 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts( 1202 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts(
1186 const base::ListValue& public_accounts) { 1203 const base::ListValue& public_accounts) {
1187 PrefService* local_state = g_browser_process->local_state(); 1204 PrefService* local_state = g_browser_process->local_state();
1188 1205
1189 // Determine the currently logged-in user's email. 1206 // Determine the currently logged-in user's email.
1190 std::string active_user_email; 1207 std::string active_user_email;
1191 if (IsUserLoggedIn()) 1208 if (IsUserLoggedIn())
1192 active_user_email = GetLoggedInUser()->email(); 1209 active_user_email = GetLoggedInUser()->email();
1193 1210
1194 // If there is a public account whose data is pending removal and the user is 1211 // If there is a public account whose data is pending removal and the user is
(...skipping 13 matching lines...) Expand all
1208 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { 1225 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) {
1209 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) 1226 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT)
1210 old_public_accounts.push_back((*it)->email()); 1227 old_public_accounts.push_back((*it)->email());
1211 else 1228 else
1212 regular_users.insert((*it)->email()); 1229 regular_users.insert((*it)->email());
1213 } 1230 }
1214 1231
1215 // Get the new list of public accounts from policy. 1232 // Get the new list of public accounts from policy.
1216 std::vector<std::string> new_public_accounts; 1233 std::vector<std::string> new_public_accounts;
1217 std::set<std::string> new_public_accounts_set; 1234 std::set<std::string> new_public_accounts_set;
1218 if (!ParseUserList(public_accounts, regular_users, active_user_email, 1235 ParseUserList(public_accounts, regular_users,
1219 &new_public_accounts, &new_public_accounts_set) && 1236 &new_public_accounts, &new_public_accounts_set);
1220 IsLoggedInAsPublicAccount()) {
1221 // If the user is currently logged into a public account that has been
1222 // removed from the list, mark the account's data as pending removal after
1223 // logout.
1224 local_state->SetString(kPublicAccountPendingDataRemoval,
1225 active_user_email);
1226 }
1227 1237
1228 // Persist the new list of public accounts in a pref. 1238 // Persist the new list of public accounts in a pref.
1229 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts); 1239 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts);
1230 scoped_ptr<base::ListValue> prefs_public_accounts(public_accounts.DeepCopy()); 1240 scoped_ptr<base::ListValue> prefs_public_accounts(public_accounts.DeepCopy());
1231 prefs_public_accounts_update->Swap(prefs_public_accounts.get()); 1241 prefs_public_accounts_update->Swap(prefs_public_accounts.get());
1232 1242
1233 // If the list of public accounts has not changed, return. 1243 // If the list of public accounts has not changed, return.
1234 if (new_public_accounts.size() == old_public_accounts.size()) { 1244 if (new_public_accounts.size() == old_public_accounts.size()) {
1235 bool changed = false; 1245 bool changed = false;
1236 for (size_t i = 0; i < new_public_accounts.size(); ++i) { 1246 for (size_t i = 0; i < new_public_accounts.size(); ++i) {
(...skipping 24 matching lines...) Expand all
1261 if (IsLoggedInAsPublicAccount() && *it == active_user_email) 1271 if (IsLoggedInAsPublicAccount() && *it == active_user_email)
1262 users_.insert(users_.begin(), GetLoggedInUser()); 1272 users_.insert(users_.begin(), GetLoggedInUser());
1263 else 1273 else
1264 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it)); 1274 users_.insert(users_.begin(), User::CreatePublicAccountUser(*it));
1265 UpdatePublicAccountDisplayName(*it); 1275 UpdatePublicAccountDisplayName(*it);
1266 } 1276 }
1267 1277
1268 user_image_manager_->LoadUserImages( 1278 user_image_manager_->LoadUserImages(
1269 UserList(users_.begin(), users_.begin() + new_public_accounts.size())); 1279 UserList(users_.begin(), users_.begin() + new_public_accounts.size()));
1270 1280
1281 // Remove data belonging to public accounts that are no longer found on the
1282 // user list.
1283 CleanUpPublicAccountNonCryptohomeData(old_public_accounts);
1284
1271 return true; 1285 return true;
1272 } 1286 }
1273 1287
1274 void UserManagerImpl::UpdatePublicAccountDisplayName( 1288 void UserManagerImpl::UpdatePublicAccountDisplayName(
1275 const std::string& username) { 1289 const std::string& username) {
1276 std::string display_name; 1290 std::string display_name;
1277 1291
1278 if (device_local_account_policy_service_) { 1292 if (device_local_account_policy_service_) {
1279 policy::DeviceLocalAccountPolicyBroker* broker = 1293 policy::DeviceLocalAccountPolicyBroker* broker =
1280 device_local_account_policy_service_->GetBrokerForAccount(username); 1294 device_local_account_policy_service_->GetBrokerForAccount(username);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 case DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP: 1502 case DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP:
1489 // TODO(mnissler, nkostylev, bartfab): Process Kiosk Apps within the 1503 // TODO(mnissler, nkostylev, bartfab): Process Kiosk Apps within the
1490 // standard login framework: http://crbug.com/234694 1504 // standard login framework: http://crbug.com/234694
1491 break; 1505 break;
1492 } 1506 }
1493 } 1507 }
1494 } 1508 }
1495 } 1509 }
1496 1510
1497 } // namespace chromeos 1511 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698