From b8cd01b01726cf60cac2272a5a6d14d77855575c Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Tue, 15 Oct 2019 14:14:42 +0100 Subject: [PATCH] Ads enabled by default for Japan on upgrade Fixes https://github.com/brave/brave-browser/issues/6449 --- browser/ui/webui/brave_rewards_page_ui.cc | 4 +- .../brave_ads/browser/ads_service_impl.cc | 72 ++++++++++++++++--- components/brave_ads/common/pref_names.cc | 2 +- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/browser/ui/webui/brave_rewards_page_ui.cc b/browser/ui/webui/brave_rewards_page_ui.cc index a91f10602220..313ee7ec056a 100644 --- a/browser/ui/webui/brave_rewards_page_ui.cc +++ b/browser/ui/webui/brave_rewards_page_ui.cc @@ -1267,7 +1267,9 @@ void RewardsDOMHandler::SaveAdsSetting(const base::ListValue* args) { const std::string value = args->GetList()[1].GetString(); if (key == "adsEnabled") { - ads_service_->SetEnabled(value == "true"); + const auto is_enabled = + value == "true" && ads_service_->IsSupportedRegion(); + ads_service_->SetEnabled(is_enabled); } else if (key == "adsPerHour") { ads_service_->SetAdsPerHour(std::stoull(value)); } diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index 05dfe6531639..a88abb804fe8 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -1285,8 +1285,8 @@ void AdsServiceImpl::MigratePrefsVersion1To2() { } void AdsServiceImpl::MigratePrefsVersion2To3() { - auto locale = GetLocale(); - auto region = ads::Ads::GetRegion(locale); + const auto locale = GetLocale(); + const auto region = ads::Ads::GetRegion(locale); // Disable ads if upgrading from a pre brave ads build due to a bug where ads // were always enabled @@ -1294,7 +1294,7 @@ void AdsServiceImpl::MigratePrefsVersion2To3() { // Disable ads for unsupported legacy regions due to a bug where ads were // enabled even if the users region was not supported - std::vector legacy_regions = { + const std::vector legacy_regions = { "US", // United States of America "CA", // Canada "GB", // United Kingdom (Great Britain and Northern Ireland) @@ -1305,7 +1305,7 @@ void AdsServiceImpl::MigratePrefsVersion2To3() { DisableAdsForUnsupportedRegions(region, legacy_regions); // On-board users for newly supported regions - std::vector new_regions = { + const std::vector new_regions = { "AU", // Australia "NZ", // New Zealand "IE" // Ireland @@ -1315,11 +1315,26 @@ void AdsServiceImpl::MigratePrefsVersion2To3() { } void AdsServiceImpl::MigratePrefsVersion3To4() { - auto locale = GetLocale(); - auto region = ads::Ads::GetRegion(locale); + const auto locale = GetLocale(); + const auto region = ads::Ads::GetRegion(locale); + + // Disable ads for unsupported legacy regions due to a bug where ads were + // enabled even if the users region was not supported + const std::vector legacy_regions = { + "US", // United States of America + "CA", // Canada + "GB", // United Kingdom (Great Britain and Northern Ireland) + "DE", // Germany + "FR", // France + "AU", // Australia + "NZ", // New Zealand + "IE" // Ireland + }; + + DisableAdsForUnsupportedRegions(region, legacy_regions); // On-board users for newly supported regions - std::vector new_regions = { + const std::vector new_regions = { "AR", // Argentina "AT", // Austria "BR", // Brazil @@ -1348,11 +1363,48 @@ void AdsServiceImpl::MigratePrefsVersion3To4() { } void AdsServiceImpl::MigratePrefsVersion4To5() { - auto locale = GetLocale(); - auto region = ads::Ads::GetRegion(locale); + const auto locale = GetLocale(); + const auto region = ads::Ads::GetRegion(locale); + + // Disable ads for unsupported legacy regions due to a bug where ads were + // enabled even if the users region was not supported + const std::vector legacy_regions = { + "US", // United States of America + "CA", // Canada + "GB", // United Kingdom (Great Britain and Northern Ireland) + "DE", // Germany + "FR", // France + "AU", // Australia + "NZ", // New Zealand + "IE", // Ireland + "AR", // Argentina + "AT", // Austria + "BR", // Brazil + "CH", // Switzerland + "CL", // Chile + "CO", // Colombia + "DK", // Denmark + "EC", // Ecuador + "IL", // Israel + "IN", // India + "IT", // Italy + "JP", // Japan + "KR", // Korea + "MX", // Mexico + "NL", // Netherlands + "PE", // Peru + "PH", // Philippines + "PL", // Poland + "SE", // Sweden + "SG", // Singapore + "VE", // Venezuela + "ZA" // South Africa + }; + + DisableAdsForUnsupportedRegions(region, legacy_regions); // On-board users for newly supported regions - std::vector new_regions = { + const std::vector new_regions = { "KY" // Cayman Islands }; diff --git a/components/brave_ads/common/pref_names.cc b/components/brave_ads/common/pref_names.cc index 3045de151e77..b71d17594242 100644 --- a/components/brave_ads/common/pref_names.cc +++ b/components/brave_ads/common/pref_names.cc @@ -36,7 +36,7 @@ const char kShouldShowMyFirstAdNotification[] = // Stores the preferences version number const char kVersion[] = "brave.brave_ads.prefs.version"; -const int kCurrentVersionNumber = 4; +const int kCurrentVersionNumber = 5; // Ads were disabled at least once. const char kBraveAdsWereDisabled[] = "brave.brave_ads.were_disabled";