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