| 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 #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/file_util.h" | 15 #include "base/file_util.h" |
| 17 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 18 #include "base/logging.h" | 17 #include "base/logging.h" |
| 19 #include "base/prefs/pref_registry_simple.h" | 18 #include "base/prefs/pref_registry_simple.h" |
| 20 #include "base/prefs/pref_service.h" | 19 #include "base/prefs/pref_service.h" |
| 21 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 22 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 23 #include "base/stringprintf.h" | 22 #include "base/stringprintf.h" |
| 24 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 25 #include "base/values.h" | 24 #include "base/values.h" |
| 26 #include "chrome/browser/app_mode/app_mode_utils.h" | 25 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 27 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/chromeos/cros/cert_library.h" | 27 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 29 #include "chrome/browser/chromeos/cros/cros_library.h" | 28 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 30 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" | 29 #include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h" |
| 31 #include "chrome/browser/chromeos/login/login_display.h" | 30 #include "chrome/browser/chromeos/login/login_display.h" |
| 32 #include "chrome/browser/chromeos/login/remove_user_delegate.h" | 31 #include "chrome/browser/chromeos/login/remove_user_delegate.h" |
| 33 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" | 32 #include "chrome/browser/chromeos/login/user_image_manager_impl.h" |
| 34 #include "chrome/browser/chromeos/login/wizard_controller.h" | 33 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 34 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 35 #include "chrome/browser/chromeos/session_length_limiter.h" | 35 #include "chrome/browser/chromeos/session_length_limiter.h" |
| 36 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 36 #include "chrome/browser/policy/browser_policy_connector.h" | 37 #include "chrome/browser/policy/browser_policy_connector.h" |
| 37 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 38 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 38 #include "chrome/browser/profiles/profile_manager.h" | 39 #include "chrome/browser/profiles/profile_manager.h" |
| 39 #include "chrome/browser/sync/profile_sync_service.h" | 40 #include "chrome/browser/sync/profile_sync_service.h" |
| 40 #include "chrome/browser/sync/profile_sync_service_factory.h" | 41 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 41 #include "chrome/common/chrome_notification_types.h" | 42 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
| 44 #include "chromeos/chromeos_switches.h" | 45 #include "chromeos/chromeos_switches.h" |
| 45 #include "chromeos/cryptohome/async_method_caller.h" | 46 #include "chromeos/cryptohome/async_method_caller.h" |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 // http://crbug.com/230860 | 650 // http://crbug.com/230860 |
| 650 // TODO(nkostylev): Figure out whether we want to have observers | 651 // TODO(nkostylev): Figure out whether we want to have observers |
| 651 // for each logged in user. | 652 // for each logged in user. |
| 652 // TODO(nkostyelv): Change observer after active user has changed. | 653 // TODO(nkostyelv): Change observer after active user has changed. |
| 653 SaveUserOAuthStatus( | 654 SaveUserOAuthStatus( |
| 654 active_user_->email(), | 655 active_user_->email(), |
| 655 User::OAUTH2_TOKEN_STATUS_INVALID); | 656 User::OAUTH2_TOKEN_STATUS_INVALID); |
| 656 } | 657 } |
| 657 } | 658 } |
| 658 | 659 |
| 659 void UserManagerImpl::OnPolicyUpdated(const std::string& account_id) { | 660 void UserManagerImpl::OnPolicyUpdated(const std::string& user_id) { |
| 660 UpdatePublicAccountDisplayName(account_id); | 661 UpdatePublicAccountDisplayName(user_id); |
| 661 NotifyUserListChanged(); | 662 NotifyUserListChanged(); |
| 662 } | 663 } |
| 663 | 664 |
| 664 void UserManagerImpl::OnDeviceLocalAccountsChanged() { | 665 void UserManagerImpl::OnDeviceLocalAccountsChanged() { |
| 665 // No action needed here, changes to the list of device-local accounts get | 666 // No action needed here, changes to the list of device-local accounts get |
| 666 // handled via the kAccountsPrefDeviceLocalAccounts device setting observer. | 667 // handled via the kAccountsPrefDeviceLocalAccounts device setting observer. |
| 667 } | 668 } |
| 668 | 669 |
| 669 bool UserManagerImpl::IsCurrentUserOwner() const { | 670 bool UserManagerImpl::IsCurrentUserOwner() const { |
| 670 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 671 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 // Schedule a callback if device policy has not yet been verified. | 903 // Schedule a callback if device policy has not yet been verified. |
| 903 if (CrosSettingsProvider::TRUSTED != cros_settings_->PrepareTrustedValues( | 904 if (CrosSettingsProvider::TRUSTED != cros_settings_->PrepareTrustedValues( |
| 904 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, | 905 base::Bind(&UserManagerImpl::RetrieveTrustedDevicePolicies, |
| 905 base::Unretained(this)))) { | 906 base::Unretained(this)))) { |
| 906 return; | 907 return; |
| 907 } | 908 } |
| 908 | 909 |
| 909 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled, | 910 cros_settings_->GetBoolean(kAccountsPrefEphemeralUsersEnabled, |
| 910 &ephemeral_users_enabled_); | 911 &ephemeral_users_enabled_); |
| 911 cros_settings_->GetString(kDeviceOwner, &owner_email_); | 912 cros_settings_->GetString(kDeviceOwner, &owner_email_); |
| 912 base::ListValue public_accounts; | 913 const base::ListValue* device_local_accounts; |
| 913 ReadPublicAccounts(&public_accounts); | 914 cros_settings_->GetList(kAccountsPrefDeviceLocalAccounts, |
| 915 &device_local_accounts); |
| 914 | 916 |
| 915 EnsureUsersLoaded(); | 917 EnsureUsersLoaded(); |
| 916 | 918 |
| 917 bool changed = UpdateAndCleanUpPublicAccounts(public_accounts); | 919 bool changed = UpdateAndCleanUpPublicAccounts( |
| 920 policy::DecodeDeviceLocalAccountsList(device_local_accounts)); |
| 918 | 921 |
| 919 // If ephemeral users are enabled and we are on the login screen, take this | 922 // If ephemeral users are enabled and we are on the login screen, take this |
| 920 // opportunity to clean up by removing all regular users except the owner. | 923 // opportunity to clean up by removing all regular users except the owner. |
| 921 if (ephemeral_users_enabled_ && !IsUserLoggedIn()) { | 924 if (ephemeral_users_enabled_ && !IsUserLoggedIn()) { |
| 922 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), | 925 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), |
| 923 kRegularUsers); | 926 kRegularUsers); |
| 924 prefs_users_update->Clear(); | 927 prefs_users_update->Clear(); |
| 925 for (UserList::iterator it = users_.begin(); it != users_.end(); ) { | 928 for (UserList::iterator it = users_.begin(); it != users_.end(); ) { |
| 926 const std::string user_email = (*it)->email(); | 929 const std::string user_email = (*it)->email(); |
| 927 if ((*it)->GetType() == User::USER_TYPE_REGULAR && | 930 if ((*it)->GetType() == User::USER_TYPE_REGULAR && |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 (*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { | 1180 (*it)->GetType() == User::USER_TYPE_LOCALLY_MANAGED) { |
| 1178 prefs_users_update->Append(new base::StringValue(user_email)); | 1181 prefs_users_update->Append(new base::StringValue(user_email)); |
| 1179 } | 1182 } |
| 1180 ++it; | 1183 ++it; |
| 1181 } | 1184 } |
| 1182 } | 1185 } |
| 1183 return user; | 1186 return user; |
| 1184 } | 1187 } |
| 1185 | 1188 |
| 1186 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts( | 1189 bool UserManagerImpl::UpdateAndCleanUpPublicAccounts( |
| 1187 const base::ListValue& public_accounts) { | 1190 const std::vector<policy::DeviceLocalAccount>& device_local_accounts) { |
| 1188 PrefService* local_state = g_browser_process->local_state(); | 1191 PrefService* local_state = g_browser_process->local_state(); |
| 1189 | 1192 |
| 1190 // Determine the currently logged-in user's email. | 1193 // Determine the currently logged-in user's email. |
| 1191 std::string active_user_email; | 1194 std::string active_user_email; |
| 1192 if (IsUserLoggedIn()) | 1195 if (IsUserLoggedIn()) |
| 1193 active_user_email = GetLoggedInUser()->email(); | 1196 active_user_email = GetLoggedInUser()->email(); |
| 1194 | 1197 |
| 1195 // If there is a public account whose data is pending removal and the user is | 1198 // If there is a public account whose data is pending removal and the user is |
| 1196 // not currently logged in with that account, take this opportunity to remove | 1199 // not currently logged in with that account, take this opportunity to remove |
| 1197 // the data. | 1200 // the data. |
| 1198 std::string public_account_pending_data_removal = | 1201 std::string public_account_pending_data_removal = |
| 1199 local_state->GetString(kPublicAccountPendingDataRemoval); | 1202 local_state->GetString(kPublicAccountPendingDataRemoval); |
| 1200 if (!public_account_pending_data_removal.empty() && | 1203 if (!public_account_pending_data_removal.empty() && |
| 1201 public_account_pending_data_removal != active_user_email) { | 1204 public_account_pending_data_removal != active_user_email) { |
| 1202 RemoveNonCryptohomeData(public_account_pending_data_removal); | 1205 RemoveNonCryptohomeData(public_account_pending_data_removal); |
| 1203 local_state->ClearPref(kPublicAccountPendingDataRemoval); | 1206 local_state->ClearPref(kPublicAccountPendingDataRemoval); |
| 1204 } | 1207 } |
| 1205 | 1208 |
| 1206 // Split the current user list public accounts and regular users. | 1209 // Split the current user list public accounts and regular users. |
| 1207 std::vector<std::string> old_public_accounts; | 1210 std::vector<std::string> old_public_accounts; |
| 1208 std::set<std::string> regular_users; | 1211 std::set<std::string> regular_users; |
| 1209 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { | 1212 for (UserList::const_iterator it = users_.begin(); it != users_.end(); ++it) { |
| 1210 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) | 1213 if ((*it)->GetType() == User::USER_TYPE_PUBLIC_ACCOUNT) |
| 1211 old_public_accounts.push_back((*it)->email()); | 1214 old_public_accounts.push_back((*it)->email()); |
| 1212 else | 1215 else |
| 1213 regular_users.insert((*it)->email()); | 1216 regular_users.insert((*it)->email()); |
| 1214 } | 1217 } |
| 1215 | 1218 |
| 1216 // Get the new list of public accounts from policy. | 1219 // Get the new list of public accounts from policy. |
| 1220 scoped_ptr<base::ListValue> prefs_public_accounts(new base::ListValue); |
| 1217 std::vector<std::string> new_public_accounts; | 1221 std::vector<std::string> new_public_accounts; |
| 1218 std::set<std::string> new_public_accounts_set; | 1222 bool logged_in_user_on_list = false; |
| 1219 if (!ParseUserList(public_accounts, regular_users, active_user_email, | 1223 for (std::vector<policy::DeviceLocalAccount>::const_iterator it = |
| 1220 &new_public_accounts, &new_public_accounts_set) && | 1224 device_local_accounts.begin(); |
| 1221 IsLoggedInAsPublicAccount()) { | 1225 it != device_local_accounts.end(); ++it) { |
| 1222 // If the user is currently logged into a public account that has been | 1226 if (it->type != policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION) |
| 1223 // removed from the list, mark the account's data as pending removal after | 1227 continue; |
| 1224 // logout. | 1228 prefs_public_accounts->AppendString(it->user_id); |
| 1229 if (it->user_id == active_user_email) { |
| 1230 logged_in_user_on_list = true; |
| 1231 continue; |
| 1232 } |
| 1233 new_public_accounts.push_back(it->user_id); |
| 1234 } |
| 1235 |
| 1236 // If the user is currently logged into a public account that has been removed |
| 1237 // from the list, mark the account's data as pending removal after logout. |
| 1238 if (!logged_in_user_on_list && IsLoggedInAsPublicAccount()) { |
| 1225 local_state->SetString(kPublicAccountPendingDataRemoval, | 1239 local_state->SetString(kPublicAccountPendingDataRemoval, |
| 1226 active_user_email); | 1240 active_user_email); |
| 1227 } | 1241 } |
| 1228 | 1242 |
| 1229 // Persist the new list of public accounts in a pref. | 1243 // Persist the new list of public accounts in a pref. |
| 1230 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts); | 1244 ListPrefUpdate prefs_public_accounts_update(local_state, kPublicAccounts); |
| 1231 scoped_ptr<base::ListValue> prefs_public_accounts(public_accounts.DeepCopy()); | |
| 1232 prefs_public_accounts_update->Swap(prefs_public_accounts.get()); | 1245 prefs_public_accounts_update->Swap(prefs_public_accounts.get()); |
| 1233 | 1246 |
| 1234 // If the list of public accounts has not changed, return. | 1247 // If the list of public accounts has not changed, return. |
| 1235 if (new_public_accounts.size() == old_public_accounts.size()) { | 1248 if (new_public_accounts.size() == old_public_accounts.size()) { |
| 1236 bool changed = false; | 1249 bool changed = false; |
| 1237 for (size_t i = 0; i < new_public_accounts.size(); ++i) { | 1250 for (size_t i = 0; i < new_public_accounts.size(); ++i) { |
| 1238 if (new_public_accounts[i] != old_public_accounts[i]) { | 1251 if (new_public_accounts[i] != old_public_accounts[i]) { |
| 1239 changed = true; | 1252 changed = true; |
| 1240 break; | 1253 break; |
| 1241 } | 1254 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1271 | 1284 |
| 1272 return true; | 1285 return true; |
| 1273 } | 1286 } |
| 1274 | 1287 |
| 1275 void UserManagerImpl::UpdatePublicAccountDisplayName( | 1288 void UserManagerImpl::UpdatePublicAccountDisplayName( |
| 1276 const std::string& username) { | 1289 const std::string& username) { |
| 1277 std::string display_name; | 1290 std::string display_name; |
| 1278 | 1291 |
| 1279 if (device_local_account_policy_service_) { | 1292 if (device_local_account_policy_service_) { |
| 1280 policy::DeviceLocalAccountPolicyBroker* broker = | 1293 policy::DeviceLocalAccountPolicyBroker* broker = |
| 1281 device_local_account_policy_service_->GetBrokerForAccount(username); | 1294 device_local_account_policy_service_->GetBrokerForUser(username); |
| 1282 if (broker) | 1295 if (broker) |
| 1283 display_name = broker->GetDisplayName(); | 1296 display_name = broker->GetDisplayName(); |
| 1284 } | 1297 } |
| 1285 | 1298 |
| 1286 // Set or clear the display name. | 1299 // Set or clear the display name. |
| 1287 SaveUserDisplayName(username, UTF8ToUTF16(display_name)); | 1300 SaveUserDisplayName(username, UTF8ToUTF16(display_name)); |
| 1288 } | 1301 } |
| 1289 | 1302 |
| 1290 void UserManagerImpl::StartLocallyManagedUserCreationTransaction( | 1303 void UserManagerImpl::StartLocallyManagedUserCreationTransaction( |
| 1291 const string16& display_name) { | 1304 const string16& display_name) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 else if (active_user_->GetType() == User::USER_TYPE_LOCALLY_MANAGED) | 1469 else if (active_user_->GetType() == User::USER_TYPE_LOCALLY_MANAGED) |
| 1457 login_user_type = LoginState::LOGGED_IN_USER_LOCALLY_MANAGED; | 1470 login_user_type = LoginState::LOGGED_IN_USER_LOCALLY_MANAGED; |
| 1458 else if (active_user_->GetType() == User::USER_TYPE_KIOSK_APP) | 1471 else if (active_user_->GetType() == User::USER_TYPE_KIOSK_APP) |
| 1459 login_user_type = LoginState::LOGGED_IN_USER_KIOSK_APP; | 1472 login_user_type = LoginState::LOGGED_IN_USER_KIOSK_APP; |
| 1460 else | 1473 else |
| 1461 login_user_type = LoginState::LOGGED_IN_USER_REGULAR; | 1474 login_user_type = LoginState::LOGGED_IN_USER_REGULAR; |
| 1462 | 1475 |
| 1463 LoginState::Get()->SetLoggedInState(logged_in_state, login_user_type); | 1476 LoginState::Get()->SetLoggedInState(logged_in_state, login_user_type); |
| 1464 } | 1477 } |
| 1465 | 1478 |
| 1466 void UserManagerImpl::ReadPublicAccounts(base::ListValue* public_accounts) { | |
| 1467 const base::ListValue* accounts = NULL; | |
| 1468 if (cros_settings_->GetList(kAccountsPrefDeviceLocalAccounts, &accounts)) { | |
| 1469 for (base::ListValue::const_iterator entry(accounts->begin()); | |
| 1470 entry != accounts->end(); ++entry) { | |
| 1471 const base::DictionaryValue* entry_dict = NULL; | |
| 1472 if (!(*entry)->GetAsDictionary(&entry_dict)) { | |
| 1473 NOTREACHED(); | |
| 1474 continue; | |
| 1475 } | |
| 1476 | |
| 1477 int type = DEVICE_LOCAL_ACCOUNT_TYPE_PUBLIC_SESSION; | |
| 1478 entry_dict->GetIntegerWithoutPathExpansion( | |
| 1479 kAccountsPrefDeviceLocalAccountsKeyType, &type); | |
| 1480 switch (type) { | |
| 1481 case DEVICE_LOCAL_ACCOUNT_TYPE_PUBLIC_SESSION: { | |
| 1482 std::string id; | |
| 1483 if (entry_dict->GetStringWithoutPathExpansion( | |
| 1484 kAccountsPrefDeviceLocalAccountsKeyId, &id)) { | |
| 1485 public_accounts->AppendString(id); | |
| 1486 } | |
| 1487 break; | |
| 1488 } | |
| 1489 case DEVICE_LOCAL_ACCOUNT_TYPE_KIOSK_APP: | |
| 1490 // TODO(mnissler, nkostylev, bartfab): Process Kiosk Apps within the | |
| 1491 // standard login framework: http://crbug.com/234694 | |
| 1492 break; | |
| 1493 } | |
| 1494 } | |
| 1495 } | |
| 1496 } | |
| 1497 | |
| 1498 } // namespace chromeos | 1479 } // namespace chromeos |
| OLD | NEW |