Skip to content

Commit

Permalink
[privacy sandbox] Rename 'dialog' to 'prompt'
Browse files Browse the repository at this point in the history
Following the original refactoring, rename more references of 'dialog' to 'prompt'. 'Prompt' is used as a generic platform-independant term.
'Dialog' should only be used when referencing an actual dialog (like
privacy sandbox consent dialog on desktop).

Bug: 1336655
Change-Id: I291bb55c091bb3b4bd087d9dcd1023fd93357bd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3926233
Reviewed-by: Theodore Olsauskas-Warren <sauski@google.com>
Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Auto-Submit: Olesia Marukhno <olesiamarukhno@google.com>
Reviewed-by: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1054096}
  • Loading branch information
Olesia Marukhno authored and Chromium LUCI CQ committed Oct 3, 2022
1 parent 82d909b commit 7739a42
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 214 deletions.
6 changes: 3 additions & 3 deletions chrome/browser/privacy_sandbox/mock_privacy_sandbox_service.h
Expand Up @@ -25,9 +25,9 @@ class MockPrivacySandboxService : public PrivacySandboxService {
PromptActionOccurred,
(PrivacySandboxService::PromptAction),
(override));
MOCK_METHOD(void, DialogOpenedForBrowser, (Browser*), (override));
MOCK_METHOD(void, DialogClosedForBrowser, (Browser*), (override));
MOCK_METHOD(bool, IsDialogOpenForBrowser, (Browser*), (override));
MOCK_METHOD(void, PromptOpenedForBrowser, (Browser*), (override));
MOCK_METHOD(void, PromptClosedForBrowser, (Browser*), (override));
MOCK_METHOD(bool, IsPromptOpenForBrowser, (Browser*), (override));
// Mock this method to enable opening the settings page in tests.
MOCK_METHOD(bool, IsPrivacySandboxRestricted, (), (override));
MOCK_METHOD((base::flat_map<net::SchemefulSite, net::SchemefulSite>),
Expand Down
60 changes: 30 additions & 30 deletions chrome/browser/privacy_sandbox/privacy_sandbox_service.cc
Expand Up @@ -45,7 +45,7 @@ namespace {

constexpr char kBlockedTopicsTopicKey[] = "topic";

bool g_dialog_diabled_for_tests = false;
bool g_prompt_disabled_for_tests = false;

// Returns whether 3P cookies are blocked by |cookie_settings|. This can be
// either through blocking 3P cookies directly, or blocking all cookies.
Expand Down Expand Up @@ -221,17 +221,17 @@ void PrivacySandboxService::PromptActionOccurred(
}

// static
bool PrivacySandboxService::IsUrlSuitableForDialog(const GURL& url) {
// The dialog should be shown on a limited list of pages:
bool PrivacySandboxService::IsUrlSuitableForPrompt(const GURL& url) {
// The prompt should be shown on a limited list of pages:

// about:blank is valid.
if (url.IsAboutBlank())
return true;
// Chrome settings page is valid. The subpages aren't as most of them are not
// related to the dialog.
// related to the prompt.
if (url == GURL(chrome::kChromeUISettingsURL))
return true;
// Chrome history is valid as the dialog mentions history.
// Chrome history is valid as the prompt mentions history.
if (url == GURL(chrome::kChromeUIHistoryURL))
return true;
// Only a Chrome controlled New Tab Page is valid. Third party NTP is still
Expand All @@ -244,22 +244,22 @@ bool PrivacySandboxService::IsUrlSuitableForDialog(const GURL& url) {
return false;
}

void PrivacySandboxService::DialogOpenedForBrowser(Browser* browser) {
DCHECK(!browsers_with_open_dialogs_.count(browser));
browsers_with_open_dialogs_.insert(browser);
void PrivacySandboxService::PromptOpenedForBrowser(Browser* browser) {
DCHECK(!browsers_with_open_prompts_.count(browser));
browsers_with_open_prompts_.insert(browser);
}

void PrivacySandboxService::DialogClosedForBrowser(Browser* browser) {
DCHECK(browsers_with_open_dialogs_.count(browser));
browsers_with_open_dialogs_.erase(browser);
void PrivacySandboxService::PromptClosedForBrowser(Browser* browser) {
DCHECK(browsers_with_open_prompts_.count(browser));
browsers_with_open_prompts_.erase(browser);
}

bool PrivacySandboxService::IsDialogOpenForBrowser(Browser* browser) {
return browsers_with_open_dialogs_.count(browser);
bool PrivacySandboxService::IsPromptOpenForBrowser(Browser* browser) {
return browsers_with_open_prompts_.count(browser);
}

void PrivacySandboxService::SetDialogDisabledForTests(bool disabled) {
g_dialog_diabled_for_tests = disabled;
void PrivacySandboxService::SetPromptDisabledForTests(bool disabled) {
g_prompt_disabled_for_tests = disabled;
}

bool PrivacySandboxService::IsPrivacySandboxEnabled() {
Expand Down Expand Up @@ -385,33 +385,33 @@ void PrivacySandboxService::RecordPrivacySandbox3StartupMetrics() {
prefs::kPrivacySandboxNoConfirmationSandboxDisabled)) {
base::UmaHistogramEnumeration(
privacy_sandbox_startup_histogram,
sandbox_v2_enabled ? PSStartupStates::kDialogOffV1OffEnabled
: PSStartupStates::kDialogOffV1OffDisabled);
sandbox_v2_enabled ? PSStartupStates::kPromptOffV1OffEnabled
: PSStartupStates::kPromptOffV1OffDisabled);
return;
}
// Handle 3PC disabled.
if (pref_service_->GetBoolean(
prefs::kPrivacySandboxNoConfirmationThirdPartyCookiesBlocked)) {
base::UmaHistogramEnumeration(
privacy_sandbox_startup_histogram,
sandbox_v2_enabled ? PSStartupStates::kDialogOff3PCOffEnabled
: PSStartupStates::kDialogOff3PCOffDisabled);
sandbox_v2_enabled ? PSStartupStates::kPromptOff3PCOffEnabled
: PSStartupStates::kPromptOff3PCOffDisabled);
return;
}
// Handle managed.
if (pref_service_->GetBoolean(
prefs::kPrivacySandboxNoConfirmationSandboxManaged)) {
base::UmaHistogramEnumeration(
privacy_sandbox_startup_histogram,
sandbox_v2_enabled ? PSStartupStates::kDialogOffManagedEnabled
: PSStartupStates::kDialogOffManagedDisabled);
sandbox_v2_enabled ? PSStartupStates::kPromptOffManagedEnabled
: PSStartupStates::kPromptOffManagedDisabled);
return;
}
// Handle restricted.
if (pref_service_->GetBoolean(
prefs::kPrivacySandboxNoConfirmationSandboxRestricted)) {
base::UmaHistogramEnumeration(privacy_sandbox_startup_histogram,
PSStartupStates::kDialogOffRestricted);
PSStartupStates::kPromptOffRestricted);
return;
}
// Handle manually controlled
Expand All @@ -420,14 +420,14 @@ void PrivacySandboxService::RecordPrivacySandbox3StartupMetrics() {
base::UmaHistogramEnumeration(
privacy_sandbox_startup_histogram,
sandbox_v2_enabled
? PSStartupStates::kDialogOffManuallyControlledEnabled
: PSStartupStates::kDialogOffManuallyControlledDisabled);
? PSStartupStates::kPromptOffManuallyControlledEnabled
: PSStartupStates::kPromptOffManuallyControlledDisabled);
return;
}
if (privacy_sandbox::kPrivacySandboxSettings3ConsentRequired.Get()) {
if (!pref_service_->GetBoolean(prefs::kPrivacySandboxConsentDecisionMade)) {
base::UmaHistogramEnumeration(privacy_sandbox_startup_histogram,
PSStartupStates::kDialogWaiting);
PSStartupStates::kPromptWaiting);
return;
}
base::UmaHistogramEnumeration(privacy_sandbox_startup_histogram,
Expand All @@ -437,7 +437,7 @@ void PrivacySandboxService::RecordPrivacySandbox3StartupMetrics() {
} else if (privacy_sandbox::kPrivacySandboxSettings3NoticeRequired.Get()) {
if (!pref_service_->GetBoolean(prefs::kPrivacySandboxNoticeDisplayed)) {
base::UmaHistogramEnumeration(privacy_sandbox_startup_histogram,
PSStartupStates::kDialogWaiting);
PSStartupStates::kPromptWaiting);
return;
}
base::UmaHistogramEnumeration(privacy_sandbox_startup_histogram,
Expand All @@ -447,8 +447,8 @@ void PrivacySandboxService::RecordPrivacySandbox3StartupMetrics() {
} else { // No prompt currently required.
base::UmaHistogramEnumeration(
privacy_sandbox_startup_histogram,
sandbox_v2_enabled ? PSStartupStates::kNoDialogRequiredEnabled
: PSStartupStates::kNoDialogRequiredDisabled);
sandbox_v2_enabled ? PSStartupStates::kNoPromptRequiredEnabled
: PSStartupStates::kNoPromptRequiredDisabled);
}
}

Expand Down Expand Up @@ -690,7 +690,7 @@ PrivacySandboxService::GetRequiredPromptTypeInternal(
privacy_sandbox::PrivacySandboxSettings* privacy_sandbox_settings,
bool third_party_cookies_blocked) {
// If the prompt is disabled for testing, never show it.
if (g_dialog_diabled_for_tests)
if (g_prompt_disabled_for_tests)
return PromptType::kNone;

// If the profile isn't a regular profile, no prompt should ever be shown.
Expand All @@ -702,7 +702,7 @@ PrivacySandboxService::GetRequiredPromptTypeInternal(
return PromptType::kNone;

// Forced testing feature parameters override everything.
if (privacy_sandbox::kPrivacySandboxSettings3DisableDialogForTesting.Get())
if (privacy_sandbox::kPrivacySandboxSettings3DisablePromptForTesting.Get())
return PromptType::kNone;

if (base::FeatureList::IsEnabled(
Expand Down
74 changes: 37 additions & 37 deletions chrome/browser/privacy_sandbox/privacy_sandbox_service.h
Expand Up @@ -119,30 +119,30 @@ class PrivacySandboxService : public KeyedService {
// This method is virtual for mocking in tests.
virtual void PromptActionOccurred(PromptAction action);

// Returns whether |url| is suitable to display the Privacy Sandbox dialog
// Returns whether |url| is suitable to display the Privacy Sandbox prompt
// over. Only about:blank and certain chrome:// URLs are considered suitable.
static bool IsUrlSuitableForDialog(const GURL& url);
static bool IsUrlSuitableForPrompt(const GURL& url);

// Functions for coordinating the display of the Privacy Sandbox dialog
// Functions for coordinating the display of the Privacy Sandbox prompts
// across multiple browser windows. Only relevant for Desktop.

// Informs the service that a Privacy Sandbox dialog |view| has been opened
// Informs the service that a Privacy Sandbox prompt has been opened
// or closed for |browser|.
// Virtual to allow mocking in tests.
virtual void DialogOpenedForBrowser(Browser* browser);
virtual void DialogClosedForBrowser(Browser* browser);
virtual void PromptOpenedForBrowser(Browser* browser);
virtual void PromptClosedForBrowser(Browser* browser);

// Returns whether a Privacy Sandbox dialog is currently open for |browser|.
// Returns whether a Privacy Sandbox prompt is currently open for |browser|.
// Virtual to allow mocking in tests.
virtual bool IsDialogOpenForBrowser(Browser* browser);
virtual bool IsPromptOpenForBrowser(Browser* browser);

// Disables the display of the Privacy Sandbox dialog for testing. When
// Disables the display of the Privacy Sandbox prompt for testing. When
// |disabled| is true, GetRequiredPromptType() will only ever return that no
// dialog is required.
// prompt is required.
// NOTE: This is set to true in InProcessBrowserTest::SetUp, disabling the
// dialog for those tests. If you set this outside of that context, you should
// prompt for those tests. If you set this outside of that context, you should
// ensure it is reset at the end of your test.
static void SetDialogDisabledForTests(bool disabled);
static void SetPromptDisabledForTests(bool disabled);

// Disables the Privacy Sandbox completely if |enabled| is false. If |enabled|
// is true, context specific as well as restriction checks will still be
Expand Down Expand Up @@ -250,17 +250,17 @@ class PrivacySandboxService : public KeyedService {
MetricsLoggingOccursCorrectly);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTestNonRegularProfile,
NoMetricsRecorded);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceDialogTest, RestrictedDialog);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceDialogTest, ManagedNoDialog);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceDialogTest,
ManuallyControlledNoDialog);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceDialogTest, NoParamNoDialog);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServicePromptTest, RestrictedPrompt);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServicePromptTest, ManagedNoPrompt);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServicePromptTest,
ManuallyControlledNoPrompt);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServicePromptTest, NoParamNoPrompt);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceDeathTest,
GetRequiredPromptType);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest,
PrivacySandboxDialogNoticeWaiting);
PrivacySandboxPromptNoticeWaiting);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest,
PrivacySandboxDialogConsentWaiting);
PrivacySandboxPromptConsentWaiting);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest,
PrivacySandboxV1OffEnabled);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest,
Expand All @@ -286,9 +286,9 @@ class PrivacySandboxService : public KeyedService {
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest,
PrivacySandboxManuallyControlledDisabled);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest,
PrivacySandboxNoDialogDisabled);
PrivacySandboxNoPromptDisabled);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest,
PrivacySandboxNoDialogEnabled);
PrivacySandboxNoPromptEnabled);
FRIEND_TEST_ALL_PREFIXES(PrivacySandboxServiceTest, PrivacySandboxRestricted);

// Should be used only for tests when mocking the service.
Expand Down Expand Up @@ -323,26 +323,26 @@ class PrivacySandboxService : public KeyedService {
// Must be kept in sync with SettingsPrivacySandboxStartupStates in
// histograms/enums.xml
enum class PSStartupStates {
kDialogWaiting = 0,
kDialogOffV1OffEnabled = 1,
kDialogOffV1OffDisabled = 2,
kPromptWaiting = 0,
kPromptOffV1OffEnabled = 1,
kPromptOffV1OffDisabled = 2,
kConsentShownEnabled = 3,
kConsentShownDisabled = 4,
kNoticeShownEnabled = 5,
kNoticeShownDisabled = 6,
kDialogOff3PCOffEnabled = 7,
kDialogOff3PCOffDisabled = 8,
kDialogOffManagedEnabled = 9,
kDialogOffManagedDisabled = 10,
kDialogOffRestricted = 11,
kDialogOffManuallyControlledEnabled = 12,
kDialogOffManuallyControlledDisabled = 13,
kNoDialogRequiredEnabled = 14,
kNoDialogRequiredDisabled = 15,
kPromptOff3PCOffEnabled = 7,
kPromptOff3PCOffDisabled = 8,
kPromptOffManagedEnabled = 9,
kPromptOffManagedDisabled = 10,
kPromptOffRestricted = 11,
kPromptOffManuallyControlledEnabled = 12,
kPromptOffManuallyControlledDisabled = 13,
kNoPromptRequiredEnabled = 14,
kNoPromptRequiredDisabled = 15,

// Add values above this line with a corresponding label in
// tools/metrics/histograms/enums.xml
kMaxValue = kNoDialogRequiredDisabled,
kMaxValue = kNoPromptRequiredDisabled,
};

// Helper function to actually make the metrics call for
Expand All @@ -353,7 +353,7 @@ class PrivacySandboxService : public KeyedService {
// profile startup.
void LogPrivacySandboxState();

// Logs the state of privacy sandbox 3 in regards to dialogs. Called once per
// Logs the state of privacy sandbox 3 in regards to prompts. Called once per
// profile startup.
void RecordPrivacySandbox3StartupMetrics();

Expand Down Expand Up @@ -392,8 +392,8 @@ class PrivacySandboxService : public KeyedService {

PrefChangeRegistrar user_prefs_registrar_;

// The set of Browser windows which have an open Privacy Sandbox dialog.
std::set<Browser*> browsers_with_open_dialogs_;
// The set of Browser windows which have an open Privacy Sandbox prompt.
std::set<Browser*> browsers_with_open_prompts_;

// Fake implementation for current and blocked topics.
std::set<privacy_sandbox::CanonicalTopic> fake_current_topics_ = {
Expand Down

0 comments on commit 7739a42

Please sign in to comment.