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/session/user_session_manager.h" | 5 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 #include "chrome/browser/supervised_user/child_accounts/child_account_service.h" | 74 #include "chrome/browser/supervised_user/child_accounts/child_account_service.h" |
75 #include "chrome/browser/supervised_user/child_accounts/child_account_service_fa
ctory.h" | 75 #include "chrome/browser/supervised_user/child_accounts/child_account_service_fa
ctory.h" |
76 #include "chrome/browser/ui/app_list/start_page_service.h" | 76 #include "chrome/browser/ui/app_list/start_page_service.h" |
77 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 77 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
78 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 78 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
79 #include "chrome/common/chrome_switches.h" | 79 #include "chrome/common/chrome_switches.h" |
80 #include "chrome/common/logging_chrome.h" | 80 #include "chrome/common/logging_chrome.h" |
81 #include "chrome/common/pref_names.h" | 81 #include "chrome/common/pref_names.h" |
82 #include "chromeos/cert_loader.h" | 82 #include "chromeos/cert_loader.h" |
83 #include "chromeos/chromeos_switches.h" | 83 #include "chromeos/chromeos_switches.h" |
| 84 #include "chromeos/cryptohome/cryptohome_parameters.h" |
84 #include "chromeos/cryptohome/cryptohome_util.h" | 85 #include "chromeos/cryptohome/cryptohome_util.h" |
85 #include "chromeos/dbus/cryptohome_client.h" | 86 #include "chromeos/dbus/cryptohome_client.h" |
86 #include "chromeos/dbus/dbus_thread_manager.h" | 87 #include "chromeos/dbus/dbus_thread_manager.h" |
87 #include "chromeos/dbus/session_manager_client.h" | 88 #include "chromeos/dbus/session_manager_client.h" |
88 #include "chromeos/login/auth/stub_authenticator.h" | 89 #include "chromeos/login/auth/stub_authenticator.h" |
89 #include "chromeos/login/user_names.h" | 90 #include "chromeos/login/user_names.h" |
90 #include "chromeos/network/portal_detector/network_portal_detector.h" | 91 #include "chromeos/network/portal_detector/network_portal_detector.h" |
91 #include "chromeos/network/portal_detector/network_portal_detector_strategy.h" | 92 #include "chromeos/network/portal_detector/network_portal_detector_strategy.h" |
92 #include "chromeos/settings/cros_settings_names.h" | 93 #include "chromeos/settings/cros_settings_names.h" |
93 #include "components/arc/arc_bridge_service.h" | 94 #include "components/arc/arc_bridge_service.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 // This makes sure that Chrome restarts with no per-session flags. The guest | 428 // This makes sure that Chrome restarts with no per-session flags. The guest |
428 // profile will always have empty set of per-session flags. If this is not | 429 // profile will always have empty set of per-session flags. If this is not |
429 // done and device owner has some per-session flags, when Chrome is relaunched | 430 // done and device owner has some per-session flags, when Chrome is relaunched |
430 // the guest profile session flags will not match the current command line and | 431 // the guest profile session flags will not match the current command line and |
431 // another restart will be attempted in order to reset the user flags for the | 432 // another restart will be attempted in order to reset the user flags for the |
432 // guest user. | 433 // guest user. |
433 const base::CommandLine user_flags(base::CommandLine::NO_PROGRAM); | 434 const base::CommandLine user_flags(base::CommandLine::NO_PROGRAM); |
434 if (!about_flags::AreSwitchesIdenticalToCurrentCommandLine( | 435 if (!about_flags::AreSwitchesIdenticalToCurrentCommandLine( |
435 user_flags, *base::CommandLine::ForCurrentProcess(), NULL)) { | 436 user_flags, *base::CommandLine::ForCurrentProcess(), NULL)) { |
436 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( | 437 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( |
437 login::GuestAccountId().GetUserEmail(), | 438 cryptohome::Identification(login::GuestAccountId()), |
438 base::CommandLine::StringVector()); | 439 base::CommandLine::StringVector()); |
439 } | 440 } |
440 | 441 |
441 RestartChrome(command_line); | 442 RestartChrome(command_line); |
442 } | 443 } |
443 | 444 |
444 scoped_refptr<Authenticator> UserSessionManager::CreateAuthenticator( | 445 scoped_refptr<Authenticator> UserSessionManager::CreateAuthenticator( |
445 AuthStatusConsumer* consumer) { | 446 AuthStatusConsumer* consumer) { |
446 // Screen locker needs new Authenticator instance each time. | 447 // Screen locker needs new Authenticator instance each time. |
447 if (ScreenLocker::default_screen_locker()) { | 448 if (ScreenLocker::default_screen_locker()) { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 | 712 |
712 LogCustomSwitches(command_line_difference); | 713 LogCustomSwitches(command_line_difference); |
713 | 714 |
714 about_flags::ReportCustomFlags("Login.CustomFlags", command_line_difference); | 715 about_flags::ReportCustomFlags("Login.CustomFlags", command_line_difference); |
715 | 716 |
716 base::CommandLine::StringVector flags; | 717 base::CommandLine::StringVector flags; |
717 // argv[0] is the program name |base::CommandLine::NO_PROGRAM|. | 718 // argv[0] is the program name |base::CommandLine::NO_PROGRAM|. |
718 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); | 719 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); |
719 LOG(WARNING) << "Restarting to apply per-session flags..."; | 720 LOG(WARNING) << "Restarting to apply per-session flags..."; |
720 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( | 721 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( |
721 user_manager::UserManager::Get()->GetActiveUser()->email(), flags); | 722 cryptohome::Identification( |
| 723 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId()), |
| 724 flags); |
722 AttemptRestart(profile); | 725 AttemptRestart(profile); |
723 return true; | 726 return true; |
724 } | 727 } |
725 | 728 |
726 bool UserSessionManager::NeedsToUpdateEasyUnlockKeys() const { | 729 bool UserSessionManager::NeedsToUpdateEasyUnlockKeys() const { |
727 return user_context_.GetAccountId().is_valid() && | 730 return user_context_.GetAccountId().is_valid() && |
728 user_manager::User::TypeHasGaiaAccount(user_context_.GetUserType()) && | 731 user_manager::User::TypeHasGaiaAccount(user_context_.GetUserType()) && |
729 user_context_.GetKey() && !user_context_.GetKey()->GetSecret().empty(); | 732 user_context_.GetKey() && !user_context_.GetKey()->GetSecret().empty(); |
730 } | 733 } |
731 | 734 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 if (!user_context_.GetGaiaID().empty()) { | 890 if (!user_context_.GetGaiaID().empty()) { |
888 user_manager::known_user::UpdateGaiaID(user_context_.GetAccountId(), | 891 user_manager::known_user::UpdateGaiaID(user_context_.GetAccountId(), |
889 user_context_.GetGaiaID()); | 892 user_context_.GetGaiaID()); |
890 } | 893 } |
891 } | 894 } |
892 | 895 |
893 void UserSessionManager::StartCrosSession() { | 896 void UserSessionManager::StartCrosSession() { |
894 BootTimesRecorder* btl = BootTimesRecorder::Get(); | 897 BootTimesRecorder* btl = BootTimesRecorder::Get(); |
895 btl->AddLoginTimeMarker("StartSession-Start", false); | 898 btl->AddLoginTimeMarker("StartSession-Start", false); |
896 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( | 899 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession( |
897 user_context_.GetAccountId().GetUserEmail()); | 900 cryptohome::Identification(user_context_.GetAccountId())); |
898 btl->AddLoginTimeMarker("StartSession-End", false); | 901 btl->AddLoginTimeMarker("StartSession-End", false); |
899 } | 902 } |
900 | 903 |
901 void UserSessionManager::NotifyUserLoggedIn() { | 904 void UserSessionManager::NotifyUserLoggedIn() { |
902 BootTimesRecorder* btl = BootTimesRecorder::Get(); | 905 BootTimesRecorder* btl = BootTimesRecorder::Get(); |
903 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); | 906 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); |
904 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 907 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
905 user_manager->UserLoggedIn(user_context_.GetAccountId(), | 908 user_manager->UserLoggedIn(user_context_.GetAccountId(), |
906 user_context_.GetUserIDHash(), false); | 909 user_context_.GetUserIDHash(), false); |
907 btl->AddLoginTimeMarker("UserLoggedIn-End", false); | 910 btl->AddLoginTimeMarker("UserLoggedIn-End", false); |
908 } | 911 } |
909 | 912 |
910 void UserSessionManager::PrepareProfile() { | 913 void UserSessionManager::PrepareProfile() { |
911 const bool is_demo_session = DemoAppLauncher::IsDemoAppSession( | 914 const bool is_demo_session = |
912 user_context_.GetAccountId().GetUserEmail()); | 915 DemoAppLauncher::IsDemoAppSession(user_context_.GetAccountId()); |
913 | 916 |
914 // TODO(nkostylev): Figure out whether demo session is using the right profile | 917 // TODO(nkostylev): Figure out whether demo session is using the right profile |
915 // path or not. See https://codereview.chromium.org/171423009 | 918 // path or not. See https://codereview.chromium.org/171423009 |
916 g_browser_process->profile_manager()->CreateProfileAsync( | 919 g_browser_process->profile_manager()->CreateProfileAsync( |
917 ProfileHelper::GetProfilePathByUserIdHash(user_context_.GetUserIDHash()), | 920 ProfileHelper::GetProfilePathByUserIdHash(user_context_.GetUserIDHash()), |
918 base::Bind(&UserSessionManager::OnProfileCreated, AsWeakPtr(), | 921 base::Bind(&UserSessionManager::OnProfileCreated, AsWeakPtr(), |
919 user_context_, is_demo_session), | 922 user_context_, is_demo_session), |
920 base::string16(), std::string(), std::string()); | 923 base::string16(), std::string(), std::string()); |
921 } | 924 } |
922 | 925 |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 // If we could not get list of active user sessions it is safer to just | 1422 // If we could not get list of active user sessions it is safer to just |
1420 // sign out so that we don't get in the inconsistent state. | 1423 // sign out so that we don't get in the inconsistent state. |
1421 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); | 1424 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession(); |
1422 return; | 1425 return; |
1423 } | 1426 } |
1424 | 1427 |
1425 // One profile has been already loaded on browser start. | 1428 // One profile has been already loaded on browser start. |
1426 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 1429 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
1427 DCHECK_EQ(1u, user_manager->GetLoggedInUsers().size()); | 1430 DCHECK_EQ(1u, user_manager->GetLoggedInUsers().size()); |
1428 DCHECK(user_manager->GetActiveUser()); | 1431 DCHECK(user_manager->GetActiveUser()); |
1429 std::string active_user_id = user_manager->GetActiveUser()->email(); | 1432 const cryptohome::Identification active_cryptohome_id = |
| 1433 cryptohome::Identification(user_manager->GetActiveUser()->GetAccountId()); |
1430 | 1434 |
1431 SessionManagerClient::ActiveSessionsMap::const_iterator it; | 1435 SessionManagerClient::ActiveSessionsMap::const_iterator it; |
1432 for (it = sessions.begin(); it != sessions.end(); ++it) { | 1436 for (it = sessions.begin(); it != sessions.end(); ++it) { |
1433 if (active_user_id == it->first) | 1437 if (active_cryptohome_id == it->first) |
1434 continue; | 1438 continue; |
1435 pending_user_sessions_[it->first] = it->second; | 1439 pending_user_sessions_[(it->first).GetAccountId()] = it->second; |
1436 } | 1440 } |
1437 RestorePendingUserSessions(); | 1441 RestorePendingUserSessions(); |
1438 } | 1442 } |
1439 | 1443 |
1440 void UserSessionManager::RestorePendingUserSessions() { | 1444 void UserSessionManager::RestorePendingUserSessions() { |
1441 if (pending_user_sessions_.empty()) { | 1445 if (pending_user_sessions_.empty()) { |
1442 user_manager::UserManager::Get()->SwitchToLastActiveUser(); | 1446 user_manager::UserManager::Get()->SwitchToLastActiveUser(); |
1443 NotifyPendingUserSessionsRestoreFinished(); | 1447 NotifyPendingUserSessionsRestoreFinished(); |
1444 return; | 1448 return; |
1445 } | 1449 } |
1446 | 1450 |
1447 // Get next user to restore sessions and delete it from list. | 1451 // Get next user to restore sessions and delete it from list. |
1448 SessionManagerClient::ActiveSessionsMap::const_iterator it = | 1452 PendingUserSessions::const_iterator it = pending_user_sessions_.begin(); |
1449 pending_user_sessions_.begin(); | 1453 const AccountId account_id = it->first; |
1450 std::string user_id = it->first; | |
1451 std::string user_id_hash = it->second; | 1454 std::string user_id_hash = it->second; |
1452 DCHECK(!user_id.empty()); | 1455 DCHECK(account_id.is_valid()); |
1453 DCHECK(!user_id_hash.empty()); | 1456 DCHECK(!user_id_hash.empty()); |
1454 pending_user_sessions_.erase(user_id); | 1457 pending_user_sessions_.erase(account_id); |
1455 | 1458 |
1456 // Check that this user is not logged in yet. | 1459 // Check that this user is not logged in yet. |
1457 user_manager::UserList logged_in_users = | 1460 user_manager::UserList logged_in_users = |
1458 user_manager::UserManager::Get()->GetLoggedInUsers(); | 1461 user_manager::UserManager::Get()->GetLoggedInUsers(); |
1459 bool user_already_logged_in = false; | 1462 bool user_already_logged_in = false; |
1460 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); | 1463 for (user_manager::UserList::const_iterator it = logged_in_users.begin(); |
1461 it != logged_in_users.end(); | 1464 it != logged_in_users.end(); |
1462 ++it) { | 1465 ++it) { |
1463 const user_manager::User* user = (*it); | 1466 const user_manager::User* user = (*it); |
1464 if (user->email() == user_id) { | 1467 if (user->GetAccountId() == account_id) { |
1465 user_already_logged_in = true; | 1468 user_already_logged_in = true; |
1466 break; | 1469 break; |
1467 } | 1470 } |
1468 } | 1471 } |
1469 DCHECK(!user_already_logged_in); | 1472 DCHECK(!user_already_logged_in); |
1470 | 1473 |
1471 if (!user_already_logged_in) { | 1474 if (!user_already_logged_in) { |
1472 UserContext user_context(AccountId::FromUserEmail(user_id)); | 1475 UserContext user_context(account_id); |
1473 user_context.SetUserIDHash(user_id_hash); | 1476 user_context.SetUserIDHash(user_id_hash); |
1474 user_context.SetIsUsingOAuth(false); | 1477 user_context.SetIsUsingOAuth(false); |
1475 | 1478 |
1476 // Will call OnProfilePrepared() once profile has been loaded. | 1479 // Will call OnProfilePrepared() once profile has been loaded. |
1477 // Only handling secondary users here since primary user profile | 1480 // Only handling secondary users here since primary user profile |
1478 // (and session) has been loaded on Chrome startup. | 1481 // (and session) has been loaded on Chrome startup. |
1479 StartSession(user_context, | 1482 StartSession(user_context, |
1480 SECONDARY_USER_SESSION_AFTER_CRASH, | 1483 SECONDARY_USER_SESSION_AFTER_CRASH, |
1481 false, // has_auth_cookies | 1484 false, // has_auth_cookies |
1482 true, // has_active_session, this is restart after crash | 1485 true, // has_active_session, this is restart after crash |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1796 token_handle_util_.reset(); | 1799 token_handle_util_.reset(); |
1797 first_run::GoodiesDisplayer::Delete(); | 1800 first_run::GoodiesDisplayer::Delete(); |
1798 } | 1801 } |
1799 | 1802 |
1800 void UserSessionManager::CreateTokenUtilIfMissing() { | 1803 void UserSessionManager::CreateTokenUtilIfMissing() { |
1801 if (!token_handle_util_.get()) | 1804 if (!token_handle_util_.get()) |
1802 token_handle_util_.reset(new TokenHandleUtil()); | 1805 token_handle_util_.reset(new TokenHandleUtil()); |
1803 } | 1806 } |
1804 | 1807 |
1805 } // namespace chromeos | 1808 } // namespace chromeos |
OLD | NEW |