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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 126 |
127 // The update received from the server contains a prefix that's already | 127 // The update received from the server contains a prefix that's already |
128 // present in the map. | 128 // present in the map. |
129 ADDITIONS_HAS_EXISTING_PREFIX_FAILURE = 5, | 129 ADDITIONS_HAS_EXISTING_PREFIX_FAILURE = 5, |
130 | 130 |
131 // The server sent a response_type that the client did not expect. | 131 // The server sent a response_type that the client did not expect. |
132 UNEXPECTED_RESPONSE_TYPE_FAILURE = 6, | 132 UNEXPECTED_RESPONSE_TYPE_FAILURE = 6, |
133 | 133 |
134 // One of more index(es) in removals field of the response is greater than | 134 // One of more index(es) in removals field of the response is greater than |
135 // the number of hash prefixes currently in the (old) store. | 135 // the number of hash prefixes currently in the (old) store. |
136 REMOVALS_INDEX_TOO_LARGE = 7, | 136 REMOVALS_INDEX_TOO_LARGE_FAILURE = 7, |
| 137 |
| 138 // Failed to decode the Rice-encoded additions/removals field. |
| 139 RICE_DECODING_FAILURE = 8, |
| 140 |
| 141 // Compression type other than RAW and RICE for additions. |
| 142 UNEXPECTED_COMPRESSION_TYPE_ADDITIONS_FAILURE = 9, |
| 143 |
| 144 // Compression type other than RAW and RICE for removals. |
| 145 UNEXPECTED_COMPRESSION_TYPE_REMOVALS_FAILURE = 10, |
137 | 146 |
138 // Memory space for histograms is determined by the max. ALWAYS | 147 // Memory space for histograms is determined by the max. ALWAYS |
139 // ADD NEW VALUES BEFORE THIS ONE. | 148 // ADD NEW VALUES BEFORE THIS ONE. |
140 APPLY_UPDATE_RESULT_MAX | 149 APPLY_UPDATE_RESULT_MAX |
141 }; | 150 }; |
142 | 151 |
143 // Factory for creating V4Store. Tests implement this factory to create fake | 152 // Factory for creating V4Store. Tests implement this factory to create fake |
144 // stores for testing. | 153 // stores for testing. |
145 class V4StoreFactory { | 154 class V4StoreFactory { |
146 public: | 155 public: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 TestHashPrefixDoesNotExistInConcatenatedList); | 240 TestHashPrefixDoesNotExistInConcatenatedList); |
232 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestFullHashExistsInMapWithSingleSize); | 241 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestFullHashExistsInMapWithSingleSize); |
233 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 242 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
234 TestFullHashExistsInMapWithDifferentSizes); | 243 TestFullHashExistsInMapWithDifferentSizes); |
235 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 244 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
236 TestHashPrefixExistsInMapWithSingleSize); | 245 TestHashPrefixExistsInMapWithSingleSize); |
237 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 246 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
238 TestHashPrefixExistsInMapWithDifferentSizes); | 247 TestHashPrefixExistsInMapWithDifferentSizes); |
239 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 248 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
240 TestHashPrefixDoesNotExistInMapWithDifferentSizes); | 249 TestHashPrefixDoesNotExistInMapWithDifferentSizes); |
| 250 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
| 251 TestAdditionsWithRiceEncodingFailsWithInvalidInput); |
| 252 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds); |
| 253 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds); |
| 254 friend class V4StoreTest; |
241 | 255 |
242 // If |prefix_size| is within expected range, and |raw_hashes| is not invalid, | 256 // If |prefix_size| is within expected range, and |raw_hashes| is not invalid, |
243 // then it sets |raw_hashes| as the value at key |prefix_size| in | 257 // then it sets |raw_hashes| as the value at key |prefix_size| in |
244 // |additions_map| | 258 // |additions_map| |
245 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, | 259 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, |
246 const std::string& raw_hashes, | 260 const std::string& raw_hashes, |
247 HashPrefixMap* additions_map); | 261 HashPrefixMap* additions_map); |
248 | 262 |
249 // Get the next unmerged hash prefix in dictionary order from | 263 // Get the next unmerged hash prefix in dictionary order from |
250 // |hash_prefix_map|. |iterator_map| is used to determine which hash prefixes | 264 // |hash_prefix_map|. |iterator_map| is used to determine which hash prefixes |
(...skipping 29 matching lines...) Expand all Loading... |
280 HashPrefixMap* additions_map); | 294 HashPrefixMap* additions_map); |
281 | 295 |
282 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the | 296 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the |
283 // update (additions_map) to populate the prefix map for the current store. | 297 // update (additions_map) to populate the prefix map for the current store. |
284 // The indices in the |raw_removals| list, which may be NULL, are not merged. | 298 // The indices in the |raw_removals| list, which may be NULL, are not merged. |
285 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map, | 299 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map, |
286 const HashPrefixMap& additions_map, | 300 const HashPrefixMap& additions_map, |
287 const ::google::protobuf::RepeatedField< | 301 const ::google::protobuf::RepeatedField< |
288 ::google::protobuf::int32>* raw_removals); | 302 ::google::protobuf::int32>* raw_removals); |
289 | 303 |
| 304 // Processes the FULL_UPDATE |response| from the server and updates the |
| 305 // V4Store in |new_store| and writes it to disk. If processing the |response| |
| 306 // succeeds, it returns APPLY_UPDATE_SUCCESS. |
| 307 ApplyUpdateResult ProcessFullUpdate( |
| 308 std::unique_ptr<ListUpdateResponse> response, |
| 309 const std::unique_ptr<V4Store>& new_store); |
| 310 |
| 311 // Processes the PARTIAL_UPDATE |response| from the server and updates the |
| 312 // V4Store in |new_store|. If processing the |response| succeeds, it returns |
| 313 // APPLY_UPDATE_SUCCESS. |
| 314 ApplyUpdateResult ProcessPartialUpdate( |
| 315 std::unique_ptr<ListUpdateResponse> response, |
| 316 const std::unique_ptr<V4Store>& new_store); |
| 317 |
290 // Reads the state of the store from the file on disk and returns the reason | 318 // Reads the state of the store from the file on disk and returns the reason |
291 // for the failure or reports success. | 319 // for the failure or reports success. |
292 StoreReadResult ReadFromDisk(); | 320 StoreReadResult ReadFromDisk(); |
293 | 321 |
294 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. | 322 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. |
295 StoreWriteResult WriteToDisk( | 323 StoreWriteResult WriteToDisk( |
296 std::unique_ptr<ListUpdateResponse> response) const; | 324 std::unique_ptr<ListUpdateResponse> response) const; |
297 | 325 |
298 // The state of the store as returned by the PVer4 server in the last applied | 326 // The state of the store as returned by the PVer4 server in the last applied |
299 // update response. | 327 // update response. |
300 std::string state_; | 328 std::string state_; |
301 const base::FilePath store_path_; | 329 const base::FilePath store_path_; |
302 HashPrefixMap hash_prefix_map_; | 330 HashPrefixMap hash_prefix_map_; |
303 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 331 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
304 }; | 332 }; |
305 | 333 |
306 std::ostream& operator<<(std::ostream& os, const V4Store& store); | 334 std::ostream& operator<<(std::ostream& os, const V4Store& store); |
307 | 335 |
308 } // namespace safe_browsing | 336 } // namespace safe_browsing |
309 | 337 |
310 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ | 338 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ |
OLD | NEW |