summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authornkostylev <nkostylev@chromium.org>2014-09-26 02:03:47 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-26 09:04:02 +0000
commit5df7e99907b42603cb0f23e8a87daf49073e2c64 (patch)
treea90782c985acca6cc5b32bfd6fbf5c8617ca06ff /components
parent923cc8ab4abcbcdff8b38f35b4575bb4343cb93b (diff)
downloadchromium_src-5df7e99907b42603cb0f23e8a87daf49073e2c64.zip
chromium_src-5df7e99907b42603cb0f23e8a87daf49073e2c64.tar.gz
chromium_src-5df7e99907b42603cb0f23e8a87daf49073e2c64.tar.bz2
Restore last used user session after crash
Since primary user profile is loaded synchronously its session will always show up first. Once all users profiles have been loaded we'll switch to the session of the user that was active before crash has happened. BUG=409226 Review URL: https://codereview.chromium.org/594163002 Cr-Commit-Position: refs/heads/master@{#296907}
Diffstat (limited to 'components')
-rw-r--r--components/user_manager/user_manager.h4
-rw-r--r--components/user_manager/user_manager_base.cc30
-rw-r--r--components/user_manager/user_manager_base.h7
3 files changed, 41 insertions, 0 deletions
diff --git a/components/user_manager/user_manager.h b/components/user_manager/user_manager.h
index 14b5d4f..a37d6f8 100644
--- a/components/user_manager/user_manager.h
+++ b/components/user_manager/user_manager.h
@@ -145,6 +145,10 @@ class USER_MANAGER_EXPORT UserManager {
// Switches to active user identified by |user_id|. User has to be logged in.
virtual void SwitchActiveUser(const std::string& user_id) = 0;
+ // Switches to the last active user (called after crash happens and session
+ // restore has completed).
+ virtual void SwitchToLastActiveUser() = 0;
+
// Called when browser session is started i.e. after
// browser_creator.LaunchBrowser(...) was called after user sign in.
// When user is at the image screen IsUserLoggedIn() will return true
diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc
index 4bf1731..abd329c 100644
--- a/components/user_manager/user_manager_base.cc
+++ b/components/user_manager/user_manager_base.cc
@@ -62,6 +62,11 @@ const char kUserForceOnlineSignin[] = "UserForceOnlineSignin";
// kiosk, public account, etc.).
const char kLastLoggedInRegularUser[] = "LastLoggedInRegularUser";
+// A string pref containing the ID of the last active user.
+// In case of browser crash, this pref will be used to set active user after
+// session restore.
+const char kLastActiveUser[] = "LastActiveUser";
+
// Upper bound for a histogram metric reporting the amount of time between
// one regular user logging out and a different regular user logging in.
const int kLogoutToLoginDelayMaxSec = 1800;
@@ -94,6 +99,7 @@ void UserManagerBase::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(kUserDisplayEmail);
registry->RegisterDictionaryPref(kUserOAuthTokenStatus);
registry->RegisterDictionaryPref(kUserForceOnlineSignin);
+ registry->RegisterStringPref(kLastActiveUser, std::string());
}
UserManagerBase::UserManagerBase(
@@ -108,6 +114,7 @@ UserManagerBase::UserManagerBase(
is_current_user_ephemeral_regular_user_(false),
ephemeral_users_enabled_(false),
manager_creation_time_(base::TimeTicks::Now()),
+ last_session_active_user_initialized_(false),
task_runner_(task_runner),
blocking_task_runner_(blocking_task_runner),
weak_factory_(this) {
@@ -153,6 +160,11 @@ void UserManagerBase::UserLoggedIn(const std::string& user_id,
bool browser_restart) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
+ if (!last_session_active_user_initialized_) {
+ last_session_active_user_ = GetLocalState()->GetString(kLastActiveUser);
+ last_session_active_user_initialized_ = true;
+ }
+
User* user = FindUserInListAndModify(user_id);
if (active_user_ && user) {
user->set_is_logged_in(true);
@@ -256,6 +268,17 @@ void UserManagerBase::SwitchActiveUser(const std::string& user_id) {
NotifyActiveUserChanged(active_user_);
}
+void UserManagerBase::SwitchToLastActiveUser() {
+ if (last_session_active_user_.empty())
+ return;
+
+ if (GetActiveUser()->email() != last_session_active_user_)
+ SwitchActiveUser(last_session_active_user_);
+
+ // Make sure that this function gets run only once.
+ last_session_active_user_.clear();
+}
+
void UserManagerBase::SessionStarted() {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
session_started_ = true;
@@ -886,6 +909,10 @@ void UserManagerBase::RemoveNonCryptohomeData(const std::string& user_id) {
DictionaryPrefUpdate prefs_force_online_update(prefs, kUserForceOnlineSignin);
prefs_force_online_update->RemoveWithoutPathExpansion(user_id, NULL);
+
+ std::string last_active_user = GetLocalState()->GetString(kLastActiveUser);
+ if (user_id == last_active_user)
+ GetLocalState()->SetString(kLastActiveUser, std::string());
}
User* UserManagerBase::RemoveRegularOrSupervisedUserFromList(
@@ -967,6 +994,9 @@ void UserManagerBase::UpdateLoginState() {
}
void UserManagerBase::SetLRUUser(User* user) {
+ GetLocalState()->SetString(kLastActiveUser, user->email());
+ GetLocalState()->CommitPendingWrite();
+
UserList::iterator it =
std::find(lru_logged_in_users_.begin(), lru_logged_in_users_.end(), user);
if (it != lru_logged_in_users_.end())
diff --git a/components/user_manager/user_manager_base.h b/components/user_manager/user_manager_base.h
index b117687..9da1cee 100644
--- a/components/user_manager/user_manager_base.h
+++ b/components/user_manager/user_manager_base.h
@@ -52,6 +52,7 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
const std::string& user_id_hash,
bool browser_restart) OVERRIDE;
virtual void SwitchActiveUser(const std::string& user_id) OVERRIDE;
+ virtual void SwitchToLastActiveUser() OVERRIDE;
virtual void SessionStarted() OVERRIDE;
virtual void RemoveUser(const std::string& user_id,
RemoveUserDelegate* delegate) OVERRIDE;
@@ -369,6 +370,12 @@ class USER_MANAGER_EXPORT UserManagerBase : public UserManager {
// as soon as user's profile is loaded.
std::string pending_user_switch_;
+ // ID of the user that was active in the previous session.
+ // Preference value is stored here before first user signs in
+ // because pref will be overidden once session restore starts.
+ std::string last_session_active_user_;
+ bool last_session_active_user_initialized_;
+
// TaskRunner for UI thread.
scoped_refptr<base::TaskRunner> task_runner_;