OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/safe_browsing/safe_browsing_store.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_store.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/task.h" | |
10 | |
11 namespace { | 9 namespace { |
12 | 10 |
13 // Find items matching between |subs| and |adds|, and remove them, | 11 // Find items matching between |subs| and |adds|, and remove them, |
14 // recording the item from |adds| in |adds_removed|. To minimize | 12 // recording the item from |adds| in |adds_removed|. To minimize |
15 // copies, the inputs are processing in parallel, so |subs| and |adds| | 13 // copies, the inputs are processing in parallel, so |subs| and |adds| |
16 // should be compatibly ordered (either by SBAddPrefixLess or | 14 // should be compatibly ordered (either by SBAddPrefixLess or |
17 // SBAddPrefixHashLess). | 15 // SBAddPrefixHashLess). |
18 // | 16 // |
19 // |predAS| provides add < sub, |predSA| provides sub < add, for the | 17 // |predAS| provides add < sub, |predSA| provides sub < add, for the |
20 // tightest compare appropriate (see calls in SBProcessSubs). | 18 // tightest compare appropriate (see calls in SBProcessSubs). |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 std::vector<SBSubFullHash>* sub_full_hashes, | 127 std::vector<SBSubFullHash>* sub_full_hashes, |
130 const base::hash_set<int32>& add_chunks_deleted, | 128 const base::hash_set<int32>& add_chunks_deleted, |
131 const base::hash_set<int32>& sub_chunks_deleted) { | 129 const base::hash_set<int32>& sub_chunks_deleted) { |
132 // It is possible to structure templates and template | 130 // It is possible to structure templates and template |
133 // specializations such that the following calls work without having | 131 // specializations such that the following calls work without having |
134 // to qualify things. It becomes very arbitrary, though, and less | 132 // to qualify things. It becomes very arbitrary, though, and less |
135 // clear how things are working. | 133 // clear how things are working. |
136 | 134 |
137 // Sort the inputs by the SBAddPrefix bits. | 135 // Sort the inputs by the SBAddPrefix bits. |
138 std::sort(add_prefixes->begin(), add_prefixes->end(), | 136 std::sort(add_prefixes->begin(), add_prefixes->end(), |
139 SBAddPrefixLess<SBAddPrefix, SBAddPrefix>); | 137 SBAddPrefixLess<SBAddPrefix,SBAddPrefix>); |
140 std::sort(sub_prefixes->begin(), sub_prefixes->end(), | 138 std::sort(sub_prefixes->begin(), sub_prefixes->end(), |
141 SBAddPrefixLess<SBSubPrefix, SBSubPrefix>); | 139 SBAddPrefixLess<SBSubPrefix,SBSubPrefix>); |
142 std::sort(add_full_hashes->begin(), add_full_hashes->end(), | 140 std::sort(add_full_hashes->begin(), add_full_hashes->end(), |
143 SBAddPrefixHashLess<SBAddFullHash, SBAddFullHash>); | 141 SBAddPrefixHashLess<SBAddFullHash,SBAddFullHash>); |
144 std::sort(sub_full_hashes->begin(), sub_full_hashes->end(), | 142 std::sort(sub_full_hashes->begin(), sub_full_hashes->end(), |
145 SBAddPrefixHashLess<SBSubFullHash, SBSubFullHash>); | 143 SBAddPrefixHashLess<SBSubFullHash,SBSubFullHash>); |
146 | 144 |
147 // Factor out the prefix subs. | 145 // Factor out the prefix subs. |
148 std::vector<SBAddPrefix> removed_adds; | 146 std::vector<SBAddPrefix> removed_adds; |
149 KnockoutSubs(sub_prefixes, add_prefixes, | 147 KnockoutSubs(sub_prefixes, add_prefixes, |
150 SBAddPrefixLess<SBAddPrefix, SBSubPrefix>, | 148 SBAddPrefixLess<SBAddPrefix,SBSubPrefix>, |
151 SBAddPrefixLess<SBSubPrefix, SBAddPrefix>, | 149 SBAddPrefixLess<SBSubPrefix,SBAddPrefix>, |
152 &removed_adds); | 150 &removed_adds); |
153 | 151 |
154 // Remove the full-hashes corrosponding to the adds which | 152 // Remove the full-hashes corrosponding to the adds which |
155 // KnockoutSubs() removed. Processing these w/in KnockoutSubs() | 153 // KnockoutSubs() removed. Processing these w/in KnockoutSubs() |
156 // would make the code more complicated, and they are very small | 154 // would make the code more complicated, and they are very small |
157 // relative to the prefix lists so the gain would be modest. | 155 // relative to the prefix lists so the gain would be modest. |
158 RemoveMatchingPrefixes(removed_adds, add_full_hashes); | 156 RemoveMatchingPrefixes(removed_adds, add_full_hashes); |
159 RemoveMatchingPrefixes(removed_adds, sub_full_hashes); | 157 RemoveMatchingPrefixes(removed_adds, sub_full_hashes); |
160 | 158 |
161 // http://crbug.com/52385 | 159 // http://crbug.com/52385 |
162 // TODO(shess): AFAICT this pass is not done on the trunk. I | 160 // TODO(shess): AFAICT this pass is not done on the trunk. I |
163 // believe that's a bug, but it may not matter because full-hash | 161 // believe that's a bug, but it may not matter because full-hash |
164 // subs almost never happen (I think you'd need multiple collisions | 162 // subs almost never happen (I think you'd need multiple collisions |
165 // where one of the sites stopped being flagged?). Enable this once | 163 // where one of the sites stopped being flagged?). Enable this once |
166 // everything is in. [if(0) instead of #ifdef 0 to make sure it | 164 // everything is in. [if(0) instead of #ifdef 0 to make sure it |
167 // compiles.] | 165 // compiles.] |
168 if (0) { | 166 if (0) { |
169 // Factor out the full-hash subs. | 167 // Factor out the full-hash subs. |
170 std::vector<SBAddFullHash> removed_full_adds; | 168 std::vector<SBAddFullHash> removed_full_adds; |
171 KnockoutSubs(sub_full_hashes, add_full_hashes, | 169 KnockoutSubs(sub_full_hashes, add_full_hashes, |
172 SBAddPrefixHashLess<SBAddFullHash, SBSubFullHash>, | 170 SBAddPrefixHashLess<SBAddFullHash,SBSubFullHash>, |
173 SBAddPrefixHashLess<SBSubFullHash, SBAddFullHash>, | 171 SBAddPrefixHashLess<SBSubFullHash,SBAddFullHash>, |
174 &removed_full_adds); | 172 &removed_full_adds); |
175 } | 173 } |
176 | 174 |
177 // Remove items from the deleted chunks. This is done after other | 175 // Remove items from the deleted chunks. This is done after other |
178 // processing to allow subs to knock out adds (and be removed) even | 176 // processing to allow subs to knock out adds (and be removed) even |
179 // if the add's chunk is deleted. | 177 // if the add's chunk is deleted. |
180 RemoveDeleted(add_prefixes, add_chunks_deleted); | 178 RemoveDeleted(add_prefixes, add_chunks_deleted); |
181 RemoveDeleted(sub_prefixes, sub_chunks_deleted); | 179 RemoveDeleted(sub_prefixes, sub_chunks_deleted); |
182 RemoveDeleted(add_full_hashes, add_chunks_deleted); | 180 RemoveDeleted(add_full_hashes, add_chunks_deleted); |
183 RemoveDeleted(sub_full_hashes, sub_chunks_deleted); | 181 RemoveDeleted(sub_full_hashes, sub_chunks_deleted); |
184 } | 182 } |
OLD | NEW |