| OLD | NEW |
| 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_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 // Session restore strategy. | 52 // Session restore strategy. |
| 53 enum SessionRestoreStrategy { | 53 enum SessionRestoreStrategy { |
| 54 // Generate OAuth2 refresh token from authentication profile's cookie jar. | 54 // Generate OAuth2 refresh token from authentication profile's cookie jar. |
| 55 // Restore session from generated OAuth2 refresh token. | 55 // Restore session from generated OAuth2 refresh token. |
| 56 RESTORE_FROM_COOKIE_JAR, | 56 RESTORE_FROM_COOKIE_JAR, |
| 57 // Restore session from saved OAuth2 refresh token from TokenServices. | 57 // Restore session from saved OAuth2 refresh token from TokenServices. |
| 58 RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN, | 58 RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN, |
| 59 // Restore session from OAuth2 refresh token passed via command line. | 59 // Restore session from OAuth2 refresh token passed via command line. |
| 60 RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN, | 60 RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN, |
| 61 // Restore session from authentication code passed via command line. | 61 // Restore session from OAuth2 access token. |
| 62 RESTORE_FROM_AUTH_CODE, | 62 RESTORE_FROM_PASSED_OAUTH2_ACCESS_TOKEN, |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class Observer { | 65 class Observer { |
| 66 public: | 66 public: |
| 67 virtual ~Observer() {} | 67 virtual ~Observer() {} |
| 68 | 68 |
| 69 // Raised when merge session state changes. | 69 // Raised when merge session state changes. |
| 70 virtual void OnSessionRestoreStateChanged(Profile* user_profile, | 70 virtual void OnSessionRestoreStateChanged(Profile* user_profile, |
| 71 SessionRestoreState state) {} | 71 SessionRestoreState state) {} |
| 72 | 72 |
| 73 // Raised when a new OAuth2 refresh token is avaialble. | 73 // Raised when a new OAuth2 refresh token is avaialble. |
| 74 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) {} | 74 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) {} |
| 75 | 75 |
| 76 // Raised when session's GAIA credentials (SID+LSID) are available to | 76 // Raised when session's GAIA credentials (SID+LSID) are available to |
| 77 // other signed in services. | 77 // other signed in services. |
| 78 virtual void OnSessionAuthenticated(Profile* user_profile) {} | 78 virtual void OnSessionAuthenticated(Profile* user_profile) {} |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 explicit OAuth2LoginManager(Profile* user_profile); | 81 explicit OAuth2LoginManager(Profile* user_profile); |
| 82 ~OAuth2LoginManager() override; | 82 ~OAuth2LoginManager() override; |
| 83 | 83 |
| 84 void AddObserver(OAuth2LoginManager::Observer* observer); | 84 void AddObserver(OAuth2LoginManager::Observer* observer); |
| 85 void RemoveObserver(OAuth2LoginManager::Observer* observer); | 85 void RemoveObserver(OAuth2LoginManager::Observer* observer); |
| 86 | 86 |
| 87 // Restores and verifies OAuth tokens either following specified | 87 // Restores and verifies OAuth tokens either following specified |
| 88 // |restore_strategy|. For |restore_strategy| with values | 88 // |restore_strategy|. For |restore_strategy| with values |
| 89 // RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN or | 89 // RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN or |
| 90 // RESTORE_FROM_AUTH_CODE, respectively | 90 // RESTORE_FROM_AUTH_CODE, respectively, parameters |oauth2_refresh_token| or |
| 91 // parameters |oauth2_refresh_token| or |auth_code| need to have non-empty | 91 // |oauth2_access_token| need to have a non-empty value. |
| 92 // value. | 92 void RestoreSession(net::URLRequestContextGetter* auth_request_context, |
| 93 void RestoreSession( | 93 SessionRestoreStrategy restore_strategy, |
| 94 net::URLRequestContextGetter* auth_request_context, | 94 const std::string& oauth2_refresh_token, |
| 95 SessionRestoreStrategy restore_strategy, | 95 const std::string& oauth2_access_token); |
| 96 const std::string& oauth2_refresh_token, | |
| 97 const std::string& auth_code); | |
| 98 | 96 |
| 99 // Continues session restore after transient network errors. | 97 // Continues session restore after transient network errors. |
| 100 void ContinueSessionRestore(); | 98 void ContinueSessionRestore(); |
| 101 | 99 |
| 102 // Start resporting session from saved OAuth2 refresh token. | 100 // Start restoring session from saved OAuth2 refresh token. |
| 103 void RestoreSessionFromSavedTokens(); | 101 void RestoreSessionFromSavedTokens(); |
| 104 | 102 |
| 105 // Stops all background authentication requests. | 103 // Stops all background authentication requests. |
| 106 void Stop(); | 104 void Stop(); |
| 107 | 105 |
| 108 // Returns session restore state. | 106 // Returns session restore state. |
| 109 SessionRestoreState state() { return state_; } | 107 SessionRestoreState state() { return state_; } |
| 110 | 108 |
| 111 const base::Time& session_restore_start() { return session_restore_start_; } | 109 const base::Time& session_restore_start() { return session_restore_start_; } |
| 112 | 110 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // Signals delegate that authentication is completed, kicks off token fetching | 171 // Signals delegate that authentication is completed, kicks off token fetching |
| 174 // process. | 172 // process. |
| 175 void CompleteAuthentication(); | 173 void CompleteAuthentication(); |
| 176 | 174 |
| 177 // Retrieves ProfileOAuth2TokenService for |user_profile_|. | 175 // Retrieves ProfileOAuth2TokenService for |user_profile_|. |
| 178 ProfileOAuth2TokenService* GetTokenService(); | 176 ProfileOAuth2TokenService* GetTokenService(); |
| 179 | 177 |
| 180 // Retrieves the primary account for |user_profile_|. | 178 // Retrieves the primary account for |user_profile_|. |
| 181 const std::string& GetPrimaryAccountId(); | 179 const std::string& GetPrimaryAccountId(); |
| 182 | 180 |
| 181 // Get External Token Handle. |
| 182 void GetTokenHandle(); |
| 183 |
| 183 // Records |refresh_token_| to token service. The associated account id is | 184 // Records |refresh_token_| to token service. The associated account id is |
| 184 // assumed to be the primary account id of the user profile. If the primary | 185 // assumed to be the primary account id of the user profile. If the primary |
| 185 // account id is not present, GetAccountInfoOfRefreshToken will be called to | 186 // account id is not present, GetAccountInfoOfRefreshToken will be called to |
| 186 // retrieve the associated account info. | 187 // retrieve the associated account info. |
| 187 void StoreOAuth2Token(); | 188 void StoreOAuth2Token(); |
| 188 | 189 |
| 189 // Get the account info corresponding to the specified refresh token. | 190 // Get the account info corresponding to the specified refresh token. |
| 190 void GetAccountInfoOfRefreshToken(const std::string& refresh_token); | 191 void GetAccountInfoOfRefreshToken(const std::string& refresh_token); |
| 191 | 192 |
| 192 // Update the token service and inform listeners of a new refresh token. | 193 // Update the token service and inform listeners of a new refresh token. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 scoped_ptr<OAuth2LoginVerifier> login_verifier_; | 242 scoped_ptr<OAuth2LoginVerifier> login_verifier_; |
| 242 scoped_ptr<gaia::GaiaOAuthClient> account_info_fetcher_; | 243 scoped_ptr<gaia::GaiaOAuthClient> account_info_fetcher_; |
| 243 scoped_ptr<TokenHandleUtil> token_handle_util_; | 244 scoped_ptr<TokenHandleUtil> token_handle_util_; |
| 244 | 245 |
| 245 // OAuth2 refresh token. | 246 // OAuth2 refresh token. |
| 246 std::string refresh_token_; | 247 std::string refresh_token_; |
| 247 | 248 |
| 248 // OAuthLogin scoped access token. | 249 // OAuthLogin scoped access token. |
| 249 std::string oauthlogin_access_token_; | 250 std::string oauthlogin_access_token_; |
| 250 | 251 |
| 251 // Authorization code for fetching OAuth2 tokens. | |
| 252 std::string auth_code_; | |
| 253 | |
| 254 // Session restore start time. | 252 // Session restore start time. |
| 255 base::Time session_restore_start_; | 253 base::Time session_restore_start_; |
| 256 | 254 |
| 257 // List of observers to notify when token availability changes. | 255 // List of observers to notify when token availability changes. |
| 258 // Makes sure list is empty on destruction. | 256 // Makes sure list is empty on destruction. |
| 259 // TODO(zelidrag|gspencer): Figure out how to get rid of ProfileHelper so we | 257 // TODO(zelidrag|gspencer): Figure out how to get rid of ProfileHelper so we |
| 260 // can change the line below to ObserverList<Observer, true>. | 258 // can change the line below to ObserverList<Observer, true>. |
| 261 ObserverList<Observer, false> observer_list_; | 259 ObserverList<Observer, false> observer_list_; |
| 262 | 260 |
| 263 base::WeakPtrFactory<OAuth2LoginManager> weak_factory_; | 261 base::WeakPtrFactory<OAuth2LoginManager> weak_factory_; |
| 264 | 262 |
| 265 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager); | 263 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager); |
| 266 }; | 264 }; |
| 267 | 265 |
| 268 } // namespace chromeos | 266 } // namespace chromeos |
| 269 | 267 |
| 270 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ | 268 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ |
| OLD | NEW |