OLD | NEW |
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 "chrome/browser/chromeos/login/users/user_manager_impl.h" | 5 #include "chrome/browser/chromeos/login/users/user_manager_impl.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "ash/multi_profile_uma.h" | 10 #include "ash/multi_profile_uma.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/prefs/scoped_user_pref_update.h" | 23 #include "base/prefs/scoped_user_pref_update.h" |
24 #include "base/rand_util.h" | 24 #include "base/rand_util.h" |
25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
27 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
28 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
29 #include "base/threading/worker_pool.h" | 29 #include "base/threading/worker_pool.h" |
30 #include "base/values.h" | 30 #include "base/values.h" |
31 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
32 #include "chrome/browser/chrome_notification_types.h" | 32 #include "chrome/browser/chrome_notification_types.h" |
33 #include "chrome/browser/chromeos/login/auth/user_context.h" | |
34 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" | 33 #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" |
35 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 34 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
36 #include "chrome/browser/chromeos/login/signin/auth_sync_observer.h" | 35 #include "chrome/browser/chromeos/login/signin/auth_sync_observer.h" |
37 #include "chrome/browser/chromeos/login/signin/auth_sync_observer_factory.h" | 36 #include "chrome/browser/chromeos/login/signin/auth_sync_observer_factory.h" |
38 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" | 37 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" |
39 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" | 38 #include "chrome/browser/chromeos/login/users/multi_profile_user_controller.h" |
40 #include "chrome/browser/chromeos/login/users/remove_user_delegate.h" | 39 #include "chrome/browser/chromeos/login/users/remove_user_delegate.h" |
41 #include "chrome/browser/chromeos/login/users/supervised_user_manager_impl.h" | 40 #include "chrome/browser/chromeos/login/users/supervised_user_manager_impl.h" |
42 #include "chrome/browser/chromeos/login/wizard_controller.h" | 41 #include "chrome/browser/chromeos/login/wizard_controller.h" |
43 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 42 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
44 #include "chrome/browser/chromeos/policy/device_local_account.h" | 43 #include "chrome/browser/chromeos/policy/device_local_account.h" |
45 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog.
h" | 44 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog.
h" |
46 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 45 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
47 #include "chrome/browser/chromeos/session_length_limiter.h" | 46 #include "chrome/browser/chromeos/session_length_limiter.h" |
48 #include "chrome/browser/profiles/profile.h" | 47 #include "chrome/browser/profiles/profile.h" |
49 #include "chrome/browser/profiles/profile_manager.h" | 48 #include "chrome/browser/profiles/profile_manager.h" |
50 #include "chrome/browser/supervised_user/chromeos/manager_password_service_facto
ry.h" | 49 #include "chrome/browser/supervised_user/chromeos/manager_password_service_facto
ry.h" |
51 #include "chrome/browser/supervised_user/chromeos/supervised_user_password_servi
ce_factory.h" | 50 #include "chrome/browser/supervised_user/chromeos/supervised_user_password_servi
ce_factory.h" |
52 #include "chrome/common/chrome_constants.h" | 51 #include "chrome/common/chrome_constants.h" |
53 #include "chrome/common/chrome_paths.h" | 52 #include "chrome/common/chrome_paths.h" |
54 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
55 #include "chrome/common/crash_keys.h" | 54 #include "chrome/common/crash_keys.h" |
56 #include "chrome/common/pref_names.h" | 55 #include "chrome/common/pref_names.h" |
57 #include "chromeos/chromeos_switches.h" | 56 #include "chromeos/chromeos_switches.h" |
58 #include "chromeos/cryptohome/async_method_caller.h" | 57 #include "chromeos/cryptohome/async_method_caller.h" |
59 #include "chromeos/dbus/dbus_thread_manager.h" | 58 #include "chromeos/dbus/dbus_thread_manager.h" |
| 59 #include "chromeos/login/auth/user_context.h" |
60 #include "chromeos/login/login_state.h" | 60 #include "chromeos/login/login_state.h" |
| 61 #include "chromeos/login/user_names.h" |
61 #include "chromeos/settings/cros_settings_names.h" | 62 #include "chromeos/settings/cros_settings_names.h" |
62 #include "components/user_manager/user_type.h" | 63 #include "components/user_manager/user_type.h" |
63 #include "content/public/browser/browser_thread.h" | 64 #include "content/public/browser/browser_thread.h" |
64 #include "content/public/browser/notification_service.h" | 65 #include "content/public/browser/notification_service.h" |
65 #include "google_apis/gaia/gaia_auth_util.h" | 66 #include "google_apis/gaia/gaia_auth_util.h" |
66 #include "google_apis/gaia/google_service_auth_error.h" | 67 #include "google_apis/gaia/google_service_auth_error.h" |
67 #include "policy/policy_constants.h" | 68 #include "policy/policy_constants.h" |
68 #include "ui/base/l10n/l10n_util.h" | 69 #include "ui/base/l10n/l10n_util.h" |
69 #include "ui/wm/core/wm_core_switches.h" | 70 #include "ui/wm/core/wm_core_switches.h" |
70 | 71 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 lru_logged_in_users_.push_back(user); | 387 lru_logged_in_users_.push_back(user); |
387 // Reset the new user flag if the user already exists. | 388 // Reset the new user flag if the user already exists. |
388 is_current_user_new_ = false; | 389 is_current_user_new_ = false; |
389 NotifyUserAddedToSession(user); | 390 NotifyUserAddedToSession(user); |
390 // Remember that we need to switch to this user as soon as profile ready. | 391 // Remember that we need to switch to this user as soon as profile ready. |
391 pending_user_switch_ = user_id; | 392 pending_user_switch_ = user_id; |
392 return; | 393 return; |
393 } | 394 } |
394 | 395 |
395 policy::DeviceLocalAccount::Type device_local_account_type; | 396 policy::DeviceLocalAccount::Type device_local_account_type; |
396 if (user_id == UserManager::kGuestUserName) { | 397 if (user_id == chromeos::login::kGuestUserName) { |
397 GuestUserLoggedIn(); | 398 GuestUserLoggedIn(); |
398 } else if (user_id == UserManager::kRetailModeUserName) { | 399 } else if (user_id == chromeos::login::kRetailModeUserName) { |
399 RetailModeUserLoggedIn(); | 400 RetailModeUserLoggedIn(); |
400 } else if (policy::IsDeviceLocalAccountUser(user_id, | 401 } else if (policy::IsDeviceLocalAccountUser(user_id, |
401 &device_local_account_type) && | 402 &device_local_account_type) && |
402 device_local_account_type == | 403 device_local_account_type == |
403 policy::DeviceLocalAccount::TYPE_KIOSK_APP) { | 404 policy::DeviceLocalAccount::TYPE_KIOSK_APP) { |
404 KioskAppLoggedIn(user_id); | 405 KioskAppLoggedIn(user_id); |
405 } else if (DemoAppLauncher::IsDemoAppSession(user_id)) { | 406 } else if (DemoAppLauncher::IsDemoAppSession(user_id)) { |
406 DemoAccountLoggedIn(); | 407 DemoAccountLoggedIn(); |
407 } else { | 408 } else { |
408 EnsureUsersLoaded(); | 409 EnsureUsersLoaded(); |
409 | 410 |
410 if (user && user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { | 411 if (user && user->GetType() == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { |
411 PublicAccountUserLoggedIn(user); | 412 PublicAccountUserLoggedIn(user); |
412 } else if ((user && | 413 } else if ((user && |
413 user->GetType() == user_manager::USER_TYPE_LOCALLY_MANAGED) || | 414 user->GetType() == user_manager::USER_TYPE_LOCALLY_MANAGED) || |
414 (!user && | 415 (!user && |
415 gaia::ExtractDomainName(user_id) == | 416 gaia::ExtractDomainName(user_id) == |
416 UserManager::kLocallyManagedUserDomain)) { | 417 chromeos::login::kLocallyManagedUserDomain)) { |
417 LocallyManagedUserLoggedIn(user_id); | 418 LocallyManagedUserLoggedIn(user_id); |
418 } else if (browser_restart && user_id == g_browser_process->local_state()-> | 419 } else if (browser_restart && user_id == g_browser_process->local_state()-> |
419 GetString(kPublicAccountPendingDataRemoval)) { | 420 GetString(kPublicAccountPendingDataRemoval)) { |
420 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id)); | 421 PublicAccountUserLoggedIn(User::CreatePublicAccountUser(user_id)); |
421 } else if (user_id != owner_email_ && !user && | 422 } else if (user_id != owner_email_ && !user && |
422 (AreEphemeralUsersEnabled() || browser_restart)) { | 423 (AreEphemeralUsersEnabled() || browser_restart)) { |
423 RegularUserLoggedInAsEphemeral(user_id); | 424 RegularUserLoggedInAsEphemeral(user_id); |
424 } else { | 425 } else { |
425 RegularUserLoggedIn(user_id); | 426 RegularUserLoggedIn(user_id); |
426 } | 427 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 delegate->OnUserRemoved(user_email); | 578 delegate->OnUserRemoved(user_email); |
578 } | 579 } |
579 | 580 |
580 void UserManagerImpl::RemoveUserFromList(const std::string& user_id) { | 581 void UserManagerImpl::RemoveUserFromList(const std::string& user_id) { |
581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
582 RemoveNonCryptohomeData(user_id); | 583 RemoveNonCryptohomeData(user_id); |
583 if (user_loading_stage_ == STAGE_LOADED) { | 584 if (user_loading_stage_ == STAGE_LOADED) { |
584 DeleteUser(RemoveRegularOrLocallyManagedUserFromList(user_id)); | 585 DeleteUser(RemoveRegularOrLocallyManagedUserFromList(user_id)); |
585 } else if (user_loading_stage_ == STAGE_LOADING) { | 586 } else if (user_loading_stage_ == STAGE_LOADING) { |
586 DCHECK(gaia::ExtractDomainName(user_id) == | 587 DCHECK(gaia::ExtractDomainName(user_id) == |
587 UserManager::kLocallyManagedUserDomain); | 588 chromeos::login::kLocallyManagedUserDomain); |
588 // Special case, removing partially-constructed supervised user during user | 589 // Special case, removing partially-constructed supervised user during user |
589 // list loading. | 590 // list loading. |
590 ListPrefUpdate users_update(g_browser_process->local_state(), | 591 ListPrefUpdate users_update(g_browser_process->local_state(), |
591 kRegularUsers); | 592 kRegularUsers); |
592 users_update->Remove(base::StringValue(user_id), NULL); | 593 users_update->Remove(base::StringValue(user_id), NULL); |
593 } else { | 594 } else { |
594 NOTREACHED() << "Users are not loaded yet."; | 595 NOTREACHED() << "Users are not loaded yet."; |
595 return; | 596 return; |
596 } | 597 } |
597 // Make sure that new data is persisted to Local State. | 598 // Make sure that new data is persisted to Local State. |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 } | 938 } |
938 | 939 |
939 bool UserManagerImpl::IsLoggedInAsKioskApp() const { | 940 bool UserManagerImpl::IsLoggedInAsKioskApp() const { |
940 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
941 return IsUserLoggedIn() && | 942 return IsUserLoggedIn() && |
942 active_user_->GetType() == user_manager::USER_TYPE_KIOSK_APP; | 943 active_user_->GetType() == user_manager::USER_TYPE_KIOSK_APP; |
943 } | 944 } |
944 | 945 |
945 bool UserManagerImpl::IsLoggedInAsStub() const { | 946 bool UserManagerImpl::IsLoggedInAsStub() const { |
946 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
947 return IsUserLoggedIn() && active_user_->email() == kStubUser; | 948 return IsUserLoggedIn() && active_user_->email() == login::kStubUser; |
948 } | 949 } |
949 | 950 |
950 bool UserManagerImpl::IsSessionStarted() const { | 951 bool UserManagerImpl::IsSessionStarted() const { |
951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 952 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
952 return session_started_; | 953 return session_started_; |
953 } | 954 } |
954 | 955 |
955 bool UserManagerImpl::UserSessionsRestored() const { | 956 bool UserManagerImpl::UserSessionsRestored() const { |
956 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
957 return user_sessions_restored_; | 958 return user_sessions_restored_; |
958 } | 959 } |
959 | 960 |
960 bool UserManagerImpl::IsUserNonCryptohomeDataEphemeral( | 961 bool UserManagerImpl::IsUserNonCryptohomeDataEphemeral( |
961 const std::string& user_id) const { | 962 const std::string& user_id) const { |
962 // Data belonging to the guest, retail mode and stub users is always | 963 // Data belonging to the guest, retail mode and stub users is always |
963 // ephemeral. | 964 // ephemeral. |
964 if (user_id == UserManager::kGuestUserName || | 965 if (user_id == login::kGuestUserName || |
965 user_id == UserManager::kRetailModeUserName || | 966 user_id == login::kRetailModeUserName || user_id == login::kStubUser) { |
966 user_id == kStubUser) { | |
967 return true; | 967 return true; |
968 } | 968 } |
969 | 969 |
970 // Data belonging to the owner, anyone found on the user list and obsolete | 970 // Data belonging to the owner, anyone found on the user list and obsolete |
971 // public accounts whose data has not been removed yet is not ephemeral. | 971 // public accounts whose data has not been removed yet is not ephemeral. |
972 if (user_id == owner_email_ || UserExistsInList(user_id) || | 972 if (user_id == owner_email_ || UserExistsInList(user_id) || |
973 user_id == g_browser_process->local_state()-> | 973 user_id == g_browser_process->local_state()-> |
974 GetString(kPublicAccountPendingDataRemoval)) { | 974 GetString(kPublicAccountPendingDataRemoval)) { |
975 return false; | 975 return false; |
976 } | 976 } |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 | 1078 |
1079 // Load regular users and locally managed users. | 1079 // Load regular users and locally managed users. |
1080 std::vector<std::string> regular_users; | 1080 std::vector<std::string> regular_users; |
1081 std::set<std::string> regular_users_set; | 1081 std::set<std::string> regular_users_set; |
1082 ParseUserList(*prefs_regular_users, public_sessions_set, | 1082 ParseUserList(*prefs_regular_users, public_sessions_set, |
1083 ®ular_users, ®ular_users_set); | 1083 ®ular_users, ®ular_users_set); |
1084 for (std::vector<std::string>::const_iterator it = regular_users.begin(); | 1084 for (std::vector<std::string>::const_iterator it = regular_users.begin(); |
1085 it != regular_users.end(); ++it) { | 1085 it != regular_users.end(); ++it) { |
1086 User* user = NULL; | 1086 User* user = NULL; |
1087 const std::string domain = gaia::ExtractDomainName(*it); | 1087 const std::string domain = gaia::ExtractDomainName(*it); |
1088 if (domain == UserManager::kLocallyManagedUserDomain) | 1088 if (domain == chromeos::login::kLocallyManagedUserDomain) |
1089 user = User::CreateLocallyManagedUser(*it); | 1089 user = User::CreateLocallyManagedUser(*it); |
1090 else | 1090 else |
1091 user = User::CreateRegularUser(*it); | 1091 user = User::CreateRegularUser(*it); |
1092 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); | 1092 user->set_oauth_token_status(LoadUserOAuthStatus(*it)); |
1093 user->set_force_online_signin(LoadForceOnlineSignin(*it)); | 1093 user->set_force_online_signin(LoadForceOnlineSignin(*it)); |
1094 users_.push_back(user); | 1094 users_.push_back(user); |
1095 | 1095 |
1096 base::string16 display_name; | 1096 base::string16 display_name; |
1097 if (prefs_display_names->GetStringWithoutPathExpansion(*it, | 1097 if (prefs_display_names->GetStringWithoutPathExpansion(*it, |
1098 &display_name)) { | 1098 &display_name)) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 } | 1207 } |
1208 | 1208 |
1209 void UserManagerImpl::GuestUserLoggedIn() { | 1209 void UserManagerImpl::GuestUserLoggedIn() { |
1210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1211 active_user_ = User::CreateGuestUser(); | 1211 active_user_ = User::CreateGuestUser(); |
1212 // TODO(nkostylev): Add support for passing guest session cryptohome | 1212 // TODO(nkostylev): Add support for passing guest session cryptohome |
1213 // mount point. Legacy (--login-profile) value will be used for now. | 1213 // mount point. Legacy (--login-profile) value will be used for now. |
1214 // http://crosbug.com/230859 | 1214 // http://crosbug.com/230859 |
1215 active_user_->SetStubImage(User::kInvalidImageIndex, false); | 1215 active_user_->SetStubImage(User::kInvalidImageIndex, false); |
1216 // Initializes wallpaper after active_user_ is set. | 1216 // Initializes wallpaper after active_user_ is set. |
1217 WallpaperManager::Get()->SetUserWallpaperNow(UserManager::kGuestUserName); | 1217 WallpaperManager::Get()->SetUserWallpaperNow(chromeos::login::kGuestUserName); |
1218 } | 1218 } |
1219 | 1219 |
1220 void UserManagerImpl::AddUserRecord(User* user) { | 1220 void UserManagerImpl::AddUserRecord(User* user) { |
1221 // Add the user to the front of the user list. | 1221 // Add the user to the front of the user list. |
1222 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), | 1222 ListPrefUpdate prefs_users_update(g_browser_process->local_state(), |
1223 kRegularUsers); | 1223 kRegularUsers); |
1224 prefs_users_update->Insert(0, new base::StringValue(user->email())); | 1224 prefs_users_update->Insert(0, new base::StringValue(user->email())); |
1225 users_.insert(users_.begin(), user); | 1225 users_.insert(users_.begin(), user); |
1226 } | 1226 } |
1227 | 1227 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 // Disable window animation since the demo app runs in a single full screen | 1368 // Disable window animation since the demo app runs in a single full screen |
1369 // window and window animation causes start-up janks. | 1369 // window and window animation causes start-up janks. |
1370 CommandLine::ForCurrentProcess()->AppendSwitch( | 1370 CommandLine::ForCurrentProcess()->AppendSwitch( |
1371 wm::switches::kWindowAnimationsDisabled); | 1371 wm::switches::kWindowAnimationsDisabled); |
1372 } | 1372 } |
1373 | 1373 |
1374 void UserManagerImpl::RetailModeUserLoggedIn() { | 1374 void UserManagerImpl::RetailModeUserLoggedIn() { |
1375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1376 is_current_user_new_ = true; | 1376 is_current_user_new_ = true; |
1377 active_user_ = User::CreateRetailModeUser(); | 1377 active_user_ = User::CreateRetailModeUser(); |
1378 GetUserImageManager(UserManager::kRetailModeUserName)->UserLoggedIn( | 1378 GetUserImageManager(chromeos::login::kRetailModeUserName) |
1379 is_current_user_new_, | 1379 ->UserLoggedIn(is_current_user_new_, true); |
1380 true); | |
1381 WallpaperManager::Get()->SetUserWallpaperNow( | 1380 WallpaperManager::Get()->SetUserWallpaperNow( |
1382 UserManager::kRetailModeUserName); | 1381 chromeos::login::kRetailModeUserName); |
1383 } | 1382 } |
1384 | 1383 |
1385 void UserManagerImpl::NotifyOnLogin() { | 1384 void UserManagerImpl::NotifyOnLogin() { |
1386 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1385 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1387 | 1386 |
1388 UserSessionManager::OverrideHomedir(); | 1387 UserSessionManager::OverrideHomedir(); |
1389 | 1388 |
1390 UpdateNumberOfUsers(); | 1389 UpdateNumberOfUsers(); |
1391 NotifyActiveUserHashChanged(active_user_->username_hash()); | 1390 NotifyActiveUserHashChanged(active_user_->username_hash()); |
1392 NotifyActiveUserChanged(active_user_); | 1391 NotifyActiveUserChanged(active_user_); |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1875 } | 1874 } |
1876 | 1875 |
1877 void UserManagerImpl::DeleteUser(User* user) { | 1876 void UserManagerImpl::DeleteUser(User* user) { |
1878 const bool is_active_user = (user == active_user_); | 1877 const bool is_active_user = (user == active_user_); |
1879 delete user; | 1878 delete user; |
1880 if (is_active_user) | 1879 if (is_active_user) |
1881 active_user_ = NULL; | 1880 active_user_ = NULL; |
1882 } | 1881 } |
1883 | 1882 |
1884 } // namespace chromeos | 1883 } // namespace chromeos |
OLD | NEW |