chromium/extensions/browser/api/declarative_net_request/prefs_helper.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// Additional preferences keys, which are not needed by external clients.

// Key corresponding to which we store a ruleset's checksum for the Declarative
// Net Request API.
constexpr std::string_view kChecksumKey =;

// Key corresponding to which we store a ruleset's disabled rule ids for the
// Declarative Net Request API.
constexpr std::string_view kDisabledStaticRuleIds =;

// Key corresponding to the list of enabled static ruleset IDs for an extension.
// Used for the Declarative Net Request API.
constexpr std::string_view kEnabledStaticRulesetIDs =;

// A preference that indicates the amount of rules allocated to an extension
// from the global pool.
constexpr std::string_view kExtensionRulesAllocated =;

// A boolean that indicates if a ruleset should be ignored.
constexpr std::string_view kIgnoreRulesetKey =;

// A boolean that indicates if an extension should have its unused rule
// allocation kept during its next load.
constexpr std::string_view kKeepExcessAllocation =;

// A boolean preference that indicates whether the extension's icon should be
// automatically badged to the matched action count for a tab. False by default.
constexpr std::string_view kUseActionCountAsBadgeText =;

// Stores preferences corresponding to dynamic indexed ruleset for the
// Declarative Net Request API. Note: we use a separate preference key for
// dynamic rulesets instead of using the `kDNRStaticRulesetPref` dictionary.
// This is because the `kDNRStaticRulesetPref` dictionary is re-populated on
// each packed extension update and also on reloads of unpacked extensions.
// However for both of these cases, we want the dynamic ruleset preferences to
// stay unchanged. Also, this helps provide flexibility to have the dynamic
// ruleset preference schema diverge from the static one.
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) {}

}  // namespace

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) {}

// Whether the ruleset for the given `extension_id` and `ruleset_id` should be
// ignored while loading the extension.
bool PrefsHelper::ShouldIgnoreRuleset(const ExtensionId& extension_id,
                                      RulesetID ruleset_id) const {}

// Returns the global rule allocation for the given |extension_id|. If no
// rules are allocated to the extension, false is returned.
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) {}

}  // namespace extensions::declarative_net_request