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

Migrate components/password_manager to SyncUserSettings

SyncUserSettings is a new class that encapsulates all the
user-configurable knobs for Sync. It replaces a bunch of setters
and getters directly on the SyncService.

While I'm here, also
- update a comment in GetSyncUsernameIfSyncingPasswords to be more
  specific, since the semantics here are a bit weird, and
- remove a CanSyncFeatureStart check from
  ShouldAffiliationBasedMatchingBeActive since it's redundant with the
  check for IsSyncFeatureActive which is strictly stronger.

Bug: 884159
Change-Id: Ibbb9a82a2d89520e1a349e29a1050cd84dd52ea5
Reviewed-on: https://chromium-review.googlesource.com/c/1344096Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609964}
parent b75f0d69
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
#include "components/password_manager/core/common/password_manager_pref_names.h" #include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/sessions/content/content_record_password_state.h" #include "components/sessions/content/content_record_password_state.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_user_settings.h"
#include "components/ukm/content/source_url_recorder.h" #include "components/ukm/content/source_url_recorder.h"
#include "components/version_info/version_info.h" #include "components/version_info/version_info.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -821,7 +823,7 @@ bool ChromePasswordManagerClient::ShouldAnnotateNavigationEntries( ...@@ -821,7 +823,7 @@ bool ChromePasswordManagerClient::ShouldAnnotateNavigationEntries(
browser_sync::ProfileSyncService* profile_sync_service = browser_sync::ProfileSyncService* profile_sync_service =
ProfileSyncServiceFactory::GetForProfile(profile); ProfileSyncServiceFactory::GetForProfile(profile);
if (!profile_sync_service || !profile_sync_service->IsSyncFeatureActive() || if (!profile_sync_service || !profile_sync_service->IsSyncFeatureActive() ||
profile_sync_service->IsUsingSecondaryPassphrase()) { profile_sync_service->GetUserSettings()->IsUsingSecondaryPassphrase()) {
return false; return false;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_user_settings.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
namespace password_bubble_experiment { namespace password_bubble_experiment {
...@@ -65,7 +66,7 @@ bool ShouldShowChromeSignInPasswordPromo( ...@@ -65,7 +66,7 @@ bool ShouldShowChromeSignInPasswordPromo(
syncer::SyncService::DISABLE_REASON_PLATFORM_OVERRIDE) || syncer::SyncService::DISABLE_REASON_PLATFORM_OVERRIDE) ||
sync_service->HasDisableReason( sync_service->HasDisableReason(
syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY) || syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY) ||
sync_service->IsFirstSetupComplete()) { sync_service->GetUserSettings()->IsFirstSetupComplete()) {
return false; return false;
} }
// Don't show the promo more than 3 times. // Don't show the promo more than 3 times.
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "components/password_manager/core/common/password_manager_pref_names.h" #include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_service.h" #include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_user_settings.h"
using autofill::PasswordForm; using autofill::PasswordForm;
...@@ -60,10 +61,10 @@ void UpdateMetadataForUsage(PasswordForm* credential) { ...@@ -60,10 +61,10 @@ void UpdateMetadataForUsage(PasswordForm* credential) {
password_manager::SyncState GetPasswordSyncState( password_manager::SyncState GetPasswordSyncState(
const syncer::SyncService* sync_service) { const syncer::SyncService* sync_service) {
if (sync_service && sync_service->IsFirstSetupComplete() && if (sync_service && sync_service->GetUserSettings()->IsFirstSetupComplete() &&
sync_service->IsSyncFeatureActive() && sync_service->IsSyncFeatureActive() &&
sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS)) { sync_service->GetActiveDataTypes().Has(syncer::PASSWORDS)) {
return sync_service->IsUsingSecondaryPassphrase() return sync_service->GetUserSettings()->IsUsingSecondaryPassphrase()
? password_manager::SYNCING_WITH_CUSTOM_PASSPHRASE ? password_manager::SYNCING_WITH_CUSTOM_PASSPHRASE
: password_manager::SYNCING_NORMAL_ENCRYPTION; : password_manager::SYNCING_NORMAL_ENCRYPTION;
} }
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h" #include "components/password_manager/core/browser/android_affiliation/affiliation_utils.h"
#include "components/password_manager/core/browser/password_manager_constants.h" #include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/common/password_manager_features.h" #include "components/password_manager/core/common/password_manager_features.h"
#include "components/sync/driver/sync_service.h"
#include "components/sync/driver/sync_user_settings.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace password_manager { namespace password_manager {
...@@ -21,10 +23,10 @@ namespace { ...@@ -21,10 +23,10 @@ namespace {
bool ShouldAffiliationBasedMatchingBeActive(syncer::SyncService* sync_service) { bool ShouldAffiliationBasedMatchingBeActive(syncer::SyncService* sync_service) {
return base::FeatureList::IsEnabled(features::kAffiliationBasedMatching) && return base::FeatureList::IsEnabled(features::kAffiliationBasedMatching) &&
sync_service && sync_service->CanSyncFeatureStart() && sync_service && sync_service->IsSyncFeatureActive() &&
sync_service->IsSyncFeatureActive() && sync_service->GetUserSettings()->GetChosenDataTypes().Has(
sync_service->GetPreferredDataTypes().Has(syncer::PASSWORDS) && syncer::PASSWORDS) &&
!sync_service->IsUsingSecondaryPassphrase(); !sync_service->GetUserSettings()->IsUsingSecondaryPassphrase();
} }
void ActivateAffiliationBasedMatching( void ActivateAffiliationBasedMatching(
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/autofill/core/common/password_form.h" #include "components/autofill/core/common/password_form.h"
#include "components/sync/base/model_type.h"
#include "components/sync/driver/sync_user_settings.h"
#include "google_apis/gaia/gaia_auth_util.h" #include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/gaia_urls.h"
#include "services/identity/public/cpp/identity_manager.h" #include "services/identity/public/cpp/identity_manager.h"
...@@ -35,9 +37,11 @@ std::string GetSyncUsernameIfSyncingPasswords( ...@@ -35,9 +37,11 @@ std::string GetSyncUsernameIfSyncingPasswords(
if (!identity_manager) if (!identity_manager)
return std::string(); return std::string();
// If sync is set up, return early if we aren't syncing passwords. // Return early if the user has explicitly disabled password sync. Note that
// this does not cover the case when sync as a whole is turned off.
if (sync_service && if (sync_service &&
!sync_service->GetPreferredDataTypes().Has(syncer::PASSWORDS)) { !sync_service->GetUserSettings()->GetChosenDataTypes().Has(
syncer::PASSWORDS)) {
return std::string(); return std::string();
} }
......
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