Skip to content

Commit

Permalink
Merge pull request #5443 from /issues/9205
Browse files Browse the repository at this point in the history
Refactored supported regions, large anonymity country codes and other country codes to use std::set
  • Loading branch information
tmancey authored May 4, 2020
2 parents 5baee7b + 3d29200 commit 420271a
Show file tree
Hide file tree
Showing 8 changed files with 545 additions and 846 deletions.
1 change: 0 additions & 1 deletion vendor/bat-native-ads/include/bat/ads/ads.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <stdint.h>
#include <string>
#include <memory>
#include <vector>

#include "bat/ads/ad_content.h"
#include "bat/ads/ads_client.h"
Expand Down
11 changes: 6 additions & 5 deletions vendor/bat-native-ads/src/bat/ads/ads.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <algorithm>
#include <set>

#include "bat/ads/ads.h"

#include "bat/ads/internal/ads_impl.h"
#include "bat/ads/internal/locale_helper.h"
#include "bat/ads/internal/static_values.h"
#include "bat/ads/internal/supported_regions.h"

namespace ads {

Expand All @@ -31,8 +32,8 @@ bool Ads::IsSupportedLocale(
const std::string& locale) {
const std::string region = GetRegion(locale);

for (const auto& schema : kSupportedRegionsSchemas) {
const std::vector<std::string> regions = schema.second;
for (const auto& schema : kSupportedRegions) {
const std::set<std::string> regions = schema.second;
const auto iter = std::find(regions.begin(), regions.end(), region);
if (iter != regions.end()) {
return true;
Expand All @@ -47,13 +48,13 @@ bool Ads::IsNewlySupportedLocale(
const int last_schema_version) {
const std::string region = GetRegion(locale);

for (const auto& schema : kSupportedRegionsSchemas) {
for (const auto& schema : kSupportedRegions) {
const int schema_version = schema.first;
if (schema_version < last_schema_version) {
continue;
}

const std::vector<std::string> regions = schema.second;
const std::set<std::string> regions = schema.second;
const auto iter = std::find(regions.begin(), regions.end(), region);
if (iter != regions.end()) {
return true;
Expand Down
311 changes: 1 addition & 310 deletions vendor/bat-native-ads/src/bat/ads/internal/static_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <stdint.h>
#include <string>
#include <map>
#include <vector>
#include <set>

#include "base/time/time.h"

Expand Down Expand Up @@ -62,315 +62,6 @@ const int kDoNotDisturbToHour = 6; // 6am
const uint64_t kRetryDownloadingCatalogAfterSeconds =
1 * base::Time::kSecondsPerMinute;

const std::map<int, std::vector<std::string>> kSupportedRegionsSchemas = {
// Append newly supported regions with a new schema version and update
// |kSupportedRegionsSchemaVersionNumber| to match the new version

// |kLargeAnonymityCountryCodes| and |kOtherCountryCodes| in
// bat-native-confirmations/src/bat/confirmations/internal/static_values.h
// must be updated to reflect newly supported regions

//
// Format: { schema_version : { region... } }
{
1, {
"US", // United States of America
"CA", // Canada
"GB", // United Kingdom (Great Britain and Northern Ireland)
"DE", // Germany
"FR" // France
}
},
{
2, {
"AU", // Australia
"NZ", // New Zealand
"IE" // Ireland
}
},
{
3, {
"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
}
},
{
4, {
"KY" // Cayman Islands
}
},
{
5, {
"AE", // United Arab Emirates
"AL", // Albania
"AZ", // Azerbaijan
"BD", // Bangladesh
"BE", // Belgium
"BG", // Bulgaria
"CN", // China
"CZ", // Czechia
"DZ", // Algeria
"EG", // Egypt
"ES", // Spain
"FI", // Finland
"GR", // Greece
"HK", // Hong Kong
"HR", // Croatia
"HU", // Hungary
"ID", // Indonesia
"IQ", // Iraq
"KH", // Cambodia
"LT", // Lithuania
"MA", // Morocco
"MY", // Malaysia
"NG", // Nigeria
"NO", // Norway
"PK", // Pakistan
"PT", // Portugal
"RO", // Romania
"RS", // Serbia
"RU", // Russia
"SA", // Saudi Arabia
"SI", // Slovenia
"SK", // Slovakia
"TH", // Thailand
"TR", // Turkey
"TW", // Taiwan
"UA", // Ukraine
"VN" // Vietnam
}
},
{
6, {
"AF", // Afghanistan
"AS", // American Samoa
"AD", // Andorra
"AO", // Angola
"AI", // Anguilla
"AQ", // Antarctica
"AG", // Antigua and Barbuda
"AM", // Armenia
"AW", // Aruba
"BS", // Bahamas
"BH", // Bahrain
"BB", // Barbados
"BY", // Belarus
"BZ", // Belize
"BJ", // Benin
"BM", // Bermuda
"BT", // Bhutan
"BO", // Bolivia
"BQ", // Bonaire
"BA", // Bosnia and Herzegovina
"BW", // Botswana
"BV", // Bouvet Island
"IO", // British Indian Ocean Territory
"BN", // Brunei Darussalam
"BF", // Burkina Faso
"BI", // Burundi
"CM", // Cameroon
"CV", // Cape Verde
"TD", // Chad
"CX", // Christmas Island
"CC", // Cocos (Keeling) Islands
"KM", // Comoros
"CG", // Republic of the Congo
"CD", // Democratic Republic of the Congo
"CK", // Cook Islands
"CR", // Costa Rica
"CW", // Curacao
"CY", // Cyprus
"CI", // Cote d'Ivoire
"DJ", // Djibouti
"DM", // Dominica
"DO", // Dominican Republic
"SV", // El Salvador
"GQ", // Equatorial Guinea
"ER", // Eritrea
"EE", // Estonia
"ET", // Ethiopia
"FK", // Falkland Islands
"FO", // Faroe Islands
"FJ", // Fiji
"GF", // French Guiana
"PF", // French Polynesia
"TF", // French and Antarctic Lands
"GA", // Gabon
"GM", // Gambia
"GE", // Georgia
"GH", // Ghana
"GI", // Gibraltar
"GL", // Greenland
"GD", // Grenada
"GP", // Guadeloupe
"GU", // Guam
"GT", // Guatemala
"GG", // Guernsey
"GN", // Guinea
"GW", // Guinea-Bissau
"GY", // Guyana
"HT", // Haiti
"HM", // Heard Island and McDonald Islands
"VA", // Vatican City
"HN", // Honduras
"IS", // Iceland
"IM", // Isle of Man
"JM", // Jamaica
"JE", // Jersey
"JO", // Jordan
"KZ", // Kazakhstan
"KE", // Kenya
"KI", // Kiribati
"KW", // Kuwait
"KG", // Kyrgyzstan
"LA", // Lao People's Democratic Republic
"LV", // Latvia
"LB", // Lebanon
"LS", // Lesotho
"LR", // Liberia
"LI", // Liechtenstein
"LU", // Luxembourg
"MO", // Macao
"MK", // Macedonia
"MG", // Madagascar
"MW", // Malawi
"MV", // Maldives
"ML", // Mali
"MT", // Malta
"MH", // Marshall Islands
"MQ", // Martinique
"MR", // Mauritania
"MU", // Mauritius
"YT", // Mayotte
"FM", // Micronesia, Federated States of
"MD", // Moldova
"MC", // Monaco
"MN", // Mongolia
"ME", // Montenegro
"MS", // Montserrat
"MZ", // Mozambique
"MM", // Myanmar
"NA", // Namibia
"NR", // Nauru
"NP", // Nepal
"NC", // New Caledonia
"NI", // Nicaragua
"NE", // Niger
"NU", // Niue
"NF", // Norfolk Island
"MP", // Northern Mariana Islands
"NO", // Norway
"OM", // Oman
"PW", // Palau
"PS", // Palestine
"PA", // Panama
"PG", // Papua New Guinea
"PY", // Paraguay
"PN", // Pitcairn
"PR", // Puerto Rico
"QA", // Qatar
"RW", // Rwanda
"RE", // Reunion
"BL", // Saint Barthelemy
"SH", // Saint Helena
"KN", // Saint Kitts and Nevis
"LC", // Saint Lucia
"MF", // Saint Martin
"PM", // Saint Pierre and Miquelon
"VC", // Saint Vincent and the Grenadines
"WS", // Samoa
"SM", // San Marino
"ST", // São Tomé and Príncipe
"SN", // Senegal
"SC", // Seychelles
"SL", // Sierra Leone
"SX", // Sint Maarten
"SB", // Solomon Islands
"GS", // South Georgia and the South Sandwich Islands
"SS", // South Sudan
"LK", // Sri Lanka
"SR", // Suriname
"SJ", // Svalbard and Jan Mayen
"SZ", // Swaziland
"TJ", // Tajikistan
"TZ", // United Republic of Tanzania
"TL", // Timor-Leste
"TG", // Togo
"TK", // Tokelau
"TO", // Tonga
"TT", // Trinidad and Tobago
"TN", // Tunisia
"TM", // Turkmenistan
"TC", // Turks and Caicos Islands
"TV", // Tuvalu
"UG", // Uganda
"UM", // United States Minor Outlying Islands
"UY", // Uruguay
"UZ", // Uzbekistan
"VU", // Vanuatu
"VG", // British Virgin Islands
"VI", // US Virgin Islands
"WF", // Wallis and Futuna
"EH", // Western Sahara
"YE", // Yemen
"ZM", // Zambia
"ZW" // Zimbabwe
}
},
{
7, {
"150", // Europe
}
},
{
8, {
"202", // Sub-Saharan Africa
"014", // Eastern Africa
"017", // Middle Africa
"018", // Southern Africa
"011", // Western Africa
"013", // Central America
"005", // South America
"021", // Northern America
"143", // Central Asia
"035", // South-eastern Asia
"151", // Eastern Europe
"154", // Northern Europe
"039", // Southern Europe
"155", // Western Europe
"009", // Oceania
"053", // Australia and New Zealand
"054", // Melanesia
"057", // Micronesia
"061" // Polynesia
}
}

// IMPORTANT: When adding new schema versions |newly_supported_locale_| must
// be updated in |BraveRewardsBrowserTest| to reflect a locale from the latest
// schema version in "bat-native-ads/src/bat/ads/internal/static_values.h"
};

const char kUntargetedPageClassification[] = "untargeted";

#if defined(OS_ANDROID)
Expand Down
Loading

0 comments on commit 420271a

Please sign in to comment.