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

Unified Diff: chrome/browser/chromeos/login/user_manager_impl.cc

Issue 15929005: [CrOS multi-profiles] Restore user sessions after crash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/user_manager_impl.cc
diff --git a/chrome/browser/chromeos/login/user_manager_impl.cc b/chrome/browser/chromeos/login/user_manager_impl.cc
index b82a92c992a559db6f825227f2bebac0fa01caf8..3e31392d76ba026b5be282dc4a5aafee56f1f5c7 100644
--- a/chrome/browser/chromeos/login/user_manager_impl.cc
+++ b/chrome/browser/chromeos/login/user_manager_impl.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/login/default_pinned_apps_field_trial.h"
#include "chrome/browser/chromeos/login/login_display.h"
+#include "chrome/browser/chromeos/login/login_utils.h"
#include "chrome/browser/chromeos/login/remove_user_delegate.h"
#include "chrome/browser/chromeos/login/user_image_manager_impl.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
@@ -846,6 +847,23 @@ void UserManagerImpl::NotifyLocalStateChanged() {
LocalStateChanged(this));
}
+void UserManagerImpl::OnProfilePrepared(Profile* profile) {
+ LoginUtils::Get()->DoBrowserLaunch(profile,
+ NULL); // host_, not needed here
+
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestName)) {
+ // Did not log in (we crashed or are debugging), need to restore Sync.
+ // TODO(nkostylev): Make sure that OAuth state is restored correctly for all
+ // users once it is fully multi-profile aware. http://crbug.com/238987
+ // For now if we have other user pending sessions they'll override OAuth
+ // session restore for previous users.
+ LoginUtils::Get()->RestoreAuthenticationSession(profile);
+ }
+
+ // Restore other user sessions if any.
+ RestorePendingUserSessions();
+}
+
void UserManagerImpl::EnsureUsersLoaded() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!g_browser_process || !g_browser_process->local_state())
@@ -1545,13 +1563,65 @@ void UserManagerImpl::SetLRUUser(User* user) {
void UserManagerImpl::OnRestoreActiveSessions(
const SessionManagerClient::ActiveSessionsMap& sessions,
bool success) {
- // TODO(nkostylev): Restore all user sessions (in the background).
- // This requires first refactoring this flow out of LoginUtils.
- // 1. UserManager::UserLoggedIn()
- // 2. InitSessionRestoreStrategy() (OAuth)
- // 2. ProfileManager::CreateDefaultProfileAsync()
- // 3. InitProfilePreferences
- // 4. chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
+ if (!success) {
+ LOG(ERROR) << "Could not get list of active user sessions after crash.";
Dmitry Polukhin 2013/05/27 13:51:04 Should we continue working or force sign out is mo
Nikita (slow) 2013/05/27 14:22:06 Done.
+ return;
+ }
+
+ // One profile has been already loaded on browser start.
+ DCHECK(GetLoggedInUsers().size() == 1);
+ DCHECK(GetActiveUser());
+ std::string active_user_id = GetActiveUser()->email();
+
+ SessionManagerClient::ActiveSessionsMap::const_iterator it;
+ for (it = sessions.begin(); it != sessions.end(); ++it) {
+ if (active_user_id == it->first)
+ continue;
+ pending_user_sessions_[it->first] = it->second;
+ }
+ RestorePendingUserSessions();
+}
+
+void UserManagerImpl::RestorePendingUserSessions() {
+ if (pending_user_sessions_.empty())
+ return;
+
+ // Get next user to restore sessions and delete it from list.
+ SessionManagerClient::ActiveSessionsMap::const_iterator it =
+ pending_user_sessions_.begin();
+ std::string user_id = it->first;
+ std::string user_id_hash = it->second;
+ DCHECK(!user_id.empty());
+ DCHECK(!user_id_hash.empty());
+ pending_user_sessions_.erase(user_id);
+
+ // Check that this user is not logged in yet
+ // i.e. session was not restored twice.
+ UserList logged_in_users = GetLoggedInUsers();
+ bool user_already_logged_in = false;
+ for (UserList::const_iterator it = logged_in_users.begin();
+ it != logged_in_users.end(); ++it) {
+ const User* user = (*it);
+ if (user->email() == user_id) {
+ user_already_logged_in = true;
+ break;
+ }
+ }
+ DCHECK(user_already_logged_in);
+
+ if (!user_already_logged_in) {
+ // Will call OnProfilePrepared() once profile has been loaded.
+ LoginUtils::Get()->PrepareProfile(UserContext(user_id,
+ std::string(), // password
+ std::string(), // auth_code
+ user_id_hash),
+ std::string(), // display_email
+ false, // using_oauth
+ false, // has_cookies
+ this);
+ } else {
+ RestorePendingUserSessions();
+ }
}
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698