| 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 <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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // static | 213 // static |
| 214 void UserSessionManager::RegisterPrefs(PrefRegistrySimple* registry) { | 214 void UserSessionManager::RegisterPrefs(PrefRegistrySimple* registry) { |
| 215 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); | 215 registry->RegisterStringPref(prefs::kRLZBrand, std::string()); |
| 216 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); | 216 registry->RegisterBooleanPref(prefs::kRLZDisabled, false); |
| 217 } | 217 } |
| 218 | 218 |
| 219 UserSessionManager::UserSessionManager() | 219 UserSessionManager::UserSessionManager() |
| 220 : delegate_(NULL), | 220 : delegate_(NULL), |
| 221 has_auth_cookies_(false), | 221 has_auth_cookies_(false), |
| 222 user_sessions_restored_(false), | 222 user_sessions_restored_(false), |
| 223 user_sessions_restore_in_progress_(false), |
| 223 exit_after_session_restore_(false), | 224 exit_after_session_restore_(false), |
| 224 session_restore_strategy_( | 225 session_restore_strategy_( |
| 225 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { | 226 OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN) { |
| 226 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 227 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 227 user_manager::UserManager::Get()->AddSessionStateObserver(this); | 228 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
| 228 } | 229 } |
| 229 | 230 |
| 230 UserSessionManager::~UserSessionManager() { | 231 UserSessionManager::~UserSessionManager() { |
| 231 // UserManager is destroyed before singletons, so we need to check if it | 232 // UserManager is destroyed before singletons, so we need to check if it |
| 232 // still exists. | 233 // still exists. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } else { | 294 } else { |
| 294 // Even if we're online we should wait till initial | 295 // Even if we're online we should wait till initial |
| 295 // OnConnectionTypeChanged() call. Otherwise starting fetchers too early may | 296 // OnConnectionTypeChanged() call. Otherwise starting fetchers too early may |
| 296 // end up canceling all request when initial network connection type is | 297 // end up canceling all request when initial network connection type is |
| 297 // processed. See http://crbug.com/121643. | 298 // processed. See http://crbug.com/121643. |
| 298 pending_signin_restore_sessions_.insert(user->email()); | 299 pending_signin_restore_sessions_.insert(user->email()); |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 | 302 |
| 302 void UserSessionManager::RestoreActiveSessions() { | 303 void UserSessionManager::RestoreActiveSessions() { |
| 304 user_sessions_restore_in_progress_ = true; |
| 303 DBusThreadManager::Get()->GetSessionManagerClient()->RetrieveActiveSessions( | 305 DBusThreadManager::Get()->GetSessionManagerClient()->RetrieveActiveSessions( |
| 304 base::Bind(&UserSessionManager::OnRestoreActiveSessions, | 306 base::Bind(&UserSessionManager::OnRestoreActiveSessions, |
| 305 base::Unretained(this))); | 307 base::Unretained(this))); |
| 306 } | 308 } |
| 307 | 309 |
| 308 bool UserSessionManager::UserSessionsRestored() const { | 310 bool UserSessionManager::UserSessionsRestored() const { |
| 309 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 311 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 310 return user_sessions_restored_; | 312 return user_sessions_restored_; |
| 311 } | 313 } |
| 312 | 314 |
| 315 bool UserSessionManager::UserSessionsRestoreInProgress() const { |
| 316 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 317 return user_sessions_restore_in_progress_; |
| 318 } |
| 319 |
| 313 void UserSessionManager::InitRlz(Profile* profile) { | 320 void UserSessionManager::InitRlz(Profile* profile) { |
| 314 #if defined(ENABLE_RLZ) | 321 #if defined(ENABLE_RLZ) |
| 315 if (!g_browser_process->local_state()->HasPrefPath(prefs::kRLZBrand)) { | 322 if (!g_browser_process->local_state()->HasPrefPath(prefs::kRLZBrand)) { |
| 316 // Read brand code asynchronously from an OEM data and repost ourselves. | 323 // Read brand code asynchronously from an OEM data and repost ourselves. |
| 317 google_brand::chromeos::InitBrand( | 324 google_brand::chromeos::InitBrand( |
| 318 base::Bind(&UserSessionManager::InitRlz, AsWeakPtr(), profile)); | 325 base::Bind(&UserSessionManager::InitRlz, AsWeakPtr(), profile)); |
| 319 return; | 326 return; |
| 320 } | 327 } |
| 321 base::PostTaskAndReplyWithResult( | 328 base::PostTaskAndReplyWithResult( |
| 322 base::WorkerPool::GetTaskRunner(false).get(), | 329 base::WorkerPool::GetTaskRunner(false).get(), |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 for (it = sessions.begin(); it != sessions.end(); ++it) { | 944 for (it = sessions.begin(); it != sessions.end(); ++it) { |
| 938 if (active_user_id == it->first) | 945 if (active_user_id == it->first) |
| 939 continue; | 946 continue; |
| 940 pending_user_sessions_[it->first] = it->second; | 947 pending_user_sessions_[it->first] = it->second; |
| 941 } | 948 } |
| 942 RestorePendingUserSessions(); | 949 RestorePendingUserSessions(); |
| 943 } | 950 } |
| 944 | 951 |
| 945 void UserSessionManager::RestorePendingUserSessions() { | 952 void UserSessionManager::RestorePendingUserSessions() { |
| 946 if (pending_user_sessions_.empty()) { | 953 if (pending_user_sessions_.empty()) { |
| 954 user_manager::UserManager::Get()->SwitchToLastActiveUser(); |
| 947 NotifyPendingUserSessionsRestoreFinished(); | 955 NotifyPendingUserSessionsRestoreFinished(); |
| 948 return; | 956 return; |
| 949 } | 957 } |
| 950 | 958 |
| 951 // Get next user to restore sessions and delete it from list. | 959 // Get next user to restore sessions and delete it from list. |
| 952 SessionManagerClient::ActiveSessionsMap::const_iterator it = | 960 SessionManagerClient::ActiveSessionsMap::const_iterator it = |
| 953 pending_user_sessions_.begin(); | 961 pending_user_sessions_.begin(); |
| 954 std::string user_id = it->first; | 962 std::string user_id = it->first; |
| 955 std::string user_id_hash = it->second; | 963 std::string user_id_hash = it->second; |
| 956 DCHECK(!user_id.empty()); | 964 DCHECK(!user_id.empty()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 984 true, // has_active_session | 992 true, // has_active_session |
| 985 this); | 993 this); |
| 986 } else { | 994 } else { |
| 987 RestorePendingUserSessions(); | 995 RestorePendingUserSessions(); |
| 988 } | 996 } |
| 989 } | 997 } |
| 990 | 998 |
| 991 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() { | 999 void UserSessionManager::NotifyPendingUserSessionsRestoreFinished() { |
| 992 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 1000 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 993 user_sessions_restored_ = true; | 1001 user_sessions_restored_ = true; |
| 1002 user_sessions_restore_in_progress_ = false; |
| 994 FOR_EACH_OBSERVER(chromeos::UserSessionStateObserver, | 1003 FOR_EACH_OBSERVER(chromeos::UserSessionStateObserver, |
| 995 session_state_observer_list_, | 1004 session_state_observer_list_, |
| 996 PendingUserSessionsRestoreFinished()); | 1005 PendingUserSessionsRestoreFinished()); |
| 997 } | 1006 } |
| 998 | 1007 |
| 999 void UserSessionManager::UpdateEasyUnlockKeys(Profile* user_profile) { | 1008 void UserSessionManager::UpdateEasyUnlockKeys(Profile* user_profile) { |
| 1000 if (!GetEasyUnlockKeyManager()) | 1009 if (!GetEasyUnlockKeyManager()) |
| 1001 return; | 1010 return; |
| 1002 | 1011 |
| 1003 // Only update Easy unlock keys for regular user. | 1012 // Only update Easy unlock keys for regular user. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 return NULL; | 1071 return NULL; |
| 1063 } | 1072 } |
| 1064 | 1073 |
| 1065 if (!easy_unlock_key_manager_) | 1074 if (!easy_unlock_key_manager_) |
| 1066 easy_unlock_key_manager_.reset(new EasyUnlockKeyManager); | 1075 easy_unlock_key_manager_.reset(new EasyUnlockKeyManager); |
| 1067 | 1076 |
| 1068 return easy_unlock_key_manager_.get(); | 1077 return easy_unlock_key_manager_.get(); |
| 1069 } | 1078 } |
| 1070 | 1079 |
| 1071 } // namespace chromeos | 1080 } // namespace chromeos |
| OLD | NEW |