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

Side by Side Diff: chrome/browser/chromeos/login/session/user_session_manager.h

Issue 1097663003: Fetch OAuth2 tokens prior to profile creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove logging Created 5 years, 8 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
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/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "chrome/browser/chromeos/base/locale_util.h" 16 #include "chrome/browser/chromeos/base/locale_util.h"
17 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" 17 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h"
18 #include "chrome/browser/chromeos/login/signin/oauth2_token_fetcher.h"
18 #include "chromeos/dbus/session_manager_client.h" 19 #include "chromeos/dbus/session_manager_client.h"
19 #include "chromeos/login/auth/authenticator.h" 20 #include "chromeos/login/auth/authenticator.h"
21 #include "chromeos/login/auth/login_performer.h"
20 #include "chromeos/login/auth/user_context.h" 22 #include "chromeos/login/auth/user_context.h"
21 #include "components/user_manager/user.h" 23 #include "components/user_manager/user.h"
22 #include "components/user_manager/user_manager.h" 24 #include "components/user_manager/user_manager.h"
23 #include "net/base/network_change_notifier.h" 25 #include "net/base/network_change_notifier.h"
24 #include "ui/base/ime/chromeos/input_method_manager.h" 26 #include "ui/base/ime/chromeos/input_method_manager.h"
25 27
26 class GURL; 28 class GURL;
27 class PrefRegistrySimple; 29 class PrefRegistrySimple;
28 class PrefService; 30 class PrefService;
29 class Profile; 31 class Profile;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // * mark user as logged in and notify observers, 74 // * mark user as logged in and notify observers,
73 // * initialize OAuth2 authentication session, 75 // * initialize OAuth2 authentication session,
74 // * initialize and launch user session based on the user type. 76 // * initialize and launch user session based on the user type.
75 // Also supports restoring active user sessions after browser crash: 77 // Also supports restoring active user sessions after browser crash:
76 // load profile, restore OAuth authentication session etc. 78 // load profile, restore OAuth authentication session etc.
77 class UserSessionManager 79 class UserSessionManager
78 : public OAuth2LoginManager::Observer, 80 : public OAuth2LoginManager::Observer,
79 public net::NetworkChangeNotifier::ConnectionTypeObserver, 81 public net::NetworkChangeNotifier::ConnectionTypeObserver,
80 public base::SupportsWeakPtr<UserSessionManager>, 82 public base::SupportsWeakPtr<UserSessionManager>,
81 public UserSessionManagerDelegate, 83 public UserSessionManagerDelegate,
82 public user_manager::UserManager::UserSessionStateObserver { 84 public user_manager::UserManager::UserSessionStateObserver,
85 public OAuth2TokenFetcher::Delegate {
83 public: 86 public:
84 // Context of StartSession calls. 87 // Context of StartSession calls.
85 typedef enum { 88 typedef enum {
86 // Starting primary user session, through login UI. 89 // Starting primary user session, through login UI.
87 PRIMARY_USER_SESSION, 90 PRIMARY_USER_SESSION,
88 91
89 // Starting secondary user session, through multi-profiles login UI. 92 // Starting secondary user session, through multi-profiles login UI.
90 SECONDARY_USER_SESSION, 93 SECONDARY_USER_SESSION,
91 94
92 // Starting primary user session after browser crash. 95 // Starting primary user session after browser crash.
93 PRIMARY_USER_SESSION_AFTER_CRASH, 96 PRIMARY_USER_SESSION_AFTER_CRASH,
94 97
95 // Starting secondary user session after browser crash. 98 // Starting secondary user session after browser crash.
96 SECONDARY_USER_SESSION_AFTER_CRASH, 99 SECONDARY_USER_SESSION_AFTER_CRASH,
97 } StartSessionType; 100 } StartSessionType;
98 101
102 using FetchOAuth2TokensCallback =
103 base::Callback<void(const UserContext& user_context,
104 LoginPerformer::AuthorizationMode auth_mode)>;
105
99 // Returns UserSessionManager instance. 106 // Returns UserSessionManager instance.
100 static UserSessionManager* GetInstance(); 107 static UserSessionManager* GetInstance();
101 108
102 // Called when user is logged in to override base::DIR_HOME path. 109 // Called when user is logged in to override base::DIR_HOME path.
103 static void OverrideHomedir(); 110 static void OverrideHomedir();
104 111
105 // Registers session related preferences. 112 // Registers session related preferences.
106 static void RegisterPrefs(PrefRegistrySimple* registry); 113 static void RegisterPrefs(PrefRegistrySimple* registry);
107 114
108 // Invoked after the tmpfs is successfully mounted. 115 // Invoked after the tmpfs is successfully mounted.
109 // Asks session_manager to restart Chrome in Guest session mode. 116 // Asks session_manager to restart Chrome in Guest session mode.
110 // |start_url| is an optional URL to be opened in Guest session browser. 117 // |start_url| is an optional URL to be opened in Guest session browser.
111 void CompleteGuestSessionLogin(const GURL& start_url); 118 void CompleteGuestSessionLogin(const GURL& start_url);
112 119
113 // Creates and returns the authenticator to use. 120 // Creates and returns the authenticator to use.
114 // Single Authenticator instance is used for entire login process, 121 // Single Authenticator instance is used for entire login process,
115 // even for multiple retries. Authenticator instance holds reference to 122 // even for multiple retries. Authenticator instance holds reference to
116 // login profile and is later used during fetching of OAuth tokens. 123 // login profile and is later used during fetching of OAuth tokens.
117 scoped_refptr<Authenticator> CreateAuthenticator( 124 scoped_refptr<Authenticator> CreateAuthenticator(
118 AuthStatusConsumer* consumer); 125 AuthStatusConsumer* consumer);
119 126
127 void FetchOAuth2Tokens(const UserContext& user_context,
128 const FetchOAuth2TokensCallback& callback);
129
120 // Start user session given |user_context|. 130 // Start user session given |user_context|.
121 // OnProfilePrepared() will be called on |delegate| once Profile is ready. 131 // OnProfilePrepared() will be called on |delegate| once Profile is ready.
122 void StartSession(const UserContext& user_context, 132 void StartSession(const UserContext& user_context,
123 StartSessionType start_session_type, 133 StartSessionType start_session_type,
124 bool has_auth_cookies, 134 bool has_auth_cookies,
125 bool has_active_session, 135 bool has_active_session,
126 UserSessionManagerDelegate* delegate); 136 UserSessionManagerDelegate* delegate);
127 137
128 // Invalidates |delegate|, which was passed to StartSession method call. 138 // Invalidates |delegate|, which was passed to StartSession method call.
129 void DelegateDeleted(UserSessionManagerDelegate* delegate); 139 void DelegateDeleted(UserSessionManagerDelegate* delegate);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 OAuth2LoginManager::SessionRestoreState state) override; 257 OAuth2LoginManager::SessionRestoreState state) override;
248 258
249 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides: 259 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides:
250 void OnConnectionTypeChanged( 260 void OnConnectionTypeChanged(
251 net::NetworkChangeNotifier::ConnectionType type) override; 261 net::NetworkChangeNotifier::ConnectionType type) override;
252 262
253 // UserSessionManagerDelegate overrides: 263 // UserSessionManagerDelegate overrides:
254 // Used when restoring user sessions after crash. 264 // Used when restoring user sessions after crash.
255 void OnProfilePrepared(Profile* profile, bool browser_launched) override; 265 void OnProfilePrepared(Profile* profile, bool browser_launched) override;
256 266
267 // OAuth2TokenFetcher::Delegate overrides.
268 void OnOAuth2TokensAvailable(
269 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) override;
270 void OnOAuth2TokensFetchFailed() override;
271
257 void ChildAccountStatusReceivedCallback(); 272 void ChildAccountStatusReceivedCallback();
258 273
259 void StopChildStatusObserving(); 274 void StopChildStatusObserving();
260 275
261 void CreateUserSession(const UserContext& user_context, 276 void CreateUserSession(const UserContext& user_context,
262 bool has_auth_cookies); 277 bool has_auth_cookies);
263 void PreStartSession(); 278 void PreStartSession();
264 279
265 // Store any useful UserContext data early on when profile has not been 280 // Store any useful UserContext data early on when profile has not been
266 // created yet and user services were not yet initialized. Can store 281 // created yet and user services were not yet initialized. Can store
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 442
428 // Set of user_id for those users that we should restore authentication 443 // Set of user_id for those users that we should restore authentication
429 // session when notified about online state change. 444 // session when notified about online state change.
430 SigninSessionRestoreStateSet pending_signin_restore_sessions_; 445 SigninSessionRestoreStateSet pending_signin_restore_sessions_;
431 446
432 // Kiosk mode related members. 447 // Kiosk mode related members.
433 // Chrome oauth client id and secret - override values for kiosk mode. 448 // Chrome oauth client id and secret - override values for kiosk mode.
434 std::string chrome_client_id_; 449 std::string chrome_client_id_;
435 std::string chrome_client_secret_; 450 std::string chrome_client_secret_;
436 451
452 std::string oauthlogin_access_token_;
xiyuan 2015/04/20 22:02:41 nit: Consider add this to UserContext.
achuithb 2015/04/21 07:10:21 Done.
453 std::string refresh_token_;
xiyuan 2015/04/20 22:02:41 nit: Use refresh_token field in user_context_.
achuithb 2015/04/21 07:10:21 Done.
454 FetchOAuth2TokensCallback login_callback_;
455
437 // Per-user-session Input Methods states. 456 // Per-user-session Input Methods states.
438 std::map<Profile*, scoped_refptr<input_method::InputMethodManager::State>, 457 std::map<Profile*, scoped_refptr<input_method::InputMethodManager::State>,
439 ProfileCompare> default_ime_states_; 458 ProfileCompare> default_ime_states_;
440 459
441 // Manages Easy unlock cryptohome keys. 460 // Manages Easy unlock cryptohome keys.
442 scoped_ptr<EasyUnlockKeyManager> easy_unlock_key_manager_; 461 scoped_ptr<EasyUnlockKeyManager> easy_unlock_key_manager_;
443 bool running_easy_unlock_key_ops_; 462 bool running_easy_unlock_key_ops_;
444 base::Closure easy_unlock_key_ops_finished_callback_; 463 base::Closure easy_unlock_key_ops_finished_callback_;
445 464
446 // Whether should launch browser, tests may override this value. 465 // Whether should launch browser, tests may override this value.
447 bool should_launch_browser_; 466 bool should_launch_browser_;
448 467
449 // Child account status is necessary for InitializeStartUrls call. 468 // Child account status is necessary for InitializeStartUrls call.
450 bool waiting_for_child_account_status_; 469 bool waiting_for_child_account_status_;
451 470
471 scoped_ptr<OAuth2TokenFetcher> oauth2_token_fetcher_;
472
452 base::WeakPtrFactory<UserSessionManager> weak_factory_; 473 base::WeakPtrFactory<UserSessionManager> weak_factory_;
453 474
454 DISALLOW_COPY_AND_ASSIGN(UserSessionManager); 475 DISALLOW_COPY_AND_ASSIGN(UserSessionManager);
455 }; 476 };
456 477
457 } // namespace chromeos 478 } // namespace chromeos
458 479
459 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_H_ 480 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698