Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ads enabled by default for Japan on upgrade #3691

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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));
}
Expand Down
72 changes: 62 additions & 10 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1285,16 +1285,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 @@ -1305,7 +1305,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 @@ -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<std::string> legacy_regions = {
masparrow marked this conversation as resolved.
Show resolved Hide resolved
"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 Expand Up @@ -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<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
"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<std::string> new_regions = {
const std::vector<std::string> new_regions = {
"KY" // Cayman Islands
};

Expand Down
2 changes: 1 addition & 1 deletion components/brave_ads/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down