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 #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 | |
OLD | NEW |