OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 GOOGLE_APIS_GAIA_UBERTOKEN_FETCHER_H_ | 5 #ifndef GOOGLE_APIS_GAIA_UBERTOKEN_FETCHER_H_ |
6 #define GOOGLE_APIS_GAIA_UBERTOKEN_FETCHER_H_ | 6 #define GOOGLE_APIS_GAIA_UBERTOKEN_FETCHER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "google_apis/gaia/gaia_auth_consumer.h" | 10 #include "google_apis/gaia/gaia_auth_consumer.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 // Allows to retrieve an uber-auth token. | 38 // Allows to retrieve an uber-auth token. |
39 class UbertokenFetcher : public GaiaAuthConsumer, | 39 class UbertokenFetcher : public GaiaAuthConsumer, |
40 public OAuth2TokenService::Consumer { | 40 public OAuth2TokenService::Consumer { |
41 public: | 41 public: |
42 // Maximum number of retries to get the uber-auth token before giving up. | 42 // Maximum number of retries to get the uber-auth token before giving up. |
43 static const int kMaxRetries; | 43 static const int kMaxRetries; |
44 | 44 |
45 UbertokenFetcher(OAuth2TokenService* token_service, | 45 UbertokenFetcher(OAuth2TokenService* token_service, |
46 UbertokenConsumer* consumer, | 46 UbertokenConsumer* consumer, |
| 47 const std::string& source, |
47 net::URLRequestContextGetter* request_context); | 48 net::URLRequestContextGetter* request_context); |
48 virtual ~UbertokenFetcher(); | 49 virtual ~UbertokenFetcher(); |
49 | 50 |
50 // Start fetching the token for |account_id|. | 51 // Start fetching the token for |account_id|. |
51 virtual void StartFetchingToken(const std::string& account_id); | 52 virtual void StartFetchingToken(const std::string& account_id); |
52 | 53 |
53 // Overriden from GaiaAuthConsumer | 54 // Overriden from GaiaAuthConsumer |
54 virtual void OnUberAuthTokenSuccess(const std::string& token) OVERRIDE; | 55 virtual void OnUberAuthTokenSuccess(const std::string& token) OVERRIDE; |
55 virtual void OnUberAuthTokenFailure( | 56 virtual void OnUberAuthTokenFailure( |
56 const GoogleServiceAuthError& error) OVERRIDE; | 57 const GoogleServiceAuthError& error) OVERRIDE; |
57 | 58 |
58 // Overriden from OAuth2TokenService::Consumer: | 59 // Overriden from OAuth2TokenService::Consumer: |
59 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 60 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
60 const std::string& access_token, | 61 const std::string& access_token, |
61 const base::Time& expiration_time) OVERRIDE; | 62 const base::Time& expiration_time) OVERRIDE; |
62 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 63 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
63 const GoogleServiceAuthError& error) OVERRIDE; | 64 const GoogleServiceAuthError& error) OVERRIDE; |
64 | 65 |
65 private: | 66 private: |
66 // Request a login-scoped access token from the token service. | 67 // Request a login-scoped access token from the token service. |
67 void RequestAccessToken(); | 68 void RequestAccessToken(); |
68 | 69 |
69 // Exchanges an oauth2 access token for an uber-auth token. | 70 // Exchanges an oauth2 access token for an uber-auth token. |
70 void ExchangeTokens(); | 71 void ExchangeTokens(); |
71 | 72 |
72 OAuth2TokenService* token_service_; | 73 OAuth2TokenService* token_service_; |
73 UbertokenConsumer* consumer_; | 74 UbertokenConsumer* consumer_; |
| 75 std::string source_; |
74 net::URLRequestContextGetter* request_context_; | 76 net::URLRequestContextGetter* request_context_; |
75 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | 77 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; |
76 scoped_ptr<OAuth2TokenService::Request> access_token_request_; | 78 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
77 std::string account_id_; | 79 std::string account_id_; |
78 std::string access_token_; | 80 std::string access_token_; |
79 int retry_number_; | 81 int retry_number_; |
80 base::OneShotTimer<UbertokenFetcher> retry_timer_; | 82 base::OneShotTimer<UbertokenFetcher> retry_timer_; |
81 bool second_access_token_request_; | 83 bool second_access_token_request_; |
82 | 84 |
83 DISALLOW_COPY_AND_ASSIGN(UbertokenFetcher); | 85 DISALLOW_COPY_AND_ASSIGN(UbertokenFetcher); |
84 }; | 86 }; |
85 | 87 |
86 #endif // GOOGLE_APIS_GAIA_UBERTOKEN_FETCHER_H_ | 88 #endif // GOOGLE_APIS_GAIA_UBERTOKEN_FETCHER_H_ |
OLD | NEW |