Commit 97e7182b authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Migrate AuthService from OAuth2TokenService to the IdentityManager

This removes the dependency on OAuth2TokenService from AuthService,
adapting all the clients of such API across the board, that is:

  - Private files from chrome/browser/chromeos/extensions/file_manager
  - drive::DriveAPIService (components/drive/service/drive_api_service.*)

Likewise, in order to keep chromium building and tests passing, this
changeset also updates the few clients of DriveAPIService in order to
pass an IdentityManager from now on, instead of an OAuth2TokenService:

  - //c/b/chromeos/drive/drive_integration_service.cc
  - //c/b/sync_file_system/drive_backend/sync_engine.*
  - //c/b/apps/platform_apps/api/sync_file_system/sync_file_system_browsertest.cc

...where //c/b stands for //chrome/browser.

Bug: 809440
Change-Id: I0c5691bcd2e86e8b0e7bca2f27fa42e2edc59a84
Reviewed-on: https://chromium-review.googlesource.com/c/1288571Reviewed-by: default avatarTaiju Tsuiki <tzik@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#602372}
parent 744e9c97
......@@ -20,6 +20,7 @@
#include "components/drive/service/fake_drive_service.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "storage/browser/quota/quota_manager.h"
#include "third_party/leveldatabase/leveldb_chrome.h"
......@@ -36,7 +37,7 @@ class FakeDriveServiceFactory
~FakeDriveServiceFactory() override {}
std::unique_ptr<drive::DriveServiceInterface> CreateDriveService(
OAuth2TokenService* oauth2_token_service,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::SequencedTaskRunner* blocking_task_runner) override {
std::unique_ptr<drive::FakeDriveService> drive_service(
......@@ -89,7 +90,7 @@ class SyncFileSystemTest : public extensions::PlatformAppBrowserTest,
nullptr, // notification_manager
extension_service,
fake_signin_manager_.get(), // signin_manager
nullptr, // token_service
nullptr, // identity_manager
nullptr, // url_loader_factory
std::move(drive_service_factory), in_memory_env_.get());
remote_service_->SetSyncEnabled(true);
......
......@@ -36,8 +36,7 @@
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/chromeos_features.h"
......@@ -55,8 +54,6 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
......@@ -619,8 +616,8 @@ DriveIntegrationService::DriveIntegrationService(
return;
}
ProfileOAuth2TokenService* oauth_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
if (test_drive_service) {
drive_service_.reset(test_drive_service);
......@@ -632,7 +629,7 @@ DriveIntegrationService::DriveIntegrationService(
->GetSharedURLLoaderFactory();
}
drive_service_ = std::make_unique<DriveAPIService>(
oauth_service, url_loader_factory, blocking_task_runner_.get(),
identity_manager, url_loader_factory, blocking_task_runner_.get(),
GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction),
GURL(google_apis::DriveApiUrlGenerator::kBaseThumbnailUrlForProduction),
GetDriveUserAgent(), NO_TRAFFIC_ANNOTATION_YET);
......@@ -1065,9 +1062,9 @@ void DriveIntegrationService::InitializeAfterMetadataInitialized(
return;
}
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile_);
drive_service_->Initialize(signin_manager->GetAuthenticatedAccountId());
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_);
drive_service_->Initialize(identity_manager->GetPrimaryAccountId());
if (error != FILE_ERROR_OK) {
LOG(WARNING) << "Failed to initialize: " << FileErrorToString(error);
......@@ -1212,9 +1209,9 @@ DriveIntegrationServiceFactory* DriveIntegrationServiceFactory::GetInstance() {
DriveIntegrationServiceFactory::DriveIntegrationServiceFactory()
: BrowserContextKeyedServiceFactory(
"DriveIntegrationService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
"DriveIntegrationService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(DriveNotificationManagerFactory::GetInstance());
DependsOn(DownloadCoreServiceFactory::GetInstance());
}
......
......@@ -34,22 +34,20 @@
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/extensions/api/file_manager_private_internal.h"
#include "chromeos/chromeos_switches.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state_handler.h"
#include "components/drive/chromeos/search_metadata.h"
#include "components/drive/event_logger.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "google_apis/drive/auth_service.h"
#include "google_apis/drive/drive_api_url_generator.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
#include "net/base/network_change_notifier.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "storage/common/fileapi/file_system_info.h"
#include "storage/common/fileapi/file_system_util.h"
......@@ -1657,11 +1655,9 @@ void FileManagerPrivateInternalGetDownloadUrlFunction::OnGotDownloadUrl(
return;
}
download_url_ = std::move(download_url);
ProfileOAuth2TokenService* oauth2_token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile());
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(GetProfile());
const std::string& account_id = signin_manager->GetAuthenticatedAccountId();
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(GetProfile());
const std::string& account_id = identity_manager->GetPrimaryAccountId();
std::vector<std::string> scopes;
scopes.emplace_back("https://www.googleapis.com/auth/drive.readonly");
......@@ -1669,7 +1665,7 @@ void FileManagerPrivateInternalGetDownloadUrlFunction::OnGotDownloadUrl(
content::BrowserContext::GetDefaultStoragePartition(GetProfile())
->GetURLLoaderFactoryForBrowserProcess();
auth_service_ = std::make_unique<google_apis::AuthService>(
oauth2_token_service, account_id, url_loader_factory, scopes);
identity_manager, account_id, url_loader_factory, scopes);
auth_service_->StartAuthentication(base::Bind(
&FileManagerPrivateInternalGetDownloadUrlFunction::OnTokenFetched, this));
}
......
......@@ -41,8 +41,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "chrome/browser/ui/chrome_pages.h"
......@@ -55,8 +54,6 @@
#include "components/drive/drive_pref_names.h"
#include "components/drive/event_logger.h"
#include "components/prefs/pref_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/user_manager/user_manager.h"
#include "components/zoom/page_zoom.h"
#include "content/public/browser/web_contents.h"
......@@ -67,6 +64,7 @@
#include "extensions/browser/app_window/app_window_registry.h"
#include "google_apis/drive/auth_service.h"
#include "net/base/hex_utils.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "storage/common/fileapi/file_system_types.h"
#include "ui/base/webui/web_ui_util.h"
......@@ -358,24 +356,22 @@ bool FileManagerPrivateRequestWebStoreAccessTokenFunction::RunAsync() {
std::vector<std::string> scopes;
scopes.emplace_back(kCWSScope);
ProfileOAuth2TokenService* oauth_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile());
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(GetProfile());
if (!oauth_service) {
if (!identity_manager) {
drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
if (logger) {
logger->Log(logging::LOG_ERROR,
"CWS OAuth token fetch failed. OAuth2TokenService can't "
"CWS Access token fetch failed. IdentityManager can't "
"be retrieved.");
}
SetResult(std::make_unique<base::Value>());
return false;
}
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(GetProfile());
auth_service_ = std::make_unique<google_apis::AuthService>(
oauth_service, signin_manager->GetAuthenticatedAccountId(),
identity_manager, identity_manager->GetPrimaryAccountId(),
g_browser_process->system_network_context_manager()
->GetSharedURLLoaderFactory(),
scopes);
......
......@@ -17,7 +17,7 @@
#include "chrome/browser/drive/drive_notification_manager_factory.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync_file_system/drive_backend/callback_helper.h"
#include "chrome/browser/sync_file_system/drive_backend/conflict_resolver.h"
......@@ -46,7 +46,6 @@
#include "components/drive/drive_uploader.h"
#include "components/drive/service/drive_api_service.h"
#include "components/drive/service/drive_service_interface.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/signin_manager.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
......@@ -61,6 +60,7 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/device/public/mojom/constants.mojom.h"
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/service_manager/public/cpp/connector.h"
#include "storage/browser/blob/scoped_file.h"
#include "storage/common/fileapi/file_system_util.h"
......@@ -96,12 +96,12 @@ constexpr net::NetworkTrafficAnnotationTag kSyncFileSystemTrafficAnnotation =
std::unique_ptr<drive::DriveServiceInterface>
SyncEngine::DriveServiceFactory::CreateDriveService(
OAuth2TokenService* oauth2_token_service,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::SequencedTaskRunner* blocking_task_runner) {
return std::unique_ptr<
drive::DriveServiceInterface>(new drive::DriveAPIService(
oauth2_token_service, url_loader_factory, blocking_task_runner,
identity_manager, url_loader_factory, blocking_task_runner,
GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction),
GURL(google_apis::DriveApiUrlGenerator::kBaseThumbnailUrlForProduction),
std::string(), /* custom_user_agent */
......@@ -213,8 +213,8 @@ std::unique_ptr<SyncEngine> SyncEngine::CreateForBrowserContext(
extensions::ExtensionSystem::Get(context)->extension_service();
SigninManagerBase* signin_manager =
SigninManagerFactory::GetForProfile(profile);
OAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory =
content::BrowserContext::GetDefaultStoragePartition(context)
->GetURLLoaderFactoryForBrowserProcess();
......@@ -222,7 +222,7 @@ std::unique_ptr<SyncEngine> SyncEngine::CreateForBrowserContext(
std::unique_ptr<drive_backend::SyncEngine> sync_engine(new SyncEngine(
ui_task_runner.get(), worker_task_runner.get(), drive_task_runner.get(),
GetSyncFileSystemDir(context->GetPath()), task_logger,
notification_manager, extension_service, signin_manager, token_service,
notification_manager, extension_service, signin_manager, identity_manager,
url_loader_factory, std::make_unique<DriveServiceFactory>(),
nullptr /* env_override */));
......@@ -237,7 +237,7 @@ void SyncEngine::AppendDependsOnFactories(
factories->insert(SigninManagerFactory::GetInstance());
factories->insert(
extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
factories->insert(ProfileOAuth2TokenServiceFactory::GetInstance());
factories->insert(IdentityManagerFactory::GetInstance());
}
SyncEngine::~SyncEngine() {
......@@ -277,7 +277,7 @@ void SyncEngine::Initialize() {
DCHECK(drive_service_factory_);
std::unique_ptr<drive::DriveServiceInterface> drive_service =
drive_service_factory_->CreateDriveService(
token_service_, url_loader_factory_, drive_task_runner_.get());
identity_manager_, url_loader_factory_, drive_task_runner_.get());
device::mojom::WakeLockProviderPtr wake_lock_provider(nullptr);
DCHECK(content::ServiceManagerConnection::GetForProcess());
......@@ -733,7 +733,7 @@ SyncEngine::SyncEngine(
drive::DriveNotificationManager* notification_manager,
extensions::ExtensionServiceInterface* extension_service,
SigninManagerBase* signin_manager,
OAuth2TokenService* token_service,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<DriveServiceFactory> drive_service_factory,
leveldb::Env* env_override)
......@@ -745,7 +745,7 @@ SyncEngine::SyncEngine(
notification_manager_(notification_manager),
extension_service_(extension_service),
signin_manager_(signin_manager),
token_service_(token_service),
identity_manager_(identity_manager),
url_loader_factory_(url_loader_factory),
drive_service_factory_(std::move(drive_service_factory)),
remote_change_processor_(nullptr),
......
......@@ -24,8 +24,6 @@
#include "services/network/public/cpp/network_connection_tracker.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
class OAuth2TokenService;
namespace base {
class SequencedTaskRunner;
}
......@@ -40,6 +38,10 @@ namespace extensions {
class ExtensionServiceInterface;
}
namespace identity {
class IdentityManager;
}
namespace leveldb {
class Env;
}
......@@ -76,7 +78,7 @@ class SyncEngine
DriveServiceFactory() {}
virtual ~DriveServiceFactory() {}
virtual std::unique_ptr<drive::DriveServiceInterface> CreateDriveService(
OAuth2TokenService* oauth2_token_service,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::SequencedTaskRunner* blocking_task_runner);
......@@ -169,7 +171,7 @@ class SyncEngine
drive::DriveNotificationManager* notification_manager,
extensions::ExtensionServiceInterface* extension_service,
SigninManagerBase* signin_manager,
OAuth2TokenService* token_service,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
std::unique_ptr<DriveServiceFactory> drive_service_factory,
leveldb::Env* env_override);
......@@ -200,7 +202,7 @@ class SyncEngine
drive::DriveNotificationManager* notification_manager_;
extensions::ExtensionServiceInterface* extension_service_;
SigninManagerBase* signin_manager_;
OAuth2TokenService* token_service_;
identity::IdentityManager* identity_manager_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
......
......@@ -223,14 +223,14 @@ void BatchRequestConfigurator::Commit() {
}
DriveAPIService::DriveAPIService(
OAuth2TokenService* oauth2_token_service,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::SequencedTaskRunner* blocking_task_runner,
const GURL& base_url,
const GURL& base_thumbnail_url,
const std::string& custom_user_agent,
const net::NetworkTrafficAnnotationTag& traffic_annotation)
: oauth2_token_service_(oauth2_token_service),
: identity_manager_(identity_manager),
url_loader_factory_(url_loader_factory),
blocking_task_runner_(blocking_task_runner),
url_generator_(base_url, base_thumbnail_url),
......@@ -252,8 +252,8 @@ void DriveAPIService::Initialize(const std::string& account_id) {
scopes.push_back(kDriveAppsScope);
sender_ = std::make_unique<RequestSender>(
std::make_unique<google_apis::AuthService>(
oauth2_token_service_, account_id, url_loader_factory_, scopes),
std::make_unique<google_apis::AuthService>(identity_manager_, account_id,
url_loader_factory_, scopes),
url_loader_factory_, blocking_task_runner_.get(), custom_user_agent_,
traffic_annotation_);
sender_->auth_service()->AddObserver(this);
......
......@@ -23,7 +23,6 @@
#include "net/traffic_annotation/network_traffic_annotation.h"
class GURL;
class OAuth2TokenService;
namespace base {
class FilePath;
......@@ -38,6 +37,10 @@ class BatchUploadRequest;
} // namespace drive
} // namespace google_apis
namespace identity {
class IdentityManager;
}
namespace network {
class SharedURLLoaderFactory;
}
......@@ -93,7 +96,7 @@ class BatchRequestConfigurator : public BatchRequestConfiguratorInterface {
class DriveAPIService : public DriveServiceInterface,
public google_apis::AuthServiceObserver {
public:
// |oauth2_token_service| is used for obtaining OAuth2 access tokens.
// |identity_manager| is used for interacting with the identity service.
// |url_request_context_getter| is used to initialize URLFetcher.
// |url_loader_factory| is used to create SimpleURLLoaders used to create
// OAuth tokens.
......@@ -106,7 +109,7 @@ class DriveAPIService : public DriveServiceInterface,
// |traffic_annotation| will be used to annotate the network request that will
// be created to perform this service.
DriveAPIService(
OAuth2TokenService* oauth2_token_service,
identity::IdentityManager* identity_manager,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::SequencedTaskRunner* blocking_task_runner,
const GURL& base_url,
......@@ -264,7 +267,7 @@ class DriveAPIService : public DriveServiceInterface,
// The class is expected to run on UI thread.
base::ThreadChecker thread_checker_;
OAuth2TokenService* oauth2_token_service_;
identity::IdentityManager* identity_manager_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
std::unique_ptr<google_apis::RequestSender> sender_;
......
......@@ -32,15 +32,14 @@ const int kSuccessRatioHistogramTemporaryFailure = 3;
const int kSuccessRatioHistogramMaxValue = 4; // The max value is exclusive.
void RecordAuthResultHistogram(int value) {
UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
value,
UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", value,
kSuccessRatioHistogramMaxValue);
}
// OAuth2 authorization token retrieval request.
class AuthRequest {
public:
AuthRequest(OAuth2TokenService* oauth2_token_service,
AuthRequest(identity::IdentityManager* identity_manager,
const std::string& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const AuthStatusCallback& callback,
......@@ -59,16 +58,17 @@ class AuthRequest {
};
AuthRequest::AuthRequest(
OAuth2TokenService* oauth2_token_service,
identity::IdentityManager* identity_manager,
const std::string& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const AuthStatusCallback& callback,
const std::vector<std::string>& scopes)
: callback_(callback) {
DCHECK(identity_manager);
DCHECK(!callback_.is_null());
access_token_fetcher_ = std::make_unique<identity::AccessTokenFetcher>(
account_id, "auth_service", oauth2_token_service, url_loader_factory,
access_token_fetcher_ = identity_manager->CreateAccessTokenFetcherForAccount(
account_id, "auth_service", url_loader_factory,
OAuth2TokenService::ScopeSet(scopes.begin(), scopes.end()),
base::BindOnce(&AuthRequest::OnAccessTokenFetchComplete,
base::Unretained(this)),
......@@ -111,25 +111,24 @@ void AuthRequest::OnAccessTokenFetchComplete(
} // namespace
AuthService::AuthService(
OAuth2TokenService* oauth2_token_service,
identity::IdentityManager* identity_manager,
const std::string& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<std::string>& scopes)
: oauth2_token_service_(oauth2_token_service),
: identity_manager_(identity_manager),
account_id_(account_id),
url_loader_factory_(url_loader_factory),
scopes_(scopes),
weak_ptr_factory_(this) {
DCHECK(oauth2_token_service);
DCHECK(identity_manager_);
// Get OAuth2 refresh token (if we have any) and register for its updates.
oauth2_token_service_->AddObserver(this);
has_refresh_token_ = oauth2_token_service_->RefreshTokenIsAvailable(
account_id_);
identity_manager_->AddObserver(this);
has_refresh_token_ =
identity_manager_->HasAccountWithRefreshToken(account_id_);
}
AuthService::~AuthService() {
oauth2_token_service_->RemoveObserver(this);
identity_manager_->RemoveObserver(this);
}
void AuthService::StartAuthentication(const AuthStatusCallback& callback) {
......@@ -141,7 +140,7 @@ void AuthService::StartAuthentication(const AuthStatusCallback& callback) {
FROM_HERE, base::Bind(callback, HTTP_SUCCESS, access_token_));
} else if (HasRefreshToken()) {
// We have refresh token, let's get an access token.
new AuthRequest(oauth2_token_service_, account_id_, url_loader_factory_,
new AuthRequest(identity_manager_, account_id_, url_loader_factory_,
base::Bind(&AuthService::OnAuthCompleted,
weak_ptr_factory_.GetWeakPtr(), callback),
scopes_);
......@@ -201,12 +200,15 @@ void AuthService::RemoveObserver(AuthServiceObserver* observer) {
observers_.RemoveObserver(observer);
}
void AuthService::OnRefreshTokenAvailable(const std::string& account_id) {
if (account_id == account_id_)
void AuthService::OnRefreshTokenUpdatedForAccount(
const AccountInfo& account_info,
bool is_valid) {
if (account_info.account_id == account_id_)
OnHandleRefreshToken(true);
}
void AuthService::OnRefreshTokenRevoked(const std::string& account_id) {
void AuthService::OnRefreshTokenRemovedForAccount(
const std::string& account_id) {
if (account_id == account_id_)
OnHandleRefreshToken(false);
}
......
......@@ -14,7 +14,7 @@
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "google_apis/drive/auth_service_interface.h"
#include "google_apis/gaia/oauth2_token_service.h"
#include "services/identity/public/cpp/identity_manager.h"
namespace network {
class SharedURLLoaderFactory;
......@@ -25,17 +25,17 @@ namespace google_apis {
class AuthServiceObserver;
// This class provides authentication for Google services.
// It integrates specific service integration with OAuth2 stack
// (OAuth2TokenService) and provides OAuth2 token refresh infrastructure.
// It integrates specific service integration with the Identity service
// (IdentityManager) and provides OAuth2 token refresh infrastructure.
// All public functions must be called on UI thread.
class AuthService : public AuthServiceInterface,
public OAuth2TokenService::Observer {
public identity::IdentityManager::Observer {
public:
// |url_loader_factory| is used to perform authentication with
// SimpleURLLoader.
//
// |scopes| specifies OAuth2 scopes.
AuthService(OAuth2TokenService* oauth2_token_service,
AuthService(identity::IdentityManager* identity_manager,
const std::string& account_id,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const std::vector<std::string>& scopes);
......@@ -51,9 +51,10 @@ class AuthService : public AuthServiceInterface,
void ClearAccessToken() override;
void ClearRefreshToken() override;
// Overridden from OAuth2TokenService::Observer:
void OnRefreshTokenAvailable(const std::string& account_id) override;
void OnRefreshTokenRevoked(const std::string& account_id) override;
// Overridden from IdentityManager::Observer
void OnRefreshTokenUpdatedForAccount(const AccountInfo& account_info,
bool is_valid) override;
void OnRefreshTokenRemovedForAccount(const std::string& account_id) override;
private:
// Called when the state of the refresh token changes.
......@@ -65,7 +66,7 @@ class AuthService : public AuthServiceInterface,
DriveApiErrorCode error,
const std::string& access_token);
OAuth2TokenService* oauth2_token_service_;
identity::IdentityManager* identity_manager_;
std::string account_id_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
bool has_refresh_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