Skip to content

Commit

Permalink
Privacy Sandbox Settings: Show snackbar when adding/blocking topic/site
Browse files Browse the repository at this point in the history
- Display the V3 snackbar when a Topic is added or removed.
- Display the V3 snackbar when a Fledge site is added or removed.
- Minor refactoring of V3 code.

Bug: 1378703, b/261820160, b/261819449
Change-Id: Ic372c47ff8d8dbf2e466a1c13823305a14d09638
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4111214
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Reviewed-by: Christian Dullweber <dullweber@chromium.org>
Commit-Queue: Rubin Deliallisi <rubindl@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1085358}
  • Loading branch information
Rubin Deliallisi authored and Chromium LUCI CQ committed Dec 20, 2022
1 parent 7081c01 commit 72f76c0
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
import org.chromium.chrome.browser.password_entry_edit.CredentialEntryFragmentViewBase;
import org.chromium.chrome.browser.privacy_guide.PrivacyGuideFragment;
import org.chromium.chrome.browser.privacy_sandbox.AdMeasurementFragment;
import org.chromium.chrome.browser.privacy_sandbox.AdPersonalizationFragment;
import org.chromium.chrome.browser.privacy_sandbox.AdPersonalizationRemovedFragment;
import org.chromium.chrome.browser.privacy_sandbox.FlocSettingsFragment;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxSettingsBaseFragment;
import org.chromium.chrome.browser.profiles.Profile;
Expand Down Expand Up @@ -253,11 +251,9 @@ public void onAttachedToWindow() {
.getSiteSettingsDelegate());
delegate.setSnackbarManager(mSnackbarManager);
}
if (fragment instanceof AdPersonalizationFragment) {
((AdPersonalizationFragment) fragment).setSnackbarManager(getSnackbarManager());
}
if (fragment instanceof AdPersonalizationRemovedFragment) {
((AdPersonalizationRemovedFragment) fragment).setSnackbarManager(getSnackbarManager());
if (fragment instanceof PrivacySandboxSettingsBaseFragment) {
((PrivacySandboxSettingsBaseFragment) fragment)
.setSnackbarManager(getSnackbarManager());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.components.browser_ui.settings.ChromeBasePreference;
import org.chromium.components.browser_ui.settings.FragmentSettingsLauncher;
import org.chromium.components.browser_ui.settings.SettingsLauncher;
Expand All @@ -42,8 +41,6 @@ public class AdPersonalizationFragment extends PrivacySandboxSettingsBaseFragmen
private static final String EMPTY_FLEDGE_PREFERENCE = "empty_fledge";
private static final String REMOVED_SITES_PREFERENCE = "removed_sites";

private SnackbarManager mSnackbarManager;

private PreferenceCategory mTopicsCategory;
private ChromeBasePreference mEmptyTopicsPreference;
private Preference mRemovedTopicsPreference;
Expand All @@ -56,10 +53,6 @@ public class AdPersonalizationFragment extends PrivacySandboxSettingsBaseFragmen
private LargeIconBridge mLargeIconBridge;
private SettingsLauncher mSettingsLauncher;

public void setSnackbarManager(SnackbarManager snackbarManager) {
mSnackbarManager = snackbarManager;
}

@Override
public void setSettingsLauncher(SettingsLauncher settingsLauncher) {
mSettingsLauncher = settingsLauncher;
Expand Down Expand Up @@ -197,16 +190,14 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
if (preference instanceof TopicPreference) {
blockTopic(((TopicPreference) preference).getTopic());
mTopicsCategory.removePreference(preference);
mSnackbarManager.showSnackbar(Snackbar.make(
getResources().getString(R.string.privacy_sandbox_remove_interest_snackbar),
null, Snackbar.TYPE_ACTION, Snackbar.UMA_PRIVACY_SANDBOX_REMOVE_INTEREST));
showSnackbar(R.string.privacy_sandbox_remove_interest_snackbar, null,
Snackbar.TYPE_ACTION, Snackbar.UMA_PRIVACY_SANDBOX_REMOVE_INTEREST);
RecordUserAction.record("Settings.PrivacySandbox.AdPersonalization.TopicRemoved");
} else if (preference instanceof FledgePreference) {
blockFledge(((FledgePreference) preference).getSite());
mFledgeCategory.removePreference(preference);
mSnackbarManager.showSnackbar(Snackbar.make(
getResources().getString(R.string.privacy_sandbox_remove_site_snackbar), null,
Snackbar.TYPE_ACTION, Snackbar.UMA_PRIVACY_SANDBOX_REMOVE_INTEREST));
showSnackbar(R.string.privacy_sandbox_remove_site_snackbar, null, Snackbar.TYPE_ACTION,
Snackbar.UMA_PRIVACY_SANDBOX_REMOVE_SITE);
RecordUserAction.record("Settings.PrivacySandbox.AdPersonalization.SiteRemoved");
} else {
assert false; // NOTREACHED.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.components.browser_ui.settings.FragmentSettingsLauncher;
import org.chromium.components.browser_ui.settings.SettingsLauncher;
import org.chromium.components.browser_ui.settings.SettingsUtils;
Expand All @@ -38,14 +37,9 @@ public class AdPersonalizationRemovedFragment extends PrivacySandboxSettingsBase
private Preference mEmptyTopicsPreference;
private PreferenceCategory mFledgeCategory;
private Preference mEmptyFledgePreference;
private SnackbarManager mSnackbarManager;
private LargeIconBridge mLargeIconBridge;
private SettingsLauncher mSettingsLauncher;

public void setSnackbarManager(SnackbarManager snackbarManager) {
mSnackbarManager = snackbarManager;
}

@Override
public void setSettingsLauncher(SettingsLauncher settingsLauncher) {
mSettingsLauncher = settingsLauncher;
Expand Down Expand Up @@ -128,16 +122,14 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
if (preference instanceof TopicPreference) {
allowTopic(((TopicPreference) preference).getTopic());
mTopicsCategory.removePreference(preference);
mSnackbarManager.showSnackbar(Snackbar.make(
getResources().getString(R.string.privacy_sandbox_add_interest_snackbar), null,
Snackbar.TYPE_ACTION, Snackbar.UMA_PRIVACY_SANDBOX_ADD_INTEREST));
showSnackbar(R.string.privacy_sandbox_add_interest_snackbar, null, Snackbar.TYPE_ACTION,
Snackbar.UMA_PRIVACY_SANDBOX_ADD_INTEREST);
RecordUserAction.record("Settings.PrivacySandbox.RemovedInterests.TopicAdded");
} else if (preference instanceof FledgePreference) {
allowFledge(((FledgePreference) preference).getSite());
mFledgeCategory.removePreference(preference);
mSnackbarManager.showSnackbar(Snackbar.make(
getResources().getString(R.string.privacy_sandbox_add_site_snackbar), null,
Snackbar.TYPE_ACTION, Snackbar.UMA_PRIVACY_SANDBOX_ADD_INTEREST));
showSnackbar(R.string.privacy_sandbox_add_site_snackbar, null, Snackbar.TYPE_ACTION,
Snackbar.UMA_PRIVACY_SANDBOX_ADD_SITE);
RecordUserAction.record("Settings.PrivacySandbox.RemovedInterests.SiteAdded");
} else {
assert false; // NOTREACHED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.privacy_sandbox.v4.PrivacySandboxSettingsFragmentV4;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.chrome.browser.ui.messages.snackbar.SnackbarManager;
import org.chromium.components.browser_ui.settings.FragmentSettingsLauncher;
import org.chromium.components.browser_ui.settings.SettingsLauncher;

Expand All @@ -41,6 +43,7 @@ public abstract class PrivacySandboxSettingsBaseFragment

private PrivacySandboxHelpers.CustomTabIntentHelper mCustomTabHelper;
private SettingsLauncher mSettingsLauncher;
private SnackbarManager mSnackbarManager;

/**
* Launches the right version of PrivacySandboxSettings depending on feature flags.
Expand Down Expand Up @@ -110,6 +113,16 @@ protected void openUrlInCct(String url) {
IntentUtils.safeStartActivity(getContext(), intent);
}

public void setSnackbarManager(SnackbarManager snackbarManager) {
mSnackbarManager = snackbarManager;
}

protected void showSnackbar(int stringResId, SnackbarManager.SnackbarController controller,
int type, int identifier) {
mSnackbarManager.showSnackbar(
Snackbar.make(getResources().getString(stringResId), controller, type, identifier));
}

protected void parseAndRecordReferrer() {
Bundle extras = getArguments();
assert (extras != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxSettingsBaseFragment;
import org.chromium.chrome.browser.privacy_sandbox.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.components.favicon.LargeIconBridge;

import java.util.List;
Expand Down Expand Up @@ -67,6 +68,9 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
PrivacySandboxBridge.setFledgeJoiningAllowed(
((FledgePreference) preference).getSite(), false);
mPreferenceScreen.removePreference(preference);

showSnackbar(R.string.privacy_sandbox_remove_site_snackbar, null, Snackbar.TYPE_ACTION,
Snackbar.UMA_PRIVACY_SANDBOX_REMOVE_SITE);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxSettingsBaseFragment;
import org.chromium.chrome.browser.privacy_sandbox.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.favicon.LargeIconBridge;

Expand Down Expand Up @@ -72,6 +73,9 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
((FledgePreference) preference).getSite(), true);
mBlockedSitesCategory.removePreference(preference);
updateBlockedSitesDescription();

showSnackbar(R.string.privacy_sandbox_add_site_snackbar, null, Snackbar.TYPE_ACTION,
Snackbar.UMA_PRIVACY_SANDBOX_ADD_SITE);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.chromium.chrome.browser.privacy_sandbox.R;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.ChromeManagedPreferenceDelegate;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.components.browser_ui.settings.ChromeBasePreference;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
import org.chromium.components.browser_ui.settings.SettingsUtils;
Expand Down Expand Up @@ -125,6 +126,9 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
((FledgePreference) preference).getSite(), false);
mCurrentSitesCategory.removePreference(preference);
updatePreferenceVisibility();

showSnackbar(R.string.privacy_sandbox_remove_site_snackbar, null, Snackbar.TYPE_ACTION,
Snackbar.UMA_PRIVACY_SANDBOX_REMOVE_SITE);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.chromium.chrome.browser.privacy_sandbox.R;
import org.chromium.chrome.browser.privacy_sandbox.Topic;
import org.chromium.chrome.browser.privacy_sandbox.TopicPreference;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.components.browser_ui.settings.SettingsUtils;

import java.util.List;
Expand Down Expand Up @@ -60,6 +61,9 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
PrivacySandboxBridge.setTopicAllowed(((TopicPreference) preference).getTopic(), true);
mBlockedTopicsCategory.removePreference(preference);
updateBlockedTopicsDescription();

showSnackbar(R.string.privacy_sandbox_add_interest_snackbar, null, Snackbar.TYPE_ACTION,
Snackbar.UMA_PRIVACY_SANDBOX_ADD_INTEREST);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.chromium.chrome.browser.privacy_sandbox.TopicPreference;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.ChromeManagedPreferenceDelegate;
import org.chromium.chrome.browser.ui.messages.snackbar.Snackbar;
import org.chromium.components.browser_ui.settings.ChromeSwitchPreference;
import org.chromium.components.browser_ui.settings.SettingsUtils;
import org.chromium.components.browser_ui.settings.TextMessagePreference;
Expand Down Expand Up @@ -119,6 +120,9 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
PrivacySandboxBridge.setTopicAllowed(((TopicPreference) preference).getTopic(), false);
mCurrentTopicsCategory.removePreference(preference);
updatePreferenceVisibility();

showSnackbar(R.string.privacy_sandbox_remove_interest_snackbar, null,
Snackbar.TYPE_ACTION, Snackbar.UMA_PRIVACY_SANDBOX_REMOVE_INTEREST);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,14 @@ public void testBlockSites() {
// Remove the first site from the list.
clickImageButtonNextToText(SITE_NAME_1);
onView(withText(SITE_NAME_1)).check(doesNotExist());
onView(withText(R.string.privacy_sandbox_remove_site_snackbar))
.check(matches(isDisplayed()));

// Remove the second site from the list.
clickImageButtonNextToText(SITE_NAME_2);
onView(withText(SITE_NAME_2)).check(doesNotExist());
onView(withText(R.string.privacy_sandbox_remove_site_snackbar))
.check(matches(isDisplayed()));

// Check that the empty state UI is displayed when the sites list is empty.
onView(withText(R.string.settings_fledge_page_current_sites_description_empty))
Expand Down Expand Up @@ -353,10 +357,12 @@ public void testUnblockSites() {
// Unblock the first site.
clickImageButtonNextToText(SITE_NAME_1);
onView(withText(SITE_NAME_1)).check(doesNotExist());
onView(withText(R.string.privacy_sandbox_add_site_snackbar)).check(matches(isDisplayed()));

// Unblock the second site.
clickImageButtonNextToText(SITE_NAME_2);
onView(withText(SITE_NAME_2)).check(doesNotExist());
onView(withText(R.string.privacy_sandbox_add_site_snackbar)).check(matches(isDisplayed()));

// Check that the empty state UI is displayed when the site list is empty.
onView(withText(R.string.settings_fledge_page_blocked_sites_description_empty))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,14 @@ public void testBlockTopics() {
// Remove the first Topic from the list.
clickImageButtonNextToText(TOPIC_NAME_1);
onView(withText(TOPIC_NAME_1)).check(doesNotExist());
onView(withText(R.string.privacy_sandbox_remove_interest_snackbar))
.check(matches(isDisplayed()));

// Remove the second Topic from the list.
clickImageButtonNextToText(TOPIC_NAME_2);
onView(withText(TOPIC_NAME_2)).check(doesNotExist());
onView(withText(R.string.privacy_sandbox_remove_interest_snackbar))
.check(matches(isDisplayed()));

// Check that the empty state UI is displayed when the Topic list is empty.
onView(withText(R.string.settings_topics_page_current_topics_description_empty))
Expand Down Expand Up @@ -339,10 +343,14 @@ public void testUnblockTopics() {
// Unblock the first Topic
clickImageButtonNextToText(TOPIC_NAME_1);
onView(withText(TOPIC_NAME_1)).check(doesNotExist());
onView(withText(R.string.privacy_sandbox_add_interest_snackbar))
.check(matches(isDisplayed()));

// Unblock the second Topic
clickImageButtonNextToText(TOPIC_NAME_2);
onView(withText(TOPIC_NAME_2)).check(doesNotExist());
onView(withText(R.string.privacy_sandbox_add_interest_snackbar))
.check(matches(isDisplayed()));

// Check that the empty state UI is displayed when the Topic list is empty.
onView(withText(R.string.settings_topics_page_blocked_topics_description_empty))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public class Snackbar {
public static final int UMA_BAD_FLAGS = 51;
public static final int UMA_DOWNLOAD_INTERSTITIAL_DOWNLOAD_DELETED = 52;
public static final int UMA_INCOGNITO_REAUTH_ENABLED_FROM_PROMO = 53;
public static final int UMA_PRIVACY_SANDBOX_ADD_SITE = 54;
public static final int UMA_PRIVACY_SANDBOX_REMOVE_SITE = 55;

private @Nullable SnackbarController mController;
private CharSequence mText;
Expand Down
2 changes: 2 additions & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94362,6 +94362,8 @@ https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
<int value="50" label="UMA_PRIVACY_SANDBOX_REMOVE_INTEREST"/>
<int value="52" label="UMA_DOWNLOAD_INTERSTITIAL_DOWNLOAD_DELETED"/>
<int value="53" label="UMA_INCOGNITO_REAUTH_ENABLED_FROM_PROMO"/>
<int value="54" label="UMA_PRIVACY_SANDBOX_ADD_SITE"/>
<int value="55" label="UMA_PRIVACY_SANDBOX_REMOVE_SITE"/>
</enum>

<enum name="SnapshotItemId">
Expand Down

0 comments on commit 72f76c0

Please sign in to comment.