OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef EXTENSIONS_BROWSER_WEBSTORE_OAUTH2_TOKEN_PROVIDER_H_ |
| 6 #define EXTENSIONS_BROWSER_WEBSTORE_OAUTH2_TOKEN_PROVIDER_H_ |
| 7 |
| 8 #include <queue> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/macros.h" |
| 12 #include "google_apis/gaia/oauth2_token_service.h" |
| 13 |
| 14 class IdentityProvider; |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 // Provides access tokens for resources |
| 19 class WebstoreOAuth2TokenProvider : public OAuth2TokenService::Consumer { |
| 20 public: |
| 21 typedef base::Callback<void(bool success, const std::string& token)> |
| 22 FetchCallback; |
| 23 |
| 24 explicit WebstoreOAuth2TokenProvider(IdentityProvider* identity_provider); |
| 25 virtual ~WebstoreOAuth2TokenProvider(); |
| 26 |
| 27 void FetchToken(const FetchCallback& callback); |
| 28 |
| 29 private: |
| 30 // OAuth2TokenService::Consumer implementation. |
| 31 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 32 const std::string& access_token, |
| 33 const base::Time& expiration_time) OVERRIDE; |
| 34 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 35 const GoogleServiceAuthError& error) OVERRIDE; |
| 36 |
| 37 // Exposes an OAuth2TokenService and information about the active account ID. |
| 38 // Not owned and must outlive this WebstoreOAuth2TokenProvider. |
| 39 IdentityProvider* identity_provider_; |
| 40 |
| 41 // A cached access token from the last successful token fetch. |
| 42 std::string access_token_; |
| 43 |
| 44 // Callbacks pending the receipt of a new token. |
| 45 typedef std::queue<FetchCallback> CallbackQueue; |
| 46 CallbackQueue pending_callbacks_; |
| 47 |
| 48 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(WebstoreOAuth2TokenProvider); |
| 51 }; |
| 52 |
| 53 } // namespace extensions |
| 54 |
| 55 #endif // EXTENSIONS_BROWSER_WEBSTORE_OAUTH2_TOKEN_PROVIDER_H_ |
OLD | NEW |