Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_SESSION_MANAGER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_SESSION_MANAGER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/singleton.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "chrome/browser/chromeos/login/auth/authenticator.h" | |
| 14 #include "chrome/browser/chromeos/login/auth/user_context.h" | |
| 15 #include "chrome/browser/chromeos/login/signin/oauth2_login_manager.h" | |
| 16 #include "net/base/network_change_notifier.h" | |
| 17 | |
| 18 class PrefRegistrySimple; | |
| 19 class PrefService; | |
| 20 class Profile; | |
| 21 | |
| 22 namespace chromeos { | |
| 23 | |
| 24 class SessionManager : | |
| 25 public OAuth2LoginManager::Observer, | |
| 26 public net::NetworkChangeNotifier::ConnectionTypeObserver, | |
| 27 public base::SupportsWeakPtr<SessionManager> { | |
| 28 public: | |
| 29 class Delegate { | |
| 30 public: | |
| 31 // Called after profile is loaded and prepared for the session. | |
| 32 virtual void OnProfilePrepared(Profile* profile) = 0; | |
| 33 | |
| 34 #if defined(ENABLE_RLZ) | |
| 35 // Called after post-profile RLZ initialization. | |
| 36 virtual void OnRlzInitialized() {} | |
| 37 #endif | |
| 38 protected: | |
| 39 virtual ~Delegate() {} | |
| 40 }; | |
| 41 | |
| 42 // Returns SessionManager instance. | |
| 43 static SessionManager* GetInstance(); | |
| 44 | |
| 45 // Registers session related preferences. | |
| 46 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 47 | |
| 48 // OAuth2LoginManager::Observer overrides: | |
| 49 virtual void OnSessionRestoreStateChanged( | |
| 50 Profile* user_profile, | |
| 51 OAuth2LoginManager::SessionRestoreState state) OVERRIDE; | |
| 52 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) OVERRIDE; | |
| 53 | |
| 54 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides: | |
| 55 virtual void OnConnectionTypeChanged( | |
| 56 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
| 57 | |
| 58 void StartSession(const UserContext& user_context, | |
|
Denis Kuznetsov (DE-MUC)
2014/06/11 15:38:50
nit:comment
Nikita (slow)
2014/06/11 16:44:02
Done.
| |
| 59 scoped_refptr<Authenticator> authenticator, | |
| 60 bool has_cookies, | |
| 61 bool has_active_session, | |
| 62 Delegate* delegate); | |
| 63 | |
| 64 // Restores authentication session after crash. | |
| 65 void RestoreAuthenticationSession(Profile* profile); | |
| 66 | |
| 67 // Initialize RLZ. | |
| 68 void InitRlz(Profile* profile); | |
| 69 | |
| 70 // TODO(nkostylev): Drop these methods once LoginUtilsImpl::AttemptRestart() | |
| 71 // is migrated. | |
| 72 OAuth2LoginManager::SessionRestoreStrategy GetSigninSessionRestoreStrategy(); | |
| 73 bool exit_after_session_restore() { return exit_after_session_restore_; } | |
| 74 void set_exit_after_session_restore(bool value) { | |
| 75 exit_after_session_restore_ = value; | |
| 76 } | |
| 77 | |
| 78 // Invoked when the user is logging in for the first time, or is logging in as | |
| 79 // a guest user. | |
| 80 static void SetFirstLoginPrefs(PrefService* prefs); | |
| 81 | |
| 82 private: | |
| 83 friend struct DefaultSingletonTraits<SessionManager>; | |
| 84 | |
| 85 typedef std::set<std::string> SessionRestoreStateSet; | |
| 86 | |
| 87 SessionManager(); | |
| 88 virtual ~SessionManager(); | |
| 89 | |
| 90 void CreateUserSession(const UserContext& user_context, | |
| 91 bool has_cookies); | |
| 92 void PreStartSession(); | |
| 93 void StartCrosSession(); | |
| 94 void NotifyUserLoggedIn(); | |
| 95 void PrepareProfile(); | |
| 96 | |
| 97 // Callback for asynchronous profile creation. | |
| 98 void OnProfileCreated(const std::string& user_id, | |
| 99 bool is_incognito_profile, | |
| 100 Profile* profile, | |
| 101 Profile::CreateStatus status); | |
| 102 | |
| 103 // Callback for Profile::CREATE_STATUS_CREATED profile state. | |
| 104 // Initializes basic preferences for newly created profile. Any other | |
| 105 // early profile initialization that needs to happen before | |
| 106 // ProfileManager::DoFinalInit() gets called is done here. | |
| 107 void InitProfilePreferences(Profile* profile, | |
| 108 const std::string& email); | |
| 109 | |
| 110 // Callback for Profile::CREATE_STATUS_INITIALIZED profile state. | |
| 111 // Profile is created, extensions and promo resources are initialized. | |
| 112 void UserProfileInitialized(Profile* profile, bool is_incognito_profile); | |
| 113 | |
| 114 // Callback to resume profile creation after transferring auth data from | |
| 115 // the authentication profile. | |
| 116 void CompleteProfileCreateAfterAuthTransfer(Profile* profile); | |
| 117 | |
| 118 // Finalized profile preparation. | |
| 119 void FinalizePrepareProfile(Profile* profile); | |
| 120 | |
| 121 // Initializes member variables needed for session restore process via | |
| 122 // OAuthLoginManager. | |
| 123 void InitSessionRestoreStrategy(); | |
| 124 | |
| 125 // Restores GAIA auth cookies for the created user profile from OAuth2 token. | |
| 126 void RestoreAuthSessionImpl(Profile* profile, | |
| 127 bool restore_from_auth_cookies); | |
| 128 | |
| 129 // Initializes RLZ. If |disabled| is true, RLZ pings are disabled. | |
| 130 void InitRlzImpl(Profile* profile, bool disabled); | |
| 131 | |
| 132 Delegate* delegate_; | |
| 133 | |
| 134 // Authentication/user context. | |
| 135 UserContext user_context_; | |
| 136 scoped_refptr<Authenticator> authenticator_; | |
| 137 | |
| 138 // True if the authentication context cookie jar should contain | |
| 139 // authentication cookies from the authentication extension log in flow. | |
| 140 bool has_web_auth_cookies_; | |
| 141 | |
| 142 // OAuth2 session related members. | |
| 143 | |
| 144 // True if we should restart chrome right after session restore. | |
| 145 bool exit_after_session_restore_; | |
| 146 | |
| 147 // Sesion restore strategy. | |
| 148 OAuth2LoginManager::SessionRestoreStrategy session_restore_strategy_; | |
| 149 | |
| 150 // OAuth2 refresh token for session restore. | |
| 151 std::string oauth2_refresh_token_; | |
| 152 | |
| 153 // Set of user_id for those users that we should restore authentication | |
| 154 // session when notified about online state change. | |
| 155 SessionRestoreStateSet pending_restore_sessions_; | |
| 156 | |
| 157 DISALLOW_COPY_AND_ASSIGN(SessionManager); | |
| 158 }; | |
| 159 | |
| 160 } // namespace chromeos | |
| 161 | |
| 162 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_SESSION_MANAGER_H_ | |
| OLD | NEW |