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