| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 VLOG(1) << "Switch leading to restart: '" << *it << "'"; | 352 VLOG(1) << "Switch leading to restart: '" << *it << "'"; |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 void RestartOnTimeout() { | 356 void RestartOnTimeout() { |
| 357 LOG(WARNING) << "Restarting Chrome because the time out was reached." | 357 LOG(WARNING) << "Restarting Chrome because the time out was reached." |
| 358 "The session restore has not finished."; | 358 "The session restore has not finished."; |
| 359 chrome::AttemptRestart(); | 359 chrome::AttemptRestart(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 bool IsRunningTest() { |
| 363 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 364 ::switches::kTestName) || |
| 365 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 366 ::switches::kTestType); |
| 367 } |
| 368 |
| 362 } // namespace | 369 } // namespace |
| 363 | 370 |
| 364 UserSessionManagerDelegate::~UserSessionManagerDelegate() { | 371 UserSessionManagerDelegate::~UserSessionManagerDelegate() { |
| 365 } | 372 } |
| 366 | 373 |
| 367 void UserSessionStateObserver::PendingUserSessionsRestoreFinished() { | 374 void UserSessionStateObserver::PendingUserSessionsRestoreFinished() { |
| 368 } | 375 } |
| 369 | 376 |
| 370 UserSessionStateObserver::~UserSessionStateObserver() { | 377 UserSessionStateObserver::~UserSessionStateObserver() { |
| 371 } | 378 } |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 } else { | 887 } else { |
| 881 // Schedule another flush after session restore for non-ephemeral profile | 888 // Schedule another flush after session restore for non-ephemeral profile |
| 882 // if not restarting. | 889 // if not restarting. |
| 883 if (!ProfileHelper::IsEphemeralUserProfile(user_profile)) | 890 if (!ProfileHelper::IsEphemeralUserProfile(user_profile)) |
| 884 ProfileHelper::Get()->FlushProfile(user_profile); | 891 ProfileHelper::Get()->FlushProfile(user_profile); |
| 885 } | 892 } |
| 886 } | 893 } |
| 887 | 894 |
| 888 void UserSessionManager::OnConnectionTypeChanged( | 895 void UserSessionManager::OnConnectionTypeChanged( |
| 889 net::NetworkChangeNotifier::ConnectionType type) { | 896 net::NetworkChangeNotifier::ConnectionType type) { |
| 890 bool is_running_test = | |
| 891 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 892 ::switches::kTestName) || | |
| 893 base::CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType); | |
| 894 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 897 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 895 if (type == net::NetworkChangeNotifier::CONNECTION_NONE || | 898 if (type == net::NetworkChangeNotifier::CONNECTION_NONE || |
| 896 !user_manager->IsUserLoggedIn() || | 899 !user_manager->IsUserLoggedIn() || |
| 897 !user_manager->IsLoggedInAsUserWithGaiaAccount() || | 900 !user_manager->IsLoggedInAsUserWithGaiaAccount() || |
| 898 user_manager->IsLoggedInAsStub() || is_running_test) { | 901 user_manager->IsLoggedInAsStub() || IsRunningTest()) { |
| 899 return; | 902 return; |
| 900 } | 903 } |
| 901 | 904 |
| 902 // Need to iterate over all users and their OAuth2 session state. | 905 // Need to iterate over all users and their OAuth2 session state. |
| 903 const user_manager::UserList& users = user_manager->GetLoggedInUsers(); | 906 const user_manager::UserList& users = user_manager->GetLoggedInUsers(); |
| 904 for (user_manager::UserList::const_iterator it = users.begin(); | 907 for (user_manager::UserList::const_iterator it = users.begin(); |
| 905 it != users.end(); | 908 it != users.end(); |
| 906 ++it) { | 909 ++it) { |
| 907 if (!(*it)->is_profile_created()) | 910 if (!(*it)->is_profile_created()) |
| 908 continue; | 911 continue; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 920 } else if (should_restore_session) { | 923 } else if (should_restore_session) { |
| 921 pending_signin_restore_sessions_.erase( | 924 pending_signin_restore_sessions_.erase( |
| 922 (*it)->GetAccountId().GetUserEmail()); | 925 (*it)->GetAccountId().GetUserEmail()); |
| 923 RestoreAuthSessionImpl(user_profile, false /* has_auth_cookies */); | 926 RestoreAuthSessionImpl(user_profile, false /* has_auth_cookies */); |
| 924 } | 927 } |
| 925 } | 928 } |
| 926 } | 929 } |
| 927 | 930 |
| 928 void UserSessionManager::OnProfilePrepared(Profile* profile, | 931 void UserSessionManager::OnProfilePrepared(Profile* profile, |
| 929 bool browser_launched) { | 932 bool browser_launched) { |
| 930 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 933 if (!IsRunningTest()) { |
| 931 ::switches::kTestName)) { | |
| 932 // Did not log in (we crashed or are debugging), need to restore Sync. | 934 // Did not log in (we crashed or are debugging), need to restore Sync. |
| 933 // TODO(nkostylev): Make sure that OAuth state is restored correctly for all | 935 // TODO(nkostylev): Make sure that OAuth state is restored correctly for all |
| 934 // users once it is fully multi-profile aware. http://crbug.com/238987 | 936 // users once it is fully multi-profile aware. http://crbug.com/238987 |
| 935 // For now if we have other user pending sessions they'll override OAuth | 937 // For now if we have other user pending sessions they'll override OAuth |
| 936 // session restore for previous users. | 938 // session restore for previous users. |
| 937 RestoreAuthenticationSession(profile); | 939 RestoreAuthenticationSession(profile); |
| 938 } | 940 } |
| 939 | 941 |
| 940 // Restore other user sessions if any. | 942 // Restore other user sessions if any. |
| 941 RestorePendingUserSessions(); | 943 RestorePendingUserSessions(); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 // not be available when unlocking a previously opened profile, or when | 1058 // not be available when unlocking a previously opened profile, or when |
| 1057 // creating a supervised users. However, in these cases the gaia_id should | 1059 // creating a supervised users. However, in these cases the gaia_id should |
| 1058 // be already available in the account tracker. | 1060 // be already available in the account tracker. |
| 1059 std::string gaia_id = user_context.GetGaiaID(); | 1061 std::string gaia_id = user_context.GetGaiaID(); |
| 1060 if (gaia_id.empty()) { | 1062 if (gaia_id.empty()) { |
| 1061 AccountTrackerService* account_tracker = | 1063 AccountTrackerService* account_tracker = |
| 1062 AccountTrackerServiceFactory::GetForProfile(profile); | 1064 AccountTrackerServiceFactory::GetForProfile(profile); |
| 1063 const AccountInfo info = account_tracker->FindAccountInfoByEmail( | 1065 const AccountInfo info = account_tracker->FindAccountInfoByEmail( |
| 1064 user_context.GetAccountId().GetUserEmail()); | 1066 user_context.GetAccountId().GetUserEmail()); |
| 1065 gaia_id = info.gaia; | 1067 gaia_id = info.gaia; |
| 1068 |
| 1069 // Use a fake gaia id for tests that do not have it. |
| 1070 if (IsRunningTest() && gaia_id.empty()) |
| 1071 gaia_id = "fake_gaia_id_" + user_context.GetAccountId().GetUserEmail(); |
| 1072 |
| 1066 DCHECK(!gaia_id.empty()); | 1073 DCHECK(!gaia_id.empty()); |
| 1067 } | 1074 } |
| 1068 | 1075 |
| 1069 // Make sure that the google service username is properly set (we do this | 1076 // Make sure that the google service username is properly set (we do this |
| 1070 // on every sign in, not just the first login, to deal with existing | 1077 // on every sign in, not just the first login, to deal with existing |
| 1071 // profiles that might not have it set yet). | 1078 // profiles that might not have it set yet). |
| 1072 SigninManagerBase* signin_manager = | 1079 SigninManagerBase* signin_manager = |
| 1073 SigninManagerFactory::GetForProfile(profile); | 1080 SigninManagerFactory::GetForProfile(profile); |
| 1074 signin_manager->SetAuthenticatedAccountInfo( | 1081 signin_manager->SetAuthenticatedAccountInfo( |
| 1075 gaia_id, user_context.GetAccountId().GetUserEmail()); | 1082 gaia_id, user_context.GetAccountId().GetUserEmail()); |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 ->browser_policy_connector_chromeos() | 1955 ->browser_policy_connector_chromeos() |
| 1949 ->IsEnterpriseManaged()) { | 1956 ->IsEnterpriseManaged()) { |
| 1950 return false; | 1957 return false; |
| 1951 } | 1958 } |
| 1952 | 1959 |
| 1953 // Do not show end of life notification if this is a guest session | 1960 // Do not show end of life notification if this is a guest session |
| 1954 return !profile->IsGuestSession(); | 1961 return !profile->IsGuestSession(); |
| 1955 } | 1962 } |
| 1956 | 1963 |
| 1957 } // namespace chromeos | 1964 } // namespace chromeos |
| OLD | NEW |