Skip to content

Commit

Permalink
Disable kPrivacySandboxApisEnabledV2 privacy sandbox API preference
Browse files Browse the repository at this point in the history
Chromium change:

https://source.chromium.org/chromium/chromium/src/+/7af9b25ea15c99177eeb7e1286c2bef002c70440

commit 7af9b25ea15c99177eeb7e1286c2bef002c70440
Author: sauski <[email protected]>
Date:   Tue Feb 1 09:59:45 2022 +0000

    Privacy Sandbox Settings: Introduce new un-synced primary preference

    This CL introduces V2 of the PrivacySandboxApisEnabled preference, which
    will replace the initial version as the primary control for Privacy
    Sandbox APIs.

    A migration is required as post Kartoffel release 3, the primary
    control will not be synced across devices. The new pref will be init
    appropriately during the confirmation moment of Kartoffel 3, and so
    is default off.

    All locations that consult or set the V1 preference have been updated
    to consult the new pref as required. The exception is the FLoC
    generated preference, which as FLoC has been discontinued will be
    removed and does not need to be updated.

    The PrivacySandboxSettings unit tests have been parameterized based
    on the value of the feature, with test utils updated to only set the
    appropriate pref.

    Bug: 1286276
  • Loading branch information
emerick committed Mar 8, 2022
1 parent 0d7d7c6 commit 111728e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
2 changes: 2 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
// Disable Chromium's privacy sandbox
registry->SetDefaultPrefValue(prefs::kPrivacySandboxApisEnabled,
base::Value(false));
registry->SetDefaultPrefValue(prefs::kPrivacySandboxApisEnabledV2,
base::Value(false));

// Disable Chromium's privacy sandbox
registry->SetDefaultPrefValue(prefs::kPrivacySandboxFlocEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,43 @@ TEST_F(PrivacySandboxServiceTest, OnPrivacySandboxPrefChanged) {
prefs::kPrivacySandboxApisEnabled, true);
testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer);
}

TEST_F(PrivacySandboxServiceTest, OnPrivacySandboxPrefV2Changed) {
// When either the main Privacy Sandbox pref, or the FLoC pref, are changed
// the FLoC ID should be reset. This will be propagated to the settings
// instance, which should then notify observers.
privacy_sandbox_test_util::MockPrivacySandboxObserver
mock_privacy_sandbox_observer;
PrivacySandboxSettingsFactory::GetForProfile(profile())->AddObserver(
&mock_privacy_sandbox_observer);
EXPECT_CALL(mock_privacy_sandbox_observer,
OnFlocDataAccessibleSinceUpdated(/*reset_compute_timer=*/true));

profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxApisEnabledV2, false);
testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer);

EXPECT_CALL(mock_privacy_sandbox_observer,
OnFlocDataAccessibleSinceUpdated(/*reset_compute_timer=*/true));
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxFlocEnabled, false);
testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer);

// OnFlocDataAccessibleSinceUpdated() will be called twice because the attempt
// to enable the pref will be immediately followed by setting it to false.
EXPECT_CALL(mock_privacy_sandbox_observer,
OnFlocDataAccessibleSinceUpdated(/*reset_compute_timer=*/true))
.Times(2);
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxFlocEnabled, true);
testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer);

// OnFlocDataAccessibleSinceUpdated() will be called twice because the attempt
// to enable the pref will be immediately followed by setting it to false.
EXPECT_CALL(mock_privacy_sandbox_observer,
OnFlocDataAccessibleSinceUpdated(/*reset_compute_timer=*/true))
.Times(2);
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxApisEnabledV2, true);
testing::Mock::VerifyAndClearExpectations(&mock_privacy_sandbox_observer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,11 @@ TEST_F(PrivacySandboxSettingsTest, IsPrivacySandboxEnabled) {
EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());

// Check that even bypassing PrivacySandboxSettings::SetPrivacySandboxEnabled,
// and manually updating the preference, we still don't get this enabled.
// and manually updating the preferences, we still don't get this enabled.
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxApisEnabled, true);
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxApisEnabledV2, true);
EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
}

Expand All @@ -503,6 +505,8 @@ TEST_F(PrivacySandboxSettingsTest, IsFlocAllowed) {
// and manually updating the preferences, we still don't get this enabled.
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxApisEnabled, true);
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxApisEnabledV2, true);
profile()->GetTestingPrefService()->SetBoolean(
prefs::kPrivacySandboxFlocEnabled, true);
EXPECT_FALSE(privacy_sandbox_settings()->IsFlocAllowed());
Expand Down
10 changes: 9 additions & 1 deletion components/privacy_sandbox/brave_privacy_sandbox_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ BravePrivacySandboxSettings::BravePrivacySandboxSettings(
base::BindRepeating(
&BravePrivacySandboxSettings::OnPrivacySandboxPrefChanged,
base::Unretained(this)));
user_prefs_registrar_.Add(
prefs::kPrivacySandboxApisEnabledV2,
base::BindRepeating(
&BravePrivacySandboxSettings::OnPrivacySandboxPrefChanged,
base::Unretained(this)));
user_prefs_registrar_.Add(
prefs::kPrivacySandboxFlocEnabled,
base::BindRepeating(
Expand All @@ -38,10 +43,13 @@ BravePrivacySandboxSettings::~BravePrivacySandboxSettings() = default;

void BravePrivacySandboxSettings::OnPrivacySandboxPrefChanged() {
// Make sure that Private Sandbox features remain disabled even if we manually
// access the Pref service and try to change the preference from there.
// access the Pref service and try to change the preferences from there.
if (pref_service_->GetBoolean(prefs::kPrivacySandboxApisEnabled)) {
pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabled, false);
}
if (pref_service_->GetBoolean(prefs::kPrivacySandboxApisEnabledV2)) {
pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabledV2, false);
}
if (pref_service_->GetBoolean(prefs::kPrivacySandboxFlocEnabled)) {
pref_service_->SetBoolean(prefs::kPrivacySandboxFlocEnabled, false);
}
Expand Down

0 comments on commit 111728e

Please sign in to comment.