Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: extensions/common/api/declarative_net_request/ruleset_indexer.h

Issue 2881453002: DNR Prototype: With flatbuffers
Patch Set: -- Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/common/api/declarative_net_request/ruleset_indexer.h
diff --git a/extensions/common/api/declarative_net_request/ruleset_indexer.h b/extensions/common/api/declarative_net_request/ruleset_indexer.h
new file mode 100644
index 0000000000000000000000000000000000000000..8d173df93902357fe2a536613683c93c47db1a55
--- /dev/null
+++ b/extensions/common/api/declarative_net_request/ruleset_indexer.h
@@ -0,0 +1,60 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef EXTENSIONS_COMMON_API_DECLARATIVE_NET_REQUEST_RULESET_INDEXER_H_
+#define EXTENSIONS_COMMON_API_DECLARATIVE_NET_REQUEST_RULESET_INDEXER_H_
+
+#include <utility>
+#include <vector>
+
+#include "base/macros.h"
+#include "components/subresource_filter/core/common/flat/extension_metadata_generated.h"
+#include "components/subresource_filter/core/common/url_pattern_index.h"
+#include "extensions/common/api/declarative_net_request.h"
+#include "third_party/flatbuffers/src/include/flatbuffers/flatbuffers.h"
+
+namespace extensions {
+namespace declarative_net_request {
+
+enum class ParseResult;
+struct IndexedRule;
+enum class RuleActionType;
+
+class RulesetIndexer {
+ public:
+ using SerializedData = std::pair<uint8_t*, size_t>;
+ using UrlPatternIndexBuilder = subresource_filter::UrlPatternIndexBuilder;
+
+ RulesetIndexer();
+ ~RulesetIndexer();
+
+ ParseResult AddUrlRule(const IndexedRule& indexed_rule);
+
+ SerializedData FinishAndGetData();
+
+ private:
+ using MetadataOffset = flatbuffers::Offset<flat::ExtensionRuleMetadata>;
+
+ UrlPatternIndexBuilder* GetBuilder(
+ api::declarative_net_request::RuleActionType type);
+
+ flatbuffers::FlatBufferBuilder builder_;
+
+ UrlPatternIndexBuilder blacklist_index_builder_;
+ UrlPatternIndexBuilder whitelist_index_builder_;
+ UrlPatternIndexBuilder redirect_index_builder_;
+ std::vector<MetadataOffset> metadata_;
+ size_t cnt_ = 0; // TODO remove.
+
+ bool finished_;
+
+ DISALLOW_COPY_AND_ASSIGN(RulesetIndexer);
+};
+
+bool VerifyRuleset(const RulesetIndexer::SerializedData& data);
+
+} // namespace declarative_net_request
+} // namespace extensions
+
+#endif // EXTENSIONS_COMMON_API_DECLARATIVE_NET_REQUEST_RULESET_INDEXER_H_

Powered by Google App Engine
This is Rietveld 408576698