OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_INDEX_H_ | 5 #ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_INDEX_H_ |
6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_INDEX_H_ | 6 #define COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_INDEX_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 // A fallback list that contains all the rules with no acceptable N-gram. | 83 // A fallback list that contains all the rules with no acceptable N-gram. |
84 MutableUrlRuleList fallback_rules_; | 84 MutableUrlRuleList fallback_rules_; |
85 | 85 |
86 // Must outlive this instance. | 86 // Must outlive this instance. |
87 flatbuffers::FlatBufferBuilder* flat_builder_; | 87 flatbuffers::FlatBufferBuilder* flat_builder_; |
88 | 88 |
89 DISALLOW_COPY_AND_ASSIGN(UrlPatternIndexBuilder); | 89 DISALLOW_COPY_AND_ASSIGN(UrlPatternIndexBuilder); |
90 }; | 90 }; |
91 | 91 |
| 92 // Need some way to inject ruleset reporting. |
| 93 class RuleRecorder { |
| 94 public: |
| 95 virtual void RecordRuleUsage(const flat::UrlRule* rule) = 0; |
| 96 virtual ~RuleRecorder(){}; |
| 97 }; |
| 98 |
92 // Encapsulates a read-only index built over the URL patterns of a set of URL | 99 // Encapsulates a read-only index built over the URL patterns of a set of URL |
93 // rules, and provides fast matching of network requests against these rules. | 100 // rules, and provides fast matching of network requests against these rules. |
94 class UrlPatternIndexMatcher { | 101 class UrlPatternIndexMatcher { |
95 public: | 102 public: |
96 // Creates an instance to access the given |flat_index|. If |flat_index| is | 103 // Creates an instance to access the given |flat_index|. If |flat_index| is |
97 // nullptr, then all requests return no match. | 104 // nullptr, then all requests return no match. |
98 explicit UrlPatternIndexMatcher(const flat::UrlPatternIndex* flat_index); | 105 explicit UrlPatternIndexMatcher(const flat::UrlPatternIndex* flat_index); |
99 ~UrlPatternIndexMatcher(); | 106 ~UrlPatternIndexMatcher(); |
100 | 107 |
101 // If the index contains one or more UrlRules that match the request, returns | 108 // If the index contains one or more UrlRules that match the request, returns |
(...skipping 12 matching lines...) Expand all Loading... |
114 // - The |first_party_origin| matches the rule's targeted domains list. | 121 // - The |first_party_origin| matches the rule's targeted domains list. |
115 // - |element_type| or |activation_type| is among the rule's targeted types. | 122 // - |element_type| or |activation_type| is among the rule's targeted types. |
116 // - The |is_third_party| bit matches the rule's requirement on the requested | 123 // - The |is_third_party| bit matches the rule's requirement on the requested |
117 // |url| being first-/third-party w.r.t. its |first_party_origin|. | 124 // |url| being first-/third-party w.r.t. its |first_party_origin|. |
118 // - The rule is not generic if |disable_generic_rules| is true. | 125 // - The rule is not generic if |disable_generic_rules| is true. |
119 const flat::UrlRule* FindMatch(const GURL& url, | 126 const flat::UrlRule* FindMatch(const GURL& url, |
120 const url::Origin& first_party_origin, | 127 const url::Origin& first_party_origin, |
121 proto::ElementType element_type, | 128 proto::ElementType element_type, |
122 proto::ActivationType activation_type, | 129 proto::ActivationType activation_type, |
123 bool is_third_party, | 130 bool is_third_party, |
124 bool disable_generic_rules) const; | 131 bool disable_generic_rules, |
| 132 RuleRecorder* recorder) const; |
125 | 133 |
126 private: | 134 private: |
127 // Must outlive this instance. | 135 // Must outlive this instance. |
128 const flat::UrlPatternIndex* flat_index_; | 136 const flat::UrlPatternIndex* flat_index_; |
129 | 137 |
130 DISALLOW_COPY_AND_ASSIGN(UrlPatternIndexMatcher); | 138 DISALLOW_COPY_AND_ASSIGN(UrlPatternIndexMatcher); |
131 }; | 139 }; |
132 | 140 |
133 } // namespace subresource_filter | 141 } // namespace subresource_filter |
134 | 142 |
135 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_INDEX_H_ | 143 #endif // COMPONENTS_SUBRESOURCE_FILTER_CORE_COMMON_URL_PATTERN_INDEX_H_ |
OLD | NEW |