| 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. |
| 62 RESTORE_FROM_AUTH_CODE, |
| 61 }; | 63 }; |
| 62 | 64 |
| 63 class Observer { | 65 class Observer { |
| 64 public: | 66 public: |
| 65 virtual ~Observer() {} | 67 virtual ~Observer() {} |
| 66 | 68 |
| 67 // Raised when merge session state changes. | 69 // Raised when merge session state changes. |
| 68 virtual void OnSessionRestoreStateChanged(Profile* user_profile, | 70 virtual void OnSessionRestoreStateChanged(Profile* user_profile, |
| 69 SessionRestoreState state) {} | 71 SessionRestoreState state) {} |
| 70 | 72 |
| 71 // Raised when a new OAuth2 refresh token is avaialble. | 73 // Raised when a new OAuth2 refresh token is avaialble. |
| 72 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) {} | 74 virtual void OnNewRefreshTokenAvaiable(Profile* user_profile) {} |
| 73 | 75 |
| 74 // Raised when session's GAIA credentials (SID+LSID) are available to | 76 // Raised when session's GAIA credentials (SID+LSID) are available to |
| 75 // other signed in services. | 77 // other signed in services. |
| 76 virtual void OnSessionAuthenticated(Profile* user_profile) {} | 78 virtual void OnSessionAuthenticated(Profile* user_profile) {} |
| 77 }; | 79 }; |
| 78 | 80 |
| 79 explicit OAuth2LoginManager(Profile* user_profile); | 81 explicit OAuth2LoginManager(Profile* user_profile); |
| 80 ~OAuth2LoginManager() override; | 82 ~OAuth2LoginManager() override; |
| 81 | 83 |
| 82 void AddObserver(OAuth2LoginManager::Observer* observer); | 84 void AddObserver(OAuth2LoginManager::Observer* observer); |
| 83 void RemoveObserver(OAuth2LoginManager::Observer* observer); | 85 void RemoveObserver(OAuth2LoginManager::Observer* observer); |
| 84 | 86 |
| 85 // Restores and verifies OAuth tokens following specified |restore_strategy|. | 87 // Restores and verifies OAuth tokens either following specified |
| 86 // For |restore_strategy| RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN, parameter | 88 // |restore_strategy|. For |restore_strategy| with values |
| 87 // |oauth2_refresh_token| needs to have a non-empty value. | 89 // RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN or |
| 88 // For |restore_strategy| RESTORE_FROM_COOKIE_JAR |auth_request_context| must | 90 // RESTORE_FROM_AUTH_CODE, respectively |
| 89 // be initialized. | 91 // parameters |oauth2_refresh_token| or |auth_code| need to have non-empty |
| 90 void RestoreSession(net::URLRequestContextGetter* auth_request_context, | 92 // value. |
| 91 SessionRestoreStrategy restore_strategy, | 93 // For |restore_strategy| with values RESTORE_FROM_COOKIE_JAR or |
| 92 const std::string& oauth2_refresh_token, | 94 // RESTORE_FROM_AUTH_CODE |auth_request_context| must be initialized. |
| 93 const std::string& oauth2_access_token); | 95 void RestoreSession( |
| 96 net::URLRequestContextGetter* auth_request_context, |
| 97 SessionRestoreStrategy restore_strategy, |
| 98 const std::string& oauth2_refresh_token, |
| 99 const std::string& auth_code); |
| 94 | 100 |
| 95 // Continues session restore after transient network errors. | 101 // Continues session restore after transient network errors. |
| 96 void ContinueSessionRestore(); | 102 void ContinueSessionRestore(); |
| 97 | 103 |
| 98 // Start restoring session from saved OAuth2 refresh token. | 104 // Start resporting session from saved OAuth2 refresh token. |
| 99 void RestoreSessionFromSavedTokens(); | 105 void RestoreSessionFromSavedTokens(); |
| 100 | 106 |
| 101 // Stops all background authentication requests. | 107 // Stops all background authentication requests. |
| 102 void Stop(); | 108 void Stop(); |
| 103 | 109 |
| 104 // Returns session restore state. | 110 // Returns session restore state. |
| 105 SessionRestoreState state() { return state_; } | 111 SessionRestoreState state() { return state_; } |
| 106 | 112 |
| 107 const base::Time& session_restore_start() { return session_restore_start_; } | 113 const base::Time& session_restore_start() { return session_restore_start_; } |
| 108 | 114 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 139 POST_MERGE_VERIFICATION_FAILED = 5, | 145 POST_MERGE_VERIFICATION_FAILED = 5, |
| 140 POST_MERGE_CONNECTION_FAILED = 6, | 146 POST_MERGE_CONNECTION_FAILED = 6, |
| 141 POST_MERGE_COUNT = 7, | 147 POST_MERGE_COUNT = 7, |
| 142 }; | 148 }; |
| 143 | 149 |
| 144 // KeyedService implementation. | 150 // KeyedService implementation. |
| 145 void Shutdown() override; | 151 void Shutdown() override; |
| 146 | 152 |
| 147 // gaia::GaiaOAuthClient::Delegate overrides. | 153 // gaia::GaiaOAuthClient::Delegate overrides. |
| 148 void OnRefreshTokenResponse(const std::string& access_token, | 154 void OnRefreshTokenResponse(const std::string& access_token, |
| 149 int expires_in_seconds) override; | 155 int expires_in_seconds) override; |
| 150 void OnGetUserInfoResponse( | 156 void OnGetUserInfoResponse( |
| 151 scoped_ptr<base::DictionaryValue> user_info) override; | 157 scoped_ptr<base::DictionaryValue> user_info) override; |
| 152 void OnOAuthError() override; | 158 void OnOAuthError() override; |
| 153 void OnNetworkError(int response_code) override; | 159 void OnNetworkError(int response_code) override; |
| 154 | 160 |
| 155 // OAuth2LoginVerifier::Delegate overrides. | 161 // OAuth2LoginVerifier::Delegate overrides. |
| 156 void OnSessionMergeSuccess() override; | 162 void OnSessionMergeSuccess() override; |
| 157 void OnSessionMergeFailure(bool connection_error) override; | 163 void OnSessionMergeFailure(bool connection_error) override; |
| 158 void OnListAccountsSuccess(const std::string& data) override; | 164 void OnListAccountsSuccess(const std::string& data) override; |
| 159 void OnListAccountsFailure(bool connection_error) override; | 165 void OnListAccountsFailure(bool connection_error) override; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 scoped_ptr<OAuth2LoginVerifier> login_verifier_; | 243 scoped_ptr<OAuth2LoginVerifier> login_verifier_; |
| 238 scoped_ptr<gaia::GaiaOAuthClient> account_info_fetcher_; | 244 scoped_ptr<gaia::GaiaOAuthClient> account_info_fetcher_; |
| 239 scoped_ptr<TokenHandleUtil> token_handle_util_; | 245 scoped_ptr<TokenHandleUtil> token_handle_util_; |
| 240 | 246 |
| 241 // OAuth2 refresh token. | 247 // OAuth2 refresh token. |
| 242 std::string refresh_token_; | 248 std::string refresh_token_; |
| 243 | 249 |
| 244 // OAuthLogin scoped access token. | 250 // OAuthLogin scoped access token. |
| 245 std::string oauthlogin_access_token_; | 251 std::string oauthlogin_access_token_; |
| 246 | 252 |
| 253 // Authorization code for fetching OAuth2 tokens. |
| 254 std::string auth_code_; |
| 255 |
| 247 // Session restore start time. | 256 // Session restore start time. |
| 248 base::Time session_restore_start_; | 257 base::Time session_restore_start_; |
| 249 | 258 |
| 250 // List of observers to notify when token availability changes. | 259 // List of observers to notify when token availability changes. |
| 251 // Makes sure list is empty on destruction. | 260 // Makes sure list is empty on destruction. |
| 252 // TODO(zelidrag|gspencer): Figure out how to get rid of ProfileHelper so we | 261 // TODO(zelidrag|gspencer): Figure out how to get rid of ProfileHelper so we |
| 253 // can change the line below to ObserverList<Observer, true>. | 262 // can change the line below to ObserverList<Observer, true>. |
| 254 ObserverList<Observer, false> observer_list_; | 263 ObserverList<Observer, false> observer_list_; |
| 255 | 264 |
| 256 base::WeakPtrFactory<OAuth2LoginManager> weak_factory_; | 265 base::WeakPtrFactory<OAuth2LoginManager> weak_factory_; |
| 257 | 266 |
| 258 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager); | 267 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager); |
| 259 }; | 268 }; |
| 260 | 269 |
| 261 } // namespace chromeos | 270 } // namespace chromeos |
| 262 | 271 |
| 263 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ | 272 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_OAUTH2_LOGIN_MANAGER_H_ |
| OLD | NEW |