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

Unified Diff: components/user_manager/user_manager_base.cc

Issue 594163002: Restore last used user session after crash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: special case in ChromeUserManagerImpl Created 6 years, 3 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
« no previous file with comments | « components/user_manager/user_manager_base.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/user_manager/user_manager_base.cc
diff --git a/components/user_manager/user_manager_base.cc b/components/user_manager/user_manager_base.cc
index 4bf1731d2953617029b9559e65f9956f495b5f6b..abd329c43327cf3e21c76f98af9de767c9d827e8 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())
« no previous file with comments | « components/user_manager/user_manager_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698