OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ | 5 #ifndef COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ |
6 #define COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ | 6 #define COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 // The number of bytes in additions isn't a multiple of prefix size. | 121 // The number of bytes in additions isn't a multiple of prefix size. |
122 ADDITIONS_SIZE_UNEXPECTED_FAILURE = 4, | 122 ADDITIONS_SIZE_UNEXPECTED_FAILURE = 4, |
123 | 123 |
124 // The update received from the server contains a prefix that's already | 124 // The update received from the server contains a prefix that's already |
125 // present in the map. | 125 // present in the map. |
126 ADDITIONS_HAS_EXISTING_PREFIX_FAILURE = 5, | 126 ADDITIONS_HAS_EXISTING_PREFIX_FAILURE = 5, |
127 | 127 |
128 // The server sent a response_type that the client did not expect. | 128 // The server sent a response_type that the client did not expect. |
129 UNEXPECTED_RESPONSE_TYPE_FAILURE = 6, | 129 UNEXPECTED_RESPONSE_TYPE_FAILURE = 6, |
130 | 130 |
131 // One of more index(es) in removals field of the response is greater than | |
132 // the number of hash prefixes currently in the (old) store. | |
133 REMOVALS_INDEX_TOO_LARGE = 7, | |
134 | |
131 // Memory space for histograms is determined by the max. ALWAYS | 135 // Memory space for histograms is determined by the max. ALWAYS |
132 // ADD NEW VALUES BEFORE THIS ONE. | 136 // ADD NEW VALUES BEFORE THIS ONE. |
133 APPLY_UPDATE_RESULT_MAX | 137 APPLY_UPDATE_RESULT_MAX |
134 }; | 138 }; |
135 | 139 |
136 // Factory for creating V4Store. Tests implement this factory to create fake | 140 // Factory for creating V4Store. Tests implement this factory to create fake |
137 // stores for testing. | 141 // stores for testing. |
138 class V4StoreFactory { | 142 class V4StoreFactory { |
139 public: | 143 public: |
140 virtual ~V4StoreFactory() {} | 144 virtual ~V4StoreFactory() {} |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestGetNextSmallestUnmergedPrefix); | 194 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestGetNextSmallestUnmergedPrefix); |
191 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesWithSameSizesInEachMap); | 195 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesWithSameSizesInEachMap); |
192 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 196 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
193 TestMergeUpdatesWithDifferentSizesInEachMap); | 197 TestMergeUpdatesWithDifferentSizesInEachMap); |
194 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesOldMapRunsOutFirst); | 198 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesOldMapRunsOutFirst); |
195 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 199 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
196 TestMergeUpdatesAdditionsMapRunsOutFirst); | 200 TestMergeUpdatesAdditionsMapRunsOutFirst); |
197 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 201 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
198 TestMergeUpdatesFailsForRepeatedHashPrefix); | 202 TestMergeUpdatesFailsForRepeatedHashPrefix); |
199 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 203 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
204 TestMergeUpdatesFailsWhenRemovalsIndexTooLarge); | |
205 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesRemovesOnlyElement); | |
206 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesRemovesFirstElement); | |
207 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesRemovesMiddleElement); | |
208 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesRemovesLastElement); | |
209 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | |
210 TestMergeUpdatesRemovesWhenOldHasDifferentSizes); | |
211 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | |
212 TestMergeUpdatesRemovesMultipleAcrossDifferentSizes); | |
213 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | |
200 TestReadFullResponseWithValidHashPrefixMap); | 214 TestReadFullResponseWithValidHashPrefixMap); |
201 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 215 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
202 TestReadFullResponseWithInvalidHashPrefixMap); | 216 TestReadFullResponseWithInvalidHashPrefixMap); |
203 | 217 |
204 // If |prefix_size| is within expected range, and |raw_hashes| is not invalid, | 218 // If |prefix_size| is within expected range, and |raw_hashes| is not invalid, |
205 // then it sets |raw_hashes| as the value at key |prefix_size| in | 219 // then it sets |raw_hashes| as the value at key |prefix_size| in |
206 // |additions_map| | 220 // |additions_map| |
207 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, | 221 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, |
208 const std::string& raw_hashes, | 222 const std::string& raw_hashes, |
209 HashPrefixMap* additions_map); | 223 HashPrefixMap* additions_map); |
(...skipping 21 matching lines...) Expand all Loading... | |
231 HashPrefixMap* prefix_map_to_update); | 245 HashPrefixMap* prefix_map_to_update); |
232 | 246 |
233 // Updates the |additions_map| with the additions received in the partial | 247 // Updates the |additions_map| with the additions received in the partial |
234 // update from the server. | 248 // update from the server. |
235 static ApplyUpdateResult UpdateHashPrefixMapFromAdditions( | 249 static ApplyUpdateResult UpdateHashPrefixMapFromAdditions( |
236 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, | 250 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, |
237 HashPrefixMap* additions_map); | 251 HashPrefixMap* additions_map); |
238 | 252 |
239 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the | 253 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the |
240 // update (additions_map) to populate the prefix map for the current store. | 254 // update (additions_map) to populate the prefix map for the current store. |
241 // TODO(vakh): Process removals also. | 255 // TODO(vakh): Process removals also. |
Nathan Parker
2016/07/18 20:42:39
remove todo, and mention that raw_removals can be
vakh (use Gerrit instead)
2016/07/18 20:54:13
Done.
| |
242 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map, | 256 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map, |
243 const HashPrefixMap& additions_map); | 257 const HashPrefixMap& additions_map, |
258 const ::google::protobuf::RepeatedField< | |
259 ::google::protobuf::int32>* raw_removals); | |
244 | 260 |
245 // Reads the state of the store from the file on disk and returns the reason | 261 // Reads the state of the store from the file on disk and returns the reason |
246 // for the failure or reports success. | 262 // for the failure or reports success. |
247 StoreReadResult ReadFromDisk(); | 263 StoreReadResult ReadFromDisk(); |
248 | 264 |
249 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. | 265 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. |
250 StoreWriteResult WriteToDisk( | 266 StoreWriteResult WriteToDisk( |
251 std::unique_ptr<ListUpdateResponse> response) const; | 267 std::unique_ptr<ListUpdateResponse> response) const; |
252 | 268 |
253 // The state of the store as returned by the PVer4 server in the last applied | 269 // The state of the store as returned by the PVer4 server in the last applied |
254 // update response. | 270 // update response. |
255 std::string state_; | 271 std::string state_; |
256 const base::FilePath store_path_; | 272 const base::FilePath store_path_; |
257 HashPrefixMap hash_prefix_map_; | 273 HashPrefixMap hash_prefix_map_; |
258 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 274 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
259 }; | 275 }; |
260 | 276 |
261 std::ostream& operator<<(std::ostream& os, const V4Store& store); | 277 std::ostream& operator<<(std::ostream& os, const V4Store& store); |
262 | 278 |
263 } // namespace safe_browsing | 279 } // namespace safe_browsing |
264 | 280 |
265 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ | 281 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ |
OLD | NEW |