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..ba73b0757e695c921f4e242350ecf00c3da68a48 |
--- /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) { |
+ if (access_token_.empty()) { |
+ OAuth2TokenService::ScopeSet scopes; |
+ scopes.insert(kChromeWebstoreOAuth2Scope); |
+ pending_callbacks_.push(callback); |
+ access_token_request_.reset( |
+ identity_provider_->GetTokenService() |
+ ->StartRequest( |
+ identity_provider_->GetActiveAccountId(), scopes, this) |
+ .release()); |
+ } else { |
+ callback.Run(true, access_token_); |
Roger Tawa OOO till Jul 10th
2014/08/07 01:35:16
There is no need to optimize the number of calls t
Ken Rockot(use gerrit already)
2014/08/07 16:49:09
Aye, this is (sort of) what I was originally doing
|
+ } |
+} |
+ |
+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 |