| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 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_OAUTH2_LOGIN_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_LOGIN_MANAGER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/chromeos/login/oauth2_login_verifier.h" |
| 12 #include "chrome/browser/chromeos/login/oauth2_policy_fetcher.h" |
| 13 #include "chrome/browser/chromeos/login/oauth2_token_fetcher.h" |
| 14 #include "chrome/browser/chromeos/login/oauth_login_manager.h" |
| 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "net/url_request/url_request_context_getter.h" |
| 18 |
| 19 class GoogleServiceAuthError; |
| 20 class Profile; |
| 21 class TokenService; |
| 22 |
| 23 namespace chromeos { |
| 24 |
| 25 // OAuth2 specialization of OAuthLoginManager. |
| 26 class OAuth2LoginManager : public OAuthLoginManager, |
| 27 public content::NotificationObserver, |
| 28 public OAuth2LoginVerifier::Delegate, |
| 29 public OAuth2TokenFetcher::Delegate { |
| 30 public: |
| 31 explicit OAuth2LoginManager(OAuthLoginManager::Delegate* delegate); |
| 32 virtual ~OAuth2LoginManager(); |
| 33 |
| 34 // OAuthLoginManager overrides. |
| 35 virtual void RestorePolicyTokens( |
| 36 net::URLRequestContextGetter* auth_request_context) OVERRIDE; |
| 37 virtual void RestoreSession( |
| 38 Profile* user_profile, |
| 39 net::URLRequestContextGetter* auth_request_context, |
| 40 bool restore_from_auth_cookies) OVERRIDE; |
| 41 virtual void ContinueSessionRestore() OVERRIDE; |
| 42 virtual void Stop() OVERRIDE; |
| 43 |
| 44 private: |
| 45 // content::NotificationObserver overrides. |
| 46 virtual void Observe(int type, |
| 47 const content::NotificationSource& source, |
| 48 const content::NotificationDetails& details) OVERRIDE; |
| 49 |
| 50 // OAuth2LoginVerifier::Delegate overrides. |
| 51 virtual void OnOAuthLoginSuccess( |
| 52 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials) OVERRIDE; |
| 53 virtual void OnOAuthLoginFailure() OVERRIDE; |
| 54 virtual void OnSessionMergeSuccess() OVERRIDE; |
| 55 virtual void OnSessionMergeFailure() OVERRIDE; |
| 56 |
| 57 // OAuth2TokenFetcher::Delegate overrides. |
| 58 virtual void OnOAuth2TokensAvailable( |
| 59 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE; |
| 60 virtual void OnOAuth2TokensFetchFailed() OVERRIDE; |
| 61 |
| 62 // Retrieves TokenService for |user_profile_| and sets up notification |
| 63 // observer events. |
| 64 TokenService* SetupTokenService(); |
| 65 |
| 66 // Removes legacy tokens form OAuth1 flow. |
| 67 void RemoveLegacyTokens(); |
| 68 |
| 69 // Loads previously stored OAuth2 tokens and kicks off its validation. |
| 70 void LoadAndVerifyOAuth2Tokens(); |
| 71 |
| 72 // Attempts to fetch OAuth2 tokens by using pre-authenticated cookie jar from |
| 73 // provided |auth_profile|. |
| 74 void FetchOAuth2Tokens(); |
| 75 |
| 76 // Reports when all tokens are loaded. |
| 77 void ReportOAuth2TokensLoaded(); |
| 78 |
| 79 // Issue GAIA cookie recovery (MergeSession) from |refresh_token_|. |
| 80 void RestoreSessionCookies(); |
| 81 |
| 82 // Fetches device policy OAuth2 access tokens if have not attempted or |
| 83 // failed that step previously. |
| 84 void FetchPolicyTokens(); |
| 85 |
| 86 // Checks GAIA error and figures out whether the request should be |
| 87 // re-attempted. |
| 88 bool RetryOnError(const GoogleServiceAuthError& error); |
| 89 |
| 90 // On successfuly OAuthLogin, starts token service token fetching process. |
| 91 void StartTokenService( |
| 92 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials); |
| 93 |
| 94 // Keeps the track if we have already reported OAuth2 token being loaded |
| 95 // by TokenService. |
| 96 bool loading_reported_; |
| 97 content::NotificationRegistrar registrar_; |
| 98 scoped_ptr<OAuth2TokenFetcher> oauth2_token_fetcher_; |
| 99 scoped_ptr<OAuth2LoginVerifier> login_verifier_; |
| 100 scoped_ptr<OAuth2PolicyFetcher> oauth2_policy_fetcher_; |
| 101 // OAuth2 refresh token. |
| 102 std::string refresh_token_; |
| 103 // GAIA service token. |
| 104 std::string gaia_token_; |
| 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(OAuth2LoginManager); |
| 107 }; |
| 108 |
| 109 } // namespace chromeos |
| 110 |
| 111 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_LOGIN_MANAGER_H_ |
| OLD | NEW |