#include "components/subresource_filter/content/shared/browser/ruleset_service.h"
#include <string_view>
#include <utility>
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/subresource_filter/content/shared/browser/ruleset_publisher.h"
#include "components/subresource_filter/content/shared/browser/unindexed_ruleset_stream_generator.h"
#include "components/subresource_filter/core/browser/copying_file_stream.h"
#include "components/subresource_filter/core/browser/subresource_filter_constants.h"
#include "components/subresource_filter/core/browser/subresource_filter_features.h"
#include "components/subresource_filter/core/common/common_features.h"
#include "components/subresource_filter/core/common/indexed_ruleset.h"
#include "components/subresource_filter/core/common/ruleset_config.h"
#include "components/subresource_filter/core/common/time_measurements.h"
#include "components/subresource_filter/core/common/unindexed_ruleset.h"
#include "components/url_pattern_index/proto/rules.pb.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h"
namespace subresource_filter {
namespace {
void RecordIndexAndWriteRulesetResult(
std::string_view uma_tag,
RulesetService::IndexAndWriteRulesetResult result) { … }
class SentinelFile { … };
}
base::FilePath IndexedRulesetLocator::GetSubdirectoryPathForVersion(
const base::FilePath& base_dir,
const IndexedRulesetVersion& version) { … }
base::FilePath IndexedRulesetLocator::GetRulesetDataFilePath(
const base::FilePath& version_directory) { … }
base::FilePath IndexedRulesetLocator::GetLicenseFilePath(
const base::FilePath& version_directory) { … }
base::FilePath IndexedRulesetLocator::GetSentinelFilePath(
const base::FilePath& version_directory) { … }
void IndexedRulesetLocator::DeleteObsoleteRulesets(
const base::FilePath& indexed_ruleset_base_dir,
const IndexedRulesetVersion& most_recent_version) { … }
decltype(&RulesetService::IndexRuleset) RulesetService::g_index_ruleset_func = …;
decltype(&base::ReplaceFile) RulesetService::g_replace_file_func = …;
std::unique_ptr<RulesetService> RulesetService::Create(
const RulesetConfig& config,
PrefService* local_state,
const base::FilePath& user_data_dir,
const RulesetPublisher::Factory& publisher_factory) { … }
RulesetService::RulesetService(
const RulesetConfig& config,
PrefService* local_state,
scoped_refptr<base::SequencedTaskRunner> background_task_runner,
const base::FilePath& indexed_ruleset_base_dir,
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner,
const RulesetPublisher::Factory& publisher_factory)
: … { … }
RulesetService::~RulesetService() { … }
void RulesetService::IndexAndStoreAndPublishRulesetIfNeeded(
const UnindexedRulesetInfo& unindexed_ruleset_info) { … }
IndexedRulesetVersion RulesetService::GetMostRecentlyIndexedVersion() const { … }
IndexedRulesetVersion RulesetService::IndexAndWriteRuleset(
const RulesetConfig& config,
const base::FilePath& indexed_ruleset_base_dir,
const UnindexedRulesetInfo& unindexed_ruleset_info) { … }
bool RulesetService::IndexRuleset(
const RulesetConfig& config,
UnindexedRulesetStreamGenerator* unindexed_ruleset_stream_generator,
RulesetIndexer* indexer) { … }
RulesetService::IndexAndWriteRulesetResult RulesetService::WriteRuleset(
const base::FilePath& indexed_ruleset_version_dir,
const base::FilePath& license_source_path,
base::span<const uint8_t> indexed_ruleset_data) { … }
void RulesetService::FinishInitialization() { … }
void RulesetService::IndexAndStoreRuleset(
const UnindexedRulesetInfo& unindexed_ruleset_info,
WriteRulesetCallback success_callback) { … }
void RulesetService::OnWrittenRuleset(WriteRulesetCallback result_callback,
const IndexedRulesetVersion& version) { … }
void RulesetService::OpenAndPublishRuleset(
const IndexedRulesetVersion& version) { … }
void RulesetService::OnRulesetSet(RulesetFilePtr file) { … }
}