blob: f683b54c038bc127621ab00a992a636ac6a4ff06 [file] [log] [blame]
tengs408c7412014-12-13 00:36:131// 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
khorimotof7a6aff2017-01-19 22:50:475#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_ACCESS_TOKEN_FETCHER_IMPL_H_
6#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_ACCESS_TOKEN_FETCHER_IMPL_H_
tengs408c7412014-12-13 00:36:137
dcheng2f012692016-04-21 00:19:348#include <memory>
9
tengs408c7412014-12-13 00:36:1310#include "base/callback.h"
avif57136c12015-12-25 23:27:4511#include "base/macros.h"
khorimoto999e934c2016-11-18 20:10:4212#include "components/cryptauth/cryptauth_access_token_fetcher.h"
tengs408c7412014-12-13 00:36:1313#include "google_apis/gaia/oauth2_token_service.h"
14
khorimoto999e934c2016-11-18 20:10:4215namespace cryptauth {
tengs408c7412014-12-13 00:36:1316
17// Implementation of CryptAuthAccessTokenFetcher fetching an access token for a
18// given account using the provided OAuth2TokenService.
tengs4cb782b2015-04-08 23:07:4119class CryptAuthAccessTokenFetcherImpl : public CryptAuthAccessTokenFetcher,
20 public OAuth2TokenService::Consumer {
tengs408c7412014-12-13 00:36:1321 public:
22 // |token_service| is not owned, and must outlive this object.
tengs4cb782b2015-04-08 23:07:4123 CryptAuthAccessTokenFetcherImpl(OAuth2TokenService* token_service,
24 const std::string& account_id);
25 ~CryptAuthAccessTokenFetcherImpl() override;
tengs408c7412014-12-13 00:36:1326
27 // CryptAuthAccessTokenFetcher:
28 void FetchAccessToken(const AccessTokenCallback& callback) override;
29
30 private:
31 // OAuth2TokenService::Consumer:
32 void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
33 const std::string& access_token,
34 const base::Time& expiration_time) override;
35 void OnGetTokenFailure(const OAuth2TokenService::Request* request,
36 const GoogleServiceAuthError& error) override;
37
38 // System service that caches and fetches tokens for a given account.
39 // Not owned.
40 OAuth2TokenService* token_service_;
41
42 // The account id for whom to mint the token.
43 std::string account_id_;
44
45 // True if FetchAccessToken() has been called.
46 bool fetch_started_;
47
48 // Stores the request from |token_service_| to mint the token.
dcheng2f012692016-04-21 00:19:3449 std::unique_ptr<OAuth2TokenService::Request> token_request_;
tengs408c7412014-12-13 00:36:1350
51 // Callback to invoke when the token fetch succeeds or fails.
52 AccessTokenCallback callback_;
53
tengs4cb782b2015-04-08 23:07:4154 DISALLOW_COPY_AND_ASSIGN(CryptAuthAccessTokenFetcherImpl);
tengs408c7412014-12-13 00:36:1355};
56
khorimoto999e934c2016-11-18 20:10:4257} // namespace cryptauth
tengs408c7412014-12-13 00:36:1358
khorimotof7a6aff2017-01-19 22:50:4759#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_ACCESS_TOKEN_FETCHER_IMPL_H_