Commit c7d2b240 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Move ClearCache*() from O2TS to PO2TS

This CL is a part of moving access token management to
OAuth2AccessTokenManager.

It is specifically a step toward folding O2TS into PO2TS
now that the latter is only one subclass of O2TS.

It moves ClearCache() and ClearCacheForAccount() into
PO2TS and this CL stops exposing O2TS::RegisterTokenResponse()
which adds a token to the cache since it's handled inside
OAuth2AccessTokenManager.

Bug: 967598
Change-Id: I1b05b0ac7fe2e6f8d0b22873d9eadaf370e2b78a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1699354
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676852}
parent eff06348
...@@ -295,6 +295,15 @@ void ProfileOAuth2TokenService::OnRefreshTokensLoaded() { ...@@ -295,6 +295,15 @@ void ProfileOAuth2TokenService::OnRefreshTokensLoaded() {
RecreateDeviceIdIfNeeded(); RecreateDeviceIdIfNeeded();
} }
void ProfileOAuth2TokenService::ClearCache() {
token_manager_->ClearCache();
}
void ProfileOAuth2TokenService::ClearCacheForAccount(
const CoreAccountId& account_id) {
token_manager_->ClearCacheForAccount(account_id);
}
bool ProfileOAuth2TokenService::HasLoadCredentialsFinishedWithNoErrors() { bool ProfileOAuth2TokenService::HasLoadCredentialsFinishedWithNoErrors() {
switch (GetDelegate()->load_credentials_state()) { switch (GetDelegate()->load_credentials_state()) {
case OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_NOT_STARTED: case OAuth2TokenServiceDelegate::LOAD_CREDENTIALS_NOT_STARTED:
......
...@@ -179,6 +179,14 @@ class ProfileOAuth2TokenService : public OAuth2TokenService { ...@@ -179,6 +179,14 @@ class ProfileOAuth2TokenService : public OAuth2TokenService {
void OnRefreshTokenRevoked(const CoreAccountId& account_id) override; void OnRefreshTokenRevoked(const CoreAccountId& account_id) override;
void OnRefreshTokensLoaded() override; void OnRefreshTokensLoaded() override;
// 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);
// Creates a new device ID if there are no accounts, or if the current device // Creates a new device ID if there are no accounts, or if the current device
// ID is empty. // ID is empty.
void RecreateDeviceIdIfNeeded(); void RecreateDeviceIdIfNeeded();
...@@ -192,6 +200,8 @@ class ProfileOAuth2TokenService : public OAuth2TokenService { ...@@ -192,6 +200,8 @@ class ProfileOAuth2TokenService : public OAuth2TokenService {
signin_metrics::SourceForRefreshTokenOperation update_refresh_token_source_ = signin_metrics::SourceForRefreshTokenOperation update_refresh_token_source_ =
signin_metrics::SourceForRefreshTokenOperation::kUnknown; signin_metrics::SourceForRefreshTokenOperation::kUnknown;
FRIEND_TEST_ALL_PREFIXES(ProfileOAuth2TokenServiceTest, UpdateClearsCache);
DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService); DISALLOW_COPY_AND_ASSIGN(ProfileOAuth2TokenService);
}; };
......
...@@ -73,8 +73,6 @@ class TestProfileOAuth2TokenService : public ProfileOAuth2TokenService { ...@@ -73,8 +73,6 @@ class TestProfileOAuth2TokenService : public ProfileOAuth2TokenService {
CancelRequestsForAccount(account_id); CancelRequestsForAccount(account_id);
} }
void ClearCacheForTest() { ClearCache(); }
FakeOAuth2TokenServiceDelegate* GetFakeOAuth2TokenServiceDelegate() { FakeOAuth2TokenServiceDelegate* GetFakeOAuth2TokenServiceDelegate() {
return static_cast<FakeOAuth2TokenServiceDelegate*>(GetDelegate()); return static_cast<FakeOAuth2TokenServiceDelegate*>(GetDelegate());
} }
...@@ -815,7 +813,7 @@ TEST_F(ProfileOAuth2TokenServiceTest, UpdateClearsCache) { ...@@ -815,7 +813,7 @@ TEST_F(ProfileOAuth2TokenServiceTest, UpdateClearsCache) {
EXPECT_EQ("token", consumer_.last_token_); EXPECT_EQ("token", consumer_.last_token_);
EXPECT_EQ(1, oauth2_service_->GetTokenCacheCount()); EXPECT_EQ(1, oauth2_service_->GetTokenCacheCount());
oauth2_service_->ClearCacheForTest(); oauth2_service_->ClearCache();
EXPECT_EQ(0, oauth2_service_->GetTokenCacheCount()); EXPECT_EQ(0, oauth2_service_->GetTokenCacheCount());
oauth2_service_->GetFakeOAuth2TokenServiceDelegate()->UpdateCredentials( oauth2_service_->GetFakeOAuth2TokenServiceDelegate()->UpdateCredentials(
......
...@@ -150,26 +150,6 @@ void OAuth2TokenService::OnRefreshTokensLoaded() { ...@@ -150,26 +150,6 @@ void OAuth2TokenService::OnRefreshTokensLoaded() {
all_credentials_loaded_ = true; all_credentials_loaded_ = true;
} }
void OAuth2TokenService::RegisterTokenResponse(
const std::string& client_id,
const CoreAccountId& account_id,
const OAuth2AccessTokenManager::ScopeSet& scopes,
const OAuth2AccessTokenConsumer::TokenResponse& token_response) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
token_manager_->RegisterTokenResponse(client_id, account_id, scopes,
token_response);
}
void OAuth2TokenService::ClearCache() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
token_manager_->ClearCache();
}
void OAuth2TokenService::ClearCacheForAccount(const CoreAccountId& account_id) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
token_manager_->ClearCacheForAccount(account_id);
}
void OAuth2TokenService::CancelAllRequests() { void OAuth2TokenService::CancelAllRequests() {
token_manager_->CancelAllRequests(); token_manager_->CancelAllRequests();
} }
......
...@@ -152,23 +152,6 @@ class OAuth2TokenService : public OAuth2TokenServiceObserver, ...@@ -152,23 +152,6 @@ class OAuth2TokenService : public OAuth2TokenServiceObserver,
// OAuth2TokenServiceObserver: // OAuth2TokenServiceObserver:
void OnRefreshTokensLoaded() override; void OnRefreshTokensLoaded() override;
// Add a new entry to the cache.
// Subclasses can override if there are implementation-specific reasons
// that an access token should ever not be cached.
virtual void RegisterTokenResponse(
const std::string& client_id,
const CoreAccountId& account_id,
const OAuth2AccessTokenManager::ScopeSet& scopes,
const OAuth2AccessTokenConsumer::TokenResponse& token_response);
// 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);
// Cancels all requests that are currently in progress. Virtual so it can be // Cancels all requests that are currently in progress. Virtual so it can be
// overridden for tests. // overridden for tests.
// Deprecated. It's moved to OAuth2AccessTokenManager. // Deprecated. It's moved to OAuth2AccessTokenManager.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment