#include "extensions/browser/api/declarative_net_request/file_sequence_helper.h"
#include <cstdint>
#include <set>
#include <utility>
#include <vector>
#include "base/barrier_closure.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/files/important_file_writer.h"
#include "base/functional/bind.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/api/declarative_net_request/constants.h"
#include "extensions/browser/api/declarative_net_request/parse_info.h"
#include "extensions/browser/api/declarative_net_request/rule_counts.h"
#include "extensions/browser/api/declarative_net_request/utils.h"
#include "extensions/browser/extension_file_task_runner.h"
#include "extensions/common/api/declarative_net_request.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension_features.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
namespace extensions::declarative_net_request {
namespace {
dnr_api;
class IndexHelper : public base::RefCountedThreadSafe<IndexHelper> { … };
UpdateDynamicRulesStatus GetUpdateDynamicRuleStatus(LoadRulesetResult result) { … }
bool GetNewDynamicRules(const FileBackedRulesetSource& source,
std::vector<int> rule_ids_to_remove,
std::vector<dnr_api::Rule> rules_to_add,
const RuleCounts& rule_limit,
std::vector<dnr_api::Rule>* new_rules,
std::string* error,
UpdateDynamicRulesStatus* status) { … }
bool UpdateAndIndexDynamicRules(const FileBackedRulesetSource& source,
std::vector<int> rule_ids_to_remove,
std::vector<dnr_api::Rule> rules_to_add,
const RuleCounts& rule_limit,
int* ruleset_checksum,
std::string* error,
UpdateDynamicRulesStatus* status) { … }
}
RulesetInfo::RulesetInfo(FileBackedRulesetSource source)
: … { … }
RulesetInfo::~RulesetInfo() = default;
RulesetInfo::RulesetInfo(RulesetInfo&&) = default;
RulesetInfo& RulesetInfo::operator=(RulesetInfo&&) = default;
std::unique_ptr<RulesetMatcher> RulesetInfo::TakeMatcher() { … }
const std::optional<LoadRulesetResult>& RulesetInfo::load_ruleset_result()
const { … }
void RulesetInfo::CreateVerifiedMatcher() { … }
LoadRequestData::LoadRequestData(ExtensionId extension_id,
base::Version extension_version)
: … { … }
LoadRequestData::~LoadRequestData() = default;
LoadRequestData::LoadRequestData(LoadRequestData&&) = default;
LoadRequestData& LoadRequestData::operator=(LoadRequestData&&) = default;
FileSequenceHelper::FileSequenceHelper() = default;
FileSequenceHelper::~FileSequenceHelper() { … }
void FileSequenceHelper::LoadRulesets(
LoadRequestData load_data,
LoadRulesetsUICallback ui_callback) const { … }
void FileSequenceHelper::UpdateDynamicRules(
LoadRequestData load_data,
std::vector<int> rule_ids_to_remove,
std::vector<api::declarative_net_request::Rule> rules_to_add,
const RuleCounts& rule_limit,
UpdateDynamicRulesUICallback ui_callback) const { … }
void FileSequenceHelper::OnRulesetsIndexed(LoadRulesetsUICallback ui_callback,
LoadRequestData load_data) const { … }
}