Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: extensions/browser/webstore_oauth2_token_provider.cc

Issue 434493002: OAuth2 support for Webstore downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 #include "extensions/browser/webstore_oauth2_token_provider.h"
6
7 #include "google_apis/gaia/identity_provider.h"
8
9 namespace extensions {
10
11 namespace {
12
13 const char kChromeWebstoreOAuth2Scope[] =
14 "https://www.googleapis.com/auth/chromewebstore.readonly";
15 const char kWebstoreOAuth2TokenConsumerId[] = "webstore-oauth2-token-provider";
16
17 } // namespace
18
19 WebstoreOAuth2TokenProvider::WebstoreOAuth2TokenProvider(
20 IdentityProvider* identity_provider)
21 : OAuth2TokenService::Consumer(kWebstoreOAuth2TokenConsumerId),
22 identity_provider_(identity_provider) {
23 }
24
25 WebstoreOAuth2TokenProvider::~WebstoreOAuth2TokenProvider() {
26 }
27
28 void WebstoreOAuth2TokenProvider::FetchToken(const FetchCallback& callback) {
29 OAuth2TokenService::ScopeSet scopes;
30 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
31 if (access_token_.empty()) {
32 pending_callbacks_.push(callback);
33 access_token_request_.reset(
34 identity_provider_->GetTokenService()
35 ->StartRequest(
36 identity_provider_->GetActiveAccountId(), scopes, this)
37 .release());
38 } else {
39 callback.Run(true, access_token_);
40 }
41 }
42
43 void WebstoreOAuth2TokenProvider::OnGetTokenSuccess(
44 const OAuth2TokenService::Request* request,
45 const std::string& access_token,
46 const base::Time& expiration_time) {
47 access_token_ = access_token;
48 CallbackQueue callbacks;
49 pending_callbacks_.swap(callbacks);
50 while (!callbacks.empty()) {
51 callbacks.front().Run(true, access_token_);
52 callbacks.pop();
53 }
54 }
55
56 void WebstoreOAuth2TokenProvider::OnGetTokenFailure(
57 const OAuth2TokenService::Request* request,
58 const GoogleServiceAuthError& error) {
59 CallbackQueue callbacks;
60 pending_callbacks_.swap(callbacks);
61 while (!callbacks.empty()) {
62 callbacks.front().Run(false, "");
63 callbacks.pop();
64 }
65 }
66
67 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698