Skip to content

Commit

Permalink
Allow users to disable Brave custom ad notification fallback from bra…
Browse files Browse the repository at this point in the history
…ve://flags
  • Loading branch information
tmancey committed Nov 15, 2021
1 parent ba3b3c2 commit cf0d766
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ constexpr char kBraveAdsCustomNotificationsName[] =
constexpr char kBraveAdsCustomNotificationsDescription[] =
"Enable Brave Ads custom notifications to support rich media";

constexpr char kBraveAdsCustomNotificationsFallbackName[] =
"Allow Brave Ads to fallback to custom notifications";
constexpr char kBraveAdsCustomNotificationsFallbackDescription[] =
"Allow Brave Ads to fallback to custom notifications on OSes which do not "
"support native notifications";

constexpr char kBraveDarkModeBlockName[] =
"Enable dark mode blocking fingerprinting protection";
constexpr char kBraveDarkModeBlockDescription[] =
Expand Down Expand Up @@ -429,6 +435,12 @@ constexpr char kFileSystemAccessAPIDescription[] =
flag_descriptions::kBraveAdsCustomNotificationsDescription, \
kOsDesktop | kOsAndroid, \
FEATURE_VALUE_TYPE(brave_ads::features::kCustomAdNotifications)}, \
{"brave-ads-disable-custom-notifications-fallback", \
flag_descriptions::kBraveAdsCustomNotificationsFallbackName, \
flag_descriptions::kBraveAdsCustomNotificationsFallbackDescription, \
kOsDesktop | kOsAndroid, \
FEATURE_VALUE_TYPE( \
brave_ads::features::kCustomAdNotificationsFallback)}, \
{"brave-sync-v2", \
flag_descriptions::kBraveSyncName, \
flag_descriptions::kBraveSyncDescription, kOsDesktop, \
Expand Down
8 changes: 7 additions & 1 deletion components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,16 @@ bool AdsServiceImpl::ShouldShowCustomAdNotifications() {
const bool can_show_native_notifications =
NotificationHelper::GetInstance()->CanShowNativeNotifications();

const bool can_fallback_to_custom_ad_notifications =
bool can_fallback_to_custom_ad_notifications =
features::CanFallbackToCustomAdNotifications();
if (!can_fallback_to_custom_ad_notifications) {
ClearPref(prefs::kAdNotificationDidFallbackToCustom);
} else {
const bool allowed_to_fallback_to_custom_ad_notifications =
features::AllowedToFallbackToCustomAdNotifications();
if (!allowed_to_fallback_to_custom_ad_notifications) {
can_fallback_to_custom_ad_notifications = false;
}
}

const bool should_show = features::IsCustomAdNotificationsEnabled();
Expand Down
11 changes: 11 additions & 0 deletions components/brave_ads/common/features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const char kFieldTrialParameterCanFallbackToCustomAdNotifications[] =
"can_fallback_to_custom_notifications";
const bool kDefaultCanFallbackToCustomAdNotifications = false;

const char kFieldTrialParameterAllowedToFallbackToCustomAdNotifications[] =
"allowed_to_fallback_to_custom_notifications";
const bool kDefaultAllowedToFallbackToCustomAdNotifications = true;

// Ad notification timeout in seconds. Set to 0 to never time out
const char kFieldTrialParameterAdNotificationTimeout[] =
"ad_notification_timeout";
Expand Down Expand Up @@ -114,6 +118,13 @@ bool CanFallbackToCustomAdNotifications() {
kDefaultCanFallbackToCustomAdNotifications);
}

bool AllowedToFallbackToCustomAdNotifications() {
return GetFieldTrialParamByFeatureAsBool(
kAdNotifications,
kFieldTrialParameterAllowedToFallbackToCustomAdNotifications,
kDefaultAllowedToFallbackToCustomAdNotifications);
}

int AdNotificationTimeout() {
return GetFieldTrialParamByFeatureAsInt(
kAdNotifications, kFieldTrialParameterAdNotificationTimeout,
Expand Down
1 change: 1 addition & 0 deletions components/brave_ads/common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern const base::Feature kAdNotifications;

bool IsAdNotificationsEnabled();
bool CanFallbackToCustomAdNotifications();
bool AllowedToFallbackToCustomAdNotifications();
int AdNotificationTimeout();

extern const base::Feature kCustomAdNotifications;
Expand Down

0 comments on commit cf0d766

Please sign in to comment.