Update privacy_sandbox_settings.cc

This commit is contained in:
Alexander David Frick 2022-02-17 11:40:37 -06:00 committed by GitHub
parent df4855ff4c
commit 18cbecc6ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -93,6 +93,12 @@ PrivacySandboxSettings::PrivacySandboxSettings(
// was shut down).
if (IsCookiesClearOnExitEnabled(host_content_settings_map_))
OnCookiesCleared();
pref_change_registrar_.Init(pref_service_);
pref_change_registrar_.Add(
prefs::kPrivacySandboxApisEnabledV2,
base::BindRepeating(&PrivacySandboxSettings::OnPrivacySandboxPrefChanged,
base::Unretained(this)));
}
PrivacySandboxSettings::~PrivacySandboxSettings() = default;
@ -311,10 +317,29 @@ void PrivacySandboxSettings::SetPrivacySandboxEnabled(bool enabled) {
}
}
bool PrivacySandboxSettings::IsTrustTokensAllowed() {
// The PrivacySandboxSettings is only involved in Trust Token access
// decisions when the Release 3 flag is enabled.
if (!base::FeatureList::IsEnabled(privacy_sandbox::kPrivacySandboxSettings3))
return true;
return IsPrivacySandboxEnabled();
}
void PrivacySandboxSettings::OnCookiesCleared() {
SetFlocDataAccessibleFromNow(/*reset_calculate_timer=*/false);
}
void PrivacySandboxSettings::OnPrivacySandboxPrefChanged() {
// The PrivacySandboxSettings is only involved in Trust Token access
// decisions when the Release 3 flag is enabled.
if (!base::FeatureList::IsEnabled(privacy_sandbox::kPrivacySandboxSettings3))
return;
for (auto& observer : observers_)
observer.OnTrustTokenBlockingChanged(!IsTrustTokensAllowed());
}
void PrivacySandboxSettings::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}