Skip to content

Commit

Permalink
Remove static Profile reference from PrivacySandboxBridge.
Browse files Browse the repository at this point in the history
Bug: 40254448
Change-Id: I5951556a28600121df1b5990456b2da95ab6612e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5454723
Reviewed-by: Andrey Zaytsev <andzaytsev@google.com>
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1290019}
  • Loading branch information
Ted Choc authored and Chromium LUCI CQ committed Apr 19, 2024
1 parent 6956be4 commit 86ac886
Show file tree
Hide file tree
Showing 27 changed files with 432 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,13 @@ void onDeferredStartup() {
mCallbackController.makeCancelable(
(profile) -> {
Profile regularProfile = profile.getOriginalProfile();
Profile currentModelProfile =
mTabModelSelectorSupplier.get().getCurrentModel().getProfile();

boolean didShowPrompt = false;
boolean shouldShowPrivacySandboxDialog =
PrivacySandboxDialogController.shouldShowPrivacySandboxDialog(
mTabModelSelectorSupplier.get().isIncognitoSelected());
currentModelProfile);
boolean isCustomTab =
mIntentDataProvider.get().getActivityType()
== ActivityType.CUSTOM_TAB
Expand Down Expand Up @@ -677,9 +680,7 @@ void onDeferredStartup() {
.maybeLaunchPrivacySandboxDialog(
mActivity,
new SettingsLauncherImpl(),
mTabModelSelectorSupplier
.get()
.isIncognitoSelected());
currentModelProfile);
}
}
if (!didShowPrompt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
return true;
});

if (PrivacySandboxBridge.isPrivacySandboxRestricted()) {
if (PrivacySandboxBridge.isRestrictedNoticeEnabled()) {
PrivacySandboxBridge privacySandboxBridge = new PrivacySandboxBridge(getProfile());
if (privacySandboxBridge.isPrivacySandboxRestricted()) {
if (privacySandboxBridge.isRestrictedNoticeEnabled()) {
// Update the summary to one that describes only ad measurement if ad-measurement
// is available to restricted users.
sandboxPreference.setSummary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class ChromeSiteSettingsDelegate implements SiteSettingsDelegate {

private final Context mContext;
private final Profile mProfile;
private final PrivacySandboxBridge mPrivacySandboxBridge;
private BrowsingDataModel mBrowsingDataModel;
private ManagedPreferenceDelegate mManagedPreferenceDelegate;
private PrivacySandboxSnackbarController mPrivacySandboxController;
Expand All @@ -74,6 +75,7 @@ public class ChromeSiteSettingsDelegate implements SiteSettingsDelegate {
public ChromeSiteSettingsDelegate(Context context, Profile profile) {
mContext = context;
mProfile = profile;
mPrivacySandboxBridge = new PrivacySandboxBridge(profile);
}

@Override
Expand Down Expand Up @@ -267,7 +269,7 @@ public void maybeDisplayPrivacySandboxSnackbar() {
// Only show the snackbar when Privacy Sandbox APIs are enabled.
if (!isAnyPrivacySandboxApiEnabledV4()) return;

if (PrivacySandboxBridge.isPrivacySandboxRestricted()) return;
if (mPrivacySandboxBridge.isPrivacySandboxRestricted()) return;

mPrivacySandboxController.showSnackbar();
}
Expand All @@ -288,17 +290,17 @@ public void dismissPrivacySandboxSnackbar() {

@Override
public boolean isFirstPartySetsDataAccessEnabled() {
return PrivacySandboxBridge.isFirstPartySetsDataAccessEnabled();
return mPrivacySandboxBridge.isFirstPartySetsDataAccessEnabled();
}

@Override
public boolean isFirstPartySetsDataAccessManaged() {
return PrivacySandboxBridge.isFirstPartySetsDataAccessManaged();
return mPrivacySandboxBridge.isFirstPartySetsDataAccessManaged();
}

@Override
public boolean isPartOfManagedFirstPartySet(String origin) {
return PrivacySandboxBridge.isPartOfManagedFirstPartySet(origin);
return mPrivacySandboxBridge.isPartOfManagedFirstPartySet(origin);
}

@Override
Expand All @@ -321,12 +323,12 @@ public boolean isBlockAll3PCDEnabledInTrackingProtection() {

@Override
public void setFirstPartySetsDataAccessEnabled(boolean enabled) {
PrivacySandboxBridge.setFirstPartySetsDataAccessEnabled(enabled);
mPrivacySandboxBridge.setFirstPartySetsDataAccessEnabled(enabled);
}

@Override
public String getFirstPartySetOwner(String memberOrigin) {
return PrivacySandboxBridge.getFirstPartySetOwner(memberOrigin);
return mPrivacySandboxBridge.getFirstPartySetOwner(memberOrigin);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ private void initializeIPH(Profile profile, boolean intentWithEffect) {
PrivacySandboxDialogController.maybeLaunchPrivacySandboxDialog(
mActivity,
new SettingsLauncherImpl(),
mTabModelSelectorSupplier.get().isIncognitoSelected());
mTabModelSelectorSupplier.get().getCurrentModel().getProfile());
}
RecordHistogram.recordBooleanHistogram(histogramName, shouldSuppressPSDialog);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.chromium.base.Callback;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxBridge;
import org.chromium.chrome.browser.privacy_sandbox.Topic;
import org.chromium.chrome.browser.profiles.Profile;

import java.util.Set;

Expand All @@ -28,83 +29,87 @@ public FakeRwsPrivacySandboxBridge(String rwsOwner, Set<String> rwsMembers) {
}

@Override
public boolean isPrivacySandboxRestricted() {
public boolean isPrivacySandboxRestricted(Profile profile) {
return false;
}

@Override
public boolean isRestrictedNoticeEnabled() {
public boolean isRestrictedNoticeEnabled(Profile profile) {
return false;
}

@Override
public boolean isFirstPartySetsDataAccessEnabled() {
public boolean isFirstPartySetsDataAccessEnabled(Profile profile) {
return true;
}

@Override
public boolean isFirstPartySetsDataAccessManaged() {
public boolean isFirstPartySetsDataAccessManaged(Profile profile) {
return true;
}

@Override
public boolean isPartOfManagedFirstPartySet(String origin) {
public boolean isPartOfManagedFirstPartySet(Profile profile, String origin) {
return mRwsMembers.contains(origin);
}

@Override
public void setFirstPartySetsDataAccessEnabled(boolean enabled) {}
public void setFirstPartySetsDataAccessEnabled(Profile profile, boolean enabled) {}

@Override
public String getFirstPartySetOwner(String memberOrigin) {
public String getFirstPartySetOwner(Profile profile, String memberOrigin) {
return mRwsMembers.contains(memberOrigin.replace("http://", "")) ? mRwsOwner : "";
}

@Override
public Topic[] getCurrentTopTopics() {
public Topic[] getCurrentTopTopics(Profile profile) {
return null;
}

@Override
public Topic[] getBlockedTopics() {
public Topic[] getBlockedTopics(Profile profile) {
return null;
}

@Override
public Topic[] getFirstLevelTopics() {
public Topic[] getFirstLevelTopics(Profile profile) {
return null;
}

@Override
public Topic[] getChildTopicsCurrentlyAssigned(int topicId, int taxonomyVersion) {
public Topic[] getChildTopicsCurrentlyAssigned(
Profile profile, int topicId, int taxonomyVersion) {
return null;
}

@Override
public void setTopicAllowed(int topicId, int taxonomyVersion, boolean allowed) {}
public void setTopicAllowed(
Profile profile, int topicId, int taxonomyVersion, boolean allowed) {}

@Override
public void getFledgeJoiningEtldPlusOneForDisplay(Callback<String[]> callback) {}
public void getFledgeJoiningEtldPlusOneForDisplay(
Profile profile, Callback<String[]> callback) {}

@Override
public String[] getBlockedFledgeJoiningTopFramesForDisplay() {
public String[] getBlockedFledgeJoiningTopFramesForDisplay(Profile profile) {
return null;
}

@Override
public void setFledgeJoiningAllowed(String topFrameEtldPlus1, boolean allowed) {}
public void setFledgeJoiningAllowed(
Profile profile, String topFrameEtldPlus1, boolean allowed) {}

@Override
public int getRequiredPromptType() {
public int getRequiredPromptType(Profile profile) {
return 0;
}

@Override
public void promptActionOccurred(int action) {}
public void promptActionOccurred(Profile profile, int action) {}

@Override
public void topicsToggleChanged(boolean newValue) {}
public void topicsToggleChanged(Profile profile, boolean newValue) {}

@Override
public void setAllPrivacySandboxAllowedForTesting() {}
public void setAllPrivacySandboxAllowedForTesting(Profile profile) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.chromium.base.IntentUtils;
import org.chromium.chrome.browser.privacy_guide.PrivacyGuideUtils.CustomTabIntentHelper;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxBridge;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxReferrer;
import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxSettingsBaseFragment;
import org.chromium.components.browser_ui.settings.SettingsLauncher;
Expand All @@ -45,8 +44,8 @@ public View onCreateView(
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

if (!PrivacySandboxBridge.isPrivacySandboxRestricted()
|| PrivacySandboxBridge.isRestrictedNoticeEnabled()) {
if (!getPrivacySandboxBridge().isPrivacySandboxRestricted()
|| getPrivacySandboxBridge().isRestrictedNoticeEnabled()) {
ChromeImageButton psButton = view.findViewById(R.id.ps_button);
psButton.setOnClickListener(this::onPsButtonClick);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

import androidx.fragment.app.Fragment;

import org.chromium.chrome.browser.privacy_sandbox.PrivacySandboxBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.ProfileDependentSetting;

/** Handles common dependencies for pages of the Privacy Guide. */
public abstract class PrivacyGuideBasePage extends Fragment implements ProfileDependentSetting {
private Profile mProfile;
private PrivacySandboxBridge mPrivacySandboxBridge;

/** Return the profile associated with this page. */
public Profile getProfile() {
Expand All @@ -21,5 +23,14 @@ public Profile getProfile() {
@Override
public void setProfile(Profile profile) {
mProfile = profile;
mPrivacySandboxBridge = new PrivacySandboxBridge(profile);
}

/**
* Return the {@link PrivacySandboxBridge} associated with the value set in {@link
* #setProfile(Profile)}.
*/
public PrivacySandboxBridge getPrivacySandboxBridge() {
return mPrivacySandboxBridge;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ private void setSignedInState(boolean isSignedIn) {
}

private void setPrivacySandboxState(boolean isRestricted, boolean isRestrictedNoticeEnabled) {
when(mPrivacySandboxBridge.isPrivacySandboxRestricted()).thenReturn(isRestricted);
when(mPrivacySandboxBridge.isRestrictedNoticeEnabled())
when(mPrivacySandboxBridge.isPrivacySandboxRestricted(mProfile)).thenReturn(isRestricted);
when(mPrivacySandboxBridge.isRestrictedNoticeEnabled(mProfile))
.thenReturn(isRestrictedNoticeEnabled);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
@Override
public void onResume() {
super.onResume();
PrivacySandboxBridge.getFledgeJoiningEtldPlusOneForDisplay(this::populateSites);
getPrivacySandboxBridge().getFledgeJoiningEtldPlusOneForDisplay(this::populateSites);
}

@Override
Expand All @@ -59,8 +59,8 @@ public void onDestroyView() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
if (preference instanceof FledgePreference) {
PrivacySandboxBridge.setFledgeJoiningAllowed(
((FledgePreference) preference).getSite(), false);
getPrivacySandboxBridge()
.setFledgeJoiningAllowed(((FledgePreference) preference).getSite(), false);
mPreferenceScreen.removePreference(preference);

showSnackbar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void onDestroyView() {
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
if (preference instanceof FledgePreference) {
PrivacySandboxBridge.setFledgeJoiningAllowed(
((FledgePreference) preference).getSite(), true);
getPrivacySandboxBridge()
.setFledgeJoiningAllowed(((FledgePreference) preference).getSite(), true);
mBlockedSitesCategory.removePreference(preference);
updateBlockedSitesDescription();

Expand All @@ -89,7 +89,7 @@ private void populateSites() {

mBlockedSitesCategory.removeAll();
List<String> blockedSites =
PrivacySandboxBridge.getBlockedFledgeJoiningTopFramesForDisplay();
getPrivacySandboxBridge().getBlockedFledgeJoiningTopFramesForDisplay();
for (String site : blockedSites) {
FledgePreference preference =
new FledgePreference(getContext(), site, mLargeIconBridge);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
@Override
public void onResume() {
super.onResume();
PrivacySandboxBridge.getFledgeJoiningEtldPlusOneForDisplay(this::populateCurrentSites);
getPrivacySandboxBridge().getFledgeJoiningEtldPlusOneForDisplay(this::populateCurrentSites);
updatePreferenceVisibility();
}

Expand Down Expand Up @@ -200,8 +200,8 @@ public boolean onPreferenceChange(@NonNull Preference preference, Object value)
@Override
public boolean onPreferenceClick(@NonNull Preference preference) {
if (preference instanceof FledgePreference) {
PrivacySandboxBridge.setFledgeJoiningAllowed(
((FledgePreference) preference).getSite(), false);
getPrivacySandboxBridge()
.setFledgeJoiningAllowed(((FledgePreference) preference).getSite(), false);
mCurrentSitesCategory.removePreference(preference);
updatePreferenceVisibility();

Expand Down
Loading

0 comments on commit 86ac886

Please sign in to comment.