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

Side by Side Diff: components/proximity_auth/cryptauth/cryptauth_account_token_fetcher.cc

Issue 792193003: Implement CryptAuthAccessTokenFetcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
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 "components/proximity_auth/cryptauth/cryptauth_account_token_fetcher.h"
6
7 namespace proximity_auth {
8
9 namespace {
10
11 OAuth2TokenService::ScopeSet GetScopes() {
Ilya Sherman 2014/12/11 02:53:21 nit: Please add a brief docstring.
Tim Song 2014/12/12 20:48:44 Done.
12 OAuth2TokenService::ScopeSet scopes;
13 scopes.insert("https://www.googleapis.com/auth/cryptauth");
14 return scopes;
15 }
16
17 } // namespace
18
19 // Inherits from OAuth2TokenService for the token caching.
Ilya Sherman 2014/12/11 02:53:21 I'm not following what this comment means -- do yo
Tim Song 2014/12/12 20:48:44 Sorry, forgot to delete this comment.
20 CryptAuthAccountTokenFetcher::CryptAuthAccountTokenFetcher(
21 OAuth2TokenService* token_service,
22 const std::string& account_id)
23 : OAuth2TokenService::Consumer("cryptauth_account_token_fetcher"),
24 token_service_(token_service),
25 account_id_(account_id),
26 fetch_started_(false) {
27 }
28
29 CryptAuthAccountTokenFetcher::~CryptAuthAccountTokenFetcher() {
30 }
31
32 void CryptAuthAccountTokenFetcher::FetchAccessToken(
33 const AccessTokenCallback& callback) {
34 if (fetch_started_) {
35 LOG(WARNING) << "Create an instance for each token fetched. Do not reuse.";
36 callback.Run(std::string());
37 return;
38 }
39
40 fetch_started_ = true;
41 callback_ = callback;
42 // The service will cache the access token, so we do not need to make a
43 // network roundtrip for each token request.
Ilya Sherman 2014/12/11 02:53:21 I don't understand this comment -- where do we tak
Tim Song 2014/12/12 20:48:44 Done.
44 token_request_ = token_service_->StartRequest(account_id_, GetScopes(), this);
45 }
46
47 void CryptAuthAccountTokenFetcher::OnGetTokenSuccess(
48 const OAuth2TokenService::Request* request,
49 const std::string& access_token,
50 const base::Time& expiration_time) {
51 callback_.Run(access_token);
52 }
53
54 void CryptAuthAccountTokenFetcher::OnGetTokenFailure(
55 const OAuth2TokenService::Request* request,
56 const GoogleServiceAuthError& error) {
57 callback_.Run(std::string());
58 }
59
60 } // namespace proximity_auth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698