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

Side by Side Diff: chrome/browser/chromeos/login/session/user_session_manager.cc

Issue 1412813003: This CL replaces user_manager::UserID with AccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@468875--Chrome-OS-handles-deletion-of-Gmail-account-poorly--Create-AccountID-structure-part2--user_names
Patch Set: Rebased. Created 5 years, 2 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
OLDNEW
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 <string> 7 #include <string>
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 443
444 void UserSessionManager::StartSession( 444 void UserSessionManager::StartSession(
445 const UserContext& user_context, 445 const UserContext& user_context,
446 StartSessionType start_session_type, 446 StartSessionType start_session_type,
447 bool has_auth_cookies, 447 bool has_auth_cookies,
448 bool has_active_session, 448 bool has_active_session,
449 UserSessionManagerDelegate* delegate) { 449 UserSessionManagerDelegate* delegate) {
450 delegate_ = delegate; 450 delegate_ = delegate;
451 start_session_type_ = start_session_type; 451 start_session_type_ = start_session_type;
452 452
453 VLOG(1) << "Starting session for " << user_context.GetUserID(); 453 VLOG(1) << "Starting session for " << user_context.GetUserID().GetUserEmail();
454 454
455 PreStartSession(); 455 PreStartSession();
456 CreateUserSession(user_context, has_auth_cookies); 456 CreateUserSession(user_context, has_auth_cookies);
457 457
458 if (!has_active_session) 458 if (!has_active_session)
459 StartCrosSession(); 459 StartCrosSession();
460 460
461 // TODO(nkostylev): Notify UserLoggedIn() after profile is actually 461 // TODO(nkostylev): Notify UserLoggedIn() after profile is actually
462 // ready to be used (http://crbug.com/361528). 462 // ready to be used (http://crbug.com/361528).
463 NotifyUserLoggedIn(); 463 NotifyUserLoggedIn();
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 case OAuth2LoginManager::SESSION_RESTORE_PREPARING: 751 case OAuth2LoginManager::SESSION_RESTORE_PREPARING:
752 case OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS: 752 case OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS:
753 return; 753 return;
754 } 754 }
755 755
756 // We should not be clearing existing token state if that was a connection 756 // We should not be clearing existing token state if that was a connection
757 // error. http://crbug.com/295245 757 // error. http://crbug.com/295245
758 if (!connection_error) { 758 if (!connection_error) {
759 // We are in one of "done" states here. 759 // We are in one of "done" states here.
760 user_manager::UserManager::Get()->SaveUserOAuthStatus( 760 user_manager::UserManager::Get()->SaveUserOAuthStatus(
761 user_manager::UserManager::Get()->GetLoggedInUser()->email(), 761 user_manager::UserManager::Get()->GetLoggedInUser()->GetUserID(),
762 user_status); 762 user_status);
763 } 763 }
764 764
765 login_manager->RemoveObserver(this); 765 login_manager->RemoveObserver(this);
766 766
767 if (exit_after_session_restore_ && 767 if (exit_after_session_restore_ &&
768 (state == OAuth2LoginManager::SESSION_RESTORE_DONE || 768 (state == OAuth2LoginManager::SESSION_RESTORE_DONE ||
769 state == OAuth2LoginManager::SESSION_RESTORE_FAILED || 769 state == OAuth2LoginManager::SESSION_RESTORE_FAILED ||
770 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED)) { 770 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED)) {
771 LOG(WARNING) << "Restarting Chrome after session restore finishes, " 771 LOG(WARNING) << "Restarting Chrome after session restore finishes, "
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 // Store obfuscated GAIA ID. 862 // Store obfuscated GAIA ID.
863 if (!user_context_.GetGaiaID().empty()) { 863 if (!user_context_.GetGaiaID().empty()) {
864 user_manager::UserManager::Get()->UpdateGaiaID(user_context_.GetUserID(), 864 user_manager::UserManager::Get()->UpdateGaiaID(user_context_.GetUserID(),
865 user_context_.GetGaiaID()); 865 user_context_.GetGaiaID());
866 } 866 }
867 } 867 }
868 868
869 void UserSessionManager::StartCrosSession() { 869 void UserSessionManager::StartCrosSession() {
870 BootTimesRecorder* btl = BootTimesRecorder::Get(); 870 BootTimesRecorder* btl = BootTimesRecorder::Get();
871 btl->AddLoginTimeMarker("StartSession-Start", false); 871 btl->AddLoginTimeMarker("StartSession-Start", false);
872 DBusThreadManager::Get()->GetSessionManagerClient()-> 872 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession(
873 StartSession(user_context_.GetUserID()); 873 user_context_.GetUserID().GetUserEmail());
874 btl->AddLoginTimeMarker("StartSession-End", false); 874 btl->AddLoginTimeMarker("StartSession-End", false);
875 } 875 }
876 876
877 void UserSessionManager::NotifyUserLoggedIn() { 877 void UserSessionManager::NotifyUserLoggedIn() {
878 BootTimesRecorder* btl = BootTimesRecorder::Get(); 878 BootTimesRecorder* btl = BootTimesRecorder::Get();
879 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); 879 btl->AddLoginTimeMarker("UserLoggedIn-Start", false);
880 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 880 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
881 user_manager->UserLoggedIn(user_context_.GetUserID(), 881 user_manager->UserLoggedIn(user_context_.GetUserID(),
882 user_context_.GetUserIDHash(), 882 user_context_.GetUserIDHash(),
883 false); 883 false);
884 btl->AddLoginTimeMarker("UserLoggedIn-End", false); 884 btl->AddLoginTimeMarker("UserLoggedIn-End", false);
885 } 885 }
886 886
887 void UserSessionManager::PrepareProfile() { 887 void UserSessionManager::PrepareProfile() {
888 bool is_demo_session = 888 bool is_demo_session = DemoAppLauncher::IsDemoAppSession(
achuithb 2015/10/23 00:08:50 const bool
Alexander Alekseev 2015/10/23 09:11:22 Done.
889 DemoAppLauncher::IsDemoAppSession(user_context_.GetUserID()); 889 user_context_.GetUserID().GetUserEmail());
890 890
891 // TODO(nkostylev): Figure out whether demo session is using the right profile 891 // TODO(nkostylev): Figure out whether demo session is using the right profile
892 // path or not. See https://codereview.chromium.org/171423009 892 // path or not. See https://codereview.chromium.org/171423009
893 g_browser_process->profile_manager()->CreateProfileAsync( 893 g_browser_process->profile_manager()->CreateProfileAsync(
894 ProfileHelper::GetProfilePathByUserIdHash(user_context_.GetUserIDHash()), 894 ProfileHelper::GetProfilePathByUserIdHash(user_context_.GetUserIDHash()),
895 base::Bind(&UserSessionManager::OnProfileCreated, 895 base::Bind(&UserSessionManager::OnProfileCreated,
896 AsWeakPtr(), 896 AsWeakPtr(),
897 user_context_, 897 user_context_,
898 is_demo_session), 898 is_demo_session),
899 base::string16(), 899 base::string16(),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 } else if (user_manager::UserManager::Get()-> 961 } else if (user_manager::UserManager::Get()->
962 IsLoggedInAsUserWithGaiaAccount()) { 962 IsLoggedInAsUserWithGaiaAccount()) {
963 // Get the Gaia ID from the user context. If it's not available, this may 963 // Get the Gaia ID from the user context. If it's not available, this may
964 // not be available when unlocking a previously opened profile, or when 964 // not be available when unlocking a previously opened profile, or when
965 // creating a supervised users. However, in these cases the gaia_id should 965 // creating a supervised users. However, in these cases the gaia_id should
966 // be already available in the account tracker. 966 // be already available in the account tracker.
967 std::string gaia_id = user_context.GetGaiaID(); 967 std::string gaia_id = user_context.GetGaiaID();
968 if (gaia_id.empty()) { 968 if (gaia_id.empty()) {
969 AccountTrackerService* account_tracker = 969 AccountTrackerService* account_tracker =
970 AccountTrackerServiceFactory::GetForProfile(profile); 970 AccountTrackerServiceFactory::GetForProfile(profile);
971 AccountInfo info = 971 AccountInfo info = account_tracker->FindAccountInfoByEmail(
achuithb 2015/10/23 00:08:50 const
Alexander Alekseev 2015/10/23 09:11:22 Done.
972 account_tracker->FindAccountInfoByEmail(user_context.GetUserID()); 972 user_context.GetUserID().GetUserEmail());
973 gaia_id = info.gaia; 973 gaia_id = info.gaia;
974 DCHECK(!gaia_id.empty()); 974 DCHECK(!gaia_id.empty());
975 } 975 }
976 976
977 // Make sure that the google service username is properly set (we do this 977 // Make sure that the google service username is properly set (we do this
978 // on every sign in, not just the first login, to deal with existing 978 // on every sign in, not just the first login, to deal with existing
979 // profiles that might not have it set yet). 979 // profiles that might not have it set yet).
980 SigninManagerBase* signin_manager = 980 SigninManagerBase* signin_manager =
981 SigninManagerFactory::GetForProfile(profile); 981 SigninManagerFactory::GetForProfile(profile);
982 signin_manager->SetAuthenticatedAccountInfo(gaia_id, 982 signin_manager->SetAuthenticatedAccountInfo(
983 user_context.GetUserID()); 983 gaia_id, user_context.GetUserID().GetUserEmail());
984 984
985 // Backfill GAIA ID in user prefs stored in Local State. 985 // Backfill GAIA ID in user prefs stored in Local State.
986 std::string tmp_gaia_id; 986 std::string tmp_gaia_id;
987 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 987 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
988 if (!user_manager->FindGaiaID(user_context.GetUserID(), &tmp_gaia_id) && 988 if (!user_manager->FindGaiaID(user_context.GetUserID(), &tmp_gaia_id) &&
989 !gaia_id.empty()) { 989 !gaia_id.empty()) {
990 user_manager->UpdateGaiaID(user_context.GetUserID(), gaia_id); 990 user_manager->UpdateGaiaID(user_context.GetUserID(), gaia_id);
991 } 991 }
992 } 992 }
993 } 993 }
994 994
995 void UserSessionManager::UserProfileInitialized(Profile* profile, 995 void UserSessionManager::UserProfileInitialized(Profile* profile,
996 bool is_incognito_profile, 996 bool is_incognito_profile,
997 const std::string& user_id) { 997 const AccountId& user_id) {
achuithb 2015/10/23 00:08:50 account_id
Alexander Alekseev 2015/10/23 09:11:22 Done.
998 // Demo user signed in. 998 // Demo user signed in.
999 if (is_incognito_profile) { 999 if (is_incognito_profile) {
1000 profile->OnLogin(); 1000 profile->OnLogin();
1001 1001
1002 // Send the notification before creating the browser so additional objects 1002 // Send the notification before creating the browser so additional objects
1003 // that need the profile (e.g. the launcher) can be created first. 1003 // that need the profile (e.g. the launcher) can be created first.
1004 content::NotificationService::current()->Notify( 1004 content::NotificationService::current()->Notify(
1005 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 1005 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
1006 content::NotificationService::AllSources(), 1006 content::NotificationService::AllSources(),
1007 content::Details<Profile>(profile)); 1007 content::Details<Profile>(profile));
1008 1008
1009 if (delegate_) 1009 if (delegate_)
1010 delegate_->OnProfilePrepared(profile, false); 1010 delegate_->OnProfilePrepared(profile, false);
1011 1011
1012 return; 1012 return;
1013 } 1013 }
1014 1014
1015 BootTimesRecorder* btl = BootTimesRecorder::Get(); 1015 BootTimesRecorder* btl = BootTimesRecorder::Get();
1016 btl->AddLoginTimeMarker("UserProfileGotten", false); 1016 btl->AddLoginTimeMarker("UserProfileGotten", false);
1017 1017
1018 if (user_context_.IsUsingOAuth()) { 1018 if (user_context_.IsUsingOAuth()) {
1019 // Retrieve the policy that indicates whether to continue copying 1019 // Retrieve the policy that indicates whether to continue copying
1020 // authentication cookies set by a SAML IdP on subsequent logins after the 1020 // authentication cookies set by a SAML IdP on subsequent logins after the
1021 // first. 1021 // first.
1022 bool transfer_saml_auth_cookies_on_subsequent_login = false; 1022 bool transfer_saml_auth_cookies_on_subsequent_login = false;
1023 if (has_auth_cookies_ && 1023 if (has_auth_cookies_ &&
1024 g_browser_process->platform_part()-> 1024 g_browser_process->platform_part()
1025 browser_policy_connector_chromeos()->GetUserAffiliation(user_id) == 1025 ->browser_policy_connector_chromeos()
1026 policy::USER_AFFILIATION_MANAGED) { 1026 ->GetUserAffiliation(user_id.GetUserEmail()) ==
1027 policy::USER_AFFILIATION_MANAGED) {
1027 CrosSettings::Get()->GetBoolean( 1028 CrosSettings::Get()->GetBoolean(
1028 kAccountsPrefTransferSAMLCookies, 1029 kAccountsPrefTransferSAMLCookies,
1029 &transfer_saml_auth_cookies_on_subsequent_login); 1030 &transfer_saml_auth_cookies_on_subsequent_login);
1030 } 1031 }
1031 1032
1032 // Transfers authentication-related data from the profile that was used for 1033 // Transfers authentication-related data from the profile that was used for
1033 // authentication to the user's profile. The proxy authentication state is 1034 // authentication to the user's profile. The proxy authentication state is
1034 // transferred unconditionally. If the user authenticated via an auth 1035 // transferred unconditionally. If the user authenticated via an auth
1035 // extension, authentication cookies and channel IDs will be transferred as 1036 // extension, authentication cookies and channel IDs will be transferred as
1036 // well when the user's cookie jar is empty. If the cookie jar is not empty, 1037 // well when the user's cookie jar is empty. If the cookie jar is not empty,
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 ++it) { 1434 ++it) {
1434 const user_manager::User* user = (*it); 1435 const user_manager::User* user = (*it);
1435 if (user->email() == user_id) { 1436 if (user->email() == user_id) {
1436 user_already_logged_in = true; 1437 user_already_logged_in = true;
1437 break; 1438 break;
1438 } 1439 }
1439 } 1440 }
1440 DCHECK(!user_already_logged_in); 1441 DCHECK(!user_already_logged_in);
1441 1442
1442 if (!user_already_logged_in) { 1443 if (!user_already_logged_in) {
1443 UserContext user_context(user_id); 1444 UserContext user_context(AccountId::FromUserEmail(user_id));
1444 user_context.SetUserIDHash(user_id_hash); 1445 user_context.SetUserIDHash(user_id_hash);
1445 user_context.SetIsUsingOAuth(false); 1446 user_context.SetIsUsingOAuth(false);
1446 1447
1447 // Will call OnProfilePrepared() once profile has been loaded. 1448 // Will call OnProfilePrepared() once profile has been loaded.
1448 // Only handling secondary users here since primary user profile 1449 // Only handling secondary users here since primary user profile
1449 // (and session) has been loaded on Chrome startup. 1450 // (and session) has been loaded on Chrome startup.
1450 StartSession(user_context, 1451 StartSession(user_context,
1451 SECONDARY_USER_SESSION_AFTER_CRASH, 1452 SECONDARY_USER_SESSION_AFTER_CRASH,
1452 false, // has_auth_cookies 1453 false, // has_auth_cookies
1453 true, // has_active_session, this is restart after crash 1454 true, // has_active_session, this is restart after crash
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 1497
1497 base::ListValue empty_list; 1498 base::ListValue empty_list;
1498 if (!device_list) 1499 if (!device_list)
1499 device_list = &empty_list; 1500 device_list = &empty_list;
1500 1501
1501 EasyUnlockKeyManager* key_manager = GetEasyUnlockKeyManager(); 1502 EasyUnlockKeyManager* key_manager = GetEasyUnlockKeyManager();
1502 running_easy_unlock_key_ops_ = true; 1503 running_easy_unlock_key_ops_ = true;
1503 key_manager->RefreshKeys( 1504 key_manager->RefreshKeys(
1504 user_context, *device_list, 1505 user_context, *device_list,
1505 base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished, AsWeakPtr(), 1506 base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished, AsWeakPtr(),
1506 user_context.GetUserID())); 1507 user_context.GetUserID().GetUserEmail()));
1507 } 1508 }
1508 1509
1509 net::URLRequestContextGetter* 1510 net::URLRequestContextGetter*
1510 UserSessionManager::GetAuthRequestContext() const { 1511 UserSessionManager::GetAuthRequestContext() const {
1511 net::URLRequestContextGetter* auth_request_context = nullptr; 1512 net::URLRequestContextGetter* auth_request_context = nullptr;
1512 1513
1513 if (StartupUtils::IsWebviewSigninEnabled()) { 1514 if (StartupUtils::IsWebviewSigninEnabled()) {
1514 // Webview uses different partition storage than iframe. We need to get 1515 // Webview uses different partition storage than iframe. We need to get
1515 // cookies from the right storage for url request to get auth token into 1516 // cookies from the right storage for url request to get auth token into
1516 // session. 1517 // session.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 exit_after_session_restore_ = true; 1558 exit_after_session_restore_ = true;
1558 } 1559 }
1559 1560
1560 void UserSessionManager::OnEasyUnlockKeyOpsFinished( 1561 void UserSessionManager::OnEasyUnlockKeyOpsFinished(
1561 const std::string& user_id, 1562 const std::string& user_id,
1562 bool success) { 1563 bool success) {
1563 running_easy_unlock_key_ops_ = false; 1564 running_easy_unlock_key_ops_ = false;
1564 if (!easy_unlock_key_ops_finished_callback_.is_null()) 1565 if (!easy_unlock_key_ops_finished_callback_.is_null())
1565 easy_unlock_key_ops_finished_callback_.Run(); 1566 easy_unlock_key_ops_finished_callback_.Run();
1566 1567
1567 const user_manager::User* user = 1568 const user_manager::User* user = user_manager::UserManager::Get()->FindUser(
1568 user_manager::UserManager::Get()->FindUser(user_id); 1569 AccountId::FromUserEmail(user_id));
1569 EasyUnlockService* easy_unlock_service = 1570 EasyUnlockService* easy_unlock_service =
1570 EasyUnlockService::GetForUser(*user); 1571 EasyUnlockService::GetForUser(*user);
1571 easy_unlock_service->CheckCryptohomeKeysAndMaybeHardlock(); 1572 easy_unlock_service->CheckCryptohomeKeysAndMaybeHardlock();
1572 } 1573 }
1573 1574
1574 void UserSessionManager::ActiveUserChanged( 1575 void UserSessionManager::ActiveUserChanged(
1575 const user_manager::User* active_user) { 1576 const user_manager::User* active_user) {
1576 if (!user_manager::UserManager::Get()->IsCurrentUserNew()) 1577 if (!user_manager::UserManager::Get()->IsCurrentUserNew())
1577 SendUserPodsMetrics(); 1578 SendUserPodsMetrics();
1578 1579
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1730 token_handle_fetcher_.reset(new TokenHandleFetcher( 1731 token_handle_fetcher_.reset(new TokenHandleFetcher(
1731 token_handle_util_.get(), context.GetUserID())); 1732 token_handle_util_.get(), context.GetUserID()));
1732 token_handle_fetcher_->FillForNewUser( 1733 token_handle_fetcher_->FillForNewUser(
1733 context.GetAccessToken(), 1734 context.GetAccessToken(),
1734 base::Bind(&UserSessionManager::OnTokenHandleObtained, 1735 base::Bind(&UserSessionManager::OnTokenHandleObtained,
1735 weak_factory_.GetWeakPtr())); 1736 weak_factory_.GetWeakPtr()));
1736 } 1737 }
1737 } 1738 }
1738 } 1739 }
1739 1740
1740 void UserSessionManager::OnTokenHandleObtained(const user_manager::UserID& id, 1741 void UserSessionManager::OnTokenHandleObtained(const AccountId& id,
achuithb 2015/10/23 00:08:50 account_id
Alexander Alekseev 2015/10/23 09:11:22 Done.
1741 bool success) { 1742 bool success) {
1742 if (!success) 1743 if (!success)
1743 LOG(ERROR) << "OAuth2 token handle fetch failed."; 1744 LOG(ERROR) << "OAuth2 token handle fetch failed.";
1744 token_handle_fetcher_.reset(); 1745 token_handle_fetcher_.reset();
1745 } 1746 }
1746 1747
1747 bool UserSessionManager::TokenHandlesEnabled() { 1748 bool UserSessionManager::TokenHandlesEnabled() {
1748 if (!should_obtain_handles_) 1749 if (!should_obtain_handles_)
1749 return false; 1750 return false;
1750 bool ephemeral_users_enabled = false; 1751 bool ephemeral_users_enabled = false;
(...skipping 12 matching lines...) Expand all
1763 first_run::GoodiesDisplayer::Delete(); 1764 first_run::GoodiesDisplayer::Delete();
1764 } 1765 }
1765 1766
1766 void UserSessionManager::CreateTokenUtilIfMissing() { 1767 void UserSessionManager::CreateTokenUtilIfMissing() {
1767 if (!token_handle_util_.get()) 1768 if (!token_handle_util_.get())
1768 token_handle_util_.reset( 1769 token_handle_util_.reset(
1769 new TokenHandleUtil(user_manager::UserManager::Get())); 1770 new TokenHandleUtil(user_manager::UserManager::Get()));
1770 } 1771 }
1771 1772
1772 } // namespace chromeos 1773 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698