OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 // Erase any leftover gap. | 69 // Erase any leftover gap. |
70 adds->erase(add_out, add_iter); | 70 adds->erase(add_out, add_iter); |
71 subs->erase(sub_out, sub_iter); | 71 subs->erase(sub_out, sub_iter); |
72 } | 72 } |
73 | 73 |
74 // Remove deleted items (|chunk_id| in |del_set|) from the container. | 74 // Remove deleted items (|chunk_id| in |del_set|) from the container. |
75 template <typename ItemsT> | 75 template <typename ItemsT> |
76 void RemoveDeleted(ItemsT* items, const base::hash_set<int32>& del_set) { | 76 void RemoveDeleted(ItemsT* items, const base::hash_set<int32_t>& del_set) { |
77 DCHECK(items); | 77 DCHECK(items); |
78 | 78 |
79 // Move items from |iter| to |end_iter|, skipping items in |del_set|. | 79 // Move items from |iter| to |end_iter|, skipping items in |del_set|. |
80 typename ItemsT::iterator end_iter = items->begin(); | 80 typename ItemsT::iterator end_iter = items->begin(); |
81 for (typename ItemsT::iterator iter = end_iter; | 81 for (typename ItemsT::iterator iter = end_iter; |
82 iter != items->end(); ++iter) { | 82 iter != items->end(); ++iter) { |
83 if (del_set.count(iter->chunk_id) == 0) { | 83 if (del_set.count(iter->chunk_id) == 0) { |
84 *end_iter = *iter; | 84 *end_iter = *iter; |
85 ++end_iter; | 85 ++end_iter; |
86 } | 86 } |
87 } | 87 } |
88 items->erase(end_iter, items->end()); | 88 items->erase(end_iter, items->end()); |
89 } | 89 } |
90 | 90 |
91 } // namespace | 91 } // namespace |
92 | 92 |
93 namespace safe_browsing { | 93 namespace safe_browsing { |
94 | 94 |
95 void SBProcessSubs(SBAddPrefixes* add_prefixes, | 95 void SBProcessSubs(SBAddPrefixes* add_prefixes, |
96 SBSubPrefixes* sub_prefixes, | 96 SBSubPrefixes* sub_prefixes, |
97 std::vector<SBAddFullHash>* add_full_hashes, | 97 std::vector<SBAddFullHash>* add_full_hashes, |
98 std::vector<SBSubFullHash>* sub_full_hashes, | 98 std::vector<SBSubFullHash>* sub_full_hashes, |
99 const base::hash_set<int32>& add_chunks_deleted, | 99 const base::hash_set<int32_t>& add_chunks_deleted, |
100 const base::hash_set<int32>& sub_chunks_deleted) { | 100 const base::hash_set<int32_t>& sub_chunks_deleted) { |
101 // It is possible to structure templates and template | 101 // It is possible to structure templates and template |
102 // specializations such that the following calls work without having | 102 // specializations such that the following calls work without having |
103 // to qualify things. It becomes very arbitrary, though, and less | 103 // to qualify things. It becomes very arbitrary, though, and less |
104 // clear how things are working. | 104 // clear how things are working. |
105 | 105 |
106 // Make sure things are sorted appropriately. | 106 // Make sure things are sorted appropriately. |
107 DCHECK(sorted(add_prefixes->begin(), add_prefixes->end(), | 107 DCHECK(sorted(add_prefixes->begin(), add_prefixes->end(), |
108 SBAddPrefixLess<SBAddPrefix,SBAddPrefix>)); | 108 SBAddPrefixLess<SBAddPrefix,SBAddPrefix>)); |
109 DCHECK(sorted(sub_prefixes->begin(), sub_prefixes->end(), | 109 DCHECK(sorted(sub_prefixes->begin(), sub_prefixes->end(), |
110 SBAddPrefixLess<SBSubPrefix,SBSubPrefix>)); | 110 SBAddPrefixLess<SBSubPrefix,SBSubPrefix>)); |
(...skipping 15 matching lines...) Expand all Loading... |
126 // Remove items from the deleted chunks. This is done after other | 126 // Remove items from the deleted chunks. This is done after other |
127 // processing to allow subs to knock out adds (and be removed) even | 127 // processing to allow subs to knock out adds (and be removed) even |
128 // if the add's chunk is deleted. | 128 // if the add's chunk is deleted. |
129 RemoveDeleted(add_prefixes, add_chunks_deleted); | 129 RemoveDeleted(add_prefixes, add_chunks_deleted); |
130 RemoveDeleted(sub_prefixes, sub_chunks_deleted); | 130 RemoveDeleted(sub_prefixes, sub_chunks_deleted); |
131 RemoveDeleted(add_full_hashes, add_chunks_deleted); | 131 RemoveDeleted(add_full_hashes, add_chunks_deleted); |
132 RemoveDeleted(sub_full_hashes, sub_chunks_deleted); | 132 RemoveDeleted(sub_full_hashes, sub_chunks_deleted); |
133 } | 133 } |
134 | 134 |
135 } // namespace safe_browsing | 135 } // namespace safe_browsing |
OLD | NEW |