Chromium Code Reviews| Index: extensions/browser/webstore_oauth2_token_provider.cc |
| diff --git a/extensions/browser/webstore_oauth2_token_provider.cc b/extensions/browser/webstore_oauth2_token_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e2f72da1b7110ea1bca775742d704ef17b60b294 |
| --- /dev/null |
| +++ b/extensions/browser/webstore_oauth2_token_provider.cc |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "extensions/browser/webstore_oauth2_token_provider.h" |
| + |
| +#include "google_apis/gaia/identity_provider.h" |
| + |
| +namespace extensions { |
| + |
| +namespace { |
| + |
| +const char kChromeWebstoreOAuth2Scope[] = |
| + "https://www.googleapis.com/auth/chromewebstore.readonly"; |
| +const char kWebstoreOAuth2TokenConsumerId[] = "webstore-oauth2-token-provider"; |
| + |
| +} // namespace |
| + |
| +WebstoreOAuth2TokenProvider::WebstoreOAuth2TokenProvider( |
| + IdentityProvider* identity_provider) |
| + : OAuth2TokenService::Consumer(kWebstoreOAuth2TokenConsumerId), |
| + identity_provider_(identity_provider) { |
| +} |
| + |
| +WebstoreOAuth2TokenProvider::~WebstoreOAuth2TokenProvider() { |
| +} |
| + |
| +void WebstoreOAuth2TokenProvider::FetchToken(const FetchCallback& callback) { |
| + OAuth2TokenService::ScopeSet scopes; |
| + scopes.insert(kChromeWebstoreOAuth2Scope); |
|
asargent_no_longer_on_chrome
2014/08/06 00:26:29
nit: can the above 2 lines be pushed inside the bo
Ken Rockot(use gerrit already)
2014/08/06 16:49:55
most definitely. done
|
| + if (access_token_.empty()) { |
| + pending_callbacks_.push(callback); |
| + access_token_request_.reset( |
| + identity_provider_->GetTokenService() |
| + ->StartRequest( |
| + identity_provider_->GetActiveAccountId(), scopes, this) |
| + .release()); |
| + } else { |
| + callback.Run(true, access_token_); |
| + } |
| +} |
| + |
| +void WebstoreOAuth2TokenProvider::OnGetTokenSuccess( |
| + const OAuth2TokenService::Request* request, |
| + const std::string& access_token, |
| + const base::Time& expiration_time) { |
| + access_token_ = access_token; |
| + CallbackQueue callbacks; |
| + pending_callbacks_.swap(callbacks); |
| + while (!callbacks.empty()) { |
| + callbacks.front().Run(true, access_token_); |
| + callbacks.pop(); |
| + } |
| +} |
| + |
| +void WebstoreOAuth2TokenProvider::OnGetTokenFailure( |
| + const OAuth2TokenService::Request* request, |
| + const GoogleServiceAuthError& error) { |
| + CallbackQueue callbacks; |
| + pending_callbacks_.swap(callbacks); |
| + while (!callbacks.empty()) { |
| + callbacks.front().Run(false, ""); |
| + callbacks.pop(); |
| + } |
| +} |
| + |
| +} // namespace extensions |