Commit b89efb1c authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

PasswordAccountStorageOptInWatcher: Observe SyncService instead of IdentityManager

Reason: The underlying state that's being watched (i.e.
password_manager_util::IsOptedInForAccountStorage) gets the relevant
account-related state from SyncService, not from IdentityManager.
So this is more consistent, and ensures that there are no
order-of-observers problems. (SyncService itself observes the
IdentityManager, so before this CL, the outcome could depend on whether
SyncService or PasswordAccountStorageOptInWatcher get notified first.)

Bug: 1024332
Change-Id: I916c6035961056d46a2061a3eeb9362467ac8d26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151871
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarMohamed Amir Yosef <mamir@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760088}
parent 4d239eeb
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "chrome/browser/password_manager/bulk_leak_check_service_factory.h" #include "chrome/browser/password_manager/bulk_leak_check_service_factory.h"
#include "chrome/browser/password_manager/password_store_factory.h" #include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/extension_system_provider.h" #include "extensions/browser/extension_system_provider.h"
...@@ -37,6 +38,7 @@ PasswordsPrivateDelegateFactory::PasswordsPrivateDelegateFactory() ...@@ -37,6 +38,7 @@ PasswordsPrivateDelegateFactory::PasswordsPrivateDelegateFactory()
BrowserContextDependencyManager::GetInstance()) { BrowserContextDependencyManager::GetInstance()) {
DependsOn(BulkLeakCheckServiceFactory::GetInstance()); DependsOn(BulkLeakCheckServiceFactory::GetInstance());
DependsOn(PasswordStoreFactory::GetInstance()); DependsOn(PasswordStoreFactory::GetInstance());
DependsOn(ProfileSyncServiceFactory::GetInstance());
} }
PasswordsPrivateDelegateFactory::~PasswordsPrivateDelegateFactory() = default; PasswordsPrivateDelegateFactory::~PasswordsPrivateDelegateFactory() = default;
......
...@@ -144,8 +144,8 @@ PasswordsPrivateDelegateImpl::PasswordsPrivateDelegateImpl(Profile* profile) ...@@ -144,8 +144,8 @@ PasswordsPrivateDelegateImpl::PasswordsPrivateDelegateImpl(Profile* profile)
password_account_storage_opt_in_watcher_( password_account_storage_opt_in_watcher_(
std::make_unique< std::make_unique<
password_manager::PasswordAccountStorageOptInWatcher>( password_manager::PasswordAccountStorageOptInWatcher>(
IdentityManagerFactory::GetForProfile(profile_),
profile_->GetPrefs(), profile_->GetPrefs(),
ProfileSyncServiceFactory::GetForProfile(profile_),
base::BindRepeating(&PasswordsPrivateDelegateImpl:: base::BindRepeating(&PasswordsPrivateDelegateImpl::
OnAccountStorageOptInStateChanged, OnAccountStorageOptInStateChanged,
base::Unretained(this)))), base::Unretained(this)))),
......
...@@ -308,12 +308,12 @@ TEST_F(PasswordsPrivateDelegateImplTest, TestShouldReauthForOptIn) { ...@@ -308,12 +308,12 @@ TEST_F(PasswordsPrivateDelegateImplTest, TestShouldReauthForOptIn) {
scoped_feature_list.InitAndEnableFeature( scoped_feature_list.InitAndEnableFeature(
password_manager::features::kEnablePasswordsAccountStorage); password_manager::features::kEnablePasswordsAccountStorage);
PasswordsPrivateDelegateImpl delegate(&profile_);
auto* test_sync_service = static_cast<syncer::SyncService*>( auto* test_sync_service = static_cast<syncer::SyncService*>(
ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
&profile_, base::BindRepeating(&BuildTestSyncService))); &profile_, base::BindRepeating(&BuildTestSyncService)));
PasswordsPrivateDelegateImpl delegate(&profile_);
password_manager_util::SetAccountStorageOptIn(profile_.GetPrefs(), password_manager_util::SetAccountStorageOptIn(profile_.GetPrefs(),
test_sync_service, false); test_sync_service, false);
...@@ -329,12 +329,12 @@ TEST_F(PasswordsPrivateDelegateImplTest, TestShouldNotReauthForOptOut) { ...@@ -329,12 +329,12 @@ TEST_F(PasswordsPrivateDelegateImplTest, TestShouldNotReauthForOptOut) {
scoped_feature_list.InitAndEnableFeature( scoped_feature_list.InitAndEnableFeature(
password_manager::features::kEnablePasswordsAccountStorage); password_manager::features::kEnablePasswordsAccountStorage);
PasswordsPrivateDelegateImpl delegate(&profile_);
auto* test_sync_service = static_cast<syncer::SyncService*>( auto* test_sync_service = static_cast<syncer::SyncService*>(
ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
&profile_, base::BindRepeating(&BuildTestSyncService))); &profile_, base::BindRepeating(&BuildTestSyncService)));
PasswordsPrivateDelegateImpl delegate(&profile_);
password_manager_util::SetAccountStorageOptIn(profile_.GetPrefs(), password_manager_util::SetAccountStorageOptIn(profile_.GetPrefs(),
test_sync_service, true); test_sync_service, true);
......
...@@ -8,18 +8,19 @@ ...@@ -8,18 +8,19 @@
#include "base/callback.h" #include "base/callback.h"
#include "components/password_manager/core/common/password_manager_pref_names.h" #include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/sync/driver/sync_service.h"
namespace password_manager { namespace password_manager {
PasswordAccountStorageOptInWatcher::PasswordAccountStorageOptInWatcher( PasswordAccountStorageOptInWatcher::PasswordAccountStorageOptInWatcher(
signin::IdentityManager* identity_manager,
PrefService* pref_service, PrefService* pref_service,
syncer::SyncService* sync_service,
base::RepeatingClosure change_callback) base::RepeatingClosure change_callback)
: identity_manager_(identity_manager), : sync_service_(sync_service),
change_callback_(std::move(change_callback)) { change_callback_(std::move(change_callback)) {
// The opt-in state is per-account, so it can change whenever the state of the // The opt-in state is per-account, so it can change whenever the state of the
// signed-in account (aka unconsented primary account) changes. // account used by Sync changes.
identity_manager_->AddObserver(this); sync_service_->AddObserver(this);
// The opt-in state is stored in a pref, so changes to the pref might indicate // The opt-in state is stored in a pref, so changes to the pref might indicate
// a change to the opt-in state. // a change to the opt-in state.
pref_change_registrar_.Init(pref_service); pref_change_registrar_.Init(pref_service);
...@@ -29,11 +30,11 @@ PasswordAccountStorageOptInWatcher::PasswordAccountStorageOptInWatcher( ...@@ -29,11 +30,11 @@ PasswordAccountStorageOptInWatcher::PasswordAccountStorageOptInWatcher(
} }
PasswordAccountStorageOptInWatcher::~PasswordAccountStorageOptInWatcher() { PasswordAccountStorageOptInWatcher::~PasswordAccountStorageOptInWatcher() {
identity_manager_->RemoveObserver(this); sync_service_->RemoveObserver(this);
} }
void PasswordAccountStorageOptInWatcher::OnUnconsentedPrimaryAccountChanged( void PasswordAccountStorageOptInWatcher::OnStateChanged(
const CoreAccountInfo& unconsented_primary_account_info) { syncer::SyncService* sync_service) {
change_callback_.Run(); change_callback_.Run();
} }
......
...@@ -7,32 +7,34 @@ ...@@ -7,32 +7,34 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "components/prefs/pref_change_registrar.h" #include "components/prefs/pref_change_registrar.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/sync/driver/sync_service_observer.h"
class PrefService; class PrefService;
namespace syncer {
class SyncService;
} // namespace syncer
namespace password_manager { namespace password_manager {
// Helper class to watch for changes to the opt-in state for the account-scoped // Helper class to watch for changes to the opt-in state for the account-scoped
// password storage (see password_manager_util::IsOptedInForAccountStorage()). // password storage (see password_manager_util::IsOptedInForAccountStorage()).
class PasswordAccountStorageOptInWatcher class PasswordAccountStorageOptInWatcher : public syncer::SyncServiceObserver {
: public signin::IdentityManager::Observer {
public: public:
// |identity_manager| and |pref_service| must not be null and must outlive // |pref_service| and |sync_service| must not be null and must outlive this
// this object. // object.
// |change_callback| will be invoked whenever the state of // |change_callback| will be invoked whenever the state of
// password_manager_util::IsOptedInForAccountStorage() might have changed. // password_manager_util::IsOptedInForAccountStorage() might have changed.
PasswordAccountStorageOptInWatcher(signin::IdentityManager* identity_manager, PasswordAccountStorageOptInWatcher(PrefService* pref_service,
PrefService* pref_service, syncer::SyncService* sync_service,
base::RepeatingClosure change_callback); base::RepeatingClosure change_callback);
~PasswordAccountStorageOptInWatcher() override; ~PasswordAccountStorageOptInWatcher() override;
// identity::IdentityManager::Observer: // syncer::SyncServiceObserver:
void OnUnconsentedPrimaryAccountChanged( void OnStateChanged(syncer::SyncService* sync_service) override;
const CoreAccountInfo& unconsented_primary_account_info) override;
private: private:
signin::IdentityManager* const identity_manager_; syncer::SyncService* const sync_service_;
base::RepeatingClosure change_callback_; base::RepeatingClosure change_callback_;
PrefChangeRegistrar pref_change_registrar_; PrefChangeRegistrar pref_change_registrar_;
......
...@@ -32,8 +32,8 @@ PasswordModelTypeController::PasswordModelTypeController( ...@@ -32,8 +32,8 @@ PasswordModelTypeController::PasswordModelTypeController(
sync_service_(sync_service), sync_service_(sync_service),
state_changed_callback_(state_changed_callback), state_changed_callback_(state_changed_callback),
account_storage_opt_in_watcher_( account_storage_opt_in_watcher_(
identity_manager_,
pref_service_, pref_service_,
sync_service_,
base::BindRepeating( base::BindRepeating(
&PasswordModelTypeController::OnOptInStateMaybeChanged, &PasswordModelTypeController::OnOptInStateMaybeChanged,
base::Unretained(this))) { base::Unretained(this))) {
......
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