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

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

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

Powered by Google App Engine
This is Rietveld 408576698