#include "components/unified_consent/unified_consent_service.h"
#include "base/check_op.h"
#include "build/build_config.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/sync/base/features.h"
#include "components/sync/base/user_selectable_type.h"
#include "components/sync/service/sync_service.h"
#include "components/sync/service/sync_user_settings.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/unified_consent/pref_names.h"
namespace unified_consent {
UnifiedConsentService::SyncState UnifiedConsentService::GetSyncState(
const syncer::SyncService* sync_service) { … }
bool UnifiedConsentService::ShouldEnableUrlKeyedAnonymizedDataCollection(
SyncState old_sync_state,
SyncState new_sync_state) { … }
bool UnifiedConsentService::ShouldDisableUrlKeyedAnonymizedDataCollection(
SyncState old_sync_state,
SyncState new_sync_state) { … }
UnifiedConsentService::UnifiedConsentService(
sync_preferences::PrefServiceSyncable* pref_service,
signin::IdentityManager* identity_manager,
syncer::SyncService* sync_service,
const std::vector<std::string>& service_pref_names)
: … { … }
UnifiedConsentService::~UnifiedConsentService() = default;
void UnifiedConsentService::RegisterPrefs(
user_prefs::PrefRegistrySyncable* registry) { … }
void UnifiedConsentService::SetUrlKeyedAnonymizedDataCollectionEnabled(
bool enabled) { … }
void UnifiedConsentService::Shutdown() { … }
void UnifiedConsentService::OnPrimaryAccountChanged(
const signin::PrimaryAccountChangeEvent& event) { … }
void UnifiedConsentService::OnStateChanged(syncer::SyncService* sync) { … }
void UnifiedConsentService::OnIsSyncingChanged() { … }
void UnifiedConsentService::StartObservingServicePrefChanges() { … }
void UnifiedConsentService::StopObservingServicePrefChanges() { … }
void UnifiedConsentService::ServicePrefChanged(const std::string& name) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
MigrationState UnifiedConsentService::GetMigrationState() {
int migration_state_int =
pref_service_->GetInteger(prefs::kUnifiedConsentMigrationState);
DCHECK_LE(static_cast<int>(MigrationState::kNotInitialized),
migration_state_int);
DCHECK_GE(static_cast<int>(MigrationState::kCompleted), migration_state_int);
return static_cast<MigrationState>(migration_state_int);
}
void UnifiedConsentService::SetMigrationState(MigrationState migration_state) {
pref_service_->SetInteger(prefs::kUnifiedConsentMigrationState,
static_cast<int>(migration_state));
}
void UnifiedConsentService::MigrateProfileToUnifiedConsent() {
DCHECK_EQ(GetMigrationState(), MigrationState::kNotInitialized);
if (!identity_manager_->HasPrimaryAccount(signin::ConsentLevel::kSync)) {
SetMigrationState(MigrationState::kCompleted);
return;
}
UpdateSettingsForMigration();
}
void UnifiedConsentService::UpdateSettingsForMigration() {
if (!sync_service_->IsEngineInitialized()) {
SetMigrationState(MigrationState::kInProgressWaitForSyncInit);
return;
}
bool url_keyed_metrics_enabled =
sync_service_->IsSyncFeatureEnabled() &&
sync_service_->GetUserSettings()->GetSelectedTypes().Has(
syncer::UserSelectableType::kHistory) &&
!sync_service_->GetUserSettings()->IsUsingExplicitPassphrase();
SetUrlKeyedAnonymizedDataCollectionEnabled(url_keyed_metrics_enabled);
}
#endif
}