Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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_TOKEN_FETCHER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_TOKEN_FETCHER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/callback.h" | |
|
xiyuan
2013/01/07 23:07:55
callback.h is probably not needed.
zel
2013/01/08 02:05:41
Done.
| |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "google_apis/gaia/gaia_auth_consumer.h" | |
| 15 #include "google_apis/gaia/gaia_auth_fetcher.h" | |
| 16 | |
| 17 class Profile; | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 // OAuth2TokenFetcher is used to convert authenticated cookie jar from the | |
| 22 // authentication profile into OAuth2 tokens and GAIA credentials that will be | |
| 23 // used to kick off other token retrieval tasks (i.e. TokenService). | |
|
xiyuan
2013/01/07 23:07:55
Update the comments here.
zel
2013/01/08 02:05:41
This is exactly what this class is used for.
| |
| 24 class OAuth2TokenFetcher : public base::SupportsWeakPtr<OAuth2TokenFetcher>, | |
| 25 public GaiaAuthConsumer { | |
| 26 public: | |
| 27 class Delegate { | |
| 28 public: | |
| 29 virtual ~Delegate() {} | |
| 30 virtual void OnOAuth2TokenAvailable( | |
| 31 const GaiaAuthConsumer::ClientLoginResult& gaia_credentials, | |
| 32 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) = 0; | |
| 33 virtual void OnOAuth2TokenFetchFailed() = 0; | |
| 34 }; | |
| 35 | |
| 36 OAuth2TokenFetcher(OAuth2TokenFetcher::Delegate* delegate, | |
| 37 Profile* auth_profile); | |
| 38 virtual ~OAuth2TokenFetcher(); | |
| 39 | |
| 40 void Start(); | |
| 41 | |
| 42 private: | |
| 43 // Starts OAuthLogin call. | |
| 44 void StartOAuthLogin(); | |
| 45 // Decides how to proceed on GAIA |error|. If the error looks temporary, | |
| 46 // retries |task| until max retry count is reached. | |
| 47 // If retry count runs out, or error condition is unrecoverable, it calls | |
| 48 // Delegate::OnOAuth2TokenFetchFailed(). | |
| 49 void RetryOnError(const GoogleServiceAuthError& error, | |
| 50 const base::Closure& task); | |
| 51 | |
| 52 // GaiaAuthConsumer overrides. | |
| 53 virtual void OnClientOAuthSuccess( | |
| 54 const GaiaAuthConsumer::ClientOAuthResult& result) OVERRIDE; | |
| 55 virtual void OnClientOAuthFailure( | |
| 56 const GoogleServiceAuthError& error) OVERRIDE; | |
| 57 virtual void OnClientLoginSuccess( | |
| 58 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | |
| 59 virtual void OnClientLoginFailure( | |
| 60 const GoogleServiceAuthError& error) OVERRIDE; | |
| 61 | |
| 62 OAuth2TokenFetcher::Delegate* delegate_; | |
| 63 Profile* auth_profile_; | |
| 64 GaiaAuthConsumer::ClientOAuthResult oauth_tokens_; | |
| 65 GaiaAuthFetcher auth_fetcher_; | |
| 66 | |
| 67 // The retry counter. Increment this only when failure happened. | |
| 68 int retry_count_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenFetcher); | |
| 71 }; | |
| 72 | |
| 73 } // namespace chromeos | |
| 74 | |
| 75 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_TOKEN_FETCHER_H_ | |
| OLD | NEW |