| 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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 VLOG(1) << "Switch leading to restart: '" << *it << "'"; | 353 VLOG(1) << "Switch leading to restart: '" << *it << "'"; |
| 354 } | 354 } |
| 355 } | 355 } |
| 356 | 356 |
| 357 void RestartOnTimeout() { | 357 void RestartOnTimeout() { |
| 358 LOG(WARNING) << "Restarting Chrome because the time out was reached." | 358 LOG(WARNING) << "Restarting Chrome because the time out was reached." |
| 359 "The session restore has not finished."; | 359 "The session restore has not finished."; |
| 360 chrome::AttemptRestart(); | 360 chrome::AttemptRestart(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 bool IsRunningTest() { |
| 364 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 365 ::switches::kTestName) || |
| 366 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 367 ::switches::kTestType); |
| 368 } |
| 369 |
| 363 } // namespace | 370 } // namespace |
| 364 | 371 |
| 365 UserSessionManagerDelegate::~UserSessionManagerDelegate() { | 372 UserSessionManagerDelegate::~UserSessionManagerDelegate() { |
| 366 } | 373 } |
| 367 | 374 |
| 368 void UserSessionStateObserver::PendingUserSessionsRestoreFinished() { | 375 void UserSessionStateObserver::PendingUserSessionsRestoreFinished() { |
| 369 } | 376 } |
| 370 | 377 |
| 371 UserSessionStateObserver::~UserSessionStateObserver() { | 378 UserSessionStateObserver::~UserSessionStateObserver() { |
| 372 } | 379 } |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 } else { | 902 } else { |
| 896 // Schedule another flush after session restore for non-ephemeral profile | 903 // Schedule another flush after session restore for non-ephemeral profile |
| 897 // if not restarting. | 904 // if not restarting. |
| 898 if (!ProfileHelper::IsEphemeralUserProfile(user_profile)) | 905 if (!ProfileHelper::IsEphemeralUserProfile(user_profile)) |
| 899 ProfileHelper::Get()->FlushProfile(user_profile); | 906 ProfileHelper::Get()->FlushProfile(user_profile); |
| 900 } | 907 } |
| 901 } | 908 } |
| 902 | 909 |
| 903 void UserSessionManager::OnConnectionTypeChanged( | 910 void UserSessionManager::OnConnectionTypeChanged( |
| 904 net::NetworkChangeNotifier::ConnectionType type) { | 911 net::NetworkChangeNotifier::ConnectionType type) { |
| 905 bool is_running_test = | |
| 906 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 907 ::switches::kTestName) || | |
| 908 base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType); | |
| 909 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 912 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 910 if (type == net::NetworkChangeNotifier::CONNECTION_NONE || | 913 if (type == net::NetworkChangeNotifier::CONNECTION_NONE || |
| 911 !user_manager->IsUserLoggedIn() || | 914 !user_manager->IsUserLoggedIn() || |
| 912 !user_manager->IsLoggedInAsUserWithGaiaAccount() || | 915 !user_manager->IsLoggedInAsUserWithGaiaAccount() || |
| 913 user_manager->IsLoggedInAsStub() || is_running_test) { | 916 user_manager->IsLoggedInAsStub() || IsRunningTest()) { |
| 914 return; | 917 return; |
| 915 } | 918 } |
| 916 | 919 |
| 917 // Need to iterate over all users and their OAuth2 session state. | 920 // Need to iterate over all users and their OAuth2 session state. |
| 918 const user_manager::UserList& users = user_manager->GetLoggedInUsers(); | 921 const user_manager::UserList& users = user_manager->GetLoggedInUsers(); |
| 919 for (user_manager::UserList::const_iterator it = users.begin(); | 922 for (user_manager::UserList::const_iterator it = users.begin(); |
| 920 it != users.end(); | 923 it != users.end(); |
| 921 ++it) { | 924 ++it) { |
| 922 if (!(*it)->is_profile_created()) | 925 if (!(*it)->is_profile_created()) |
| 923 continue; | 926 continue; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 935 } else if (should_restore_session) { | 938 } else if (should_restore_session) { |
| 936 pending_signin_restore_sessions_.erase( | 939 pending_signin_restore_sessions_.erase( |
| 937 (*it)->GetAccountId().GetUserEmail()); | 940 (*it)->GetAccountId().GetUserEmail()); |
| 938 RestoreAuthSessionImpl(user_profile, false /* has_auth_cookies */); | 941 RestoreAuthSessionImpl(user_profile, false /* has_auth_cookies */); |
| 939 } | 942 } |
| 940 } | 943 } |
| 941 } | 944 } |
| 942 | 945 |
| 943 void UserSessionManager::OnProfilePrepared(Profile* profile, | 946 void UserSessionManager::OnProfilePrepared(Profile* profile, |
| 944 bool browser_launched) { | 947 bool browser_launched) { |
| 945 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 948 if (!IsRunningTest()) { |
| 946 ::switches::kTestName)) { | |
| 947 // Did not log in (we crashed or are debugging), need to restore Sync. | 949 // Did not log in (we crashed or are debugging), need to restore Sync. |
| 948 // TODO(nkostylev): Make sure that OAuth state is restored correctly for all | 950 // TODO(nkostylev): Make sure that OAuth state is restored correctly for all |
| 949 // users once it is fully multi-profile aware. http://crbug.com/238987 | 951 // users once it is fully multi-profile aware. http://crbug.com/238987 |
| 950 // For now if we have other user pending sessions they'll override OAuth | 952 // For now if we have other user pending sessions they'll override OAuth |
| 951 // session restore for previous users. | 953 // session restore for previous users. |
| 952 RestoreAuthenticationSession(profile); | 954 RestoreAuthenticationSession(profile); |
| 953 } | 955 } |
| 954 | 956 |
| 955 // Restore other user sessions if any. | 957 // Restore other user sessions if any. |
| 956 RestorePendingUserSessions(); | 958 RestorePendingUserSessions(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 // not be available when unlocking a previously opened profile, or when | 1073 // not be available when unlocking a previously opened profile, or when |
| 1072 // creating a supervised users. However, in these cases the gaia_id should | 1074 // creating a supervised users. However, in these cases the gaia_id should |
| 1073 // be already available in the account tracker. | 1075 // be already available in the account tracker. |
| 1074 std::string gaia_id = user_context.GetGaiaID(); | 1076 std::string gaia_id = user_context.GetGaiaID(); |
| 1075 if (gaia_id.empty()) { | 1077 if (gaia_id.empty()) { |
| 1076 AccountTrackerService* account_tracker = | 1078 AccountTrackerService* account_tracker = |
| 1077 AccountTrackerServiceFactory::GetForProfile(profile); | 1079 AccountTrackerServiceFactory::GetForProfile(profile); |
| 1078 const AccountInfo info = account_tracker->FindAccountInfoByEmail( | 1080 const AccountInfo info = account_tracker->FindAccountInfoByEmail( |
| 1079 user_context.GetAccountId().GetUserEmail()); | 1081 user_context.GetAccountId().GetUserEmail()); |
| 1080 gaia_id = info.gaia; | 1082 gaia_id = info.gaia; |
| 1083 |
| 1084 // Use a fake gaia id for tests that do not have it. |
| 1085 if (IsRunningTest() && gaia_id.empty()) |
| 1086 gaia_id = "fake_gaia_id_" + user_context.GetAccountId().GetUserEmail(); |
| 1087 |
| 1081 DCHECK(!gaia_id.empty()); | 1088 DCHECK(!gaia_id.empty()); |
| 1082 } | 1089 } |
| 1083 | 1090 |
| 1084 // Make sure that the google service username is properly set (we do this | 1091 // Make sure that the google service username is properly set (we do this |
| 1085 // on every sign in, not just the first login, to deal with existing | 1092 // on every sign in, not just the first login, to deal with existing |
| 1086 // profiles that might not have it set yet). | 1093 // profiles that might not have it set yet). |
| 1087 SigninManagerBase* signin_manager = | 1094 SigninManagerBase* signin_manager = |
| 1088 SigninManagerFactory::GetForProfile(profile); | 1095 SigninManagerFactory::GetForProfile(profile); |
| 1089 signin_manager->SetAuthenticatedAccountInfo( | 1096 signin_manager->SetAuthenticatedAccountInfo( |
| 1090 gaia_id, user_context.GetAccountId().GetUserEmail()); | 1097 gaia_id, user_context.GetAccountId().GetUserEmail()); |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1963 ->browser_policy_connector_chromeos() | 1970 ->browser_policy_connector_chromeos() |
| 1964 ->IsEnterpriseManaged()) { | 1971 ->IsEnterpriseManaged()) { |
| 1965 return false; | 1972 return false; |
| 1966 } | 1973 } |
| 1967 | 1974 |
| 1968 // Do not show end of life notification if this is a guest session | 1975 // Do not show end of life notification if this is a guest session |
| 1969 return !profile->IsGuestSession(); | 1976 return !profile->IsGuestSession(); |
| 1970 } | 1977 } |
| 1971 | 1978 |
| 1972 } // namespace chromeos | 1979 } // namespace chromeos |
| OLD | NEW |