Commit d3f0bde5 authored by Mario Sanchez Prada's avatar Mario Sanchez Prada Committed by Commit Bot

Only require IdentityManager as main parameter for identity_test_utils.h APIs

This will remove the need to know about specific instances of SigninManager,
AccountTrackerService, ProfileOAuth2TokenService and GaiaCookieManagerService
from the calling places for those methods.

Also move the SigninManagerForTest definition in identity_test_environment.h
one level up, to allow sharing it among |IdentityManagerDependenciesOwner|
and |IdentityTestEnvironment| without relying on such definition being also
available from identity_test_utils.h (from where it's now being removed due
to no longer being required by those test utilities).

Bug: 904404
Change-Id: If96b0c7dea763030dc7372d58922f82a31eb5733
Reviewed-on: https://chromium-review.googlesource.com/c/1336127
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609216}
parent 8bbbc97c
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_function_test_utils.h" #include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h" #include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -37,7 +36,6 @@ ...@@ -37,7 +36,6 @@
#include "components/drive/drive_pref_names.h" #include "components/drive/drive_pref_names.h"
#include "components/drive/file_change.h" #include "components/drive/file_change.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/signin/core/browser/signin_manager_base.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/install_warning.h" #include "extensions/common/install_warning.h"
#include "google_apis/drive/test_util.h" #include "google_apis/drive/test_util.h"
...@@ -365,7 +363,6 @@ class FileManagerPrivateApiTest : public extensions::ExtensionApiTest { ...@@ -365,7 +363,6 @@ class FileManagerPrivateApiTest : public extensions::ExtensionApiTest {
{features::kCrostini, features::kExperimentalCrostiniUI}, {}); {features::kCrostini, features::kExperimentalCrostiniUI}, {});
// Profile must be signed in with email for crostini. // Profile must be signed in with email for crostini.
identity::SetPrimaryAccount( identity::SetPrimaryAccount(
SigninManagerFactory::GetForProfileIfExists(browser()->profile()),
IdentityManagerFactory::GetForProfileIfExists(browser()->profile()), IdentityManagerFactory::GetForProfileIfExists(browser()->profile()),
"testuser@gmail.com"); "testuser@gmail.com");
} }
......
...@@ -489,8 +489,7 @@ class IdentityTestWithSignin : public AsyncExtensionBrowserTest { ...@@ -489,8 +489,7 @@ class IdentityTestWithSignin : public AsyncExtensionBrowserTest {
std::string SignIn(const std::string& email) { std::string SignIn(const std::string& email) {
identity::IdentityManager* identity_manager = identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile()); IdentityManagerFactory::GetForProfile(profile());
identity::MakePrimaryAccountAvailable(signin_manager_, token_service_, identity::MakePrimaryAccountAvailable(identity_manager, email);
identity_manager, email);
return identity_manager->GetPrimaryAccountId(); return identity_manager->GetPrimaryAccountId();
} }
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h" #include "chrome/browser/sync/test/integration/quiesce_status_change_checker.h"
#include "chrome/browser/sync/test/integration/single_client_status_change_checker.h" #include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
...@@ -25,7 +23,6 @@ ...@@ -25,7 +23,6 @@
#include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h"
#include "chrome/browser/unified_consent/unified_consent_service_factory.h" #include "chrome/browser/unified_consent/unified_consent_service_factory.h"
#include "chrome/common/channel_info.h" #include "chrome/common/channel_info.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync/driver/about_sync_util.h" #include "components/sync/driver/about_sync_util.h"
#include "components/sync/engine/sync_string_conversions.h" #include "components/sync/engine/sync_string_conversions.h"
#include "components/unified_consent/feature.h" #include "components/unified_consent/feature.h"
...@@ -140,8 +137,6 @@ bool ProfileSyncServiceHarness::SignInPrimaryAccount() { ...@@ -140,8 +137,6 @@ bool ProfileSyncServiceHarness::SignInPrimaryAccount() {
case SigninType::FAKE_SIGNIN: { case SigninType::FAKE_SIGNIN: {
identity::IdentityManager* identity_manager = identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_); IdentityManagerFactory::GetForProfile(profile_);
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
// Verify HasPrimaryAccount() separately because // Verify HasPrimaryAccount() separately because
// MakePrimaryAccountAvailable() below DCHECK fails if there is already // MakePrimaryAccountAvailable() below DCHECK fails if there is already
...@@ -154,13 +149,11 @@ bool ProfileSyncServiceHarness::SignInPrimaryAccount() { ...@@ -154,13 +149,11 @@ bool ProfileSyncServiceHarness::SignInPrimaryAccount() {
// always hand out the same access token string, any new access token // always hand out the same access token string, any new access token
// acquired later would also be considered invalid. // acquired later would also be considered invalid.
if (!identity_manager->HasPrimaryAccountWithRefreshToken()) { if (!identity_manager->HasPrimaryAccountWithRefreshToken()) {
identity::SetRefreshTokenForPrimaryAccount(token_service, identity::SetRefreshTokenForPrimaryAccount(identity_manager);
identity_manager);
} }
} else { } else {
// Authenticate sync client using GAIA credentials. // Authenticate sync client using GAIA credentials.
identity::MakePrimaryAccountAvailable( identity::MakePrimaryAccountAvailable(
SigninManagerFactory::GetForProfile(profile_), token_service,
identity_manager, username_); identity_manager, username_);
} }
return true; return true;
...@@ -175,7 +168,6 @@ bool ProfileSyncServiceHarness::SignInPrimaryAccount() { ...@@ -175,7 +168,6 @@ bool ProfileSyncServiceHarness::SignInPrimaryAccount() {
void ProfileSyncServiceHarness::SignOutPrimaryAccount() { void ProfileSyncServiceHarness::SignOutPrimaryAccount() {
DCHECK(!username_.empty()); DCHECK(!username_.empty());
identity::ClearPrimaryAccount( identity::ClearPrimaryAccount(
SigninManagerFactory::GetForProfile(profile_),
IdentityManagerFactory::GetForProfile(profile_), IdentityManagerFactory::GetForProfile(profile_),
identity::ClearPrimaryAccountPolicy::REMOVE_ALL_ACCOUNTS); identity::ClearPrimaryAccountPolicy::REMOVE_ALL_ACCOUNTS);
} }
......
...@@ -6,11 +6,9 @@ ...@@ -6,11 +6,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
#include "chrome/browser/signin/fake_gaia_cookie_manager_service_builder.h" #include "chrome/browser/signin/fake_gaia_cookie_manager_service_builder.h"
#include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/signin/signin_manager_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/signin/core/browser/fake_gaia_cookie_manager_service.h" #include "components/signin/core/browser/fake_gaia_cookie_manager_service.h"
...@@ -69,8 +67,6 @@ void SignInSecondaryAccount(Profile* profile, const std::string& email) { ...@@ -69,8 +67,6 @@ void SignInSecondaryAccount(Profile* profile, const std::string& email) {
identity::IdentityManager* identity_manager = identity::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile); IdentityManagerFactory::GetForProfile(profile);
AccountInfo account_info = identity::MakeAccountAvailable( AccountInfo account_info = identity::MakeAccountAvailable(
AccountTrackerServiceFactory::GetForProfile(profile),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
identity_manager, email); identity_manager, email);
FakeGaiaCookieManagerService* fake_cookie_service = FakeGaiaCookieManagerService* fake_cookie_service =
static_cast<FakeGaiaCookieManagerService*>( static_cast<FakeGaiaCookieManagerService*>(
......
...@@ -10,15 +10,12 @@ ...@@ -10,15 +10,12 @@
#include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/extensions/extension_installed_bubble.h" #include "chrome/browser/ui/extensions/extension_installed_bubble.h"
#include "chrome/browser/ui/test/test_browser_dialog.h" #include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "components/bubble/bubble_controller.h" #include "components/bubble/bubble_controller.h"
#include "components/bubble/bubble_ui.h" #include "components/bubble/bubble_ui.h"
#include "components/signin/core/browser/signin_manager.h"
#include "extensions/common/extension_builder.h" #include "extensions/common/extension_builder.h"
#include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_constants.h"
#include "services/identity/public/cpp/identity_test_utils.h" #include "services/identity/public/cpp/identity_test_utils.h"
...@@ -142,8 +139,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionInstalledBubbleBrowserTest, ...@@ -142,8 +139,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionInstalledBubbleBrowserTest,
DISABLED_InvokeUi_NoAction) { DISABLED_InvokeUi_NoAction) {
// Sign in to supppress the signin promo. // Sign in to supppress the signin promo.
identity::MakePrimaryAccountAvailable( identity::MakePrimaryAccountAvailable(
SigninManagerFactory::GetForProfile(profile()),
ProfileOAuth2TokenServiceFactory::GetForProfile(profile()),
IdentityManagerFactory::GetForProfile(profile()), "test@example.com"); IdentityManagerFactory::GetForProfile(profile()), "test@example.com");
ShowAndVerifyUi(); ShowAndVerifyUi();
} }
......
...@@ -366,8 +366,6 @@ class LocalDiscoveryUITest : public WebUIBrowserTest { ...@@ -366,8 +366,6 @@ class LocalDiscoveryUITest : public WebUIBrowserTest {
kResponseRegisterComplete); kResponseRegisterComplete);
identity::MakePrimaryAccountAvailable( identity::MakePrimaryAccountAvailable(
SigninManagerFactory::GetForProfile(browser()->profile()),
ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()),
IdentityManagerFactory::GetForProfile(browser()->profile()), IdentityManagerFactory::GetForProfile(browser()->profile()),
kSampleUser); kSampleUser);
......
...@@ -207,6 +207,18 @@ void IdentityManager::RemoveDiagnosticsObserver(DiagnosticsObserver* observer) { ...@@ -207,6 +207,18 @@ void IdentityManager::RemoveDiagnosticsObserver(DiagnosticsObserver* observer) {
diagnostics_observer_list_.RemoveObserver(observer); diagnostics_observer_list_.RemoveObserver(observer);
} }
SigninManagerBase* IdentityManager::GetSigninManager() {
return signin_manager_;
}
ProfileOAuth2TokenService* IdentityManager::GetTokenService() {
return token_service_;
}
AccountTrackerService* IdentityManager::GetAccountTrackerService() {
return account_tracker_service_;
}
void IdentityManager::SetPrimaryAccountSynchronouslyForTests( void IdentityManager::SetPrimaryAccountSynchronouslyForTests(
const std::string& gaia_id, const std::string& gaia_id,
const std::string& email_address, const std::string& email_address,
......
...@@ -46,6 +46,7 @@ class MultiProfileDownloadNotificationTest; ...@@ -46,6 +46,7 @@ class MultiProfileDownloadNotificationTest;
namespace identity { namespace identity {
class PrimaryAccountMutator; class PrimaryAccountMutator;
enum class ClearPrimaryAccountPolicy;
// Gives access to information about the user's Google identities. See // Gives access to information about the user's Google identities. See
// ./README.md for detailed documentation. // ./README.md for detailed documentation.
...@@ -265,10 +266,32 @@ class IdentityManager : public SigninManagerBase::Observer, ...@@ -265,10 +266,32 @@ class IdentityManager : public SigninManagerBase::Observer,
void RemoveDiagnosticsObserver(DiagnosticsObserver* observer); void RemoveDiagnosticsObserver(DiagnosticsObserver* observer);
private: private:
// These clients need to call SetPrimaryAccountSynchronouslyForTests(). // These test helpers need to use some of the private methods below.
friend AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager, friend AccountInfo SetPrimaryAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& email); const std::string& email);
friend void SetRefreshTokenForPrimaryAccount(
IdentityManager* identity_manager);
friend void SetInvalidRefreshTokenForPrimaryAccount(
IdentityManager* identity_manager);
friend void RemoveRefreshTokenForPrimaryAccount(
IdentityManager* identity_manager);
friend AccountInfo MakePrimaryAccountAvailable(
IdentityManager* identity_manager,
const std::string& email);
friend void ClearPrimaryAccount(IdentityManager* identity_manager,
ClearPrimaryAccountPolicy policy);
friend AccountInfo MakeAccountAvailable(IdentityManager* identity_manager,
const std::string& email);
friend void SetRefreshTokenForAccount(IdentityManager* identity_manager,
const std::string& account_id);
friend void SetInvalidRefreshTokenForAccount(
IdentityManager* identity_manager,
const std::string& account_id);
friend void RemoveRefreshTokenForAccount(IdentityManager* identity_manager,
const std::string& account_id);
friend void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
AccountInfo account_info);
friend MultiProfileDownloadNotificationTest; friend MultiProfileDownloadNotificationTest;
friend file_manager::MultiProfileFilesAppBrowserTest; friend file_manager::MultiProfileFilesAppBrowserTest;
...@@ -278,6 +301,11 @@ class IdentityManager : public SigninManagerBase::Observer, ...@@ -278,6 +301,11 @@ class IdentityManager : public SigninManagerBase::Observer,
friend chromeos::ChromeSessionManager; friend chromeos::ChromeSessionManager;
friend chromeos::UserSessionManager; friend chromeos::UserSessionManager;
// Private getters used for testing only (i.e. see identity_test_utils.h).
SigninManagerBase* GetSigninManager();
ProfileOAuth2TokenService* GetTokenService();
AccountTrackerService* GetAccountTrackerService();
// Sets the primary account info synchronously with both the IdentityManager // Sets the primary account info synchronously with both the IdentityManager
// and its backing SigninManager/ProfileOAuth2TokenService instances. // and its backing SigninManager/ProfileOAuth2TokenService instances.
// Prefer using the methods in identity_test_{environment, utils}.h to using // Prefer using the methods in identity_test_{environment, utils}.h to using
......
...@@ -207,58 +207,50 @@ IdentityManager* IdentityTestEnvironment::identity_manager() { ...@@ -207,58 +207,50 @@ IdentityManager* IdentityTestEnvironment::identity_manager() {
AccountInfo IdentityTestEnvironment::SetPrimaryAccount( AccountInfo IdentityTestEnvironment::SetPrimaryAccount(
const std::string& email) { const std::string& email) {
return identity::SetPrimaryAccount(signin_manager_, identity_manager(), return identity::SetPrimaryAccount(identity_manager(), email);
email);
} }
void IdentityTestEnvironment::SetRefreshTokenForPrimaryAccount() { void IdentityTestEnvironment::SetRefreshTokenForPrimaryAccount() {
identity::SetRefreshTokenForPrimaryAccount(token_service_, identity::SetRefreshTokenForPrimaryAccount(identity_manager());
identity_manager());
} }
void IdentityTestEnvironment::SetInvalidRefreshTokenForPrimaryAccount() { void IdentityTestEnvironment::SetInvalidRefreshTokenForPrimaryAccount() {
identity::SetInvalidRefreshTokenForPrimaryAccount(token_service_, identity::SetInvalidRefreshTokenForPrimaryAccount(identity_manager());
identity_manager());
} }
void IdentityTestEnvironment::RemoveRefreshTokenForPrimaryAccount() { void IdentityTestEnvironment::RemoveRefreshTokenForPrimaryAccount() {
identity::RemoveRefreshTokenForPrimaryAccount(token_service_, identity::RemoveRefreshTokenForPrimaryAccount(identity_manager());
identity_manager());
} }
AccountInfo IdentityTestEnvironment::MakePrimaryAccountAvailable( AccountInfo IdentityTestEnvironment::MakePrimaryAccountAvailable(
const std::string& email) { const std::string& email) {
return identity::MakePrimaryAccountAvailable(signin_manager_, token_service_, return identity::MakePrimaryAccountAvailable(identity_manager(), email);
identity_manager(), email);
} }
void IdentityTestEnvironment::ClearPrimaryAccount( void IdentityTestEnvironment::ClearPrimaryAccount(
ClearPrimaryAccountPolicy policy) { ClearPrimaryAccountPolicy policy) {
identity::ClearPrimaryAccount(signin_manager_, identity_manager(), policy); identity::ClearPrimaryAccount(identity_manager(), policy);
} }
AccountInfo IdentityTestEnvironment::MakeAccountAvailable( AccountInfo IdentityTestEnvironment::MakeAccountAvailable(
const std::string& email) { const std::string& email) {
return identity::MakeAccountAvailable( return identity::MakeAccountAvailable(identity_manager(), email);
account_tracker_service_, token_service_, identity_manager(), email);
} }
void IdentityTestEnvironment::SetRefreshTokenForAccount( void IdentityTestEnvironment::SetRefreshTokenForAccount(
const std::string& account_id) { const std::string& account_id) {
return identity::SetRefreshTokenForAccount(token_service_, identity_manager(), return identity::SetRefreshTokenForAccount(identity_manager(), account_id);
account_id);
} }
void IdentityTestEnvironment::SetInvalidRefreshTokenForAccount( void IdentityTestEnvironment::SetInvalidRefreshTokenForAccount(
const std::string& account_id) { const std::string& account_id) {
return identity::SetInvalidRefreshTokenForAccount( return identity::SetInvalidRefreshTokenForAccount(identity_manager(),
token_service_, identity_manager(), account_id); account_id);
} }
void IdentityTestEnvironment::RemoveRefreshTokenForAccount( void IdentityTestEnvironment::RemoveRefreshTokenForAccount(
const std::string& account_id) { const std::string& account_id) {
return identity::RemoveRefreshTokenForAccount(token_service_, return identity::RemoveRefreshTokenForAccount(identity_manager(), account_id);
identity_manager(), account_id);
} }
void IdentityTestEnvironment::SetCookieAccounts( void IdentityTestEnvironment::SetCookieAccounts(
...@@ -407,7 +399,7 @@ void IdentityTestEnvironment::WaitForAccessTokenRequestIfNecessary( ...@@ -407,7 +399,7 @@ void IdentityTestEnvironment::WaitForAccessTokenRequestIfNecessary(
void IdentityTestEnvironment::UpdateAccountInfoForAccount( void IdentityTestEnvironment::UpdateAccountInfoForAccount(
AccountInfo account_info) { AccountInfo account_info) {
identity::UpdateAccountInfoForAccount(account_tracker_service_, account_info); identity::UpdateAccountInfoForAccount(identity_manager(), account_info);
} }
} // namespace identity } // namespace identity
...@@ -18,6 +18,14 @@ class IdentityTestEnvironmentProfileAdaptor; ...@@ -18,6 +18,14 @@ class IdentityTestEnvironmentProfileAdaptor;
namespace identity { namespace identity {
namespace {
#if defined(OS_CHROMEOS)
using SigninManagerForTest = FakeSigninManagerBase;
#else
using SigninManagerForTest = FakeSigninManager;
#endif // OS_CHROMEOS
}
// Internal class that creates and owns dependencies of IdentityManager // Internal class that creates and owns dependencies of IdentityManager
// when those dependencies are not passed in externally. // when those dependencies are not passed in externally.
class IdentityManagerDependenciesOwner; class IdentityManagerDependenciesOwner;
...@@ -31,12 +39,6 @@ class IdentityManagerDependenciesOwner; ...@@ -31,12 +39,6 @@ class IdentityManagerDependenciesOwner;
// base::test::ScopedTaskEnvironment instance variable to fulfill this // base::test::ScopedTaskEnvironment instance variable to fulfill this
// requirement. // requirement.
class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver { class IdentityTestEnvironment : public IdentityManager::DiagnosticsObserver {
#if defined(OS_CHROMEOS)
using SigninManagerForTest = FakeSigninManagerBase;
#else
using SigninManagerForTest = FakeSigninManager;
#endif // OS_CHROMEOS
public: public:
// Preferred constructor: constructs an IdentityManager object and its // Preferred constructor: constructs an IdentityManager object and its
// dependencies internally. Cannot be used if the client of this class // dependencies internally. Cannot be used if the client of this class
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "components/signin/core/browser/account_tracker_service.h" #include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/fake_gaia_cookie_manager_service.h" #include "components/signin/core/browser/fake_gaia_cookie_manager_service.h"
#include "components/signin/core/browser/fake_signin_manager.h"
#include "components/signin/core/browser/profile_oauth2_token_service.h" #include "components/signin/core/browser/profile_oauth2_token_service.h"
#include "services/identity/public/cpp/identity_manager.h" #include "services/identity/public/cpp/identity_manager.h"
...@@ -127,11 +126,13 @@ void UpdateRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, ...@@ -127,11 +126,13 @@ void UpdateRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
} // namespace } // namespace
AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager, AccountInfo SetPrimaryAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& email) { const std::string& email) {
DCHECK(!signin_manager->IsAuthenticated());
DCHECK(!identity_manager->HasPrimaryAccount()); DCHECK(!identity_manager->HasPrimaryAccount());
SigninManagerBase* signin_manager = identity_manager->GetSigninManager();
DCHECK(!signin_manager->IsAuthenticated());
std::string gaia_id = "gaia_id_for_" + email; std::string gaia_id = "gaia_id_for_" + email;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -168,48 +169,41 @@ AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager, ...@@ -168,48 +169,41 @@ AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager,
return identity_manager->GetPrimaryAccountInfo(); return identity_manager->GetPrimaryAccountInfo();
} }
void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service, void SetRefreshTokenForPrimaryAccount(IdentityManager* identity_manager) {
IdentityManager* identity_manager) {
DCHECK(identity_manager->HasPrimaryAccount()); DCHECK(identity_manager->HasPrimaryAccount());
std::string account_id = identity_manager->GetPrimaryAccountId(); std::string account_id = identity_manager->GetPrimaryAccountId();
std::string refresh_token = "refresh_token_for_" + account_id; std::string refresh_token = "refresh_token_for_" + account_id;
SetRefreshTokenForAccount(token_service, identity_manager, account_id); SetRefreshTokenForAccount(identity_manager, account_id);
} }
void SetInvalidRefreshTokenForPrimaryAccount( void SetInvalidRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager) { IdentityManager* identity_manager) {
DCHECK(identity_manager->HasPrimaryAccount()); DCHECK(identity_manager->HasPrimaryAccount());
std::string account_id = identity_manager->GetPrimaryAccountId(); std::string account_id = identity_manager->GetPrimaryAccountId();
SetInvalidRefreshTokenForAccount(token_service, identity_manager, account_id); SetInvalidRefreshTokenForAccount(identity_manager, account_id);
} }
void RemoveRefreshTokenForPrimaryAccount( void RemoveRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager) { IdentityManager* identity_manager) {
if (!identity_manager->HasPrimaryAccount()) if (!identity_manager->HasPrimaryAccount())
return; return;
std::string account_id = identity_manager->GetPrimaryAccountId(); std::string account_id = identity_manager->GetPrimaryAccountId();
RemoveRefreshTokenForAccount(token_service, identity_manager, account_id); RemoveRefreshTokenForAccount(identity_manager, account_id);
} }
AccountInfo MakePrimaryAccountAvailable( AccountInfo MakePrimaryAccountAvailable(
SigninManagerBase* signin_manager,
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email) { const std::string& email) {
AccountInfo account_info = AccountInfo account_info = SetPrimaryAccount(identity_manager, email);
SetPrimaryAccount(signin_manager, identity_manager, email); SetRefreshTokenForPrimaryAccount(identity_manager);
SetRefreshTokenForPrimaryAccount(token_service, identity_manager);
return account_info; return account_info;
} }
void ClearPrimaryAccount(SigninManagerBase* signin_manager, void ClearPrimaryAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
ClearPrimaryAccountPolicy policy) { ClearPrimaryAccountPolicy policy) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// TODO(blundell): If we ever need this functionality on ChromeOS (which seems // TODO(blundell): If we ever need this functionality on ChromeOS (which seems
...@@ -225,8 +219,8 @@ void ClearPrimaryAccount(SigninManagerBase* signin_manager, ...@@ -225,8 +219,8 @@ void ClearPrimaryAccount(SigninManagerBase* signin_manager,
identity_manager, run_loop.QuitClosure(), identity_manager, run_loop.QuitClosure(),
IdentityManagerEvent::PRIMARY_ACCOUNT_CLEARED); IdentityManagerEvent::PRIMARY_ACCOUNT_CLEARED);
SigninManager* real_signin_manager = SigninManager* real_signin_manager = SigninManager::FromSigninManagerBase(
SigninManager::FromSigninManagerBase(signin_manager); identity_manager->GetSigninManager());
signin_metrics::ProfileSignout signout_source_metric = signin_metrics::ProfileSignout signout_source_metric =
signin_metrics::SIGNOUT_TEST; signin_metrics::SIGNOUT_TEST;
signin_metrics::SignoutDelete signout_delete_metric = signin_metrics::SignoutDelete signout_delete_metric =
...@@ -251,10 +245,12 @@ void ClearPrimaryAccount(SigninManagerBase* signin_manager, ...@@ -251,10 +245,12 @@ void ClearPrimaryAccount(SigninManagerBase* signin_manager,
#endif #endif
} }
AccountInfo MakeAccountAvailable(AccountTrackerService* account_tracker_service, AccountInfo MakeAccountAvailable(IdentityManager* identity_manager,
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& email) { const std::string& email) {
AccountTrackerService* account_tracker_service =
identity_manager->GetAccountTrackerService();
DCHECK(account_tracker_service);
DCHECK(account_tracker_service->FindAccountInfoByEmail(email).IsEmpty()); DCHECK(account_tracker_service->FindAccountInfoByEmail(email).IsEmpty());
std::string gaia_id = "gaia_id_for_" + email; std::string gaia_id = "gaia_id_for_" + email;
...@@ -264,30 +260,26 @@ AccountInfo MakeAccountAvailable(AccountTrackerService* account_tracker_service, ...@@ -264,30 +260,26 @@ AccountInfo MakeAccountAvailable(AccountTrackerService* account_tracker_service,
account_tracker_service->FindAccountInfoByEmail(email); account_tracker_service->FindAccountInfoByEmail(email);
DCHECK(!account_info.account_id.empty()); DCHECK(!account_info.account_id.empty());
SetRefreshTokenForAccount(token_service, identity_manager, SetRefreshTokenForAccount(identity_manager, account_info.account_id);
account_info.account_id);
return account_info; return account_info;
} }
void SetRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void SetRefreshTokenForAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& account_id) { const std::string& account_id) {
std::string refresh_token = "refresh_token_for_" + account_id; std::string refresh_token = "refresh_token_for_" + account_id;
UpdateRefreshTokenForAccount(token_service, identity_manager, account_id, UpdateRefreshTokenForAccount(identity_manager->GetTokenService(),
refresh_token); identity_manager, account_id, refresh_token);
} }
void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void SetInvalidRefreshTokenForAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& account_id) { const std::string& account_id) {
UpdateRefreshTokenForAccount( UpdateRefreshTokenForAccount(
token_service, identity_manager, account_id, identity_manager->GetTokenService(), identity_manager, account_id,
OAuth2TokenServiceDelegate::kInvalidRefreshToken); OAuth2TokenServiceDelegate::kInvalidRefreshToken);
} }
void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void RemoveRefreshTokenForAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& account_id) { const std::string& account_id) {
if (!identity_manager->HasAccountWithRefreshToken(account_id)) if (!identity_manager->HasAccountWithRefreshToken(account_id))
return; return;
...@@ -297,7 +289,7 @@ void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, ...@@ -297,7 +289,7 @@ void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service,
identity_manager, run_loop.QuitClosure(), identity_manager, run_loop.QuitClosure(),
IdentityManagerEvent::REFRESH_TOKEN_REMOVED); IdentityManagerEvent::REFRESH_TOKEN_REMOVED);
token_service->RevokeCredentials(account_id); identity_manager->GetTokenService()->RevokeCredentials(account_id);
run_loop.Run(); run_loop.Run();
} }
...@@ -326,9 +318,14 @@ void SetCookieAccounts(FakeGaiaCookieManagerService* cookie_manager, ...@@ -326,9 +318,14 @@ void SetCookieAccounts(FakeGaiaCookieManagerService* cookie_manager,
run_loop.Run(); run_loop.Run();
} }
void UpdateAccountInfoForAccount(AccountTrackerService* account_tracker_service, void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
AccountInfo account_info) { AccountInfo account_info) {
// Make sure the account being updated is a known account. // Make sure the account being updated is a known account.
AccountTrackerService* account_tracker_service =
identity_manager->GetAccountTrackerService();
DCHECK(account_tracker_service);
DCHECK(!account_tracker_service->GetAccountInfo(account_info.account_id) DCHECK(!account_tracker_service->GetAccountInfo(account_info.account_id)
.account_id.empty()); .account_id.empty());
......
...@@ -10,18 +10,7 @@ ...@@ -10,18 +10,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/signin/core/browser/account_info.h" #include "components/signin/core/browser/account_info.h"
class AccountTrackerService;
class FakeGaiaCookieManagerService; class FakeGaiaCookieManagerService;
class FakeSigninManagerBase;
class FakeSigninManager;
class ProfileOAuth2TokenService;
class SigninManagerBase;
#if defined(OS_CHROMEOS)
using SigninManagerForTest = FakeSigninManagerBase;
#else
using SigninManagerForTest = FakeSigninManager;
#endif // OS_CHROMEOS
// Test-related utilities that don't fit in either IdentityTestEnvironment or // Test-related utilities that don't fit in either IdentityTestEnvironment or
// IdentityManager itself. NOTE: Using these utilities directly is discouraged, // IdentityManager itself. NOTE: Using these utilities directly is discouraged,
...@@ -57,28 +46,24 @@ class IdentityManager; ...@@ -57,28 +46,24 @@ class IdentityManager;
// SigninManager callbacks for signin success. Blocks until the primary account // SigninManager callbacks for signin success. Blocks until the primary account
// is set. Returns the AccountInfo of the newly-set account. // is set. Returns the AccountInfo of the newly-set account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
AccountInfo SetPrimaryAccount(SigninManagerBase* signin_manager, AccountInfo SetPrimaryAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& email); const std::string& email);
// Sets a refresh token for the primary account (which must already be set). // Sets a refresh token for the primary account (which must already be set).
// Blocks until the refresh token is set. // Blocks until the refresh token is set.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void SetRefreshTokenForPrimaryAccount(ProfileOAuth2TokenService* token_service, void SetRefreshTokenForPrimaryAccount(IdentityManager* identity_manager);
IdentityManager* identity_manager);
// Sets a special invalid refresh token for the primary account (which must // Sets a special invalid refresh token for the primary account (which must
// already be set). Blocks until the refresh token is set. // already be set). Blocks until the refresh token is set.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void SetInvalidRefreshTokenForPrimaryAccount( void SetInvalidRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager); IdentityManager* identity_manager);
// Removes any refresh token for the primary account, if present. Blocks until // Removes any refresh token for the primary account, if present. Blocks until
// the refresh token is removed. // the refresh token is removed.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void RemoveRefreshTokenForPrimaryAccount( void RemoveRefreshTokenForPrimaryAccount(
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager); IdentityManager* identity_manager);
// Makes the primary account (which must not already be set) available for the // Makes the primary account (which must not already be set) available for the
...@@ -89,8 +74,6 @@ void RemoveRefreshTokenForPrimaryAccount( ...@@ -89,8 +74,6 @@ void RemoveRefreshTokenForPrimaryAccount(
// newly-available account. // newly-available account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
AccountInfo MakePrimaryAccountAvailable( AccountInfo MakePrimaryAccountAvailable(
SigninManagerBase* signin_manager,
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager, IdentityManager* identity_manager,
const std::string& email); const std::string& email);
...@@ -100,7 +83,6 @@ AccountInfo MakePrimaryAccountAvailable( ...@@ -100,7 +83,6 @@ AccountInfo MakePrimaryAccountAvailable(
// until the primary account is cleared. // until the primary account is cleared.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void ClearPrimaryAccount( void ClearPrimaryAccount(
SigninManagerBase* signin_manager,
IdentityManager* identity_manager, IdentityManager* identity_manager,
ClearPrimaryAccountPolicy policy = ClearPrimaryAccountPolicy::DEFAULT); ClearPrimaryAccountPolicy policy = ClearPrimaryAccountPolicy::DEFAULT);
...@@ -109,31 +91,26 @@ void ClearPrimaryAccount( ...@@ -109,31 +91,26 @@ void ClearPrimaryAccount(
// until the account is available. Returns the AccountInfo of the // until the account is available. Returns the AccountInfo of the
// newly-available account. // newly-available account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
AccountInfo MakeAccountAvailable(AccountTrackerService* account_tracker_service, AccountInfo MakeAccountAvailable(IdentityManager* identity_manager,
ProfileOAuth2TokenService* token_service,
IdentityManager* identity_manager,
const std::string& email); const std::string& email);
// Sets a refresh token for the given account (which must already be available). // Sets a refresh token for the given account (which must already be available).
// Blocks until the refresh token is set. // Blocks until the refresh token is set.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void SetRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void SetRefreshTokenForAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& account_id); const std::string& account_id);
// Sets a special invalid refresh token for the given account (which must // Sets a special invalid refresh token for the given account (which must
// already be available). Blocks until the refresh token is set. // already be available). Blocks until the refresh token is set.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void SetInvalidRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void SetInvalidRefreshTokenForAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& account_id); const std::string& account_id);
// Removes any refresh token that is present for the given account. Blocks until // Removes any refresh token that is present for the given account. Blocks until
// the refresh token is removed. Is a no-op if no refresh token is present for // the refresh token is removed. Is a no-op if no refresh token is present for
// the given account. // the given account.
// NOTE: See disclaimer at top of file re: direct usage. // NOTE: See disclaimer at top of file re: direct usage.
void RemoveRefreshTokenForAccount(ProfileOAuth2TokenService* token_service, void RemoveRefreshTokenForAccount(IdentityManager* identity_manager,
IdentityManager* identity_manager,
const std::string& account_id); const std::string& account_id);
// Puts the given accounts into the Gaia cookie, replacing any previous // Puts the given accounts into the Gaia cookie, replacing any previous
...@@ -145,7 +122,7 @@ void SetCookieAccounts(FakeGaiaCookieManagerService* cookie_manager, ...@@ -145,7 +122,7 @@ void SetCookieAccounts(FakeGaiaCookieManagerService* cookie_manager,
// Updates the info for |account_info.account_id|, which must be a known // Updates the info for |account_info.account_id|, which must be a known
// account. // account.
void UpdateAccountInfoForAccount(AccountTrackerService* account_tracker_service, void UpdateAccountInfoForAccount(IdentityManager* identity_manager,
AccountInfo account_info); AccountInfo account_info);
} // namespace identity } // namespace identity
......
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