Skip to content

Commit

Permalink
Merge pull request #7608 from /issues/13592
Browse files Browse the repository at this point in the history
Fixes custom Brave ad notifications should not be shown on Dev channel builds
  • Loading branch information
tmancey authored Jan 15, 2021
2 parents 46f319a + 00f386c commit af91e44
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 20 deletions.
11 changes: 7 additions & 4 deletions common/brave_channel_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ std::string GetChannelName() {
#endif // !OFFICIAL_BUILD
}

bool IsDevOrCanaryBuild() {
return chrome::GetChannel() == version_info::Channel::DEV ||
chrome::GetChannel() == version_info::Channel::CANARY ||
chrome::GetChannel() == version_info::Channel::UNKNOWN;
bool IsNightlyOrDeveloperBuild() {
#if defined(OFFICIAL_BUILD)
return chrome::GetChannel() == version_info::Channel::CANARY ||
chrome::GetChannel() == version_info::Channel::UNKNOWN;
#else // OFFICIAL_BUILD
return true;
#endif // !OFFICIAL_BUILD
}

} // namespace brave
2 changes: 1 addition & 1 deletion common/brave_channel_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace brave {

std::string GetChannelName();
bool IsDevOrCanaryBuild();
bool IsNightlyOrDeveloperBuild();

}

Expand Down
12 changes: 4 additions & 8 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ void AdsServiceImpl::OnInitialize(

is_initialized_ = true;

if (!brave::IsDevOrCanaryBuild()) {
if (!brave::IsNightlyOrDeveloperBuild()) {
SetAdsServiceForNotificationHandler();
}

Expand Down Expand Up @@ -1216,10 +1216,6 @@ void AdsServiceImpl::OnGetAdsHistory(
}

bool AdsServiceImpl::CanShowBackgroundNotifications() const {
if (brave::IsDevOrCanaryBuild()) {
return true;
}

return NotificationHelper::GetInstance()->CanShowBackgroundNotifications();
}

Expand Down Expand Up @@ -1732,7 +1728,7 @@ std::string AdsServiceImpl::LoadDataResourceAndDecompressIfNeeded(
// types of notification.h
void AdsServiceImpl::ShowNotification(
const ads::AdNotificationInfo& ad_notification) {
if (brave::IsDevOrCanaryBuild()) {
if (brave::IsNightlyOrDeveloperBuild()) {
auto notification = CreateAdNotification(ad_notification);

std::unique_ptr<PlatformBridge> platform_bridge =
Expand All @@ -1751,7 +1747,7 @@ void AdsServiceImpl::ShowNotification(
void AdsServiceImpl::StartNotificationTimeoutTimer(
const std::string& uuid) {
#if defined(OS_ANDROID)
if (!brave::IsDevOrCanaryBuild()) {
if (!brave::IsNightlyOrDeveloperBuild()) {
return;
}
#endif
Expand Down Expand Up @@ -1792,7 +1788,7 @@ bool AdsServiceImpl::ShouldShowNotifications() {

void AdsServiceImpl::CloseNotification(
const std::string& uuid) {
if (brave::IsDevOrCanaryBuild()) {
if (brave::IsNightlyOrDeveloperBuild()) {
std::unique_ptr<PlatformBridge>
platform_bridge = std::make_unique<PlatformBridge>(profile_);
platform_bridge->Close(profile_, uuid);
Expand Down
8 changes: 6 additions & 2 deletions components/brave_ads/browser/notification_helper_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ NotificationHelperAndroid::NotificationHelperAndroid() = default;
NotificationHelperAndroid::~NotificationHelperAndroid() = default;

bool NotificationHelperAndroid::ShouldShowNotifications() {
if (brave::IsDevOrCanaryBuild()) {
if (brave::IsNightlyOrDeveloperBuild()) {
return true;
}

Expand All @@ -58,7 +58,7 @@ bool NotificationHelperAndroid::ShowMyFirstAdNotification() {
return false;
}

const bool use_custom_notifications = brave::IsDevOrCanaryBuild();
const bool use_custom_notifications = brave::IsNightlyOrDeveloperBuild();

JNIEnv* env = base::android::AttachCurrentThread();
Java_BraveAdsSignupDialog_enqueueOnboardingNotificationNative(
Expand All @@ -69,6 +69,10 @@ bool NotificationHelperAndroid::ShowMyFirstAdNotification() {
}

bool NotificationHelperAndroid::CanShowBackgroundNotifications() const {
if (brave::IsNightlyOrDeveloperBuild()) {
return true;
}

JNIEnv* env = base::android::AttachCurrentThread();
return Java_BraveAdsSignupDialog_showAdsInBackground(env);
}
Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/browser/notification_helper_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bool NotificationHelperLinux::ShouldShowNotifications() {
return false;
}

if (brave::IsDevOrCanaryBuild()) {
if (brave::IsNightlyOrDeveloperBuild()) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/browser/notification_helper_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
return false;
}

if (brave::IsDevOrCanaryBuild()) {
if (brave::IsNightlyOrDeveloperBuild()) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/browser/notification_helper_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool NotificationHelperWin::ShouldShowNotifications() {
return false;
}

if (brave::IsDevOrCanaryBuild()) {
if (brave::IsNightlyOrDeveloperBuild()) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ uint64_t AdNotifications::Count() const {

#if defined(OS_ANDROID)
void AdNotifications::RemoveAllAfterReboot() {
if (brave::IsDevOrCanaryBuild()) {
if (brave::IsNightlyOrDeveloperBuild()) {
return;
}

database::table::AdEvents database_table;
database_table.GetAll([=](
const Result result,
Expand All @@ -217,9 +218,10 @@ void AdNotifications::RemoveAllAfterReboot() {
}

void AdNotifications::RemoveAllAfterUpdate() {
if (brave::IsDevOrCanaryBuild()) {
if (brave::IsNightlyOrDeveloperBuild()) {
return;
}

const std::string current_version_code =
base::android::BuildInfo::GetInstance()->package_version_code();

Expand Down

0 comments on commit af91e44

Please sign in to comment.