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 #include "components/subresource_filter/core/common/url_pattern_index.h" | 5 #include "components/subresource_filter/core/common/url_pattern_index.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } | 544 } |
545 | 545 |
546 UrlPatternIndexMatcher::~UrlPatternIndexMatcher() = default; | 546 UrlPatternIndexMatcher::~UrlPatternIndexMatcher() = default; |
547 | 547 |
548 const flat::UrlRule* UrlPatternIndexMatcher::FindMatch( | 548 const flat::UrlRule* UrlPatternIndexMatcher::FindMatch( |
549 const GURL& url, | 549 const GURL& url, |
550 const url::Origin& first_party_origin, | 550 const url::Origin& first_party_origin, |
551 proto::ElementType element_type, | 551 proto::ElementType element_type, |
552 proto::ActivationType activation_type, | 552 proto::ActivationType activation_type, |
553 bool is_third_party, | 553 bool is_third_party, |
554 bool disable_generic_rules) const { | 554 bool disable_generic_rules, |
| 555 RuleRecorder* recorder) const { |
555 if (!flat_index_ || !url.is_valid()) | 556 if (!flat_index_ || !url.is_valid()) |
556 return nullptr; | 557 return nullptr; |
557 if ((element_type == proto::ELEMENT_TYPE_UNSPECIFIED) == | 558 if ((element_type == proto::ELEMENT_TYPE_UNSPECIFIED) == |
558 (activation_type == proto::ACTIVATION_TYPE_UNSPECIFIED)) { | 559 (activation_type == proto::ACTIVATION_TYPE_UNSPECIFIED)) { |
559 return nullptr; | 560 return nullptr; |
560 } | 561 } |
561 | 562 |
562 return FindMatchInFlatUrlPatternIndex(*flat_index_, url, first_party_origin, | 563 const flat::UrlRule* rule = FindMatchInFlatUrlPatternIndex( |
563 element_type, activation_type, | 564 *flat_index_, url, first_party_origin, element_type, activation_type, |
564 is_third_party, disable_generic_rules); | 565 is_third_party, disable_generic_rules); |
| 566 |
| 567 // Log the rule if used. We don't care about blacklist or whitelist I assume. |
| 568 // Can we just use url_pattern or are there rules with same pattern |
| 569 // but different options. |
| 570 if (recorder && rule) |
| 571 recorder->RecordRuleUsage(rule); |
| 572 return rule; |
565 } | 573 } |
566 | 574 |
567 } // namespace subresource_filter | 575 } // namespace subresource_filter |
OLD | NEW |