| 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_OAUTH_LOGIN_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH_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_token_fetcher.h" |
| 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" |
| 15 |
| 16 class GaiaAuthFetcher; |
| 17 class GoogleServiceAuthError; |
| 18 class Profile; |
| 19 class TokenService; |
| 20 |
| 21 namespace chromeos { |
| 22 |
| 23 // Observes token change events in TokenService and coordinates appropriate |
| 24 // response from ChromeOS login flow. |
| 25 class OAuthLoginManager : public content::NotificationObserver, |
| 26 public OAuth2LoginVerifier::Delegate, |
| 27 public OAuth2TokenFetcher::Delegate { |
| 28 public: |
| 29 class Delegate { |
| 30 public: |
| 31 virtual ~Delegate() {} |
| 32 // Raised when cookie jar authentication is successfully completed. |
| 33 virtual void OnCompletedAuthentication(Profile* user_profile) = 0; |
| 34 }; |
| 35 |
| 36 OAuthLoginManager(Delegate* delegate, |
| 37 Profile* user_profile, |
| 38 Profile* auth_profile, |
| 39 bool has_web_auth_cookies); |
| 40 |
| 41 // Restores and verified OAuth tokens either from TokenService or |
| 42 void RestoreOAuth2Tokens(); |
| 43 |
| 44 private: |
| 45 // content::NotificationObserver overrides. |
| 46 void Observe(int type, |
| 47 const content::NotificationSource& source, |
| 48 const content::NotificationDetails& details) OVERRIDE; |
| 49 |
| 50 // OAuth2LoginVerifier::Delegate overrides. |
| 51 virtual void OnOAuth2LoginVerifierSuccess(const std::string& sid, |
| 52 const std::string& lsid, |
| 53 const std::string& auth) OVERRIDE; |
| 54 virtual void OnOAuth2LoginVerifierFaulure() OVERRIDE; |
| 55 |
| 56 // OAuth2TokenFetcher::Delegate overrides. |
| 57 virtual void OnOAuth2TokenAvailable( |
| 58 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials, |
| 59 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) OVERRIDE; |
| 60 virtual void OnOAuth2TokenFetchFailed() OVERRIDE; |
| 61 |
| 62 |
| 63 // Retrieves TokenService for |user_profile_| and sets up notification |
| 64 // observer events. |
| 65 TokenService* SetupTokenService(); |
| 66 // Loads previously stored OAuth2 tokens and kicks off its validation. |
| 67 void LoadAndVerifyOAuth2Tokens(); |
| 68 // Attempts to fetch OAuth2 tokens by using pre-authenticated cookie jar from |
| 69 // provided |auth_profile|. |
| 70 void FetchOAuth2Tokens(); |
| 71 // Reports when all tokens are loaded. |
| 72 void ReportTokenLoaded(); |
| 73 // Issue GAIA cookie recovery (MergeSession) from |uber_token_|. |
| 74 void RestoreSessionCookies(); |
| 75 // Checks GAIA error and figures out whether the request should be |
| 76 // re-attempted. |
| 77 bool RetryOnError(const GoogleServiceAuthError& error); |
| 78 |
| 79 Delegate* delegate_; |
| 80 Profile* user_profile_; |
| 81 Profile* auth_profile_; |
| 82 bool has_web_auth_cookies_; |
| 83 // Keeps the track if we have already reported OAuth2 token being loaded |
| 84 // by TokenService. |
| 85 bool loading_reported_; |
| 86 int restore_attempt_count_; |
| 87 content::NotificationRegistrar registrar_; |
| 88 scoped_ptr<OAuth2TokenFetcher> oauth2_token_fetcher_; |
| 89 scoped_ptr<OAuth2LoginVerifier> login_verifier_; |
| 90 std::string refresh_token_; |
| 91 }; |
| 92 |
| 93 } // namespace chromeos |
| 94 |
| 95 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH_LOGIN_MANAGER_H_ |
| OLD | NEW |