chromium/components/subresource_filter/core/common/unindexed_ruleset.h

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

// Semantically speaking, an unindexed ruleset consists of a single
// url_pattern_index::proto::FilteringRules message. However, because the
// ruleset can be relatively large, we want to avoid deserializing all of it at
// once, as doing so can lead to memory allocation bursts.
//
// To work around the limitation that partial (or streaming) deserialization is
// not supported by the proto parser, the UnindexedRulesetReader/Writer classes
// implement a format where the ruleset is split into several chunks. Each chunk
// is itself a url_pattern_index::proto::FilteringRules message. If all chunks
// were merged, they would add up to the original
// url_pattern_index::proto::FilteringRules message representing the entire
// ruleset.
//
// Consumers of an unindexed ruleset in this format will be able to read it one
// chunk at a time, and are expected to fully process and discard the chunk
// before reading the next one. In practice, this should not be an issue as
// indexing of the ruleset is expected to be performed in an on-line fashion.

#ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_UNINDEXED_RULESET_H_
#define COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_UNINDEXED_RULESET_H_

#include "components/url_pattern_index/proto/rules.pb.h"
#include "third_party/protobuf/src/google/protobuf/io/coded_stream.h"
#include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h"

namespace subresource_filter {

// Reads an unindexed ruleset from |stream| one chunk at a time.
class UnindexedRulesetReader {};

// Divides an unindexed ruleset into chunks and writes them into |stream|.
//
// Writing methods of this class return bool false if an I/O error occurrs
// during these calls. In this case the UnindexedRulesetWriter becomes broken,
// and write operations should not be used further.
class UnindexedRulesetWriter {};

}  // namespace subresource_filter

#endif  // COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_UNINDEXED_RULESET_H_