#include "components/sync/service/sync_user_settings_impl.h"
#include <utility>
#include "base/check.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/version.h"
#include "build/chromeos_buildflags.h"
#include "components/signin/public/base/gaia_id_hash.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/sync/base/features.h"
#include "components/sync/base/passphrase_enums.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/engine/nigori/nigori.h"
#include "components/sync/service/sync_prefs.h"
#include "components/sync/service/sync_service_crypto.h"
#include "components/version_info/version_info.h"
namespace syncer {
namespace {
DataTypeSet UserSelectableTypesToDataTypes(
UserSelectableTypeSet selected_types) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
DataTypeSet UserSelectableOsTypesToDataTypes(
UserSelectableOsTypeSet selected_types) {
DataTypeSet preferred_types;
for (UserSelectableOsType type : selected_types) {
preferred_types.PutAll(UserSelectableOsTypeToAllDataTypes(type));
}
return preferred_types;
}
#endif
int GetCurrentMajorProductVersion() { … }
bool ShouldAutofillWalletCredentialBeIgnoredIfOnlyEncryptedType(
const SyncPrefs& prefs) { … }
}
SyncUserSettingsImpl::SyncUserSettingsImpl(Delegate* delegate,
SyncServiceCrypto* crypto,
SyncPrefs* prefs,
DataTypeSet registered_data_types)
: … { … }
SyncUserSettingsImpl::~SyncUserSettingsImpl() = default;
bool SyncUserSettingsImpl::IsInitialSyncFeatureSetupComplete() const { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
void SyncUserSettingsImpl::SetInitialSyncFeatureSetupComplete(
SyncFirstSetupCompleteSource source) { … }
#endif
bool SyncUserSettingsImpl::IsSyncEverythingEnabled() const { … }
UserSelectableTypeSet SyncUserSettingsImpl::GetSelectedTypes() const { … }
bool SyncUserSettingsImpl::IsTypeManagedByPolicy(
UserSelectableType type) const { … }
bool SyncUserSettingsImpl::IsTypeManagedByCustodian(
UserSelectableType type) const { … }
SyncUserSettings::UserSelectableTypePrefState
SyncUserSettingsImpl::GetTypePrefStateForAccount(
UserSelectableType type) const { … }
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
int SyncUserSettingsImpl::GetNumberOfAccountsWithPasswordsSelected() const { … }
#endif
void SyncUserSettingsImpl::SetSelectedTypes(bool sync_everything,
UserSelectableTypeSet types) { … }
void SyncUserSettingsImpl::SetSelectedType(UserSelectableType type,
bool is_type_on) { … }
void SyncUserSettingsImpl::KeepAccountSettingsPrefsOnlyForUsers(
const std::vector<signin::GaiaIdHash>& available_gaia_ids) { … }
UserSelectableTypeSet SyncUserSettingsImpl::GetRegisteredSelectableTypes()
const { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
void SyncUserSettingsImpl::SetSyncFeatureDisabledViaDashboard() {
prefs_->SetSyncFeatureDisabledViaDashboard();
}
void SyncUserSettingsImpl::ClearSyncFeatureDisabledViaDashboard() {
prefs_->ClearSyncFeatureDisabledViaDashboard();
}
bool SyncUserSettingsImpl::IsSyncFeatureDisabledViaDashboard() const {
return prefs_->IsSyncFeatureDisabledViaDashboard();
}
bool SyncUserSettingsImpl::IsSyncAllOsTypesEnabled() const {
return prefs_->IsSyncAllOsTypesEnabled();
}
UserSelectableOsTypeSet SyncUserSettingsImpl::GetSelectedOsTypes() const {
UserSelectableOsTypeSet types = prefs_->GetSelectedOsTypes();
types.RetainAll(GetRegisteredSelectableOsTypes());
return types;
}
bool SyncUserSettingsImpl::IsOsTypeManagedByPolicy(
UserSelectableOsType type) const {
return prefs_->IsOsTypeManagedByPolicy(type);
}
void SyncUserSettingsImpl::SetSelectedOsTypes(bool sync_all_os_types,
UserSelectableOsTypeSet types) {
UserSelectableOsTypeSet registered_types = GetRegisteredSelectableOsTypes();
DCHECK(registered_types.HasAll(types));
prefs_->SetSelectedOsTypes(sync_all_os_types, registered_types, types);
}
UserSelectableOsTypeSet SyncUserSettingsImpl::GetRegisteredSelectableOsTypes()
const {
UserSelectableOsTypeSet registered_types;
for (UserSelectableOsType type : UserSelectableOsTypeSet::All()) {
if (!base::Intersection(registered_data_types_,
UserSelectableOsTypeToAllDataTypes(type))
.empty()) {
registered_types.Put(type);
}
}
return registered_types;
}
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
void SyncUserSettingsImpl::SetAppsSyncEnabledByOs(bool apps_sync_enabled) {
DCHECK(base::FeatureList::IsEnabled(kSyncChromeOSAppsToggleSharing));
prefs_->SetAppsSyncEnabledByOs(apps_sync_enabled);
}
#endif
bool SyncUserSettingsImpl::IsCustomPassphraseAllowed() const { … }
bool SyncUserSettingsImpl::IsEncryptEverythingEnabled() const { … }
bool SyncUserSettingsImpl::IsPassphraseRequired() const { … }
bool SyncUserSettingsImpl::IsPassphraseRequiredForPreferredDataTypes() const { … }
bool SyncUserSettingsImpl::IsPassphrasePromptMutedForCurrentProductVersion()
const { … }
void SyncUserSettingsImpl::MarkPassphrasePromptMutedForCurrentProductVersion() { … }
bool SyncUserSettingsImpl::IsTrustedVaultKeyRequired() const { … }
bool SyncUserSettingsImpl::IsTrustedVaultKeyRequiredForPreferredDataTypes()
const { … }
bool SyncUserSettingsImpl::IsTrustedVaultRecoverabilityDegraded() const { … }
bool SyncUserSettingsImpl::IsUsingExplicitPassphrase() const { … }
base::Time SyncUserSettingsImpl::GetExplicitPassphraseTime() const { … }
std::optional<PassphraseType> SyncUserSettingsImpl::GetPassphraseType() const { … }
void SyncUserSettingsImpl::SetEncryptionPassphrase(
const std::string& passphrase) { … }
bool SyncUserSettingsImpl::SetDecryptionPassphrase(
const std::string& passphrase) { … }
void SyncUserSettingsImpl::SetExplicitPassphraseDecryptionNigoriKey(
std::unique_ptr<Nigori> nigori) { … }
std::unique_ptr<Nigori>
SyncUserSettingsImpl::GetExplicitPassphraseDecryptionNigoriKey() const { … }
DataTypeSet SyncUserSettingsImpl::GetPreferredDataTypes() const { … }
DataTypeSet SyncUserSettingsImpl::GetAllEncryptedDataTypes() const { … }
bool SyncUserSettingsImpl::IsEncryptedDatatypePreferred() const { … }
std::string SyncUserSettingsImpl::GetEncryptionBootstrapToken() const { … }
void SyncUserSettingsImpl::SetEncryptionBootstrapToken(
const std::string& token) { … }
}