Commit d681bcb7 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

IdentityManager: Move method to AccountsCookieMutator

IdentityManager has an iOS-specific ForceTriggerOnCookieChange() method.
This method makes more sense on AccountsCookieMutator, together with
other similar methods (e.g., TriggerCookieJarUpdate()).

This change came about while auditing the interface of
identity_manager.h.

Bug: 930582, 964235
Change-Id: I3a0d023e3f84831a26250177f657e7c2646b8e17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1791147Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695144}
parent 043b94a0
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "build/build_config.h"
#include "components/signin/internal/identity_manager/account_tracker_service.h" #include "components/signin/internal/identity_manager/account_tracker_service.h"
#include "components/signin/internal/identity_manager/gaia_cookie_manager_service.h" #include "components/signin/internal/identity_manager/gaia_cookie_manager_service.h"
#include "google_apis/gaia/core_account_id.h" #include "google_apis/gaia/core_account_id.h"
...@@ -59,6 +60,12 @@ void AccountsCookieMutatorImpl::TriggerCookieJarUpdate() { ...@@ -59,6 +60,12 @@ void AccountsCookieMutatorImpl::TriggerCookieJarUpdate() {
gaia_cookie_manager_service_->TriggerListAccounts(); gaia_cookie_manager_service_->TriggerListAccounts();
} }
#if defined(OS_IOS)
void AccountsCookieMutatorImpl::ForceTriggerOnCookieChange() {
gaia_cookie_manager_service_->ForceOnCookieChangeProcessing();
}
#endif
void AccountsCookieMutatorImpl::LogOutAllAccounts(gaia::GaiaSource source) { void AccountsCookieMutatorImpl::LogOutAllAccounts(gaia::GaiaSource source) {
gaia_cookie_manager_service_->LogOutAllAccounts(source); gaia_cookie_manager_service_->LogOutAllAccounts(source);
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h"
#include "components/signin/public/identity_manager/accounts_cookie_mutator.h" #include "components/signin/public/identity_manager/accounts_cookie_mutator.h"
class AccountTrackerService; class AccountTrackerService;
...@@ -47,6 +48,10 @@ class AccountsCookieMutatorImpl : public AccountsCookieMutator { ...@@ -47,6 +48,10 @@ class AccountsCookieMutatorImpl : public AccountsCookieMutator {
void TriggerCookieJarUpdate() override; void TriggerCookieJarUpdate() override;
#if defined(OS_IOS)
void ForceTriggerOnCookieChange() override;
#endif
void LogOutAllAccounts(gaia::GaiaSource source) override; void LogOutAllAccounts(gaia::GaiaSource source) override;
private: private:
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "components/signin/core/browser/account_reconcilor.h" #include "components/signin/core/browser/account_reconcilor.h"
#include "components/signin/core/browser/signin_header_helper.h" #include "components/signin/core/browser/signin_header_helper.h"
#include "components/signin/public/base/account_consistency_method.h" #include "components/signin/public/base/account_consistency_method.h"
#include "components/signin/public/identity_manager/accounts_cookie_mutator.h"
#include "ios/web/common/web_view_creation_util.h" #include "ios/web/common/web_view_creation_util.h"
#include "ios/web/public/browser_state.h" #include "ios/web/public/browser_state.h"
#import "ios/web/public/navigation/web_state_policy_decider.h" #import "ios/web/public/navigation/web_state_policy_decider.h"
...@@ -473,7 +474,7 @@ void AccountConsistencyService::OnBrowsingDataRemoved() { ...@@ -473,7 +474,7 @@ void AccountConsistencyService::OnBrowsingDataRemoved() {
// APISID cookie has been removed, notify the GCMS. // APISID cookie has been removed, notify the GCMS.
// TODO(https://crbug.com/930582) : Remove the need to expose this method // TODO(https://crbug.com/930582) : Remove the need to expose this method
// or move it to the network::CookieManager. // or move it to the network::CookieManager.
identity_manager_->ForceTriggerOnCookieChange(); identity_manager_->GetAccountsCookieMutator()->ForceTriggerOnCookieChange();
} }
void AccountConsistencyService::OnPrimaryAccountSet( void AccountConsistencyService::OnPrimaryAccountSet(
......
...@@ -441,8 +441,9 @@ TEST_F(AccountConsistencyServiceTest, DomainsClearedOnBrowsingDataRemoved) { ...@@ -441,8 +441,9 @@ TEST_F(AccountConsistencyServiceTest, DomainsClearedOnBrowsingDataRemoved) {
base::RunLoop run_loop; base::RunLoop run_loop;
identity_test_env_->identity_manager_observer() identity_test_env_->identity_manager_observer()
->SetOnAccountsInCookieUpdatedCallback(run_loop.QuitClosure()); ->SetOnAccountsInCookieUpdatedCallback(run_loop.QuitClosure());
// OnBrowsingDataRemoved triggers IdentityManager::ForceTriggerOnCookieChange // OnBrowsingDataRemoved triggers
// and finally IdentityManager::Observer::OnAccountsInCookieUpdated is called. // AccountsCookieMutator::ForceTriggerOnCookieChange and finally
// IdentityManager::Observer::OnAccountsInCookieUpdated is called.
account_consistency_service_->OnBrowsingDataRemoved(); account_consistency_service_->OnBrowsingDataRemoved();
run_loop.Run(); run_loop.Run();
...@@ -468,8 +469,9 @@ TEST_F(AccountConsistencyServiceTest, DomainsClearedOnBrowsingDataRemoved2) { ...@@ -468,8 +469,9 @@ TEST_F(AccountConsistencyServiceTest, DomainsClearedOnBrowsingDataRemoved2) {
base::RunLoop run_loop; base::RunLoop run_loop;
identity_test_env_->identity_manager_observer() identity_test_env_->identity_manager_observer()
->SetOnAccountsInCookieUpdatedCallback(run_loop.QuitClosure()); ->SetOnAccountsInCookieUpdatedCallback(run_loop.QuitClosure());
// OnBrowsingDataRemoved triggers IdentityManager::ForceTriggerOnCookieChange // OnBrowsingDataRemoved triggers
// and finally IdentityManager::Observer::OnAccountsInCookieUpdated is called. // AccountsCookieMutator::ForceTriggerOnCookieChange and finally
// IdentityManager::Observer::OnAccountsInCookieUpdated is called.
account_consistency_service_->OnBrowsingDataRemoved(); account_consistency_service_->OnBrowsingDataRemoved();
run_loop.Run(); run_loop.Run();
EXPECT_TRUE(remove_cookie_callback_called_); EXPECT_TRUE(remove_cookie_callback_called_);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h"
#include "google_apis/gaia/gaia_auth_fetcher.h" #include "google_apis/gaia/gaia_auth_fetcher.h"
struct CoreAccountId; struct CoreAccountId;
...@@ -63,6 +64,16 @@ class AccountsCookieMutator { ...@@ -63,6 +64,16 @@ class AccountsCookieMutator {
// know that the contents of the Gaia cookie might have changed. // know that the contents of the Gaia cookie might have changed.
virtual void TriggerCookieJarUpdate() = 0; virtual void TriggerCookieJarUpdate() = 0;
#if defined(OS_IOS)
// Forces the processing of GaiaCookieManagerService::OnCookieChange. On
// iOS, it's necessary to force-trigger the processing of cookie changes
// from the client as the normal mechanism for internally observing them
// is not wired up.
// TODO(https://crbug.com/930582) : Remove the need to expose this method
// or move it to the network::CookieManager.
virtual void ForceTriggerOnCookieChange() = 0;
#endif
// Remove all accounts from the Gaia cookie. // Remove all accounts from the Gaia cookie.
virtual void LogOutAllAccounts(gaia::GaiaSource source) = 0; virtual void LogOutAllAccounts(gaia::GaiaSource source) = 0;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "base/test/gtest_util.h" #include "base/test/gtest_util.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/signin/public/base/list_accounts_test_utils.h" #include "components/signin/public/base/list_accounts_test_utils.h"
#include "components/signin/public/base/test_signin_client.h" #include "components/signin/public/base/test_signin_client.h"
#include "components/signin/public/identity_manager/accounts_in_cookie_jar_info.h" #include "components/signin/public/identity_manager/accounts_in_cookie_jar_info.h"
...@@ -53,6 +54,7 @@ enum class AccountsCookiesMutatorAction { ...@@ -53,6 +54,7 @@ enum class AccountsCookiesMutatorAction {
kSetAccountsInCookie, kSetAccountsInCookie,
kTriggerCookieJarUpdateNoAccounts, kTriggerCookieJarUpdateNoAccounts,
kTriggerCookieJarUpdateOneAccount, kTriggerCookieJarUpdateOneAccount,
kTriggerOnCookieChangeNoAccounts,
}; };
} // namespace } // namespace
...@@ -119,6 +121,9 @@ class AccountsCookieMutatorTest : public testing::Test { ...@@ -119,6 +121,9 @@ class AccountsCookieMutatorTest : public testing::Test {
SetListAccountsResponseOneAccount(kTestAccountEmail, kTestAccountGaiaId, SetListAccountsResponseOneAccount(kTestAccountEmail, kTestAccountGaiaId,
GetTestURLLoaderFactory()); GetTestURLLoaderFactory());
break; break;
case AccountsCookiesMutatorAction::kTriggerOnCookieChangeNoAccounts:
SetListAccountsResponseNoAccounts(GetTestURLLoaderFactory());
break;
} }
} }
...@@ -401,6 +406,22 @@ TEST_F(AccountsCookieMutatorTest, TriggerCookieJarUpdate_OneListedAccounts) { ...@@ -401,6 +406,22 @@ TEST_F(AccountsCookieMutatorTest, TriggerCookieJarUpdate_OneListedAccounts) {
GoogleServiceAuthError::NONE); GoogleServiceAuthError::NONE);
} }
#if defined(OS_IOS)
TEST_F(AccountsCookieMutatorTest, ForceTriggerOnCookieChange) {
PrepareURLLoaderResponsesForAction(
AccountsCookiesMutatorAction::kTriggerOnCookieChangeNoAccounts);
base::RunLoop run_loop;
identity_manager_observer()->SetOnAccountsInCookieUpdatedCallback(
run_loop.QuitClosure());
// Forces the processing of OnCookieChange and it calls
// OnGaiaAccountsInCookieUpdated.
accounts_cookie_mutator()->ForceTriggerOnCookieChange();
run_loop.Run();
}
#endif
// Test that trying to log out all sessions generates the right network request. // Test that trying to log out all sessions generates the right network request.
TEST_F(AccountsCookieMutatorTest, LogOutAllAccounts) { TEST_F(AccountsCookieMutatorTest, LogOutAllAccounts) {
base::RunLoop run_loop; base::RunLoop run_loop;
......
...@@ -402,12 +402,6 @@ DiagnosticsProvider* IdentityManager::GetDiagnosticsProvider() { ...@@ -402,12 +402,6 @@ DiagnosticsProvider* IdentityManager::GetDiagnosticsProvider() {
return diagnostics_provider_.get(); return diagnostics_provider_.get();
} }
#if defined(OS_IOS)
void IdentityManager::ForceTriggerOnCookieChange() {
gaia_cookie_manager_service_->ForceOnCookieChangeProcessing();
}
#endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
void IdentityManager::LegacyReloadAccountsFromSystem() { void IdentityManager::LegacyReloadAccountsFromSystem() {
token_service_->GetDelegate()->ReloadAccountsFromSystem( token_service_->GetDelegate()->ReloadAccountsFromSystem(
......
...@@ -425,16 +425,6 @@ class IdentityManager : public KeyedService, ...@@ -425,16 +425,6 @@ class IdentityManager : public KeyedService,
// state of IdentityManager. // state of IdentityManager.
DiagnosticsProvider* GetDiagnosticsProvider(); DiagnosticsProvider* GetDiagnosticsProvider();
#if defined(OS_IOS)
// Forces the processing of GaiaCookieManagerService::OnCookieChange. On
// iOS, it's necessary to force-trigger the processing of cookie changes
// from the client as the normal mechanism for internally observing them
// is not wired up.
// TODO(https://crbug.com/930582) : Remove the need to expose this method
// or move it to the network::CookieManager.
void ForceTriggerOnCookieChange();
#endif
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Reloads the accounts in the token service from the system accounts. This // Reloads the accounts in the token service from the system accounts. This
// API calls ProfileOAuth2TokenServiceDelegate::ReloadAccountsFromSystem and // API calls ProfileOAuth2TokenServiceDelegate::ReloadAccountsFromSystem and
......
...@@ -1334,20 +1334,6 @@ TEST_F(IdentityManagerTest, GetAccountsCookieMutator) { ...@@ -1334,20 +1334,6 @@ TEST_F(IdentityManagerTest, GetAccountsCookieMutator) {
EXPECT_TRUE(mutator); EXPECT_TRUE(mutator);
} }
#if defined(OS_IOS)
TEST_F(IdentityManagerTest, ForceTriggerOnCookieChange) {
base::RunLoop run_loop;
identity_manager_observer()->SetOnAccountsInCookieUpdatedCallback(
run_loop.QuitClosure());
SetListAccountsResponseNoAccounts(test_url_loader_factory());
// Forces the processing of OnCookieChange and it calls
// OnGaiaAccountsInCookieUpdated.
identity_manager()->ForceTriggerOnCookieChange();
run_loop.Run();
}
#endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// On ChromeOS, AccountTrackerService first receives the normalized email // On ChromeOS, AccountTrackerService first receives the normalized email
// address from GAIA and then later has it updated with the user's // address from GAIA and then later has it updated with the user's
......
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