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

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: Update after review. Created 5 years, 1 month 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 "
454 << user_context.GetAccountId().GetUserEmail();
454 455
455 PreStartSession(); 456 PreStartSession();
456 CreateUserSession(user_context, has_auth_cookies); 457 CreateUserSession(user_context, has_auth_cookies);
457 458
458 if (!has_active_session) 459 if (!has_active_session)
459 StartCrosSession(); 460 StartCrosSession();
460 461
461 // TODO(nkostylev): Notify UserLoggedIn() after profile is actually 462 // TODO(nkostylev): Notify UserLoggedIn() after profile is actually
462 // ready to be used (http://crbug.com/361528). 463 // ready to be used (http://crbug.com/361528).
463 NotifyUserLoggedIn(); 464 NotifyUserLoggedIn();
464 465
465 if (!user_context.GetDeviceId().empty()) { 466 if (!user_context.GetDeviceId().empty()) {
466 user_manager::UserManager::Get()->SetKnownUserDeviceId( 467 user_manager::UserManager::Get()->SetKnownUserDeviceId(
467 user_context.GetUserID(), user_context.GetDeviceId()); 468 user_context.GetAccountId(), user_context.GetDeviceId());
468 } 469 }
469 470
470 PrepareProfile(); 471 PrepareProfile();
471 } 472 }
472 473
473 void UserSessionManager::DelegateDeleted(UserSessionManagerDelegate* delegate) { 474 void UserSessionManager::DelegateDeleted(UserSessionManagerDelegate* delegate) {
474 if (delegate_ == delegate) 475 if (delegate_ == delegate)
475 delegate_ = nullptr; 476 delegate_ = nullptr;
476 } 477 }
477 478
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 // argv[0] is the program name |base::CommandLine::NO_PROGRAM|. 694 // argv[0] is the program name |base::CommandLine::NO_PROGRAM|.
694 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); 695 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end());
695 LOG(WARNING) << "Restarting to apply per-session flags..."; 696 LOG(WARNING) << "Restarting to apply per-session flags...";
696 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( 697 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser(
697 user_manager::UserManager::Get()->GetActiveUser()->email(), flags); 698 user_manager::UserManager::Get()->GetActiveUser()->email(), flags);
698 AttemptRestart(profile); 699 AttemptRestart(profile);
699 return true; 700 return true;
700 } 701 }
701 702
702 bool UserSessionManager::NeedsToUpdateEasyUnlockKeys() const { 703 bool UserSessionManager::NeedsToUpdateEasyUnlockKeys() const {
703 return !user_context_.GetUserID().empty() && 704 return user_context_.GetAccountId().is_valid() &&
704 user_manager::User::TypeHasGaiaAccount(user_context_.GetUserType()) && 705 user_manager::User::TypeHasGaiaAccount(user_context_.GetUserType()) &&
705 user_context_.GetKey() && !user_context_.GetKey()->GetSecret().empty(); 706 user_context_.GetKey() && !user_context_.GetKey()->GetSecret().empty();
706 } 707 }
707 708
708 bool UserSessionManager::CheckEasyUnlockKeyOps(const base::Closure& callback) { 709 bool UserSessionManager::CheckEasyUnlockKeyOps(const base::Closure& callback) {
709 if (!running_easy_unlock_key_ops_) 710 if (!running_easy_unlock_key_ops_)
710 return false; 711 return false;
711 712
712 // Assumes only one deferred callback is needed. 713 // Assumes only one deferred callback is needed.
713 DCHECK(easy_unlock_key_ops_finished_callback_.is_null()); 714 DCHECK(easy_unlock_key_ops_finished_callback_.is_null());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 case OAuth2LoginManager::SESSION_RESTORE_PREPARING: 752 case OAuth2LoginManager::SESSION_RESTORE_PREPARING:
752 case OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS: 753 case OAuth2LoginManager::SESSION_RESTORE_IN_PROGRESS:
753 return; 754 return;
754 } 755 }
755 756
756 // We should not be clearing existing token state if that was a connection 757 // We should not be clearing existing token state if that was a connection
757 // error. http://crbug.com/295245 758 // error. http://crbug.com/295245
758 if (!connection_error) { 759 if (!connection_error) {
759 // We are in one of "done" states here. 760 // We are in one of "done" states here.
760 user_manager::UserManager::Get()->SaveUserOAuthStatus( 761 user_manager::UserManager::Get()->SaveUserOAuthStatus(
761 user_manager::UserManager::Get()->GetLoggedInUser()->email(), 762 user_manager::UserManager::Get()->GetLoggedInUser()->GetAccountId(),
762 user_status); 763 user_status);
763 } 764 }
764 765
765 login_manager->RemoveObserver(this); 766 login_manager->RemoveObserver(this);
766 767
767 if (exit_after_session_restore_ && 768 if (exit_after_session_restore_ &&
768 (state == OAuth2LoginManager::SESSION_RESTORE_DONE || 769 (state == OAuth2LoginManager::SESSION_RESTORE_DONE ||
769 state == OAuth2LoginManager::SESSION_RESTORE_FAILED || 770 state == OAuth2LoginManager::SESSION_RESTORE_FAILED ||
770 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED)) { 771 state == OAuth2LoginManager::SESSION_RESTORE_CONNECTION_FAILED)) {
771 LOG(WARNING) << "Restarting Chrome after session restore finishes, " 772 LOG(WARNING) << "Restarting Chrome after session restore finishes, "
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 855
855 void UserSessionManager::PreStartSession() { 856 void UserSessionManager::PreStartSession() {
856 // Switch log file as soon as possible. 857 // Switch log file as soon as possible.
857 if (base::SysInfo::IsRunningOnChromeOS()) 858 if (base::SysInfo::IsRunningOnChromeOS())
858 logging::RedirectChromeLogging(*(base::CommandLine::ForCurrentProcess())); 859 logging::RedirectChromeLogging(*(base::CommandLine::ForCurrentProcess()));
859 } 860 }
860 861
861 void UserSessionManager::StoreUserContextDataBeforeProfileIsCreated() { 862 void UserSessionManager::StoreUserContextDataBeforeProfileIsCreated() {
862 // Store obfuscated GAIA ID. 863 // Store obfuscated GAIA ID.
863 if (!user_context_.GetGaiaID().empty()) { 864 if (!user_context_.GetGaiaID().empty()) {
864 user_manager::UserManager::Get()->UpdateGaiaID(user_context_.GetUserID(), 865 user_manager::UserManager::Get()->UpdateGaiaID(user_context_.GetAccountId(),
865 user_context_.GetGaiaID()); 866 user_context_.GetGaiaID());
866 } 867 }
867 } 868 }
868 869
869 void UserSessionManager::StartCrosSession() { 870 void UserSessionManager::StartCrosSession() {
870 BootTimesRecorder* btl = BootTimesRecorder::Get(); 871 BootTimesRecorder* btl = BootTimesRecorder::Get();
871 btl->AddLoginTimeMarker("StartSession-Start", false); 872 btl->AddLoginTimeMarker("StartSession-Start", false);
872 DBusThreadManager::Get()->GetSessionManagerClient()-> 873 DBusThreadManager::Get()->GetSessionManagerClient()->StartSession(
873 StartSession(user_context_.GetUserID()); 874 user_context_.GetAccountId().GetUserEmail());
874 btl->AddLoginTimeMarker("StartSession-End", false); 875 btl->AddLoginTimeMarker("StartSession-End", false);
875 } 876 }
876 877
877 void UserSessionManager::NotifyUserLoggedIn() { 878 void UserSessionManager::NotifyUserLoggedIn() {
878 BootTimesRecorder* btl = BootTimesRecorder::Get(); 879 BootTimesRecorder* btl = BootTimesRecorder::Get();
879 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); 880 btl->AddLoginTimeMarker("UserLoggedIn-Start", false);
880 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 881 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
881 user_manager->UserLoggedIn(user_context_.GetUserID(), 882 user_manager->UserLoggedIn(user_context_.GetAccountId(),
882 user_context_.GetUserIDHash(), 883 user_context_.GetUserIDHash(), 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 const bool is_demo_session = DemoAppLauncher::IsDemoAppSession(
889 DemoAppLauncher::IsDemoAppSession(user_context_.GetUserID()); 889 user_context_.GetAccountId().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(),
900 base::string16(), 900 base::string16(),
901 std::string()); 901 std::string());
902 } 902 }
903 903
904 void UserSessionManager::OnProfileCreated(const UserContext& user_context, 904 void UserSessionManager::OnProfileCreated(const UserContext& user_context,
905 bool is_incognito_profile, 905 bool is_incognito_profile,
906 Profile* profile, 906 Profile* profile,
907 Profile::CreateStatus status) { 907 Profile::CreateStatus status) {
908 CHECK(profile); 908 CHECK(profile);
909 909
910 switch (status) { 910 switch (status) {
911 case Profile::CREATE_STATUS_CREATED: 911 case Profile::CREATE_STATUS_CREATED:
912 // Profile created but before initializing extensions and promo resources. 912 // Profile created but before initializing extensions and promo resources.
913 InitProfilePreferences(profile, user_context); 913 InitProfilePreferences(profile, user_context);
914 break; 914 break;
915 case Profile::CREATE_STATUS_INITIALIZED: 915 case Profile::CREATE_STATUS_INITIALIZED:
916 // Profile is created, extensions and promo resources are initialized. 916 // Profile is created, extensions and promo resources are initialized.
917 // At this point all other Chrome OS services will be notified that it is 917 // At this point all other Chrome OS services will be notified that it is
918 // safe to use this profile. 918 // safe to use this profile.
919 UserProfileInitialized(profile, 919 UserProfileInitialized(profile, is_incognito_profile,
920 is_incognito_profile, 920 user_context.GetAccountId());
921 user_context.GetUserID());
922 break; 921 break;
923 case Profile::CREATE_STATUS_LOCAL_FAIL: 922 case Profile::CREATE_STATUS_LOCAL_FAIL:
924 case Profile::CREATE_STATUS_REMOTE_FAIL: 923 case Profile::CREATE_STATUS_REMOTE_FAIL:
925 case Profile::CREATE_STATUS_CANCELED: 924 case Profile::CREATE_STATUS_CANCELED:
926 case Profile::MAX_CREATE_STATUS: 925 case Profile::MAX_CREATE_STATUS:
927 NOTREACHED(); 926 NOTREACHED();
928 break; 927 break;
929 } 928 }
930 } 929 }
931 930
(...skipping 29 matching lines...) Expand all
961 } else if (user_manager::UserManager::Get()-> 960 } else if (user_manager::UserManager::Get()->
962 IsLoggedInAsUserWithGaiaAccount()) { 961 IsLoggedInAsUserWithGaiaAccount()) {
963 // Get the Gaia ID from the user context. If it's not available, this may 962 // 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 963 // not be available when unlocking a previously opened profile, or when
965 // creating a supervised users. However, in these cases the gaia_id should 964 // creating a supervised users. However, in these cases the gaia_id should
966 // be already available in the account tracker. 965 // be already available in the account tracker.
967 std::string gaia_id = user_context.GetGaiaID(); 966 std::string gaia_id = user_context.GetGaiaID();
968 if (gaia_id.empty()) { 967 if (gaia_id.empty()) {
969 AccountTrackerService* account_tracker = 968 AccountTrackerService* account_tracker =
970 AccountTrackerServiceFactory::GetForProfile(profile); 969 AccountTrackerServiceFactory::GetForProfile(profile);
971 AccountInfo info = 970 const AccountInfo info = account_tracker->FindAccountInfoByEmail(
972 account_tracker->FindAccountInfoByEmail(user_context.GetUserID()); 971 user_context.GetAccountId().GetUserEmail());
973 gaia_id = info.gaia; 972 gaia_id = info.gaia;
974 DCHECK(!gaia_id.empty()); 973 DCHECK(!gaia_id.empty());
975 } 974 }
976 975
977 // Make sure that the google service username is properly set (we do this 976 // 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 977 // on every sign in, not just the first login, to deal with existing
979 // profiles that might not have it set yet). 978 // profiles that might not have it set yet).
980 SigninManagerBase* signin_manager = 979 SigninManagerBase* signin_manager =
981 SigninManagerFactory::GetForProfile(profile); 980 SigninManagerFactory::GetForProfile(profile);
982 signin_manager->SetAuthenticatedAccountInfo(gaia_id, 981 signin_manager->SetAuthenticatedAccountInfo(
983 user_context.GetUserID()); 982 gaia_id, user_context.GetAccountId().GetUserEmail());
984 983
985 // Backfill GAIA ID in user prefs stored in Local State. 984 // Backfill GAIA ID in user prefs stored in Local State.
986 std::string tmp_gaia_id; 985 std::string tmp_gaia_id;
987 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 986 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
988 if (!user_manager->FindGaiaID(user_context.GetUserID(), &tmp_gaia_id) && 987 if (!user_manager->FindGaiaID(user_context.GetAccountId(), &tmp_gaia_id) &&
989 !gaia_id.empty()) { 988 !gaia_id.empty()) {
990 user_manager->UpdateGaiaID(user_context.GetUserID(), gaia_id); 989 user_manager->UpdateGaiaID(user_context.GetAccountId(), gaia_id);
991 } 990 }
992 } 991 }
993 } 992 }
994 993
995 void UserSessionManager::UserProfileInitialized(Profile* profile, 994 void UserSessionManager::UserProfileInitialized(Profile* profile,
996 bool is_incognito_profile, 995 bool is_incognito_profile,
997 const std::string& user_id) { 996 const AccountId& account_id) {
998 // Demo user signed in. 997 // Demo user signed in.
999 if (is_incognito_profile) { 998 if (is_incognito_profile) {
1000 profile->OnLogin(); 999 profile->OnLogin();
1001 1000
1002 // Send the notification before creating the browser so additional objects 1001 // Send the notification before creating the browser so additional objects
1003 // that need the profile (e.g. the launcher) can be created first. 1002 // that need the profile (e.g. the launcher) can be created first.
1004 content::NotificationService::current()->Notify( 1003 content::NotificationService::current()->Notify(
1005 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 1004 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
1006 content::NotificationService::AllSources(), 1005 content::NotificationService::AllSources(),
1007 content::Details<Profile>(profile)); 1006 content::Details<Profile>(profile));
1008 1007
1009 if (delegate_) 1008 if (delegate_)
1010 delegate_->OnProfilePrepared(profile, false); 1009 delegate_->OnProfilePrepared(profile, false);
1011 1010
1012 return; 1011 return;
1013 } 1012 }
1014 1013
1015 BootTimesRecorder* btl = BootTimesRecorder::Get(); 1014 BootTimesRecorder* btl = BootTimesRecorder::Get();
1016 btl->AddLoginTimeMarker("UserProfileGotten", false); 1015 btl->AddLoginTimeMarker("UserProfileGotten", false);
1017 1016
1018 if (user_context_.IsUsingOAuth()) { 1017 if (user_context_.IsUsingOAuth()) {
1019 // Retrieve the policy that indicates whether to continue copying 1018 // Retrieve the policy that indicates whether to continue copying
1020 // authentication cookies set by a SAML IdP on subsequent logins after the 1019 // authentication cookies set by a SAML IdP on subsequent logins after the
1021 // first. 1020 // first.
1022 bool transfer_saml_auth_cookies_on_subsequent_login = false; 1021 bool transfer_saml_auth_cookies_on_subsequent_login = false;
1023 if (has_auth_cookies_ && 1022 if (has_auth_cookies_ &&
1024 g_browser_process->platform_part()-> 1023 g_browser_process->platform_part()
1025 browser_policy_connector_chromeos()->GetUserAffiliation(user_id) == 1024 ->browser_policy_connector_chromeos()
1026 policy::USER_AFFILIATION_MANAGED) { 1025 ->GetUserAffiliation(account_id.GetUserEmail()) ==
1026 policy::USER_AFFILIATION_MANAGED) {
1027 CrosSettings::Get()->GetBoolean( 1027 CrosSettings::Get()->GetBoolean(
1028 kAccountsPrefTransferSAMLCookies, 1028 kAccountsPrefTransferSAMLCookies,
1029 &transfer_saml_auth_cookies_on_subsequent_login); 1029 &transfer_saml_auth_cookies_on_subsequent_login);
1030 } 1030 }
1031 1031
1032 // Transfers authentication-related data from the profile that was used for 1032 // Transfers authentication-related data from the profile that was used for
1033 // authentication to the user's profile. The proxy authentication state is 1033 // authentication to the user's profile. The proxy authentication state is
1034 // transferred unconditionally. If the user authenticated via an auth 1034 // transferred unconditionally. If the user authenticated via an auth
1035 // extension, authentication cookies and channel IDs will be transferred as 1035 // 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, 1036 // well when the user's cookie jar is empty. If the cookie jar is not empty,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 if (cryptohome_util::TpmIsOwned()) 1085 if (cryptohome_util::TpmIsOwned())
1086 client->CallTpmClearStoredPasswordAndBlock(); 1086 client->CallTpmClearStoredPasswordAndBlock();
1087 else 1087 else
1088 client->TpmCanAttemptOwnership(EmptyVoidDBusMethodCallback()); 1088 client->TpmCanAttemptOwnership(EmptyVoidDBusMethodCallback());
1089 } 1089 }
1090 btl->AddLoginTimeMarker("TPMOwn-End", false); 1090 btl->AddLoginTimeMarker("TPMOwn-End", false);
1091 1091
1092 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 1092 user_manager::UserManager* user_manager = user_manager::UserManager::Get();
1093 if (user_manager->IsLoggedInAsUserWithGaiaAccount()) { 1093 if (user_manager->IsLoggedInAsUserWithGaiaAccount()) {
1094 if (user_context_.GetAuthFlow() == UserContext::AUTH_FLOW_GAIA_WITH_SAML) 1094 if (user_context_.GetAuthFlow() == UserContext::AUTH_FLOW_GAIA_WITH_SAML)
1095 user_manager->UpdateUsingSAML(user_context_.GetUserID(), true); 1095 user_manager->UpdateUsingSAML(user_context_.GetAccountId(), true);
1096 SAMLOfflineSigninLimiter* saml_offline_signin_limiter = 1096 SAMLOfflineSigninLimiter* saml_offline_signin_limiter =
1097 SAMLOfflineSigninLimiterFactory::GetForProfile(profile); 1097 SAMLOfflineSigninLimiterFactory::GetForProfile(profile);
1098 if (saml_offline_signin_limiter) 1098 if (saml_offline_signin_limiter)
1099 saml_offline_signin_limiter->SignedIn(user_context_.GetAuthFlow()); 1099 saml_offline_signin_limiter->SignedIn(user_context_.GetAuthFlow());
1100 } 1100 }
1101 1101
1102 profile->OnLogin(); 1102 profile->OnLogin();
1103 1103
1104 g_browser_process->platform_part()->SessionManager()->SetSessionState( 1104 g_browser_process->platform_part()->SessionManager()->SetSessionState(
1105 session_manager::SESSION_STATE_LOGGED_IN_NOT_ACTIVE); 1105 session_manager::SESSION_STATE_LOGGED_IN_NOT_ACTIVE);
(...skipping 12 matching lines...) Expand all
1118 InitRlz(profile); 1118 InitRlz(profile);
1119 InitializeCerts(profile); 1119 InitializeCerts(profile);
1120 InitializeCRLSetFetcher(user); 1120 InitializeCRLSetFetcher(user);
1121 InitializeEVCertificatesWhitelistComponent(user); 1121 InitializeEVCertificatesWhitelistComponent(user);
1122 } 1122 }
1123 1123
1124 UpdateEasyUnlockKeys(user_context_); 1124 UpdateEasyUnlockKeys(user_context_);
1125 user_context_.ClearSecrets(); 1125 user_context_.ClearSecrets();
1126 if (TokenHandlesEnabled()) { 1126 if (TokenHandlesEnabled()) {
1127 CreateTokenUtilIfMissing(); 1127 CreateTokenUtilIfMissing();
1128 if (token_handle_util_->ShouldObtainHandle(user->GetUserID())) { 1128 if (token_handle_util_->ShouldObtainHandle(user->GetAccountId())) {
1129 if (!token_handle_fetcher_.get()) { 1129 if (!token_handle_fetcher_.get()) {
1130 token_handle_fetcher_.reset(new TokenHandleFetcher( 1130 token_handle_fetcher_.reset(new TokenHandleFetcher(
1131 token_handle_util_.get(), user->GetUserID())); 1131 token_handle_util_.get(), user->GetAccountId()));
1132 token_handle_fetcher_->BackfillToken( 1132 token_handle_fetcher_->BackfillToken(
1133 profile, base::Bind(&UserSessionManager::OnTokenHandleObtained, 1133 profile, base::Bind(&UserSessionManager::OnTokenHandleObtained,
1134 weak_factory_.GetWeakPtr())); 1134 weak_factory_.GetWeakPtr()));
1135 } 1135 }
1136 } 1136 }
1137 } 1137 }
1138 1138
1139 // Now that profile is ready, proceed to either alternative login flows or 1139 // Now that profile is ready, proceed to either alternative login flows or
1140 // launch browser. 1140 // launch browser.
1141 bool browser_launched = InitializeUserSession(profile); 1141 bool browser_launched = InitializeUserSession(profile);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 ++it) { 1433 ++it) {
1434 const user_manager::User* user = (*it); 1434 const user_manager::User* user = (*it);
1435 if (user->email() == user_id) { 1435 if (user->email() == user_id) {
1436 user_already_logged_in = true; 1436 user_already_logged_in = true;
1437 break; 1437 break;
1438 } 1438 }
1439 } 1439 }
1440 DCHECK(!user_already_logged_in); 1440 DCHECK(!user_already_logged_in);
1441 1441
1442 if (!user_already_logged_in) { 1442 if (!user_already_logged_in) {
1443 UserContext user_context(user_id); 1443 UserContext user_context(AccountId::FromUserEmail(user_id));
1444 user_context.SetUserIDHash(user_id_hash); 1444 user_context.SetUserIDHash(user_id_hash);
1445 user_context.SetIsUsingOAuth(false); 1445 user_context.SetIsUsingOAuth(false);
1446 1446
1447 // Will call OnProfilePrepared() once profile has been loaded. 1447 // Will call OnProfilePrepared() once profile has been loaded.
1448 // Only handling secondary users here since primary user profile 1448 // Only handling secondary users here since primary user profile
1449 // (and session) has been loaded on Chrome startup. 1449 // (and session) has been loaded on Chrome startup.
1450 StartSession(user_context, 1450 StartSession(user_context,
1451 SECONDARY_USER_SESSION_AFTER_CRASH, 1451 SECONDARY_USER_SESSION_AFTER_CRASH,
1452 false, // has_auth_cookies 1452 false, // has_auth_cookies
1453 true, // has_active_session, this is restart after crash 1453 true, // has_active_session, this is restart after crash
(...skipping 17 matching lines...) Expand all
1471 // and RefreshKeys op expects a failure to stop. As a result, some tests would 1471 // and RefreshKeys op expects a failure to stop. As a result, some tests would
1472 // timeout. 1472 // timeout.
1473 // TODO(xiyuan): Revisit this when adding tests. 1473 // TODO(xiyuan): Revisit this when adding tests.
1474 if (!base::SysInfo::IsRunningOnChromeOS()) 1474 if (!base::SysInfo::IsRunningOnChromeOS())
1475 return; 1475 return;
1476 1476
1477 // Only update Easy unlock keys for regular user. 1477 // Only update Easy unlock keys for regular user.
1478 // TODO(xiyuan): Fix inconsistency user type of |user_context| introduced in 1478 // TODO(xiyuan): Fix inconsistency user type of |user_context| introduced in
1479 // authenticator. 1479 // authenticator.
1480 const user_manager::User* user = 1480 const user_manager::User* user =
1481 user_manager::UserManager::Get()->FindUser(user_context.GetUserID()); 1481 user_manager::UserManager::Get()->FindUser(user_context.GetAccountId());
1482 if (!user || !user->HasGaiaAccount()) 1482 if (!user || !user->HasGaiaAccount())
1483 return; 1483 return;
1484 1484
1485 // Bail if |user_context| does not have secret. 1485 // Bail if |user_context| does not have secret.
1486 if (user_context.GetKey()->GetSecret().empty()) 1486 if (user_context.GetKey()->GetSecret().empty())
1487 return; 1487 return;
1488 1488
1489 const base::ListValue* device_list = NULL; 1489 const base::ListValue* device_list = NULL;
1490 EasyUnlockService* easy_unlock_service = EasyUnlockService::GetForUser(*user); 1490 EasyUnlockService* easy_unlock_service = EasyUnlockService::GetForUser(*user);
1491 if (easy_unlock_service) { 1491 if (easy_unlock_service) {
1492 device_list = easy_unlock_service->GetRemoteDevices(); 1492 device_list = easy_unlock_service->GetRemoteDevices();
1493 easy_unlock_service->SetHardlockState( 1493 easy_unlock_service->SetHardlockState(
1494 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); 1494 EasyUnlockScreenlockStateHandler::NO_HARDLOCK);
1495 } 1495 }
1496 1496
1497 base::ListValue empty_list; 1497 base::ListValue empty_list;
1498 if (!device_list) 1498 if (!device_list)
1499 device_list = &empty_list; 1499 device_list = &empty_list;
1500 1500
1501 EasyUnlockKeyManager* key_manager = GetEasyUnlockKeyManager(); 1501 EasyUnlockKeyManager* key_manager = GetEasyUnlockKeyManager();
1502 running_easy_unlock_key_ops_ = true; 1502 running_easy_unlock_key_ops_ = true;
1503 key_manager->RefreshKeys( 1503 key_manager->RefreshKeys(
1504 user_context, *device_list, 1504 user_context, *device_list,
1505 base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished, AsWeakPtr(), 1505 base::Bind(&UserSessionManager::OnEasyUnlockKeyOpsFinished, AsWeakPtr(),
1506 user_context.GetUserID())); 1506 user_context.GetAccountId().GetUserEmail()));
1507 } 1507 }
1508 1508
1509 net::URLRequestContextGetter* 1509 net::URLRequestContextGetter*
1510 UserSessionManager::GetAuthRequestContext() const { 1510 UserSessionManager::GetAuthRequestContext() const {
1511 net::URLRequestContextGetter* auth_request_context = nullptr; 1511 net::URLRequestContextGetter* auth_request_context = nullptr;
1512 1512
1513 if (StartupUtils::IsWebviewSigninEnabled()) { 1513 if (StartupUtils::IsWebviewSigninEnabled()) {
1514 // Webview uses different partition storage than iframe. We need to get 1514 // 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 1515 // cookies from the right storage for url request to get auth token into
1516 // session. 1516 // session.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 exit_after_session_restore_ = true; 1557 exit_after_session_restore_ = true;
1558 } 1558 }
1559 1559
1560 void UserSessionManager::OnEasyUnlockKeyOpsFinished( 1560 void UserSessionManager::OnEasyUnlockKeyOpsFinished(
1561 const std::string& user_id, 1561 const std::string& user_id,
1562 bool success) { 1562 bool success) {
1563 running_easy_unlock_key_ops_ = false; 1563 running_easy_unlock_key_ops_ = false;
1564 if (!easy_unlock_key_ops_finished_callback_.is_null()) 1564 if (!easy_unlock_key_ops_finished_callback_.is_null())
1565 easy_unlock_key_ops_finished_callback_.Run(); 1565 easy_unlock_key_ops_finished_callback_.Run();
1566 1566
1567 const user_manager::User* user = 1567 const user_manager::User* user = user_manager::UserManager::Get()->FindUser(
1568 user_manager::UserManager::Get()->FindUser(user_id); 1568 AccountId::FromUserEmail(user_id));
1569 EasyUnlockService* easy_unlock_service = 1569 EasyUnlockService* easy_unlock_service =
1570 EasyUnlockService::GetForUser(*user); 1570 EasyUnlockService::GetForUser(*user);
1571 easy_unlock_service->CheckCryptohomeKeysAndMaybeHardlock(); 1571 easy_unlock_service->CheckCryptohomeKeysAndMaybeHardlock();
1572 } 1572 }
1573 1573
1574 void UserSessionManager::ActiveUserChanged( 1574 void UserSessionManager::ActiveUserChanged(
1575 const user_manager::User* active_user) { 1575 const user_manager::User* active_user) {
1576 if (!user_manager::UserManager::Get()->IsCurrentUserNew()) 1576 if (!user_manager::UserManager::Get()->IsCurrentUserNew())
1577 SendUserPodsMetrics(); 1577 SendUserPodsMetrics();
1578 1578
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 else 1719 else
1720 display = USER_PODS_DISPLAY_DISABLED_REGULAR; 1720 display = USER_PODS_DISPLAY_DISABLED_REGULAR;
1721 } 1721 }
1722 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display, 1722 UMA_HISTOGRAM_ENUMERATION("UserSessionManager.UserPodsDisplay", display,
1723 NUM_USER_PODS_DISPLAY); 1723 NUM_USER_PODS_DISPLAY);
1724 } 1724 }
1725 1725
1726 void UserSessionManager::OnOAuth2TokensFetched(UserContext context) { 1726 void UserSessionManager::OnOAuth2TokensFetched(UserContext context) {
1727 if (StartupUtils::IsWebviewSigninEnabled() && TokenHandlesEnabled()) { 1727 if (StartupUtils::IsWebviewSigninEnabled() && TokenHandlesEnabled()) {
1728 CreateTokenUtilIfMissing(); 1728 CreateTokenUtilIfMissing();
1729 if (token_handle_util_->ShouldObtainHandle(context.GetUserID())) { 1729 if (token_handle_util_->ShouldObtainHandle(context.GetAccountId())) {
1730 token_handle_fetcher_.reset(new TokenHandleFetcher( 1730 token_handle_fetcher_.reset(new TokenHandleFetcher(
1731 token_handle_util_.get(), context.GetUserID())); 1731 token_handle_util_.get(), context.GetAccountId()));
1732 token_handle_fetcher_->FillForNewUser( 1732 token_handle_fetcher_->FillForNewUser(
1733 context.GetAccessToken(), 1733 context.GetAccessToken(),
1734 base::Bind(&UserSessionManager::OnTokenHandleObtained, 1734 base::Bind(&UserSessionManager::OnTokenHandleObtained,
1735 weak_factory_.GetWeakPtr())); 1735 weak_factory_.GetWeakPtr()));
1736 } 1736 }
1737 } 1737 }
1738 } 1738 }
1739 1739
1740 void UserSessionManager::OnTokenHandleObtained(const user_manager::UserID& id, 1740 void UserSessionManager::OnTokenHandleObtained(const AccountId& account_id,
1741 bool success) { 1741 bool success) {
1742 if (!success) 1742 if (!success)
1743 LOG(ERROR) << "OAuth2 token handle fetch failed."; 1743 LOG(ERROR) << "OAuth2 token handle fetch failed.";
1744 token_handle_fetcher_.reset(); 1744 token_handle_fetcher_.reset();
1745 } 1745 }
1746 1746
1747 bool UserSessionManager::TokenHandlesEnabled() { 1747 bool UserSessionManager::TokenHandlesEnabled() {
1748 if (!should_obtain_handles_) 1748 if (!should_obtain_handles_)
1749 return false; 1749 return false;
1750 bool ephemeral_users_enabled = false; 1750 bool ephemeral_users_enabled = false;
(...skipping 12 matching lines...) Expand all
1763 first_run::GoodiesDisplayer::Delete(); 1763 first_run::GoodiesDisplayer::Delete();
1764 } 1764 }
1765 1765
1766 void UserSessionManager::CreateTokenUtilIfMissing() { 1766 void UserSessionManager::CreateTokenUtilIfMissing() {
1767 if (!token_handle_util_.get()) 1767 if (!token_handle_util_.get())
1768 token_handle_util_.reset( 1768 token_handle_util_.reset(
1769 new TokenHandleUtil(user_manager::UserManager::Get())); 1769 new TokenHandleUtil(user_manager::UserManager::Get()));
1770 } 1770 }
1771 1771
1772 } // namespace chromeos 1772 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698