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

Move RefreshTokenIsAvailable and GetAccounts to DeviceO2TS

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

It is specifically a step toward folding
DeviceO2TSDelegate into DeviceO2TS now that the latter
is no longer an O2TS subclass.

It moves RefreshTokenIsAvailable and GetAccounts from
DeviceO2TSDelegate to DeviceO2TS not to refer to
|delegate_|.

Bug: 967598
Change-Id: I75faec6e9aa747dc908f9d9c2782dd01e426b847
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1692382Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#676317}
parent 3705a590
......@@ -110,7 +110,9 @@ void DeviceOAuth2TokenService::InvalidateAccessToken(
bool DeviceOAuth2TokenService::RefreshTokenIsAvailable(
const CoreAccountId& account_id) const {
return delegate_->RefreshTokenIsAvailable(account_id);
auto accounts = GetAccounts();
return std::find(accounts.begin(), accounts.end(), account_id) !=
accounts.end();
}
OAuth2AccessTokenManager* DeviceOAuth2TokenService::GetAccessTokenManager() {
......@@ -221,4 +223,24 @@ void DeviceOAuth2TokenService::FailRequest(
request->AsWeakPtr(), auth_error,
OAuth2AccessTokenConsumer::TokenResponse()));
}
std::vector<CoreAccountId> DeviceOAuth2TokenService::GetAccounts() const {
std::vector<CoreAccountId> accounts;
switch (delegate_->state_) {
case DeviceOAuth2TokenServiceDelegate::STATE_NO_TOKEN:
case DeviceOAuth2TokenServiceDelegate::STATE_TOKEN_INVALID:
return accounts;
case DeviceOAuth2TokenServiceDelegate::STATE_LOADING:
case DeviceOAuth2TokenServiceDelegate::STATE_VALIDATION_PENDING:
case DeviceOAuth2TokenServiceDelegate::STATE_VALIDATION_STARTED:
case DeviceOAuth2TokenServiceDelegate::STATE_TOKEN_VALID:
if (!GetRobotAccountId().empty())
accounts.push_back(GetRobotAccountId());
return accounts;
}
NOTREACHED() << "Unhandled state " << delegate_->state_;
return accounts;
}
} // namespace chromeos
......@@ -137,6 +137,9 @@ class DeviceOAuth2TokenService
void FailRequest(OAuth2AccessTokenManager::RequestImpl* request,
GoogleServiceAuthError::State error);
// Returns a list of accounts based on |state_|.
std::vector<CoreAccountId> GetAccounts() const;
// TODO(https://crbug.com/967598): Merge DeviceOAuth2TokenServiceDelegate
// into DeviceOAuth2TokenService.
std::unique_ptr<DeviceOAuth2TokenServiceDelegate> delegate_;
......
......@@ -83,33 +83,6 @@ void DeviceOAuth2TokenServiceDelegate::SetAndSaveRefreshToken(
}
}
bool DeviceOAuth2TokenServiceDelegate::RefreshTokenIsAvailable(
const CoreAccountId& account_id) const {
auto accounts = GetAccounts();
return std::find(accounts.begin(), accounts.end(), account_id) !=
accounts.end();
}
std::vector<CoreAccountId> DeviceOAuth2TokenServiceDelegate::GetAccounts()
const {
std::vector<CoreAccountId> accounts;
switch (state_) {
case STATE_NO_TOKEN:
case STATE_TOKEN_INVALID:
return accounts;
case STATE_LOADING:
case STATE_VALIDATION_PENDING:
case STATE_VALIDATION_STARTED:
case STATE_TOKEN_VALID:
if (!GetRobotAccountId().empty())
accounts.push_back(GetRobotAccountId());
return accounts;
}
NOTREACHED() << "Unhandled state " << state_;
return accounts;
}
CoreAccountId DeviceOAuth2TokenServiceDelegate::GetRobotAccountId() const {
if (!robot_account_id_for_testing_.empty()) {
return robot_account_id_for_testing_;
......
......@@ -59,13 +59,11 @@ class DeviceOAuth2TokenServiceDelegate
robot_account_id_for_testing_ = account_id;
}
bool RefreshTokenIsAvailable(const CoreAccountId& account_id) const;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() const;
std::unique_ptr<OAuth2AccessTokenFetcher> CreateAccessTokenFetcher(
const CoreAccountId& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
OAuth2AccessTokenConsumer* consumer);
std::vector<CoreAccountId> GetAccounts() const;
// gaia::GaiaOAuthClient::Delegate implementation.
void OnRefreshTokenResponse(const std::string& access_token,
......
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