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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
13 #include "chrome/browser/chromeos/base/locale_util.h" 14 #include "chrome/browser/chromeos/base/locale_util.h"
14 #include "chrome/browser/chromeos/login/auth/authenticator.h" 15 #include "chrome/browser/chromeos/login/auth/authenticator.h"
15 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" 16 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
16 #include "chrome/browser/chromeos/login/users/user.h" 17 #include "chrome/browser/chromeos/login/users/user.h"
18 #include "chromeos/dbus/session_manager_client.h"
17 #include "chromeos/login/auth/user_context.h" 19 #include "chromeos/login/auth/user_context.h"
18 #include "net/base/network_change_notifier.h" 20 #include "net/base/network_change_notifier.h"
19 21
20 class PrefRegistrySimple; 22 class PrefRegistrySimple;
21 class PrefService; 23 class PrefService;
22 class Profile; 24 class Profile;
23 25
24 namespace chromeos { 26 namespace chromeos {
25 27
28 class UserSessionManagerDelegate {
29 public:
30 // Called after profile is loaded and prepared for the session.
31 virtual void OnProfilePrepared(Profile* profile) = 0;
32
33 #if defined(ENABLE_RLZ)
34 // Called after post-profile RLZ initialization.
35 virtual void OnRlzInitialized();
36 #endif
37 protected:
38 virtual ~UserSessionManagerDelegate();
39 };
40
41 class UserSessionStateObserver {
42 public:
43 // Called when UserManager finishes restoring user sessions after crash.
44 virtual void PendingUserSessionsRestoreFinished();
45
46 protected:
47 virtual ~UserSessionStateObserver();
48 };
49
26 // UserSessionManager is responsible for starting user session which includes: 50 // UserSessionManager is responsible for starting user session which includes:
27 // load and initialize Profile (including custom Profile preferences), 51 // load and initialize Profile (including custom Profile preferences),
28 // mark user as logged in and notify observers, 52 // mark user as logged in and notify observers,
29 // initialize OAuth2 authentication session, 53 // initialize OAuth2 authentication session,
30 // initialize and launch user session based on the user type. 54 // initialize and launch user session based on the user type.
31 class UserSessionManager : 55 // Also supports restoring active user sessions after browser crash:
32 public OAuth2LoginManager::Observer, 56 // load profile, restore OAuth authentication session etc.
33 public net::NetworkChangeNotifier::ConnectionTypeObserver, 57 class UserSessionManager
34 public base::SupportsWeakPtr<UserSessionManager> { 58 : public OAuth2LoginManager::Observer,
59 public net::NetworkChangeNotifier::ConnectionTypeObserver,
60 public base::SupportsWeakPtr<UserSessionManager>,
61 public UserSessionManagerDelegate {
35 public: 62 public:
36 class Delegate {
37 public:
38 // Called after profile is loaded and prepared for the session.
39 virtual void OnProfilePrepared(Profile* profile) = 0;
40
41 #if defined(ENABLE_RLZ)
42 // Called after post-profile RLZ initialization.
43 virtual void OnRlzInitialized() {}
44 #endif
45 protected:
46 virtual ~Delegate() {}
47 };
48
49 // Returns UserSessionManager instance. 63 // Returns UserSessionManager instance.
50 static UserSessionManager* GetInstance(); 64 static UserSessionManager* GetInstance();
51 65
52 // Called when user is logged in to override base::DIR_HOME path. 66 // Called when user is logged in to override base::DIR_HOME path.
53 static void OverrideHomedir(); 67 static void OverrideHomedir();
54 68
55 // Registers session related preferences. 69 // Registers session related preferences.
56 static void RegisterPrefs(PrefRegistrySimple* registry); 70 static void RegisterPrefs(PrefRegistrySimple* registry);
57 71
58 // Start user session given |user_context| and |authenticator| which holds 72 // Start user session given |user_context| and |authenticator| which holds
59 // authentication context (profile). 73 // authentication context (profile).
60 void StartSession(const UserContext& user_context, 74 void StartSession(const UserContext& user_context,
61 scoped_refptr<Authenticator> authenticator, 75 scoped_refptr<Authenticator> authenticator,
62 bool has_auth_cookies, 76 bool has_auth_cookies,
63 bool has_active_session, 77 bool has_active_session,
64 Delegate* delegate); 78 UserSessionManagerDelegate* delegate);
65 79
66 // Perform additional actions once system wide notification 80 // Perform additional actions once system wide notification
67 // "UserLoggedIn" has been sent. 81 // "UserLoggedIn" has been sent.
68 void PerformPostUserLoggedInActions(); 82 void PerformPostUserLoggedInActions();
69 83
70 // Restores authentication session after crash. 84 // Restores authentication session after crash.
71 void RestoreAuthenticationSession(Profile* profile); 85 void RestoreAuthenticationSession(Profile* profile);
72 86
87 // Usually is called when Chrome is restarted after a crash and there's an
88 // active session. First user (one that is passed with --login-user) Chrome
89 // session has been already restored at this point. This method asks session
90 // manager for all active user sessions, marks them as logged in
91 // and notifies observers.
92 void RestoreActiveSessions();
93
94 // Returns true iff browser has been restarted after crash and UserManager
95 // finished restoring user sessions.
96 bool UserSessionsRestored() const;
97
73 // Initialize RLZ. 98 // Initialize RLZ.
74 void InitRlz(Profile* profile); 99 void InitRlz(Profile* profile);
75 100
76 // Returns true when the browser has crashed and restarted during the current 101 // Returns true when the browser has crashed and restarted during the current
77 // user's session. 102 // user's session.
78 bool HasBrowserRestarted() const; 103 bool HasBrowserRestarted() const;
79 104
80 // TODO(nkostylev): Drop these methods once LoginUtilsImpl::AttemptRestart() 105 // TODO(nkostylev): Drop these methods once LoginUtilsImpl::AttemptRestart()
81 // is migrated. 106 // is migrated.
82 OAuth2LoginManager::SessionRestoreStrategy GetSigninSessionRestoreStrategy(); 107 OAuth2LoginManager::SessionRestoreStrategy GetSigninSessionRestoreStrategy();
(...skipping 16 matching lines...) Expand all
99 const std::string& chrome_client_secret); 124 const std::string& chrome_client_secret);
100 125
101 // Changes browser locale (selects best suitable locale from different 126 // Changes browser locale (selects best suitable locale from different
102 // user settings). Returns true if callback will be called. 127 // user settings). Returns true if callback will be called.
103 // Returns true if callback will be called. 128 // Returns true if callback will be called.
104 bool RespectLocalePreference( 129 bool RespectLocalePreference(
105 Profile* profile, 130 Profile* profile,
106 const User* user, 131 const User* user,
107 scoped_ptr<locale_util::SwitchLanguageCallback> callback) const; 132 scoped_ptr<locale_util::SwitchLanguageCallback> callback) const;
108 133
134 void AddSessionStateObserver(UserSessionStateObserver* observer);
135 void RemoveSessionStateObserver(UserSessionStateObserver* observer);
136
109 private: 137 private:
110 friend struct DefaultSingletonTraits<UserSessionManager>; 138 friend struct DefaultSingletonTraits<UserSessionManager>;
111 139
112 typedef std::set<std::string> SessionRestoreStateSet; 140 typedef std::set<std::string> SigninSessionRestoreStateSet;
113 141
114 UserSessionManager(); 142 UserSessionManager();
115 virtual ~UserSessionManager(); 143 virtual ~UserSessionManager();
116 144
117 // OAuth2LoginManager::Observer overrides: 145 // OAuth2LoginManager::Observer overrides:
118 virtual void OnSessionRestoreStateChanged( 146 virtual void OnSessionRestoreStateChanged(
119 Profile* user_profile, 147 Profile* user_profile,
120 OAuth2LoginManager::SessionRestoreState state) OVERRIDE; 148 OAuth2LoginManager::SessionRestoreState state) OVERRIDE;
121 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) OVERRIDE; 149 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) OVERRIDE;
122 150
123 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides: 151 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides:
124 virtual void OnConnectionTypeChanged( 152 virtual void OnConnectionTypeChanged(
125 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 153 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
126 154
155 // UserSessionManagerDelegate overrides:
156 // Used when restoring user sessions after crash.
157 virtual void OnProfilePrepared(Profile* profile) OVERRIDE;
158
127 void CreateUserSession(const UserContext& user_context, 159 void CreateUserSession(const UserContext& user_context,
128 bool has_auth_cookies); 160 bool has_auth_cookies);
129 void PreStartSession(); 161 void PreStartSession();
130 void StartCrosSession(); 162 void StartCrosSession();
131 void NotifyUserLoggedIn(); 163 void NotifyUserLoggedIn();
132 void PrepareProfile(); 164 void PrepareProfile();
133 165
134 // Callback for asynchronous profile creation. 166 // Callback for asynchronous profile creation.
135 void OnProfileCreated(const std::string& user_id, 167 void OnProfileCreated(const std::string& user_id,
136 bool is_incognito_profile, 168 bool is_incognito_profile,
(...skipping 26 matching lines...) Expand all
163 void RestoreAuthSessionImpl(Profile* profile, 195 void RestoreAuthSessionImpl(Profile* profile,
164 bool restore_from_auth_cookies); 196 bool restore_from_auth_cookies);
165 197
166 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. 198 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled.
167 void InitRlzImpl(Profile* profile, bool disabled); 199 void InitRlzImpl(Profile* profile, bool disabled);
168 200
169 // Get the NSS cert database for the primary user and start certificate 201 // Get the NSS cert database for the primary user and start certificate
170 // loader with it. 202 // loader with it.
171 void InitializeCertsForPrimaryUser(Profile* profile); 203 void InitializeCertsForPrimaryUser(Profile* profile);
172 204
173 Delegate* delegate_; 205 // Callback to process RetrieveActiveSessions() request results.
206 void OnRestoreActiveSessions(
207 const SessionManagerClient::ActiveSessionsMap& sessions,
208 bool success);
209
210 // Called by OnRestoreActiveSessions() when there're user sessions in
211 // |pending_user_sessions_| that has to be restored one by one.
212 // Also called after first user session from that list is restored and so on.
213 // Process continues till |pending_user_sessions_| map is not empty.
214 void RestorePendingUserSessions();
215
216 // Notifies observers that user pending sessions restore has finished.
217 void NotifyPendingUserSessionsRestoreFinished();
218
219 UserSessionManagerDelegate* delegate_;
174 220
175 // Authentication/user context. 221 // Authentication/user context.
176 UserContext user_context_; 222 UserContext user_context_;
177 scoped_refptr<Authenticator> authenticator_; 223 scoped_refptr<Authenticator> authenticator_;
178 224
179 // True if the authentication context's cookie jar contains authentication 225 // True if the authentication context's cookie jar contains authentication
180 // cookies from the authentication extension login flow. 226 // cookies from the authentication extension login flow.
181 bool has_auth_cookies_; 227 bool has_auth_cookies_;
182 228
229 // Active user session restoration related members.
230
231 // True is user sessions has been restored after crash.
232 // On a normal boot then login into user sessions this will be false.
233 bool user_sessions_restored_;
234
235 // User sessions that have to be restored after browser crash.
236 // [user_id] > [user_id_hash]
237 SessionManagerClient::ActiveSessionsMap pending_user_sessions_;
238
239 ObserverList<UserSessionStateObserver> session_state_observer_list_;
240
183 // OAuth2 session related members. 241 // OAuth2 session related members.
184 242
185 // True if we should restart chrome right after session restore. 243 // True if we should restart chrome right after session restore.
186 bool exit_after_session_restore_; 244 bool exit_after_session_restore_;
187 245
188 // Sesion restore strategy. 246 // Sesion restore strategy.
189 OAuth2LoginManager::SessionRestoreStrategy session_restore_strategy_; 247 OAuth2LoginManager::SessionRestoreStrategy session_restore_strategy_;
190 248
191 // OAuth2 refresh token for session restore. 249 // OAuth2 refresh token for session restore.
192 std::string oauth2_refresh_token_; 250 std::string oauth2_refresh_token_;
193 251
194 // Set of user_id for those users that we should restore authentication 252 // Set of user_id for those users that we should restore authentication
195 // session when notified about online state change. 253 // session when notified about online state change.
196 SessionRestoreStateSet pending_restore_sessions_; 254 SigninSessionRestoreStateSet pending_signin_restore_sessions_;
197 255
198 // Kiosk mode related members. 256 // Kiosk mode related members.
199 // Chrome oauth client id and secret - override values for kiosk mode. 257 // Chrome oauth client id and secret - override values for kiosk mode.
200 std::string chrome_client_id_; 258 std::string chrome_client_id_;
201 std::string chrome_client_secret_; 259 std::string chrome_client_secret_;
202 260
203 DISALLOW_COPY_AND_ASSIGN(UserSessionManager); 261 DISALLOW_COPY_AND_ASSIGN(UserSessionManager);
204 }; 262 };
205 263
206 } // namespace chromeos 264 } // namespace chromeos
207 265
208 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_H_ 266 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_H_
OLDNEW
« 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