#include "extensions/browser/api/declarative_net_request/prefs_helper.h"
#include <string>
#include <string_view>
#include "base/containers/contains.h"
#include "base/strings/string_util.h"
#include "extensions/browser/api/declarative_net_request/utils.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/common/constants.h"
#include "services/preferences/public/cpp/scoped_pref_update.h"
namespace extensions::declarative_net_request {
namespace {
constexpr std::string_view kChecksumKey = …;
constexpr std::string_view kDisabledStaticRuleIds = …;
constexpr std::string_view kEnabledStaticRulesetIDs = …;
constexpr std::string_view kExtensionRulesAllocated = …;
constexpr std::string_view kIgnoreRulesetKey = …;
constexpr std::string_view kKeepExcessAllocation = …;
constexpr std::string_view kUseActionCountAsBadgeText = …;
constexpr std::string_view kDynamicRulesetPref = …;
base::flat_set<int> GetDisabledStaticRuleIdsFromDict(
const base::Value::Dict* disabled_rule_ids_dict,
RulesetID ruleset_id) { … }
size_t CountDisabledRules(const base::Value::Dict* disabled_rule_ids_dict) { … }
bool ReadPrefAsBooleanAndReturn(const ExtensionPrefs& prefs,
const ExtensionId& extension_id,
std::string_view key) { … }
}
PrefsHelper::PrefsHelper(ExtensionPrefs& prefs)
: … { … }
PrefsHelper::~PrefsHelper() = default;
PrefsHelper::RuleIdsToUpdate::RuleIdsToUpdate(
const std::optional<std::vector<int>>& ids_to_disable,
const std::optional<std::vector<int>>& ids_to_enable) { … }
PrefsHelper::RuleIdsToUpdate::RuleIdsToUpdate(
RuleIdsToUpdate&& other) = default;
PrefsHelper::RuleIdsToUpdate::~RuleIdsToUpdate() = default;
PrefsHelper::UpdateDisabledStaticRulesResult::
UpdateDisabledStaticRulesResult() = default;
PrefsHelper::UpdateDisabledStaticRulesResult::
UpdateDisabledStaticRulesResult(UpdateDisabledStaticRulesResult&& other) =
default;
PrefsHelper::UpdateDisabledStaticRulesResult::
~UpdateDisabledStaticRulesResult() = default;
const base::Value::Dict*
PrefsHelper::GetDisabledRuleIdsDict(
const ExtensionId& extension_id) const { … }
base::flat_set<int> PrefsHelper::GetDisabledStaticRuleIds(
const ExtensionId& extension_id,
RulesetID ruleset_id) const { … }
size_t PrefsHelper::GetDisabledStaticRuleCount(
const ExtensionId& extension_id) const { … }
void PrefsHelper::SetDisabledStaticRuleIds(
const ExtensionId& extension_id,
RulesetID ruleset_id,
const base::flat_set<int>& disabled_rule_ids) { … }
PrefsHelper::UpdateDisabledStaticRulesResult
PrefsHelper::UpdateDisabledStaticRules(
const ExtensionId& extension_id,
RulesetID ruleset_id,
const RuleIdsToUpdate& rule_ids_to_update) { … }
bool PrefsHelper::GetStaticRulesetChecksum(
const ExtensionId& extension_id,
declarative_net_request::RulesetID ruleset_id,
int& checksum) const { … }
void PrefsHelper::SetStaticRulesetChecksum(
const ExtensionId& extension_id,
declarative_net_request::RulesetID ruleset_id,
int checksum) { … }
bool PrefsHelper::GetDynamicRulesetChecksum(const ExtensionId& extension_id,
int& checksum) const { … }
void PrefsHelper::SetDynamicRulesetChecksum(const ExtensionId& extension_id,
int checksum) { … }
std::optional<std::set<RulesetID>> PrefsHelper::GetEnabledStaticRulesets(
const ExtensionId& extension_id) const { … }
void PrefsHelper::SetEnabledStaticRulesets(const ExtensionId& extension_id,
const std::set<RulesetID>& ids) { … }
bool PrefsHelper::GetUseActionCountAsBadgeText(
const ExtensionId& extension_id) const { … }
void PrefsHelper::SetUseActionCountAsBadgeText(
const ExtensionId& extension_id,
bool use_action_count_as_badge_text) { … }
bool PrefsHelper::ShouldIgnoreRuleset(const ExtensionId& extension_id,
RulesetID ruleset_id) const { … }
bool PrefsHelper::GetAllocatedGlobalRuleCount(const ExtensionId& extension_id,
int& rule_count) const { … }
void PrefsHelper::SetAllocatedGlobalRuleCount(const ExtensionId& extension_id,
int rule_count) { … }
bool PrefsHelper::GetKeepExcessAllocation(
const ExtensionId& extension_id) const { … }
void PrefsHelper::SetKeepExcessAllocation(const ExtensionId& extension_id,
bool keep_excess_allocation) { … }
}