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

Side by Side Diff: components/subresource_filter/core/common/indexed_ruleset.cc

Issue 2894523006: Add instrumentation hooks to mesaure which subresource filter rules are used.
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1
1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 4 // found in the LICENSE file.
4 5
5 #include "components/subresource_filter/core/common/indexed_ruleset.h" 6 #include "components/subresource_filter/core/common/indexed_ruleset.h"
6 7
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "components/subresource_filter/core/common/first_party_origin.h" 9 #include "components/subresource_filter/core/common/first_party_origin.h"
9 #include "url/gurl.h" 10 #include "url/gurl.h"
10 #include "url/origin.h" 11 #include "url/origin.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 55
55 // IndexedRulesetMatcher ------------------------------------------------------- 56 // IndexedRulesetMatcher -------------------------------------------------------
56 57
57 // static 58 // static
58 bool IndexedRulesetMatcher::Verify(const uint8_t* buffer, size_t size) { 59 bool IndexedRulesetMatcher::Verify(const uint8_t* buffer, size_t size) {
59 flatbuffers::Verifier verifier(buffer, size); 60 flatbuffers::Verifier verifier(buffer, size);
60 return flat::VerifyIndexedRulesetBuffer(verifier); 61 return flat::VerifyIndexedRulesetBuffer(verifier);
61 } 62 }
62 63
63 IndexedRulesetMatcher::IndexedRulesetMatcher(const uint8_t* buffer, size_t size) 64 IndexedRulesetMatcher::IndexedRulesetMatcher(const uint8_t* buffer, size_t size)
65 : IndexedRulesetMatcher(buffer, size, nullptr) {}
66
67 IndexedRulesetMatcher::IndexedRulesetMatcher(
68 const uint8_t* buffer,
69 size_t size,
70 std::unique_ptr<RuleRecorder> recorder)
64 : root_(flat::GetIndexedRuleset(buffer)), 71 : root_(flat::GetIndexedRuleset(buffer)),
65 blacklist_(root_->blacklist_index()), 72 blacklist_(root_->blacklist_index()),
66 whitelist_(root_->whitelist_index()), 73 whitelist_(root_->whitelist_index()),
67 deactivation_(root_->deactivation_index()) {} 74 deactivation_(root_->deactivation_index()),
75 recorder_(std::move(recorder)) {}
68 76
69 bool IndexedRulesetMatcher::ShouldDisableFilteringForDocument( 77 bool IndexedRulesetMatcher::ShouldDisableFilteringForDocument(
70 const GURL& document_url, 78 const GURL& document_url,
71 const url::Origin& parent_document_origin, 79 const url::Origin& parent_document_origin,
72 proto::ActivationType activation_type) const { 80 proto::ActivationType activation_type) const {
73 return !!deactivation_.FindMatch( 81 return !!deactivation_.FindMatch(
74 document_url, parent_document_origin, proto::ELEMENT_TYPE_UNSPECIFIED, 82 document_url, parent_document_origin, proto::ELEMENT_TYPE_UNSPECIFIED,
75 activation_type, 83 activation_type,
76 FirstPartyOrigin::IsThirdParty(document_url, parent_document_origin), 84 FirstPartyOrigin::IsThirdParty(document_url, parent_document_origin),
77 false); 85 false, nullptr);
78 } 86 }
79 87
80 bool IndexedRulesetMatcher::ShouldDisallowResourceLoad( 88 bool IndexedRulesetMatcher::ShouldDisallowResourceLoad(
81 const GURL& url, 89 const GURL& url,
82 const FirstPartyOrigin& first_party, 90 const FirstPartyOrigin& first_party,
83 proto::ElementType element_type, 91 proto::ElementType element_type,
84 bool disable_generic_rules) const { 92 bool disable_generic_rules) const {
85 const bool is_third_party = first_party.IsThirdParty(url); 93 const bool is_third_party = first_party.IsThirdParty(url);
86 return !!blacklist_.FindMatch(url, first_party.origin(), element_type, 94 return !!blacklist_.FindMatch(url, first_party.origin(), element_type,
87 proto::ACTIVATION_TYPE_UNSPECIFIED, 95 proto::ACTIVATION_TYPE_UNSPECIFIED,
88 is_third_party, disable_generic_rules) && 96 is_third_party, disable_generic_rules,
97 recorder_.get()) &&
89 !whitelist_.FindMatch(url, first_party.origin(), element_type, 98 !whitelist_.FindMatch(url, first_party.origin(), element_type,
90 proto::ACTIVATION_TYPE_UNSPECIFIED, 99 proto::ACTIVATION_TYPE_UNSPECIFIED,
91 is_third_party, disable_generic_rules); 100 is_third_party, disable_generic_rules,
101 recorder_.get());
92 } 102 }
93 103
94 } // namespace subresource_filter 104 } // namespace subresource_filter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698