Commit 4e2d3aec authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Clear opt-in for account-scoped passwords when Sync is turned off

This CL also clears the opt-in for the account-scoped password storage
when Sync is turned off (and the Sync consent is revoked).

Bug: 1098382
Change-Id: I4211a4f66c580f02d0844771dc1d09a03be268a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261272
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarAlex Ilin <alexilin@chromium.org>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781891}
parent 06c37675
...@@ -532,6 +532,11 @@ IN_PROC_BROWSER_TEST_F(SingleClientPasswordsWithAccountStorageSyncTest, ...@@ -532,6 +532,11 @@ IN_PROC_BROWSER_TEST_F(SingleClientPasswordsWithAccountStorageSyncTest,
ASSERT_TRUE(GetClient(0)->AwaitSyncTransportActive()); ASSERT_TRUE(GetClient(0)->AwaitSyncTransportActive());
ASSERT_FALSE(GetSyncService(0)->IsSyncFeatureEnabled()); ASSERT_FALSE(GetSyncService(0)->IsSyncFeatureEnabled());
// The account-storage opt-in gets cleared when turning off Sync, so opt in
// again.
OptInToAccountStorage(GetProfile(0)->GetPrefs(), GetSyncService(0));
PasswordSyncActiveChecker(GetSyncService(0)).Wait();
// Now the password should be in both stores: The profile store does *not* get // Now the password should be in both stores: The profile store does *not* get
// cleared when Sync gets disabled. // cleared when Sync gets disabled.
EXPECT_EQ(passwords_helper::GetAllLogins(profile_store).size(), 1u); EXPECT_EQ(passwords_helper::GetAllLogins(profile_store).size(), 1u);
......
...@@ -264,6 +264,12 @@ void OptOutOfAccountStorageAndClearSettings( ...@@ -264,6 +264,12 @@ void OptOutOfAccountStorageAndClearSettings(
return; return;
} }
OptOutOfAccountStorageAndClearSettingsForAccount(pref_service, gaia_id);
}
void OptOutOfAccountStorageAndClearSettingsForAccount(
PrefService* pref_service,
const std::string& gaia_id) {
ScopedAccountStorageSettingsUpdate(pref_service, ScopedAccountStorageSettingsUpdate(pref_service,
GaiaIdHash::FromGaiaId(gaia_id)) GaiaIdHash::FromGaiaId(gaia_id))
.ClearAllSettings(); .ClearAllSettings();
......
...@@ -61,6 +61,12 @@ void OptOutOfAccountStorageAndClearSettings( ...@@ -61,6 +61,12 @@ void OptOutOfAccountStorageAndClearSettings(
PrefService* pref_service, PrefService* pref_service,
const syncer::SyncService* sync_service); const syncer::SyncService* sync_service);
// Like OptOutOfAccountStorageAndClearSettings(), but applies to a specific
// given |gaia_id| rather than to the current signed-in user.
void OptOutOfAccountStorageAndClearSettingsForAccount(
PrefService* pref_service,
const std::string& gaia_id);
// Whether it makes sense to ask the user about the store when saving a // Whether it makes sense to ask the user about the store when saving a
// password (i.e. profile or account store). This is true if the user has // password (i.e. profile or account store). This is true if the user has
// opted in already, or hasn't opted in but all other requirements are met (i.e. // opted in already, or hasn't opted in but all other requirements are met (i.e.
......
...@@ -124,6 +124,17 @@ void PasswordModelTypeController::OnAccountsCookieDeletedByUserAction() { ...@@ -124,6 +124,17 @@ void PasswordModelTypeController::OnAccountsCookieDeletedByUserAction() {
features_util::ClearAccountStorageSettingsForAllUsers(pref_service_); features_util::ClearAccountStorageSettingsForAllUsers(pref_service_);
} }
void PasswordModelTypeController::OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) {
// Note: OnPrimaryAccountCleared() basically means that the consent for
// Sync-the-feature was revoked. In this case, also clear any possible
// matching opt-in for the account-scoped storage, since it'd probably be
// surprising to the user if their account passwords still remained after
// disabling Sync.
features_util::OptOutOfAccountStorageAndClearSettingsForAccount(
pref_service_, previous_primary_account_info.gaia);
}
void PasswordModelTypeController::OnOptInStateMaybeChanged() { void PasswordModelTypeController::OnOptInStateMaybeChanged() {
// Note: This method gets called in many other situations as well, not just // Note: This method gets called in many other situations as well, not just
// when the opt-in state changes, but DataTypePreconditionChanged() is cheap // when the opt-in state changes, but DataTypePreconditionChanged() is cheap
......
...@@ -54,6 +54,8 @@ class PasswordModelTypeController : public syncer::ModelTypeController, ...@@ -54,6 +54,8 @@ class PasswordModelTypeController : public syncer::ModelTypeController,
const signin::AccountsInCookieJarInfo& accounts_in_cookie_jar_info, const signin::AccountsInCookieJarInfo& accounts_in_cookie_jar_info,
const GoogleServiceAuthError& error) override; const GoogleServiceAuthError& error) override;
void OnAccountsCookieDeletedByUserAction() override; void OnAccountsCookieDeletedByUserAction() override;
void OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) override;
private: private:
void OnOptInStateMaybeChanged(); void OnOptInStateMaybeChanged();
......
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