Commit 619e8002 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

Rename AuthenticationService::HaveAccountsChanged to HaveAccountsChangedWhileInBackground.

There was significant confusion about the name of the function AuthenticationService::HaveAccountsChanged
as it was not clear that it was only tracking if the accounts changed while Chrome was in
background. This CL attempts to rename the variable and all the corresponding functions to
make more clear its semantics.

Bug: None

Change-Id: Ic5a609de5ab04e60e9acadedbf72c1b978125e9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827157
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707352}
parent 46d18a1e
...@@ -66,7 +66,7 @@ class AuthenticationService : public KeyedService, ...@@ -66,7 +66,7 @@ class AuthenticationService : public KeyedService,
// they were stored in the browser state prefs. This storing happens every // they were stored in the browser state prefs. This storing happens every
// time the accounts change in foreground. // time the accounts change in foreground.
// This reloads the cached accounts if the information might be stale. // This reloads the cached accounts if the information might be stale.
virtual bool HaveAccountsChanged() const; virtual bool HaveAccountsChangedWhileInBackground() const;
// ChromeIdentity management // ChromeIdentity management
...@@ -126,14 +126,23 @@ class AuthenticationService : public KeyedService, ...@@ -126,14 +126,23 @@ class AuthenticationService : public KeyedService,
// ids. // ids.
void MigrateAccountsStoredInPrefsIfNeeded(); void MigrateAccountsStoredInPrefsIfNeeded();
// Stores the token service accounts in the browser state prefs. // Saves the last known list of accounts from the token service when
void StoreAccountsInPrefs(); // the app is in foreground. This can be used when app comes back from
// background to detect if any changes occurred to the list. Must only
// Gets the accounts previously stored in the browser state prefs. // be called when the application is in foreground.
std::vector<std::string> GetAccountsInPrefs(); // See HaveAccountsChangesWhileInBackground().
void StoreKnownAccountsWhileInForeground();
// Returns the cached MDM infos associated with |identity|. If the cache is
// stale for |identity|, the entry might be removed. // Gets the accounts previously stored as the foreground accounts in the
// browser state prefs.
// Returns the list of previously stored known accounts. This list
// is only updated when the app is in foreground and used to detect
// if any change occurred while the app was in background.
// See HaveAccountsChangesWhileInBackground().
std::vector<std::string> GetLastKnownAccountsFromForeground();
// Returns the cached MDM infos associated with |identity|. If the cache
// is stale for |identity|, the entry might be removed.
NSDictionary* GetCachedMDMInfo(ChromeIdentity* identity) const; NSDictionary* GetCachedMDMInfo(ChromeIdentity* identity) const;
// Handles an MDM notification |user_info| associated with |identity|. // Handles an MDM notification |user_info| associated with |identity|.
...@@ -147,7 +156,7 @@ class AuthenticationService : public KeyedService, ...@@ -147,7 +156,7 @@ class AuthenticationService : public KeyedService,
// //
// |in_foreground| indicates whether the application was in foreground when // |in_foreground| indicates whether the application was in foreground when
// the identity list change notification was received. // the identity list change notification was received.
void HandleIdentityListChanged(bool in_foreground); void HandleIdentityListChanged();
// Verifies that the authenticated user is still associated with a valid // Verifies that the authenticated user is still associated with a valid
// ChromeIdentity. This method must only be called when the user is // ChromeIdentity. This method must only be called when the user is
...@@ -177,6 +186,9 @@ class AuthenticationService : public KeyedService, ...@@ -177,6 +186,9 @@ class AuthenticationService : public KeyedService,
// or when the application is entering foregorund. // or when the application is entering foregorund.
void UpdateHaveAccountsChangedWhileInBackground(); void UpdateHaveAccountsChangedWhileInBackground();
// Returns whether the application is currently in the foreground or not.
bool InForeground() const;
// signin::IdentityManager::Observer implementation. // signin::IdentityManager::Observer implementation.
void OnEndBatchOfRefreshTokenStateChanges() override; void OnEndBatchOfRefreshTokenStateChanges() override;
...@@ -203,7 +215,7 @@ class AuthenticationService : public KeyedService, ...@@ -203,7 +215,7 @@ class AuthenticationService : public KeyedService,
// Whether the accounts have changed while the AuthenticationService was in // Whether the accounts have changed while the AuthenticationService was in
// background. When the AuthenticationService is in background, this value // background. When the AuthenticationService is in background, this value
// cannot be trusted. // cannot be trusted.
bool have_accounts_changed_ = false; bool have_accounts_changed_while_in_background_ = false;
// Whether the AuthenticationService is currently reloading credentials, used // Whether the AuthenticationService is currently reloading credentials, used
// to avoid an infinite reloading loop. // to avoid an infinite reloading loop.
......
...@@ -123,7 +123,7 @@ void AuthenticationService::Shutdown() { ...@@ -123,7 +123,7 @@ void AuthenticationService::Shutdown() {
} }
void AuthenticationService::OnApplicationWillEnterForeground() { void AuthenticationService::OnApplicationWillEnterForeground() {
if (identity_manager_observer_.IsObservingSources()) if (InForeground())
return; return;
identity_manager_observer_.Add(identity_manager_); identity_manager_observer_.Add(identity_manager_);
...@@ -133,7 +133,7 @@ void AuthenticationService::OnApplicationWillEnterForeground() { ...@@ -133,7 +133,7 @@ void AuthenticationService::OnApplicationWillEnterForeground() {
// changed (both are done by |UpdateHaveAccountsChangedWhileInBackground|). // changed (both are done by |UpdateHaveAccountsChangedWhileInBackground|).
// After that, save the current list of accounts. // After that, save the current list of accounts.
UpdateHaveAccountsChangedWhileInBackground(); UpdateHaveAccountsChangedWhileInBackground();
StoreAccountsInPrefs(); StoreKnownAccountsWhileInForeground();
if (IsAuthenticated()) { if (IsAuthenticated()) {
bool sync_enabled = sync_setup_service_->IsSyncEnabled(); bool sync_enabled = sync_setup_service_->IsSyncEnabled();
...@@ -166,13 +166,23 @@ void AuthenticationService::OnApplicationWillEnterForeground() { ...@@ -166,13 +166,23 @@ void AuthenticationService::OnApplicationWillEnterForeground() {
} }
void AuthenticationService::OnApplicationDidEnterBackground() { void AuthenticationService::OnApplicationDidEnterBackground() {
if (!identity_manager_observer_.IsObservingSources()) if (!InForeground())
return; return;
// Stop observing |identity_manager_| when in the background. Note that // Stop observing |identity_manager_| when in the background. Note that
// this allows checking whether the app is in background without having a // this allows checking whether the app is in background without having a
// separate bool by using identity_manager_observer_.IsObservingSources(). // separate bool by using identity_manager_observer_.IsObservingSources().
identity_manager_observer_.Remove(identity_manager_); identity_manager_observer_.Remove(identity_manager_);
// Reset the state |have_accounts_changed_while_in_background_| as the
// application just entered background.
have_accounts_changed_while_in_background_ = false;
}
bool AuthenticationService::InForeground() const {
// The application is in foreground when |identity_manager_observer_| is
// observing sources.
return identity_manager_observer_.IsObservingSources();
} }
void AuthenticationService::SetPromptForSignIn() { void AuthenticationService::SetPromptForSignIn() {
...@@ -191,8 +201,9 @@ void AuthenticationService::UpdateHaveAccountsChangedWhileInBackground() { ...@@ -191,8 +201,9 @@ void AuthenticationService::UpdateHaveAccountsChangedWhileInBackground() {
// Load accounts from preference before synchronizing the accounts with // Load accounts from preference before synchronizing the accounts with
// the system, otherwiser we would never detect any changes to the list // the system, otherwiser we would never detect any changes to the list
// of accounts. // of accounts.
std::vector<std::string> old_accounts = GetAccountsInPrefs(); std::vector<std::string> last_foreground_accounts =
std::sort(old_accounts.begin(), old_accounts.end()); GetLastKnownAccountsFromForeground();
std::sort(last_foreground_accounts.begin(), last_foreground_accounts.end());
// Reload credentials to ensure the accounts from the token service are // Reload credentials to ensure the accounts from the token service are
// up-to-date. // up-to-date.
...@@ -201,18 +212,19 @@ void AuthenticationService::UpdateHaveAccountsChangedWhileInBackground() { ...@@ -201,18 +212,19 @@ void AuthenticationService::UpdateHaveAccountsChangedWhileInBackground() {
// must be set to true. // must be set to true.
ReloadCredentialsFromIdentities(/*should_prompt=*/true); ReloadCredentialsFromIdentities(/*should_prompt=*/true);
std::vector<CoreAccountInfo> new_accounts_info = std::vector<CoreAccountInfo> current_accounts_info =
identity_manager_->GetAccountsWithRefreshTokens(); identity_manager_->GetAccountsWithRefreshTokens();
std::vector<std::string> new_accounts; std::vector<std::string> current_accounts;
for (const CoreAccountInfo& account_info : new_accounts_info) for (const CoreAccountInfo& account_info : current_accounts_info)
new_accounts.push_back(account_info.account_id); current_accounts.push_back(account_info.account_id);
std::sort(new_accounts.begin(), new_accounts.end()); std::sort(current_accounts.begin(), current_accounts.end());
have_accounts_changed_ = old_accounts != new_accounts; have_accounts_changed_while_in_background_ =
last_foreground_accounts != current_accounts;
} }
bool AuthenticationService::HaveAccountsChanged() const { bool AuthenticationService::HaveAccountsChangedWhileInBackground() const {
return have_accounts_changed_; return have_accounts_changed_while_in_background_;
} }
void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() { void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() {
...@@ -227,7 +239,7 @@ void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() { ...@@ -227,7 +239,7 @@ void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() {
return; return;
} }
std::vector<std::string> account_ids = GetAccountsInPrefs(); std::vector<std::string> account_ids = GetLastKnownAccountsFromForeground();
std::vector<base::Value> accounts_pref_value; std::vector<base::Value> accounts_pref_value;
for (const std::string& account_id : account_ids) { for (const std::string& account_id : account_ids) {
if (identity_manager_->HasAccountWithRefreshToken(account_id)) { if (identity_manager_->HasAccountWithRefreshToken(account_id)) {
...@@ -235,8 +247,8 @@ void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() { ...@@ -235,8 +247,8 @@ void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() {
} else { } else {
// The account for |email| was removed since the last application cold // The account for |email| was removed since the last application cold
// start. Insert |kFakeAccountIdForRemovedAccount| to ensure // start. Insert |kFakeAccountIdForRemovedAccount| to ensure
// |have_accounts_changed_| will be set to true and the removal won't be // |have_accounts_changed_while_in_background_| will be set to true and
// silently ignored. // the removal won't be silently ignored.
accounts_pref_value.emplace_back(kFakeAccountIdForRemovedAccount); accounts_pref_value.emplace_back(kFakeAccountIdForRemovedAccount);
} }
} }
...@@ -245,7 +257,8 @@ void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() { ...@@ -245,7 +257,8 @@ void AuthenticationService::MigrateAccountsStoredInPrefsIfNeeded() {
pref_service_->SetBoolean(prefs::kSigninLastAccountsMigrated, true); pref_service_->SetBoolean(prefs::kSigninLastAccountsMigrated, true);
} }
void AuthenticationService::StoreAccountsInPrefs() { void AuthenticationService::StoreKnownAccountsWhileInForeground() {
DCHECK(InForeground());
std::vector<CoreAccountInfo> accounts( std::vector<CoreAccountInfo> accounts(
identity_manager_->GetAccountsWithRefreshTokens()); identity_manager_->GetAccountsWithRefreshTokens());
std::vector<base::Value> accounts_pref_value; std::vector<base::Value> accounts_pref_value;
...@@ -255,7 +268,8 @@ void AuthenticationService::StoreAccountsInPrefs() { ...@@ -255,7 +268,8 @@ void AuthenticationService::StoreAccountsInPrefs() {
base::Value(std::move(accounts_pref_value))); base::Value(std::move(accounts_pref_value)));
} }
std::vector<std::string> AuthenticationService::GetAccountsInPrefs() { std::vector<std::string>
AuthenticationService::GetLastKnownAccountsFromForeground() {
const base::Value* accounts_pref = const base::Value* accounts_pref =
pref_service_->GetList(prefs::kSigninLastAccounts); pref_service_->GetList(prefs::kSigninLastAccounts);
...@@ -418,7 +432,7 @@ void AuthenticationService::OnEndBatchOfRefreshTokenStateChanges() { ...@@ -418,7 +432,7 @@ void AuthenticationService::OnEndBatchOfRefreshTokenStateChanges() {
// Accounts maybe have been excluded or included from the current browser // Accounts maybe have been excluded or included from the current browser
// state, without any change to the identity list. // state, without any change to the identity list.
// Store the current list of accounts to make sure it is up-to-date. // Store the current list of accounts to make sure it is up-to-date.
StoreAccountsInPrefs(); StoreKnownAccountsWhileInForeground();
} }
void AuthenticationService::OnIdentityListChanged() { void AuthenticationService::OnIdentityListChanged() {
...@@ -429,8 +443,7 @@ void AuthenticationService::OnIdentityListChanged() { ...@@ -429,8 +443,7 @@ void AuthenticationService::OnIdentityListChanged() {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&AuthenticationService::HandleIdentityListChanged, base::BindOnce(&AuthenticationService::HandleIdentityListChanged,
GetWeakPtr(), GetWeakPtr()));
identity_manager_observer_.IsObservingSources()));
} }
bool AuthenticationService::HandleMDMNotification(ChromeIdentity* identity, bool AuthenticationService::HandleMDMNotification(ChromeIdentity* identity,
...@@ -494,10 +507,10 @@ void AuthenticationService::OnChromeIdentityServiceWillBeDestroyed() { ...@@ -494,10 +507,10 @@ void AuthenticationService::OnChromeIdentityServiceWillBeDestroyed() {
identity_service_observer_.RemoveAll(); identity_service_observer_.RemoveAll();
} }
void AuthenticationService::HandleIdentityListChanged(bool in_foreground) { void AuthenticationService::HandleIdentityListChanged() {
// Only notify the user about an identity change notification if the // Only notify the user about an identity change notification if the
// application was in background. // application was in background.
if (in_foreground) { if (InForeground()) {
// Do not update the have accounts change state when in foreground. // Do not update the have accounts change state when in foreground.
ReloadCredentialsFromIdentities(/*should_prompt=*/false); ReloadCredentialsFromIdentities(/*should_prompt=*/false);
return; return;
......
...@@ -31,9 +31,9 @@ class AuthenticationServiceFake : public AuthenticationService { ...@@ -31,9 +31,9 @@ class AuthenticationServiceFake : public AuthenticationService {
void SignOut(signin_metrics::ProfileSignout signout_source, void SignOut(signin_metrics::ProfileSignout signout_source,
ProceduralBlock completion) override; ProceduralBlock completion) override;
void SetHaveAccountsChanged(bool changed); void SetHaveAccountsChangedWhileInBackground(bool changed);
bool HaveAccountsChanged() const override; bool HaveAccountsChangedWhileInBackground() const override;
bool IsAuthenticated() const override; bool IsAuthenticated() const override;
...@@ -46,7 +46,7 @@ class AuthenticationServiceFake : public AuthenticationService { ...@@ -46,7 +46,7 @@ class AuthenticationServiceFake : public AuthenticationService {
syncer::SyncService* sync_service); syncer::SyncService* sync_service);
__strong ChromeIdentity* authenticated_identity_; __strong ChromeIdentity* authenticated_identity_;
bool have_accounts_changed_; bool have_accounts_changed_while_in_background_;
}; };
#endif // IOS_CHROME_BROWSER_SIGNIN_AUTHENTICATION_SERVICE_FAKE_H_ #endif // IOS_CHROME_BROWSER_SIGNIN_AUTHENTICATION_SERVICE_FAKE_H_
...@@ -29,7 +29,7 @@ AuthenticationServiceFake::AuthenticationServiceFake( ...@@ -29,7 +29,7 @@ AuthenticationServiceFake::AuthenticationServiceFake(
sync_setup_service, sync_setup_service,
identity_manager, identity_manager,
sync_service), sync_service),
have_accounts_changed_(false) {} have_accounts_changed_while_in_background_(false) {}
AuthenticationServiceFake::~AuthenticationServiceFake() {} AuthenticationServiceFake::~AuthenticationServiceFake() {}
...@@ -48,12 +48,13 @@ void AuthenticationServiceFake::SignOut( ...@@ -48,12 +48,13 @@ void AuthenticationServiceFake::SignOut(
completion(); completion();
} }
void AuthenticationServiceFake::SetHaveAccountsChanged(bool changed) { void AuthenticationServiceFake::SetHaveAccountsChangedWhileInBackground(
have_accounts_changed_ = changed; bool changed) {
have_accounts_changed_while_in_background_ = changed;
} }
bool AuthenticationServiceFake::HaveAccountsChanged() const { bool AuthenticationServiceFake::HaveAccountsChangedWhileInBackground() const {
return have_accounts_changed_; return have_accounts_changed_while_in_background_;
} }
bool AuthenticationServiceFake::IsAuthenticated() const { bool AuthenticationServiceFake::IsAuthenticated() const {
......
...@@ -108,12 +108,12 @@ class AuthenticationServiceTest : public PlatformTest { ...@@ -108,12 +108,12 @@ class AuthenticationServiceTest : public PlatformTest {
EXPECT_CALL(*sync_setup_service_mock(), PrepareForFirstSyncSetup()); EXPECT_CALL(*sync_setup_service_mock(), PrepareForFirstSyncSetup());
} }
void StoreAccountsInPrefs() { void StoreKnownAccountsWhileInForeground() {
authentication_service()->StoreAccountsInPrefs(); authentication_service()->StoreKnownAccountsWhileInForeground();
} }
std::vector<std::string> GetAccountsInPrefs() { std::vector<std::string> GetLastKnownAccountsFromForeground() {
return authentication_service()->GetAccountsInPrefs(); return authentication_service()->GetLastKnownAccountsFromForeground();
} }
void FireApplicationWillEnterForeground() { void FireApplicationWillEnterForeground() {
...@@ -249,7 +249,7 @@ TEST_F(AuthenticationServiceTest, TestHandleForgottenIdentityPromptSignIn) { ...@@ -249,7 +249,7 @@ TEST_F(AuthenticationServiceTest, TestHandleForgottenIdentityPromptSignIn) {
TEST_F(AuthenticationServiceTest, StoreAndGetAccountsInPrefs) { TEST_F(AuthenticationServiceTest, StoreAndGetAccountsInPrefs) {
// Profile starts empty. // Profile starts empty.
std::vector<std::string> accounts = GetAccountsInPrefs(); std::vector<std::string> accounts = GetLastKnownAccountsFromForeground();
EXPECT_TRUE(accounts.empty()); EXPECT_TRUE(accounts.empty());
// Sign in. // Sign in.
...@@ -258,12 +258,11 @@ TEST_F(AuthenticationServiceTest, StoreAndGetAccountsInPrefs) { ...@@ -258,12 +258,11 @@ TEST_F(AuthenticationServiceTest, StoreAndGetAccountsInPrefs) {
// Store the accounts and get them back from the prefs. They should be the // Store the accounts and get them back from the prefs. They should be the
// same as the token service accounts. // same as the token service accounts.
StoreAccountsInPrefs(); StoreKnownAccountsWhileInForeground();
accounts = GetAccountsInPrefs(); accounts = GetLastKnownAccountsFromForeground();
ASSERT_EQ(2u, accounts.size()); ASSERT_EQ(2u, accounts.size());
EXPECT_EQ("foo2ID", accounts[0]);
EXPECT_EQ("foo2ID", accounts[0]); EXPECT_EQ("fooID", accounts[1]);
EXPECT_EQ("fooID", accounts[1]);
} }
TEST_F(AuthenticationServiceTest, TEST_F(AuthenticationServiceTest,
...@@ -282,9 +281,8 @@ TEST_F(AuthenticationServiceTest, ...@@ -282,9 +281,8 @@ TEST_F(AuthenticationServiceTest,
identity_manager()->GetAccountsWithRefreshTokens(); identity_manager()->GetAccountsWithRefreshTokens();
std::sort(accounts.begin(), accounts.end(), account_compare_func); std::sort(accounts.begin(), accounts.end(), account_compare_func);
ASSERT_EQ(2u, accounts.size()); ASSERT_EQ(2u, accounts.size());
EXPECT_EQ("foo2ID", accounts[0].account_id);
EXPECT_EQ("foo2ID", accounts[0].account_id); EXPECT_EQ("fooID", accounts[1].account_id);
EXPECT_EQ("fooID", accounts[1].account_id);
// Simulate a switching to background and back to foreground, triggering a // Simulate a switching to background and back to foreground, triggering a
// credentials reload. // credentials reload.
...@@ -296,13 +294,14 @@ TEST_F(AuthenticationServiceTest, ...@@ -296,13 +294,14 @@ TEST_F(AuthenticationServiceTest,
accounts = identity_manager()->GetAccountsWithRefreshTokens(); accounts = identity_manager()->GetAccountsWithRefreshTokens();
std::sort(accounts.begin(), accounts.end(), account_compare_func); std::sort(accounts.begin(), accounts.end(), account_compare_func);
ASSERT_EQ(3u, accounts.size()); ASSERT_EQ(3u, accounts.size());
EXPECT_EQ("foo2ID", accounts[0].account_id); EXPECT_EQ("foo2ID", accounts[0].account_id);
EXPECT_EQ("foo3ID", accounts[1].account_id); EXPECT_EQ("foo3ID", accounts[1].account_id);
EXPECT_EQ("fooID", accounts[2].account_id); EXPECT_EQ("fooID", accounts[2].account_id);
} }
TEST_F(AuthenticationServiceTest, HaveAccountsChanged_Default) { TEST_F(AuthenticationServiceTest, HaveAccountsChanged_Default) {
EXPECT_FALSE(authentication_service()->HaveAccountsChanged()); EXPECT_FALSE(
authentication_service()->HaveAccountsChangedWhileInBackground());
} }
TEST_F(AuthenticationServiceTest, HaveAccountsChanged_NoChange) { TEST_F(AuthenticationServiceTest, HaveAccountsChanged_NoChange) {
...@@ -315,15 +314,18 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_NoChange) { ...@@ -315,15 +314,18 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_NoChange) {
// If an account is added while the application is in foreground, then the // If an account is added while the application is in foreground, then the
// have accounts changed state should stay false. // have accounts changed state should stay false.
EXPECT_FALSE(authentication_service()->HaveAccountsChanged()); EXPECT_FALSE(
authentication_service()->HaveAccountsChangedWhileInBackground());
// Backgrounding the app should not change the have accounts changed state. // Backgrounding the app should not change the have accounts changed state.
FireApplicationDidEnterBackground(); FireApplicationDidEnterBackground();
EXPECT_FALSE(authentication_service()->HaveAccountsChanged()); EXPECT_FALSE(
authentication_service()->HaveAccountsChangedWhileInBackground());
// Foregrounding the app should not change the have accounts changed state. // Foregrounding the app should not change the have accounts changed state.
FireApplicationWillEnterForeground(); FireApplicationWillEnterForeground();
EXPECT_FALSE(authentication_service()->HaveAccountsChanged()); EXPECT_FALSE(
authentication_service()->HaveAccountsChangedWhileInBackground());
} }
TEST_F(AuthenticationServiceTest, HaveAccountsChanged_ChangedInBackground) { TEST_F(AuthenticationServiceTest, HaveAccountsChanged_ChangedInBackground) {
...@@ -333,14 +335,15 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_ChangedInBackground) { ...@@ -333,14 +335,15 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_ChangedInBackground) {
identity_service()->AddIdentities(@[ @"foo3" ]); identity_service()->AddIdentities(@[ @"foo3" ]);
FireIdentityListChanged(); FireIdentityListChanged();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(authentication_service()->HaveAccountsChanged()); EXPECT_FALSE(
authentication_service()->HaveAccountsChangedWhileInBackground());
// Simulate a switching to background and back to foreground, changing the // Simulate a switching to background and back to foreground, changing the
// accounts while in background (no notification fired by |identity_service|). // accounts while in background (no notification fired by |identity_service|).
FireApplicationDidEnterBackground(); FireApplicationDidEnterBackground();
identity_service()->AddIdentities(@[ @"foo4" ]); identity_service()->AddIdentities(@[ @"foo4" ]);
FireApplicationWillEnterForeground(); FireApplicationWillEnterForeground();
EXPECT_TRUE(authentication_service()->HaveAccountsChanged()); EXPECT_TRUE(authentication_service()->HaveAccountsChangedWhileInBackground());
} }
TEST_F(AuthenticationServiceTest, HaveAccountsChanged_CalledInBackground) { TEST_F(AuthenticationServiceTest, HaveAccountsChanged_CalledInBackground) {
...@@ -350,7 +353,8 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_CalledInBackground) { ...@@ -350,7 +353,8 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_CalledInBackground) {
identity_service()->AddIdentities(@[ @"foo3" ]); identity_service()->AddIdentities(@[ @"foo3" ]);
FireIdentityListChanged(); FireIdentityListChanged();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(authentication_service()->HaveAccountsChanged()); EXPECT_FALSE(
authentication_service()->HaveAccountsChangedWhileInBackground());
// Simulate a switching to background, changing the accounts while in // Simulate a switching to background, changing the accounts while in
// background. // background.
...@@ -358,11 +362,11 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_CalledInBackground) { ...@@ -358,11 +362,11 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_CalledInBackground) {
identity_service()->AddIdentities(@[ @"foo4" ]); identity_service()->AddIdentities(@[ @"foo4" ]);
FireIdentityListChanged(); FireIdentityListChanged();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_TRUE(authentication_service()->HaveAccountsChanged()); EXPECT_TRUE(authentication_service()->HaveAccountsChangedWhileInBackground());
// Entering foreground should not change the have accounts changed state. // Entering foreground should not change the have accounts changed state.
FireApplicationWillEnterForeground(); FireApplicationWillEnterForeground();
EXPECT_TRUE(authentication_service()->HaveAccountsChanged()); EXPECT_TRUE(authentication_service()->HaveAccountsChangedWhileInBackground());
} }
// Regression test for http://crbug.com/1006717 // Regression test for http://crbug.com/1006717
...@@ -373,7 +377,8 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_ResetOntwoBackgrounds) { ...@@ -373,7 +377,8 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_ResetOntwoBackgrounds) {
identity_service()->AddIdentities(@[ @"foo3" ]); identity_service()->AddIdentities(@[ @"foo3" ]);
FireIdentityListChanged(); FireIdentityListChanged();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_FALSE(authentication_service()->HaveAccountsChanged()); EXPECT_FALSE(
authentication_service()->HaveAccountsChangedWhileInBackground());
// Simulate a switching to background, changing the accounts while in // Simulate a switching to background, changing the accounts while in
// background. // background.
...@@ -386,14 +391,15 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_ResetOntwoBackgrounds) { ...@@ -386,14 +391,15 @@ TEST_F(AuthenticationServiceTest, HaveAccountsChanged_ResetOntwoBackgrounds) {
// When entering foreground, the have accounts changed state should be // When entering foreground, the have accounts changed state should be
// updated. // updated.
FireApplicationWillEnterForeground(); FireApplicationWillEnterForeground();
EXPECT_TRUE(authentication_service()->HaveAccountsChanged()); EXPECT_TRUE(authentication_service()->HaveAccountsChangedWhileInBackground());
// Backgrounding and foregrounding the application a second time should update // Backgrounding and foregrounding the application a second time should update
// the list of accounts in |kSigninLastAccounts| and should reset the have // the list of accounts in |kSigninLastAccounts| and should reset the have
// account changed state. // account changed state.
FireApplicationDidEnterBackground(); FireApplicationDidEnterBackground();
FireApplicationWillEnterForeground(); FireApplicationWillEnterForeground();
EXPECT_FALSE(authentication_service()->HaveAccountsChanged()); EXPECT_FALSE(
authentication_service()->HaveAccountsChangedWhileInBackground());
} }
TEST_F(AuthenticationServiceTest, IsAuthenticatedBackground) { TEST_F(AuthenticationServiceTest, IsAuthenticatedBackground) {
......
...@@ -206,11 +206,12 @@ BOOL gSignedInAccountsViewControllerIsShown = NO; ...@@ -206,11 +206,12 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
if (prevSessionInfo.isFirstSessionAfterUpgrade && if (prevSessionInfo.isFirstSessionAfterUpgrade &&
[prevSessionInfo.previousSessionVersion hasPrefix:@"77."]) { [prevSessionInfo.previousSessionVersion hasPrefix:@"77."]) {
// In M77, showing the signed-in account view was disabled due to the fact // In M77, showing the signed-in account view was disabled due to the fact
// that the preferences used to compute authService->HaveAccountsChanged() // that the preferences used to compute
// were not correctly updated (see crbug.com/1006717). // authService->HaveAccountsChangedWhileInBackground() were not correctly
// To avoid user confusion, it is important to avoid showing the signed-in // updated (see crbug.com/1006717). To avoid user confusion, it is important
// accounts dialog on the first session after an update from M77 in order // to avoid showing the signed-in accounts dialog on the first session after
// to allow the authentication service to update its internal preferences. // an update from M77 in order to allow the authentication service to update
// its internal preferences.
// //
// TODO(crbug.com/1007990) Remove this code after M81 (revert // TODO(crbug.com/1007990) Remove this code after M81 (revert
// https://chromium-review.googlesource.com/c/chromium/src/+/1824259 ). // https://chromium-review.googlesource.com/c/chromium/src/+/1824259 ).
...@@ -220,7 +221,8 @@ BOOL gSignedInAccountsViewControllerIsShown = NO; ...@@ -220,7 +221,8 @@ BOOL gSignedInAccountsViewControllerIsShown = NO;
AuthenticationService* authService = AuthenticationService* authService =
AuthenticationServiceFactory::GetForBrowserState(browserState); AuthenticationServiceFactory::GetForBrowserState(browserState);
return !gSignedInAccountsViewControllerIsShown && return !gSignedInAccountsViewControllerIsShown &&
authService->IsAuthenticated() && authService->HaveAccountsChanged(); authService->IsAuthenticated() &&
authService->HaveAccountsChangedWhileInBackground();
} }
#pragma mark Initialization #pragma mark Initialization
......
...@@ -63,7 +63,7 @@ TEST_F(SignedInAccountsViewControllerTest, ...@@ -63,7 +63,7 @@ TEST_F(SignedInAccountsViewControllerTest,
// have changed. // have changed.
TEST_F(SignedInAccountsViewControllerTest, TEST_F(SignedInAccountsViewControllerTest,
ShouldBePresentedForBrowserStateNecessary) { ShouldBePresentedForBrowserStateNecessary) {
auth_service_->SetHaveAccountsChanged(true); auth_service_->SetHaveAccountsChangedWhileInBackground(true);
EXPECT_TRUE([SignedInAccountsViewController EXPECT_TRUE([SignedInAccountsViewController
shouldBePresentedForBrowserState:browser_state_.get()]); shouldBePresentedForBrowserState:browser_state_.get()]);
} }
...@@ -72,7 +72,7 @@ TEST_F(SignedInAccountsViewControllerTest, ...@@ -72,7 +72,7 @@ TEST_F(SignedInAccountsViewControllerTest,
// session after upgrade. // session after upgrade.
TEST_F(SignedInAccountsViewControllerTest, TEST_F(SignedInAccountsViewControllerTest,
ShouldBePresentedForBrowserStateAfterUpgrade) { ShouldBePresentedForBrowserStateAfterUpgrade) {
auth_service_->SetHaveAccountsChanged(true); auth_service_->SetHaveAccountsChangedWhileInBackground(true);
{ {
[PreviousSessionInfo resetSharedInstanceForTesting]; [PreviousSessionInfo resetSharedInstanceForTesting];
......
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