Chromium Code Reviews| Index: chrome/browser/chromeos/login/oauth2_login_manager.h |
| diff --git a/chrome/browser/chromeos/login/oauth2_login_manager.h b/chrome/browser/chromeos/login/oauth2_login_manager.h |
| index ea7e2c78d818f816a8c82e217cd3c17ec9073b28..bc72e4533225a01a46ab24828e62eb74aac638dd 100644 |
| --- a/chrome/browser/chromeos/login/oauth2_login_manager.h |
| +++ b/chrome/browser/chromeos/login/oauth2_login_manager.h |
| @@ -8,9 +8,10 @@ |
| #include <string> |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| #include "chrome/browser/chromeos/login/oauth2_login_verifier.h" |
| #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h" |
| -#include "chrome/browser/chromeos/login/oauth_login_manager.h" |
| +#include "components/browser_context_keyed_service/browser_context_keyed_service.h" |
| #include "google_apis/gaia/oauth2_token_service.h" |
| #include "net/url_request/url_request_context_getter.h" |
| @@ -21,23 +22,75 @@ class TokenService; |
| namespace chromeos { |
| // OAuth2 specialization of OAuthLoginManager. |
| -class OAuth2LoginManager : public OAuthLoginManager, |
| +class OAuth2LoginManager : public BrowserContextKeyedService, |
|
xiyuan
2013/09/06 01:35:49
nit: Update comments.
zel
2013/09/07 02:03:42
Done.
|
| public OAuth2LoginVerifier::Delegate, |
| public OAuth2TokenFetcher::Delegate, |
| public OAuth2TokenService::Observer { |
| public: |
| - explicit OAuth2LoginManager(OAuthLoginManager::Delegate* delegate); |
| + // Session restore states. |
| + enum SessionRestoreState { |
| + // Session restore is not started. |
| + SESSION_RESTORE_NOT_STARTED, |
| + // Session restore is in progress. We are currently issuing calls to verify |
| + // stored OAuth tokens and populate cookie jar with GAIA credentials. |
| + SESSION_RESTORE_IN_PROGRESS, |
| + // Session restore is completed. |
| + SESSION_RESTORE_DONE, |
| + }; |
| + |
| + // Session restore strategy. |
| + enum SessionRestoreStrategy { |
| + // Generate OAuth2 refresh token from authentication profile's cookie jar. |
| + // Restore session from generated OAuth2 refresh token. |
| + RESTORE_FROM_COOKIE_JAR, |
| + // Restore session from saved OAuth2 refresh token from TokenServices. |
| + RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN, |
| + // Restore session from OAuth2 refresh token passed via command line. |
| + RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN, |
| + // Restore session from authentication code passed via command line. |
| + RESTORE_FROM_AUTH_CODE, |
| + }; |
| + |
| + class Observer { |
| + public: |
| + virtual ~Observer() {} |
| + |
| + // Raised when merge session process starts. |
| + virtual void OnStartMergeSession(Profile* user_profile) {} |
| + |
| + // Raised when merge session is completed. |
| + virtual void OnCompletedMergeSession(Profile* user_profile) {} |
| + |
| + // Raised when cookie jar authentication is successfully completed. |
| + virtual void OnCompletedAuthentication(Profile* user_profile) {} |
| + }; |
| + |
| + explicit OAuth2LoginManager(Profile* user_profile); |
| virtual ~OAuth2LoginManager(); |
| - // OAuthLoginManager overrides. |
| - virtual void RestoreSession( |
| - Profile* user_profile, |
| + void AddObserver(OAuth2LoginManager::Observer* observer); |
| + void RemoveObserver(OAuth2LoginManager::Observer* observer); |
| + |
| + // Restores and verifies OAuth tokens either following specified |
| + // |restore_strategy|. For |restore_strategy| with values |
| + // RESTORE_FROM_PASSED_OAUTH2_REFRESH_TOKEN or |
| + // RESTORE_FROM_AUTH_CODE, respectively |
| + // parameters |oauth2_refresh_token| or |auth_code| need to have non-empty |
| + // value. |
| + void RestoreSession( |
| net::URLRequestContextGetter* auth_request_context, |
| SessionRestoreStrategy restore_strategy, |
| const std::string& oauth2_refresh_token, |
| const std::string& auth_code) OVERRIDE; |
| - virtual void ContinueSessionRestore() OVERRIDE; |
| - virtual void Stop() OVERRIDE; |
| + |
| + // Continues session restore after transient network errors. |
| + void ContinueSessionRestore(); |
| + |
| + // Stops all background authentication requests. |
| + void Stop(); |
| + |
| + // Returns session restore state. |
| + SessionRestoreState state() { return state_; } |
| private: |
| // Session restore outcomes (for UMA). |
| @@ -51,6 +104,9 @@ class OAuth2LoginManager : public OAuthLoginManager, |
| SESSION_RESTORE_COUNT = SESSION_RESTORE_MERGE_SESSION_FAILED, |
| }; |
| + // BrowserContextKeyedService implementation. |
| + virtual void Shutdown() OVERRIDE; |
| + |
| // OAuth2LoginVerifier::Delegate overrides. |
| virtual void OnOAuthLoginSuccess( |
| const GaiaAuthConsumer::ClientLoginResult& gaia_credentials) OVERRIDE; |
| @@ -66,6 +122,10 @@ class OAuth2LoginManager : public OAuthLoginManager, |
| // OAuth2TokenService::Observer implementation: |
| virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| + // Signals delegate that authentication is completed, kicks off token fetching |
| + // process in TokenService. |
| + void CompleteAuthentication(); |
| + |
| // Retrieves TokenService for |user_profile_| and sets up notification |
| // observer events. |
| TokenService* SetupTokenService(); |
| @@ -96,19 +156,28 @@ class OAuth2LoginManager : public OAuthLoginManager, |
| void StartTokenService( |
| const GaiaAuthConsumer::ClientLoginResult& gaia_credentials); |
| - // Stops listening for a new login refresh token. |
| - void StopObservingRefreshToken(); |
| - |
| // Keeps the track if we have already reported OAuth2 token being loaded |
| // by TokenService. |
| + Profile* user_profile_; |
| + scoped_refptr<net::URLRequestContextGetter> auth_request_context_; |
| + SessionRestoreStrategy restore_strategy_; |
| + SessionRestoreState state_; |
| + |
| bool loading_reported_; |
| + |
| scoped_ptr<OAuth2TokenFetcher> oauth2_token_fetcher_; |
| scoped_ptr<OAuth2LoginVerifier> login_verifier_; |
| + |
| // OAuth2 refresh token. |
| std::string refresh_token_; |
| + |
| // Authorization code for fetching OAuth2 tokens. |
| std::string auth_code_; |
| + // List of observers to notify when token availability changes. |
| + // Makes sure list is empty on destruction. |
| + ObserverList<Observer, true> observer_list_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager); |
| }; |