OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/proximity_auth/cryptauth/cryptauth_account_token_fetcher.h" | 5 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher_imp
l.h" |
6 | 6 |
7 namespace proximity_auth { | 7 namespace proximity_auth { |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
11 // Returns the set of OAuth2 scopes that CryptAuth uses. | 11 // Returns the set of OAuth2 scopes that CryptAuth uses. |
12 OAuth2TokenService::ScopeSet GetScopes() { | 12 OAuth2TokenService::ScopeSet GetScopes() { |
13 OAuth2TokenService::ScopeSet scopes; | 13 OAuth2TokenService::ScopeSet scopes; |
14 scopes.insert("https://www.googleapis.com/auth/cryptauth"); | 14 scopes.insert("https://www.googleapis.com/auth/cryptauth"); |
15 return scopes; | 15 return scopes; |
16 } | 16 } |
17 | 17 |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 CryptAuthAccountTokenFetcher::CryptAuthAccountTokenFetcher( | 20 CryptAuthAccessTokenFetcherImpl::CryptAuthAccessTokenFetcherImpl( |
21 OAuth2TokenService* token_service, | 21 OAuth2TokenService* token_service, |
22 const std::string& account_id) | 22 const std::string& account_id) |
23 : OAuth2TokenService::Consumer("cryptauth_account_token_fetcher"), | 23 : OAuth2TokenService::Consumer("cryptauth_access_token_fetcher"), |
24 token_service_(token_service), | 24 token_service_(token_service), |
25 account_id_(account_id), | 25 account_id_(account_id), |
26 fetch_started_(false) { | 26 fetch_started_(false) { |
27 } | 27 } |
28 | 28 |
29 CryptAuthAccountTokenFetcher::~CryptAuthAccountTokenFetcher() { | 29 CryptAuthAccessTokenFetcherImpl::~CryptAuthAccessTokenFetcherImpl() { |
30 } | 30 } |
31 | 31 |
32 void CryptAuthAccountTokenFetcher::FetchAccessToken( | 32 void CryptAuthAccessTokenFetcherImpl::FetchAccessToken( |
33 const AccessTokenCallback& callback) { | 33 const AccessTokenCallback& callback) { |
34 if (fetch_started_) { | 34 if (fetch_started_) { |
35 LOG(WARNING) << "Create an instance for each token fetched. Do not reuse."; | 35 LOG(WARNING) << "Create an instance for each token fetched. Do not reuse."; |
36 callback.Run(std::string()); | 36 callback.Run(std::string()); |
37 return; | 37 return; |
38 } | 38 } |
39 | 39 |
40 fetch_started_ = true; | 40 fetch_started_ = true; |
41 callback_ = callback; | 41 callback_ = callback; |
42 // This request will return a cached result if it is available, saving a | 42 // This request will return a cached result if it is available, saving a |
43 // network round trip every time we fetch the access token. | 43 // network round trip every time we fetch the access token. |
44 token_request_ = token_service_->StartRequest(account_id_, GetScopes(), this); | 44 token_request_ = token_service_->StartRequest(account_id_, GetScopes(), this); |
45 } | 45 } |
46 | 46 |
47 void CryptAuthAccountTokenFetcher::OnGetTokenSuccess( | 47 void CryptAuthAccessTokenFetcherImpl::OnGetTokenSuccess( |
48 const OAuth2TokenService::Request* request, | 48 const OAuth2TokenService::Request* request, |
49 const std::string& access_token, | 49 const std::string& access_token, |
50 const base::Time& expiration_time) { | 50 const base::Time& expiration_time) { |
51 callback_.Run(access_token); | 51 callback_.Run(access_token); |
52 } | 52 } |
53 | 53 |
54 void CryptAuthAccountTokenFetcher::OnGetTokenFailure( | 54 void CryptAuthAccessTokenFetcherImpl::OnGetTokenFailure( |
55 const OAuth2TokenService::Request* request, | 55 const OAuth2TokenService::Request* request, |
56 const GoogleServiceAuthError& error) { | 56 const GoogleServiceAuthError& error) { |
57 callback_.Run(std::string()); | 57 callback_.Run(std::string()); |
58 } | 58 } |
59 | 59 |
60 } // namespace proximity_auth | 60 } // namespace proximity_auth |
OLD | NEW |