Skip to content

Commit

Permalink
Ads enabled by default for Japan on upgrade (#3721)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Oct 17, 2019
1 parent e85d04c commit f668ceb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
4 changes: 3 additions & 1 deletion browser/ui/webui/brave_rewards_page_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,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));
}
Expand Down
29 changes: 22 additions & 7 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1270,16 +1270,16 @@ 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
DisableAdsIfUpgradingFromPreBraveAdsBuild();

// Disable ads for unsupported legacy regions due to a bug where ads were
// enabled even if the users region was not supported
std::vector<std::string> legacy_regions = {
const std::vector<std::string> legacy_regions = {
"US", // United States of America
"CA", // Canada
"GB", // United Kingdom (Great Britain and Northern Ireland)
Expand All @@ -1290,7 +1290,7 @@ void AdsServiceImpl::MigratePrefsVersion2To3() {
DisableAdsForUnsupportedRegions(region, legacy_regions);

// On-board users for newly supported regions
std::vector<std::string> new_regions = {
const std::vector<std::string> new_regions = {
"AU", // Australia
"NZ", // New Zealand
"IE" // Ireland
Expand All @@ -1300,11 +1300,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<std::string> 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<std::string> new_regions = {
const std::vector<std::string> new_regions = {
"AR", // Argentina
"AT", // Austria
"BR", // Brazil
Expand Down

0 comments on commit f668ceb

Please sign in to comment.