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

Unified Diff: chrome/browser/chromeos/login/session/user_session_manager.h

Issue 385633002: UserManager refactoring: move active user session restoration to UserSessionManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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/session/user_session_manager.h
diff --git a/chrome/browser/chromeos/login/session/user_session_manager.h b/chrome/browser/chromeos/login/session/user_session_manager.h
index 945dc663392079d48596969fb0bd87b8629861e2..b370267328b324168c4103887a02b3c2f110fda5 100644
--- a/chrome/browser/chromeos/login/session/user_session_manager.h
+++ b/chrome/browser/chromeos/login/session/user_session_manager.h
@@ -10,10 +10,12 @@
#include "base/basictypes.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
#include "chrome/browser/chromeos/base/locale_util.h"
#include "chrome/browser/chromeos/login/auth/authenticator.h"
#include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
#include "chrome/browser/chromeos/login/users/user.h"
+#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/login/auth/user_context.h"
#include "net/base/network_change_notifier.h"
@@ -23,29 +25,41 @@ class Profile;
namespace chromeos {
+class UserSessionManagerDelegate {
+ public:
+ // Called after profile is loaded and prepared for the session.
+ virtual void OnProfilePrepared(Profile* profile) = 0;
+
+#if defined(ENABLE_RLZ)
+ // Called after post-profile RLZ initialization.
+ virtual void OnRlzInitialized();
+#endif
+ protected:
+ virtual ~UserSessionManagerDelegate();
+};
+
+class UserSessionStateObserver {
+ public:
+ // Called when UserManager finishes restoring user sessions after crash.
+ virtual void PendingUserSessionsRestoreFinished();
+
+ protected:
+ virtual ~UserSessionStateObserver();
+};
+
// UserSessionManager is responsible for starting user session which includes:
// load and initialize Profile (including custom Profile preferences),
// mark user as logged in and notify observers,
// initialize OAuth2 authentication session,
// initialize and launch user session based on the user type.
-class UserSessionManager :
- public OAuth2LoginManager::Observer,
- public net::NetworkChangeNotifier::ConnectionTypeObserver,
- public base::SupportsWeakPtr<UserSessionManager> {
+// Also supports restoring active user sessions after browser crash:
+// load profile, restore OAuth authentication session etc.
+class UserSessionManager
+ : public OAuth2LoginManager::Observer,
+ public net::NetworkChangeNotifier::ConnectionTypeObserver,
+ public base::SupportsWeakPtr<UserSessionManager>,
+ public UserSessionManagerDelegate {
public:
- class Delegate {
- public:
- // Called after profile is loaded and prepared for the session.
- virtual void OnProfilePrepared(Profile* profile) = 0;
-
-#if defined(ENABLE_RLZ)
- // Called after post-profile RLZ initialization.
- virtual void OnRlzInitialized() {}
-#endif
- protected:
- virtual ~Delegate() {}
- };
-
// Returns UserSessionManager instance.
static UserSessionManager* GetInstance();
@@ -61,7 +75,7 @@ class UserSessionManager :
scoped_refptr<Authenticator> authenticator,
bool has_auth_cookies,
bool has_active_session,
- Delegate* delegate);
+ UserSessionManagerDelegate* delegate);
// Perform additional actions once system wide notification
// "UserLoggedIn" has been sent.
@@ -70,6 +84,17 @@ class UserSessionManager :
// Restores authentication session after crash.
void RestoreAuthenticationSession(Profile* profile);
+ // Usually is called when Chrome is restarted after a crash and there's an
+ // active session. First user (one that is passed with --login-user) Chrome
+ // session has been already restored at this point. This method asks session
+ // manager for all active user sessions, marks them as logged in
+ // and notifies observers.
+ void RestoreActiveSessions();
+
+ // Returns true iff browser has been restarted after crash and UserManager
+ // finished restoring user sessions.
+ bool UserSessionsRestored() const;
+
// Initialize RLZ.
void InitRlz(Profile* profile);
@@ -106,10 +131,13 @@ class UserSessionManager :
const User* user,
scoped_ptr<locale_util::SwitchLanguageCallback> callback) const;
+ void AddSessionStateObserver(UserSessionStateObserver* observer);
+ void RemoveSessionStateObserver(UserSessionStateObserver* observer);
+
private:
friend struct DefaultSingletonTraits<UserSessionManager>;
- typedef std::set<std::string> SessionRestoreStateSet;
+ typedef std::set<std::string> SigninSessionRestoreStateSet;
UserSessionManager();
virtual ~UserSessionManager();
@@ -124,6 +152,10 @@ class UserSessionManager :
virtual void OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
+ // UserSessionManagerDelegate overrides:
+ // Used when restoring user sessions after crash.
+ virtual void OnProfilePrepared(Profile* profile) OVERRIDE;
+
void CreateUserSession(const UserContext& user_context,
bool has_auth_cookies);
void PreStartSession();
@@ -170,7 +202,21 @@ class UserSessionManager :
// loader with it.
void InitializeCertsForPrimaryUser(Profile* profile);
- Delegate* delegate_;
+ // Callback to process RetrieveActiveSessions() request results.
+ void OnRestoreActiveSessions(
+ const SessionManagerClient::ActiveSessionsMap& sessions,
+ bool success);
+
+ // Called by OnRestoreActiveSessions() when there're user sessions in
+ // |pending_user_sessions_| that has to be restored one by one.
+ // Also called after first user session from that list is restored and so on.
+ // Process continues till |pending_user_sessions_| map is not empty.
+ void RestorePendingUserSessions();
+
+ // Notifies observers that user pending sessions restore has finished.
+ void NotifyPendingUserSessionsRestoreFinished();
+
+ UserSessionManagerDelegate* delegate_;
// Authentication/user context.
UserContext user_context_;
@@ -180,6 +226,18 @@ class UserSessionManager :
// cookies from the authentication extension login flow.
bool has_auth_cookies_;
+ // Active user session restoration related members.
+
+ // True is user sessions has been restored after crash.
+ // On a normal boot then login into user sessions this will be false.
+ bool user_sessions_restored_;
+
+ // User sessions that have to be restored after browser crash.
+ // [user_id] > [user_id_hash]
+ SessionManagerClient::ActiveSessionsMap pending_user_sessions_;
+
+ ObserverList<UserSessionStateObserver> session_state_observer_list_;
+
// OAuth2 session related members.
// True if we should restart chrome right after session restore.
@@ -193,7 +251,7 @@ class UserSessionManager :
// Set of user_id for those users that we should restore authentication
// session when notified about online state change.
- SessionRestoreStateSet pending_restore_sessions_;
+ SigninSessionRestoreStateSet pending_signin_restore_sessions_;
// Kiosk mode related members.
// Chrome oauth client id and secret - override values for kiosk mode.
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.cc ('k') | chrome/browser/chromeos/login/session/user_session_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698