OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_OAUTH1_TOKEN_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH1_TOKEN_FETCHER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH1_TOKEN_FETCHER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH1_TOKEN_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 13 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
14 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" | 14 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" |
15 | 15 |
16 class Profile; | 16 namespace net { |
| 17 class URLRequestContextGetter; |
| 18 } |
17 | 19 |
18 namespace chromeos { | 20 namespace chromeos { |
19 | 21 |
20 // Given the authenticated credentials from the cookie jar, try to exchange | 22 // Given the authenticated credentials from the cookie jar, try to exchange |
21 // fetch OAuth1 token and secret. Automatically retries until max retry count is | 23 // fetch OAuth1 token and secret. Automatically retries until max retry count is |
22 // reached. | 24 // reached. |
23 class OAuth1TokenFetcher : public base::SupportsWeakPtr<OAuth1TokenFetcher>, | 25 class OAuth1TokenFetcher : public base::SupportsWeakPtr<OAuth1TokenFetcher>, |
24 public GaiaOAuthConsumer { | 26 public GaiaOAuthConsumer { |
25 public: | 27 public: |
26 class Delegate { | 28 class Delegate { |
27 public: | 29 public: |
28 virtual ~Delegate() {} | 30 virtual ~Delegate() {} |
29 virtual void OnOAuth1AccessTokenAvailable(const std::string& token, | 31 virtual void OnOAuth1AccessTokenAvailable(const std::string& token, |
30 const std::string& secret) = 0; | 32 const std::string& secret) = 0; |
31 virtual void OnOAuth1AccessTokenFetchFailed() = 0; | 33 virtual void OnOAuth1AccessTokenFetchFailed() = 0; |
32 }; | 34 }; |
33 | 35 |
34 OAuth1TokenFetcher(OAuth1TokenFetcher::Delegate* delegate, | 36 OAuth1TokenFetcher(OAuth1TokenFetcher::Delegate* delegate, |
35 Profile* auth_profile); | 37 net::URLRequestContextGetter* auth_context_getter); |
36 virtual ~OAuth1TokenFetcher(); | 38 virtual ~OAuth1TokenFetcher(); |
37 | 39 |
38 void Start(); | 40 void Start(); |
39 | 41 |
40 private: | 42 private: |
41 // Decides how to proceed on GAIA response and other errors. If the error | 43 // Decides how to proceed on GAIA response and other errors. If the error |
42 // looks temporary, retries token fetching until max retry count is reached. | 44 // looks temporary, retries token fetching until max retry count is reached. |
43 // If retry count runs out, or error condition is unrecoverable, returns | 45 // If retry count runs out, or error condition is unrecoverable, returns |
44 // false. | 46 // false. |
45 bool RetryOnError(const GoogleServiceAuthError& error); | 47 bool RetryOnError(const GoogleServiceAuthError& error); |
46 | 48 |
47 // GaiaOAuthConsumer implementation: | 49 // GaiaOAuthConsumer implementation: |
48 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; | 50 virtual void OnGetOAuthTokenSuccess(const std::string& oauth_token) OVERRIDE; |
49 virtual void OnGetOAuthTokenFailure( | 51 virtual void OnGetOAuthTokenFailure( |
50 const GoogleServiceAuthError& error) OVERRIDE; | 52 const GoogleServiceAuthError& error) OVERRIDE; |
51 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token, | 53 virtual void OnOAuthGetAccessTokenSuccess(const std::string& token, |
52 const std::string& secret) OVERRIDE; | 54 const std::string& secret) OVERRIDE; |
53 virtual void OnOAuthGetAccessTokenFailure( | 55 virtual void OnOAuthGetAccessTokenFailure( |
54 const GoogleServiceAuthError& error) OVERRIDE; | 56 const GoogleServiceAuthError& error) OVERRIDE; |
55 | 57 |
56 OAuth1TokenFetcher::Delegate* delegate_; | 58 OAuth1TokenFetcher::Delegate* delegate_; |
57 Profile* auth_profile_; | |
58 GaiaOAuthFetcher oauth_fetcher_; | 59 GaiaOAuthFetcher oauth_fetcher_; |
59 | 60 |
60 // The retry counter. Increment this only when failure happened. | 61 // The retry counter. Increment this only when failure happened. |
61 int retry_count_; | 62 int retry_count_; |
62 | 63 |
63 DISALLOW_COPY_AND_ASSIGN(OAuth1TokenFetcher); | 64 DISALLOW_COPY_AND_ASSIGN(OAuth1TokenFetcher); |
64 }; | 65 }; |
65 | 66 |
66 } // namespace chromeos | 67 } // namespace chromeos |
67 | 68 |
68 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH1_TOKEN_FETCHER_H_ | 69 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_OAUTH1_TOKEN_FETCHER_H_ |
OLD | NEW |