Commit b995c41b authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Extract remaining platform-dependent parameters from PO2TSBuilder

This is an intermediate step in the process of moving all of
ProfileOAuth2TokenServiceBuilder code into IdentityManagerBuilder. To do
this, the building of PO2TS cannot use Profile not any code from
//chrome/browser.

In this CL, ProfileOAuth2TokenServiceBuilder is modified to access
cookie settings, the web data service and the reauth callback from
parameters provided by IdentityManagerFactory.

Bug: 974198
Change-Id: I9fe95b2f63859e5bcdd8128b362846ed5b212a50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1690843Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Cr-Commit-Position: refs/heads/master@{#676370}
parent 84adf551
...@@ -20,12 +20,17 @@ ...@@ -20,12 +20,17 @@
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/core/browser/webdata/token_web_data.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_manager_builder.h" #include "components/signin/public/identity_manager/identity_manager_builder.h"
#include "content/public/browser/network_service_instance.h" #include "content/public/browser/network_service_instance.h"
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/web_data_service_factory.h" #include "chrome/browser/web_data_service_factory.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/signin/core/browser/cookie_settings_util.h"
#include "components/signin/core/browser/mutable_profile_oauth2_token_service_delegate.h" #include "components/signin/core/browser/mutable_profile_oauth2_token_service_delegate.h"
#endif #endif
...@@ -35,6 +40,11 @@ ...@@ -35,6 +40,11 @@
#include "chromeos/components/account_manager/account_manager_factory.h" #include "chromeos/components/account_manager/account_manager_factory.h"
#endif #endif
#if defined(OS_WIN)
#include "base/bind.h"
#include "chrome/browser/signin/signin_util_win.h"
#endif
namespace { namespace {
std::unique_ptr<AccountTrackerService> BuildAccountTrackerService( std::unique_ptr<AccountTrackerService> BuildAccountTrackerService(
...@@ -114,6 +124,14 @@ KeyedService* IdentityManagerFactory::BuildServiceInstanceFor( ...@@ -114,6 +124,14 @@ KeyedService* IdentityManagerFactory::BuildServiceInstanceFor(
params.pref_service = profile->GetPrefs(); params.pref_service = profile->GetPrefs();
params.signin_client = ChromeSigninClientFactory::GetForProfile(profile); params.signin_client = ChromeSigninClientFactory::GetForProfile(profile);
#if !defined(OS_ANDROID)
params.delete_signin_cookies_on_exit =
signin::SettingsDeleteSigninCookiesOnExit(
CookieSettingsFactory::GetForProfile(profile).get());
params.token_web_data = WebDataServiceFactory::GetTokenWebDataForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS);
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::AccountManagerFactory* factory = chromeos::AccountManagerFactory* factory =
g_browser_process->platform_part()->GetAccountManagerFactory(); g_browser_process->platform_part()->GetAccountManagerFactory();
...@@ -125,11 +143,23 @@ KeyedService* IdentityManagerFactory::BuildServiceInstanceFor( ...@@ -125,11 +143,23 @@ KeyedService* IdentityManagerFactory::BuildServiceInstanceFor(
!chromeos::ProfileHelper::IsLockScreenAppProfile(profile); !chromeos::ProfileHelper::IsLockScreenAppProfile(profile);
#endif #endif
#if defined(OS_WIN)
params.reauth_callback =
base::BindRepeating(&signin_util::ReauthWithCredentialProviderIfPossible,
base::Unretained(profile));
#endif
params.token_service = ProfileOAuth2TokenServiceBuilder::BuildInstanceFor( params.token_service = ProfileOAuth2TokenServiceBuilder::BuildInstanceFor(
context, params.pref_service, params.account_tracker_service.get(), context, params.pref_service, params.account_tracker_service.get(),
params.network_connection_tracker, params.account_consistency, params.network_connection_tracker, params.account_consistency,
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
params.account_manager, params.is_regular_profile, params.account_manager, params.is_regular_profile,
#endif
#if !defined(OS_ANDROID)
params.delete_signin_cookies_on_exit, params.token_web_data,
#endif
#if defined(OS_WIN)
params.reauth_callback,
#endif #endif
params.signin_client); params.signin_client);
......
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/bind.h"
#include "base/callback.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "components/signin/public/base/account_consistency_method.h" #include "components/signin/public/base/account_consistency_method.h"
...@@ -19,11 +17,8 @@ ...@@ -19,11 +17,8 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "components/signin/core/browser/oauth2_token_service_delegate_android.h" #include "components/signin/core/browser/oauth2_token_service_delegate_android.h"
#else #else
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/web_data_service_factory.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/signin/core/browser/cookie_settings_util.h"
#include "components/signin/core/browser/mutable_profile_oauth2_token_service_delegate.h" #include "components/signin/core/browser/mutable_profile_oauth2_token_service_delegate.h"
#include "components/signin/core/browser/webdata/token_web_data.h"
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -33,10 +28,6 @@ ...@@ -33,10 +28,6 @@
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
#if defined(OS_WIN)
#include "chrome/browser/signin/signin_util_win.h"
#endif
namespace { namespace {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -82,27 +73,30 @@ CreateMutableProfileOAuthDelegate( ...@@ -82,27 +73,30 @@ CreateMutableProfileOAuthDelegate(
Profile* profile, Profile* profile,
AccountTrackerService* account_tracker_service, AccountTrackerService* account_tracker_service,
signin::AccountConsistencyMethod account_consistency, signin::AccountConsistencyMethod account_consistency,
bool delete_signin_cookies_on_exit,
scoped_refptr<TokenWebData> token_web_data,
SigninClient* signin_client, SigninClient* signin_client,
#if defined(OS_WIN)
MutableProfileOAuth2TokenServiceDelegate::FixRequestErrorCallback
reauth_callback,
#endif
network::NetworkConnectionTracker* network_connection_tracker) { network::NetworkConnectionTracker* network_connection_tracker) {
// When signin cookies are cleared on exit and Dice is enabled, all tokens // When signin cookies are cleared on exit and Dice is enabled, all tokens
// should also be cleared. // should also be cleared.
bool revoke_all_tokens_on_load = bool revoke_all_tokens_on_load =
(account_consistency == signin::AccountConsistencyMethod::kDice) && (account_consistency == signin::AccountConsistencyMethod::kDice) &&
signin::SettingsDeleteSigninCookiesOnExit( delete_signin_cookies_on_exit;
CookieSettingsFactory::GetForProfile(profile).get());
return std::make_unique<MutableProfileOAuth2TokenServiceDelegate>( return std::make_unique<MutableProfileOAuth2TokenServiceDelegate>(
signin_client, account_tracker_service, network_connection_tracker, signin_client, account_tracker_service, network_connection_tracker,
WebDataServiceFactory::GetTokenWebDataForProfile( token_web_data, account_consistency, revoke_all_tokens_on_load,
profile, ServiceAccessType::EXPLICIT_ACCESS),
account_consistency, revoke_all_tokens_on_load,
CanRevokeCredentials(profile), CanRevokeCredentials(profile),
#if defined(OS_WIN) #if defined(OS_WIN)
base::BindRepeating(&signin_util::ReauthWithCredentialProviderIfPossible, reauth_callback
base::Unretained(profile)));
#else #else
MutableProfileOAuth2TokenServiceDelegate::FixRequestErrorCallback()); MutableProfileOAuth2TokenServiceDelegate::FixRequestErrorCallback()
#endif // defined(OS_WIN) #endif // defined(OS_WIN)
);
} }
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
...@@ -114,6 +108,14 @@ std::unique_ptr<OAuth2TokenServiceDelegate> CreateOAuth2TokenServiceDelegate( ...@@ -114,6 +108,14 @@ std::unique_ptr<OAuth2TokenServiceDelegate> CreateOAuth2TokenServiceDelegate(
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::AccountManager* account_manager, chromeos::AccountManager* account_manager,
bool is_regular_profile, bool is_regular_profile,
#endif
#if !defined(OS_ANDROID)
bool delete_signin_cookies_on_exit,
scoped_refptr<TokenWebData> token_web_data,
#endif
#if defined(OS_WIN)
MutableProfileOAuth2TokenServiceDelegate::FixRequestErrorCallback
reauth_callback,
#endif #endif
network::NetworkConnectionTracker* network_connection_tracker) { network::NetworkConnectionTracker* network_connection_tracker) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -131,9 +133,14 @@ std::unique_ptr<OAuth2TokenServiceDelegate> CreateOAuth2TokenServiceDelegate( ...@@ -131,9 +133,14 @@ std::unique_ptr<OAuth2TokenServiceDelegate> CreateOAuth2TokenServiceDelegate(
// 1. On all platforms other than Android and Chrome OS. // 1. On all platforms other than Android and Chrome OS.
// 2. On Chrome OS, if Account Manager has not been switched on yet // 2. On Chrome OS, if Account Manager has not been switched on yet
// (chromeos::switches::IsAccountManagerEnabled). // (chromeos::switches::IsAccountManagerEnabled).
return CreateMutableProfileOAuthDelegate(profile, account_tracker_service, return CreateMutableProfileOAuthDelegate(
account_consistency, signin_client, profile, account_tracker_service, account_consistency,
network_connection_tracker); delete_signin_cookies_on_exit, token_web_data, signin_client,
#if defined(OS_WIN)
reauth_callback,
#endif
network_connection_tracker);
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
} }
...@@ -150,6 +157,14 @@ ProfileOAuth2TokenServiceBuilder::BuildInstanceFor( ...@@ -150,6 +157,14 @@ ProfileOAuth2TokenServiceBuilder::BuildInstanceFor(
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::AccountManager* account_manager, chromeos::AccountManager* account_manager,
bool is_regular_profile, bool is_regular_profile,
#endif
#if !defined(OS_ANDROID)
bool delete_signin_cookies_on_exit,
scoped_refptr<TokenWebData> token_web_data,
#endif
#if defined(OS_WIN)
MutableProfileOAuth2TokenServiceDelegate::FixRequestErrorCallback
reauth_callback,
#endif #endif
SigninClient* signin_client) { SigninClient* signin_client) {
Profile* profile = static_cast<Profile*>(context); Profile* profile = static_cast<Profile*>(context);
...@@ -165,10 +180,16 @@ ProfileOAuth2TokenServiceBuilder::BuildInstanceFor( ...@@ -165,10 +180,16 @@ ProfileOAuth2TokenServiceBuilder::BuildInstanceFor(
return std::make_unique<ProfileOAuth2TokenService>( return std::make_unique<ProfileOAuth2TokenService>(
pref_service, pref_service,
CreateOAuth2TokenServiceDelegate(profile, account_tracker_service, CreateOAuth2TokenServiceDelegate(
account_consistency, signin_client, profile, account_tracker_service, account_consistency, signin_client,
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
account_manager, is_regular_profile, account_manager, is_regular_profile,
#endif
#if !defined(OS_ANDROID)
delete_signin_cookies_on_exit, token_web_data,
#endif
#if defined(OS_WIN)
reauth_callback,
#endif #endif
network_connection_tracker)); network_connection_tracker));
} }
...@@ -7,13 +7,19 @@ ...@@ -7,13 +7,19 @@
#include <memory> #include <memory>
#include "base/memory/scoped_refptr.h"
#include "build/build_config.h" #include "build/build_config.h"
#if defined(OS_WIN)
#include "components/signin/core/browser/mutable_profile_oauth2_token_service_delegate.h"
#endif
class AccountTrackerService; class AccountTrackerService;
class IdentityManagerFactory; class IdentityManagerFactory;
class PrefService; class PrefService;
class ProfileOAuth2TokenService; class ProfileOAuth2TokenService;
class SigninClient; class SigninClient;
class TokenWebData;
namespace signin { namespace signin {
enum class AccountConsistencyMethod; enum class AccountConsistencyMethod;
...@@ -45,6 +51,14 @@ class ProfileOAuth2TokenServiceBuilder { ...@@ -45,6 +51,14 @@ class ProfileOAuth2TokenServiceBuilder {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::AccountManager* account_manager, chromeos::AccountManager* account_manager,
bool is_regular_profile, bool is_regular_profile,
#endif
#if !defined(OS_ANDROID)
bool delete_signin_cookies_on_exit,
scoped_refptr<TokenWebData> token_web_data,
#endif
#if defined(OS_WIN)
MutableProfileOAuth2TokenServiceDelegate::FixRequestErrorCallback
reauth_callback,
#endif #endif
SigninClient* signin_client); SigninClient* signin_client);
......
...@@ -46,6 +46,7 @@ source_set("identity_manager") { ...@@ -46,6 +46,7 @@ source_set("identity_manager") {
"//components/image_fetcher/core", "//components/image_fetcher/core",
"//components/prefs", "//components/prefs",
"//components/signin/core/browser:internals", "//components/signin/core/browser:internals",
"//components/signin/core/browser/webdata",
"//components/signin/internal/identity_manager", "//components/signin/internal/identity_manager",
"//services/network/public/cpp", "//services/network/public/cpp",
] ]
......
...@@ -20,9 +20,12 @@ ...@@ -20,9 +20,12 @@
#include "components/signin/public/identity_manager/accounts_mutator.h" #include "components/signin/public/identity_manager/accounts_mutator.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#if !defined(OS_ANDROID) && !defined(OS_IOS) #if !defined(OS_ANDROID)
#include "components/signin/core/browser/webdata/token_web_data.h"
#if !defined(OS_IOS)
#include "components/signin/internal/identity_manager/accounts_mutator_impl.h" #include "components/signin/internal/identity_manager/accounts_mutator_impl.h"
#endif #endif
#endif
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
#include "components/signin/core/browser/primary_account_policy_manager_impl.h" #include "components/signin/core/browser/primary_account_policy_manager_impl.h"
......
...@@ -7,12 +7,18 @@ ...@@ -7,12 +7,18 @@
#include <memory> #include <memory>
#include "base/memory/scoped_refptr.h"
#include "build/build_config.h" #include "build/build_config.h"
#if defined(OS_WIN)
#include "base/callback.h"
#endif
class AccountTrackerService; class AccountTrackerService;
class PrefService; class PrefService;
class ProfileOAuth2TokenService; class ProfileOAuth2TokenService;
class SigninClient; class SigninClient;
class TokenWebData;
namespace image_fetcher { namespace image_fetcher {
class ImageDecoder; class ImageDecoder;
...@@ -48,10 +54,19 @@ struct IdentityManagerBuildParams { ...@@ -48,10 +54,19 @@ struct IdentityManagerBuildParams {
SigninClient* signin_client; SigninClient* signin_client;
std::unique_ptr<ProfileOAuth2TokenService> token_service; std::unique_ptr<ProfileOAuth2TokenService> token_service;
#if !defined(OS_ANDROID)
bool delete_signin_cookies_on_exit;
scoped_refptr<TokenWebData> token_web_data;
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::AccountManager* account_manager; chromeos::AccountManager* account_manager;
bool is_regular_profile; bool is_regular_profile;
#endif #endif
#if defined(OS_WIN)
base::RepeatingCallback<bool()> reauth_callback;
#endif
}; };
// Builds an IdentityManager instance from the supplied embedder-level // Builds an IdentityManager instance from the supplied embedder-level
......
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