Commit 908bc1a5 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Clean up DeviceO2TSDelegate

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

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

It moves GetURLLoaderFactory() and CreateAccessTokenFetcher()
to DeviceO2TS and eliminating DeviceO2TS inheriting from
DeviceOAuth2TokenServiceDelegate::ValidationStatusDelegate
since DeviceO2TS can handle ReportServiceError() by itself.

With this CL, device_oauth2_token_service_delegate.cc/h
are removed from the source tree.

Bug: 967598
Change-Id: I5e391cee94a67185c6e83aab8fccb54cf4b215a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1697002
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676378}
parent aa7e3f38
......@@ -1922,8 +1922,6 @@ source_set("chromeos") {
"settings/device_identity_provider.h",
"settings/device_oauth2_token_service.cc",
"settings/device_oauth2_token_service.h",
"settings/device_oauth2_token_service_delegate.cc",
"settings/device_oauth2_token_service_delegate.h",
"settings/device_oauth2_token_service_factory.cc",
"settings/device_oauth2_token_service_factory.h",
"settings/device_settings_cache.cc",
......
......@@ -24,7 +24,9 @@
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
#include "google_apis/gaia/oauth2_access_token_fetcher.h"
#include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace chromeos {
......@@ -46,22 +48,14 @@ struct DeviceOAuth2TokenService::PendingRequest {
const OAuth2AccessTokenManager::ScopeSet scopes;
};
void DeviceOAuth2TokenService::OnValidationCompleted(
GoogleServiceAuthError::State error) {
if (error == GoogleServiceAuthError::NONE)
FlushPendingRequests(true, GoogleServiceAuthError::NONE);
else
FlushPendingRequests(false, error);
}
DeviceOAuth2TokenService::DeviceOAuth2TokenService(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
PrefService* local_state)
: local_state_(local_state),
: url_loader_factory_(url_loader_factory),
local_state_(local_state),
state_(STATE_LOADING),
max_refresh_token_validation_retries_(3),
validation_requested_(false),
validation_status_delegate_(nullptr),
service_account_identity_subscription_(
CrosSettings::Get()->AddSettingsObserver(
kServiceAccountIdentity,
......@@ -69,11 +63,8 @@ DeviceOAuth2TokenService::DeviceOAuth2TokenService(
&DeviceOAuth2TokenService::OnServiceAccountIdentityChanged,
base::Unretained(this)))),
weak_ptr_factory_(this) {
delegate_ = std::make_unique<DeviceOAuth2TokenServiceDelegate>(
url_loader_factory, this);
token_manager_ = std::make_unique<OAuth2AccessTokenManager>(
this /* OAuth2AccessTokenManager::Delegate* */);
InitializeWithValidationStatusDelegate(this);
// Pull in the system salt.
SystemSaltGetter::Get()->GetSystemSalt(
base::Bind(&DeviceOAuth2TokenService::DidGetSystemSalt,
......@@ -82,7 +73,6 @@ DeviceOAuth2TokenService::DeviceOAuth2TokenService(
DeviceOAuth2TokenService::~DeviceOAuth2TokenService() {
FlushTokenSaveCallbacks(false);
ClearValidationStatusDelegate();
FlushPendingRequests(false, GoogleServiceAuthError::REQUEST_CANCELED);
}
......@@ -204,8 +194,10 @@ DeviceOAuth2TokenService::CreateAccessTokenFetcher(
const CoreAccountId& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
OAuth2AccessTokenConsumer* consumer) {
return delegate_->CreateAccessTokenFetcher(account_id, url_loader_factory,
consumer);
std::string refresh_token = GetRefreshToken();
DCHECK(!refresh_token.empty());
return std::make_unique<OAuth2AccessTokenFetcherImpl>(
consumer, url_loader_factory, refresh_token);
}
bool DeviceOAuth2TokenService::HasRefreshToken(
......@@ -215,7 +207,7 @@ bool DeviceOAuth2TokenService::HasRefreshToken(
scoped_refptr<network::SharedURLLoaderFactory>
DeviceOAuth2TokenService::GetURLLoaderFactory() const {
return delegate_->GetURLLoaderFactory();
return url_loader_factory_;
}
void DeviceOAuth2TokenService::FireRefreshTokenAvailable(
......@@ -279,9 +271,9 @@ void DeviceOAuth2TokenService::FlushPendingRequests(
if (token_is_valid) {
token_manager_->FetchOAuth2Token(
scoped_request->request.get(),
scoped_request->request->GetAccountId(),
delegate_->GetURLLoaderFactory(), scoped_request->client_id,
scoped_request->client_secret, scoped_request->scopes);
scoped_request->request->GetAccountId(), GetURLLoaderFactory(),
scoped_request->client_id, scoped_request->client_secret,
scoped_request->scopes);
} else {
FailRequest(scoped_request->request.get(), error);
}
......@@ -465,7 +457,7 @@ void DeviceOAuth2TokenService::StartValidation() {
state_ = STATE_VALIDATION_STARTED;
gaia_oauth_client_ =
std::make_unique<gaia::GaiaOAuthClient>(delegate_->url_loader_factory_);
std::make_unique<gaia::GaiaOAuthClient>(url_loader_factory_);
GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
gaia::OAuthClientInfo client_info;
......@@ -482,20 +474,12 @@ void DeviceOAuth2TokenService::RequestValidation() {
validation_requested_ = true;
}
void DeviceOAuth2TokenService::InitializeWithValidationStatusDelegate(
ValidationStatusDelegate* delegate) {
validation_status_delegate_ = delegate;
}
void DeviceOAuth2TokenService::ClearValidationStatusDelegate() {
validation_status_delegate_ = nullptr;
}
void DeviceOAuth2TokenService::ReportServiceError(
GoogleServiceAuthError::State error) {
if (validation_status_delegate_) {
validation_status_delegate_->OnValidationCompleted(error);
}
if (error == GoogleServiceAuthError::NONE)
FlushPendingRequests(true, GoogleServiceAuthError::NONE);
else
FlushPendingRequests(false, error);
}
} // namespace chromeos
......@@ -12,17 +12,17 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h"
#include "google_apis/gaia/core_account_id.h"
#include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
#include "google_apis/gaia/oauth2_access_token_manager.h"
namespace network {
class SharedURLLoaderFactory;
}
class OAuth2AccessTokenFetcher;
class OAuth2AccessTokenConsumer;
class PrefRegistrySimple;
class PrefService;
......@@ -35,10 +35,8 @@ namespace chromeos {
// be used in places where API expects |account_id|.
//
// Note that requests must be made from the UI thread.
class DeviceOAuth2TokenService
: public OAuth2AccessTokenManager::Delegate,
public gaia::GaiaOAuthClient::Delegate,
public DeviceOAuth2TokenServiceDelegate::ValidationStatusDelegate {
class DeviceOAuth2TokenService : public OAuth2AccessTokenManager::Delegate,
public gaia::GaiaOAuthClient::Delegate {
public:
typedef base::RepeatingCallback<void(const CoreAccountId& /* account_id */)>
RefreshTokenAvailableCallback;
......@@ -105,9 +103,6 @@ class DeviceOAuth2TokenService
void OnNetworkError(int response_code) override;
private:
// TODO(https://crbug.com/967598): Merge DeviceOAuth2TokenServiceDelegate
// into DeviceOAuth2TokenService.
friend class DeviceOAuth2TokenServiceDelegate;
friend class DeviceOAuth2TokenServiceFactory;
friend class DeviceOAuth2TokenServiceTest;
struct PendingRequest;
......@@ -147,13 +142,6 @@ class DeviceOAuth2TokenService
void FireRefreshTokenAvailable(const CoreAccountId& account_id);
void FireRefreshTokenRevoked(const CoreAccountId& account_id);
void InitializeWithValidationStatusDelegate(
ValidationStatusDelegate* delegate);
void ClearValidationStatusDelegate();
// Implementation of
// DeviceOAuth2TokenServiceDelegate::ValidationStatusDelegate.
void OnValidationCompleted(GoogleServiceAuthError::State error) override;
// Use DeviceOAuth2TokenServiceFactory to get an instance of this class.
explicit DeviceOAuth2TokenService(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
......@@ -198,9 +186,6 @@ class DeviceOAuth2TokenService
void ReportServiceError(GoogleServiceAuthError::State error);
// TODO(https://crbug.com/967598): Merge DeviceOAuth2TokenServiceDelegate
// into DeviceOAuth2TokenService.
std::unique_ptr<DeviceOAuth2TokenServiceDelegate> delegate_;
std::unique_ptr<OAuth2AccessTokenManager> token_manager_;
// Currently open requests that are waiting while loading the system salt or
......@@ -211,6 +196,8 @@ class DeviceOAuth2TokenService
RefreshTokenAvailableCallback on_refresh_token_available_callback_;
RefreshTokenRevokedCallback on_refresh_token_revoked_callback_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
PrefService* local_state_;
// Current operational state.
......@@ -227,9 +214,6 @@ class DeviceOAuth2TokenService
// Flag to indicate whether there are pending requests.
bool validation_requested_;
// Validation status delegate
ValidationStatusDelegate* validation_status_delegate_;
// Cache the decrypted refresh token, so we only decrypt once.
std::string refresh_token_;
......
// Copyright 2015 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.
#include "chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h"
#include <string>
#include "base/values.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
#include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace chromeos {
DeviceOAuth2TokenServiceDelegate::DeviceOAuth2TokenServiceDelegate(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
DeviceOAuth2TokenService* service)
: url_loader_factory_(url_loader_factory),
service_(service) {}
DeviceOAuth2TokenServiceDelegate::~DeviceOAuth2TokenServiceDelegate() = default;
scoped_refptr<network::SharedURLLoaderFactory>
DeviceOAuth2TokenServiceDelegate::GetURLLoaderFactory() const {
return url_loader_factory_;
}
std::unique_ptr<OAuth2AccessTokenFetcher>
DeviceOAuth2TokenServiceDelegate::CreateAccessTokenFetcher(
const CoreAccountId& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
OAuth2AccessTokenConsumer* consumer) {
std::string refresh_token = service_->GetRefreshToken();
DCHECK(!refresh_token.empty());
return std::make_unique<OAuth2AccessTokenFetcherImpl>(
consumer, url_loader_factory, refresh_token);
}
} // namespace chromeos
// Copyright 2015 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 CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "google_apis/gaia/core_account_id.h"
#include "google_apis/gaia/google_service_auth_error.h"
namespace network {
class SharedURLLoaderFactory;
}
class OAuth2AccessTokenFetcher;
class OAuth2AccessTokenConsumer;
namespace chromeos {
class DeviceOAuth2TokenService;
class DeviceOAuth2TokenServiceDelegate {
public:
DeviceOAuth2TokenServiceDelegate(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
DeviceOAuth2TokenService* service);
~DeviceOAuth2TokenServiceDelegate();
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() const;
std::unique_ptr<OAuth2AccessTokenFetcher> CreateAccessTokenFetcher(
const CoreAccountId& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
OAuth2AccessTokenConsumer* consumer);
class ValidationStatusDelegate {
public:
virtual void OnValidationCompleted(GoogleServiceAuthError::State error) {}
};
private:
friend class DeviceOAuth2TokenService;
friend class DeviceOAuth2TokenServiceTest;
// Dependencies.
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
// TODO(https://crbug.com/967598): Completely merge this class into
// DeviceOAuth2TokenService.
DeviceOAuth2TokenService* service_;
DISALLOW_COPY_AND_ASSIGN(DeviceOAuth2TokenServiceDelegate);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SETTINGS_DEVICE_OAUTH2_TOKEN_SERVICE_DELEGATE_H_
......@@ -7,7 +7,6 @@
#include <memory>
#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h"
#include "chrome/browser/chromeos/settings/token_encryptor.h"
#include "chromeos/cryptohome/system_salt_getter.h"
#include "content/public/browser/browser_thread.h"
......
......@@ -15,7 +15,6 @@
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/chromeos/policy/device_policy_builder.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/settings/device_oauth2_token_service_delegate.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/chromeos/settings/scoped_testing_cros_settings.h"
#include "chrome/browser/chromeos/settings/token_encryptor.h"
......
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