forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth2_access_token_manager.h
70 lines (56 loc) · 2.84 KB
/
oauth2_access_token_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_MANAGER_H_
#define GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_MANAGER_H_
#include "base/sequence_checker.h"
#include "google_apis/gaia/core_account_id.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
// TODO(https://crbug.com/967598): Remove this once OAuth2AccessTokenManager's
// separated from OAuth2TokenService.
#include "google_apis/gaia/oauth2_token_service.h"
// Class that manages requests for OAuth2 access tokens.
class OAuth2AccessTokenManager {
public:
// TODO(https://crbug.com/967598): Remove |token_service| parameter once
// OAuth2AccessTokenManager fully manages access tokens independently of
// OAuth2TokenService.
explicit OAuth2AccessTokenManager(OAuth2TokenService* token_service);
virtual ~OAuth2AccessTokenManager();
// Add a new entry to the cache.
void RegisterTokenResponse(
const std::string& client_id,
const CoreAccountId& account_id,
const OAuth2TokenService::ScopeSet& scopes,
const OAuth2AccessTokenConsumer::TokenResponse& token_response);
// Returns a currently valid OAuth2 access token for the given set of scopes,
// or NULL if none have been cached. Note the user of this method should
// ensure no entry with the same |client_scopes| is added before the usage of
// the returned entry is done.
const OAuth2AccessTokenConsumer::TokenResponse* GetCachedTokenResponse(
const OAuth2TokenService::RequestParameters& client_scopes);
// Clears the internal token cache.
void ClearCache();
// Clears all of the tokens belonging to |account_id| from the internal token
// cache. It does not matter what other parameters, like |client_id| were
// used to request the tokens.
void ClearCacheForAccount(const CoreAccountId& account_id);
private:
// TODO(https://crbug.com/967598): Remove this once |token_cache_| management
// is moved to OAuth2AccessTokenManager.
friend class OAuth2TokenService;
OAuth2TokenService::TokenCache& token_cache() { return token_cache_; }
// Removes an access token for the given set of scopes from the cache.
// Returns true if the entry was removed, otherwise false.
bool RemoveCachedTokenResponse(
const OAuth2TokenService::RequestParameters& client_scopes,
const std::string& token_to_remove);
// The cache of currently valid tokens.
OAuth2TokenService::TokenCache token_cache_;
// TODO(https://crbug.com/967598): Remove this once OAuth2AccessTokenManager
// fully manages access tokens independently of OAuth2TokenService.
OAuth2TokenService* token_service_;
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(OAuth2AccessTokenManager);
};
#endif // GOOGLE_APIS_GAIA_OAUTH2_ACCESS_TOKEN_MANAGER_H_