Skip to content

Commit

Permalink
move cookie list override logic to account for uninitialized preferences
Browse files Browse the repository at this point in the history
The previous implementation only iterated through lists that existed in
the preferences already, so in practice it would only override lists
that had `enabled: false` - i.e. lists that had been enabled and
disabled again before the "touched" preference was introduced.

This fix clones the preferences dictionary and adds the cookie list with
`enabled: true` to the cloned dictionary if the override should occur.
  • Loading branch information
antonok-edm committed Jan 4, 2022
1 parent 3f7e9cc commit ccef18a
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,24 @@ void AdBlockRegionalServiceManager::StartRegionalServices() {
base::AutoLock lock(regional_services_lock_);
const base::DictionaryValue* regional_filters_dict =
local_state->GetDictionary(prefs::kAdBlockRegionalFilters);
for (base::DictionaryValue::Iterator it(*regional_filters_dict);
!it.IsAtEnd(); it.Advance()) {
const std::string uuid = it.key();

base::Value regional_filters_dict_with_cookielist =
base::Value(regional_filters_dict->Clone());
if (base::FeatureList::IsEnabled(kBraveAdblockCookieListDefault) &&
!cookie_list_touched) {
auto cookie_list_entry = base::Value(base::Value::Type::DICTIONARY);
cookie_list_entry.SetBoolKey("enabled", true);
regional_filters_dict_with_cookielist.SetKey(kCookieListUuid,
std::move(cookie_list_entry));
}

for (const auto kv : regional_filters_dict_with_cookielist.DictItems()) {
const std::string uuid = kv.first;
bool enabled = false;
const base::DictionaryValue* regional_filter_dict = nullptr;
regional_filters_dict->GetDictionary(uuid, &regional_filter_dict);
if (uuid == kCookieListUuid &&
base::FeatureList::IsEnabled(kBraveAdblockCookieListDefault) &&
!cookie_list_touched) {
enabled = true;
} else if (regional_filter_dict) {
regional_filter_dict->GetBoolean("enabled", &enabled);
const base::Value* regional_filter_dict =
regional_filters_dict_with_cookielist.FindDictKey(uuid);
if (regional_filter_dict) {
enabled = regional_filter_dict->FindBoolKey("enabled").value_or(false);
}
if (enabled) {
auto catalog_entry = brave_shields::FindAdBlockFilterListByUUID(
Expand Down

0 comments on commit ccef18a

Please sign in to comment.