OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_OAUTH2_TOKEN_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_TOKEN_FETCHER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_TOKEN_FETCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_TOKEN_FETCHER_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
10 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
11 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
12 #include "google_apis/gaia/gaia_auth_consumer.h" | 14 #include "google_apis/gaia/gaia_auth_consumer.h" |
13 #include "google_apis/gaia/gaia_auth_fetcher.h" | 15 #include "google_apis/gaia/gaia_auth_fetcher.h" |
14 | 16 |
15 namespace net { | 17 namespace net { |
16 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
17 } | 19 } |
(...skipping 11 matching lines...) Expand all Loading... |
29 virtual ~Delegate() {} | 31 virtual ~Delegate() {} |
30 virtual void OnOAuth2TokensAvailable( | 32 virtual void OnOAuth2TokensAvailable( |
31 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) = 0; | 33 const GaiaAuthConsumer::ClientOAuthResult& oauth2_tokens) = 0; |
32 virtual void OnOAuth2TokensFetchFailed() = 0; | 34 virtual void OnOAuth2TokensFetchFailed() = 0; |
33 }; | 35 }; |
34 | 36 |
35 OAuth2TokenFetcher(OAuth2TokenFetcher::Delegate* delegate, | 37 OAuth2TokenFetcher(OAuth2TokenFetcher::Delegate* delegate, |
36 net::URLRequestContextGetter* context_getter); | 38 net::URLRequestContextGetter* context_getter); |
37 virtual ~OAuth2TokenFetcher(); | 39 virtual ~OAuth2TokenFetcher(); |
38 | 40 |
39 void Start(); | 41 void StartExchangeFromCookies(); |
| 42 void StartExchangeFromAuthCode(const std::string& auth_code); |
40 | 43 |
41 private: | 44 private: |
42 // Decides how to proceed on GAIA |error|. If the error looks temporary, | 45 // Decides how to proceed on GAIA |error|. If the error looks temporary, |
43 // retries |task| until max retry count is reached. | 46 // retries |task| until max retry count is reached. |
44 // If retry count runs out, or error condition is unrecoverable, it runs | 47 // If retry count runs out, or error condition is unrecoverable, it runs |
45 // |error_handler|. | 48 // |error_handler|. |
46 void RetryOnError(const GoogleServiceAuthError& error, | 49 void RetryOnError(const GoogleServiceAuthError& error, |
47 const base::Closure& task, | 50 const base::Closure& task, |
48 const base::Closure& error_handler); | 51 const base::Closure& error_handler); |
49 | 52 |
50 // GaiaAuthConsumer overrides. | 53 // GaiaAuthConsumer overrides. |
51 virtual void OnClientOAuthSuccess( | 54 virtual void OnClientOAuthSuccess( |
52 const GaiaAuthConsumer::ClientOAuthResult& result) OVERRIDE; | 55 const GaiaAuthConsumer::ClientOAuthResult& result) OVERRIDE; |
53 virtual void OnClientOAuthFailure( | 56 virtual void OnClientOAuthFailure( |
54 const GoogleServiceAuthError& error) OVERRIDE; | 57 const GoogleServiceAuthError& error) OVERRIDE; |
55 | 58 |
56 OAuth2TokenFetcher::Delegate* delegate_; | 59 OAuth2TokenFetcher::Delegate* delegate_; |
57 GaiaAuthConsumer::ClientOAuthResult oauth_tokens_; | 60 GaiaAuthConsumer::ClientOAuthResult oauth_tokens_; |
58 GaiaAuthFetcher auth_fetcher_; | 61 GaiaAuthFetcher auth_fetcher_; |
59 | 62 |
60 // The retry counter. Increment this only when failure happened. | 63 // The retry counter. Increment this only when failure happened. |
61 int retry_count_; | 64 int retry_count_; |
| 65 std::string auth_code_; |
62 | 66 |
63 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenFetcher); | 67 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenFetcher); |
64 }; | 68 }; |
65 | 69 |
66 } // namespace chromeos | 70 } // namespace chromeos |
67 | 71 |
68 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_TOKEN_FETCHER_H_ | 72 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH2_TOKEN_FETCHER_H_ |
OLD | NEW |