| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 TestHashPrefixExistsInMapWithDifferentSizes); | 249 TestHashPrefixExistsInMapWithDifferentSizes); |
| 250 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 250 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
| 251 TestHashPrefixDoesNotExistInMapWithDifferentSizes); | 251 TestHashPrefixDoesNotExistInMapWithDifferentSizes); |
| 252 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 252 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
| 253 TestAdditionsWithRiceEncodingFailsWithInvalidInput); | 253 TestAdditionsWithRiceEncodingFailsWithInvalidInput); |
| 254 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds); | 254 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds); |
| 255 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds); | 255 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds); |
| 256 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesFailsChecksum); | 256 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesFailsChecksum); |
| 257 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestChecksumErrorOnStartup); | 257 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestChecksumErrorOnStartup); |
| 258 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, WriteToDiskFails); | 258 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, WriteToDiskFails); |
| 259 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, FullUpdateFailsChecksumSynchronously); |
| 259 friend class V4StoreTest; | 260 friend class V4StoreTest; |
| 260 | 261 |
| 261 // If |prefix_size| is within expected range, and |raw_hashes_length| is a | 262 // If |prefix_size| is within expected range, and |raw_hashes_length| is a |
| 262 // multiple of prefix_size, then it sets the string of length | 263 // multiple of prefix_size, then it sets the string of length |
| 263 // |raw_hashes_length| starting at |raw_hashes_begin| as the value at key | 264 // |raw_hashes_length| starting at |raw_hashes_begin| as the value at key |
| 264 // |prefix_size| in |additions_map| | 265 // |prefix_size| in |additions_map| |
| 265 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, | 266 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, |
| 266 const char* raw_hashes_begin, | 267 const char* raw_hashes_begin, |
| 267 const size_t raw_hashes_length, | 268 const size_t raw_hashes_length, |
| 268 HashPrefixMap* additions_map); | 269 HashPrefixMap* additions_map); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 299 // be small and infrequent. | 300 // be small and infrequent. |
| 300 static void ReserveSpaceInPrefixMap(const HashPrefixMap& other_prefixes_map, | 301 static void ReserveSpaceInPrefixMap(const HashPrefixMap& other_prefixes_map, |
| 301 HashPrefixMap* prefix_map_to_update); | 302 HashPrefixMap* prefix_map_to_update); |
| 302 | 303 |
| 303 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the | 304 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the |
| 304 // update (additions_map) to populate the prefix map for the current store. | 305 // update (additions_map) to populate the prefix map for the current store. |
| 305 // The indices in the |raw_removals| list, which may be NULL, are not merged. | 306 // The indices in the |raw_removals| list, which may be NULL, are not merged. |
| 306 // The SHA256 checksum of the final list of hash prefixes, in | 307 // The SHA256 checksum of the final list of hash prefixes, in |
| 307 // lexicographically sorted order, must match |expected_checksum| (if it's not | 308 // lexicographically sorted order, must match |expected_checksum| (if it's not |
| 308 // empty). | 309 // empty). |
| 309 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map, | 310 ApplyUpdateResult MergeUpdate( |
| 310 const HashPrefixMap& additions_map, | 311 const HashPrefixMap& old_hash_prefix_map, |
| 311 const ::google::protobuf::RepeatedField< | 312 const HashPrefixMap& additions_map, |
| 312 ::google::protobuf::int32>* raw_removals, | 313 const ::google::protobuf::RepeatedField<::google::protobuf::int32>* |
| 313 const std::string& expected_checksum); | 314 raw_removals, |
| 315 const std::string& expected_checksum); |
| 314 | 316 |
| 315 // Processes the FULL_UPDATE |response| from the server, and writes the | 317 // Processes the FULL_UPDATE |response| from the server, and writes the |
| 316 // merged V4Store to disk. If processing the |response| succeeds, it returns | 318 // merged V4Store to disk. If processing the |response| succeeds, it returns |
| 317 // APPLY_UPDATE_SUCCESS. The UMA metrics for all interesting sub-operations | 319 // APPLY_UPDATE_SUCCESS. The UMA metrics for all interesting sub-operations |
| 318 // use the prefix |metric|. | 320 // use the prefix |metric|. |
| 319 // This method is only called when we receive a FULL_UPDATE from the server. | 321 // This method is only called when we receive a FULL_UPDATE from the server. |
| 320 ApplyUpdateResult ProcessFullUpdateAndWriteToDisk( | 322 ApplyUpdateResult ProcessFullUpdateAndWriteToDisk( |
| 321 const std::string& metric, | 323 const std::string& metric, |
| 322 std::unique_ptr<ListUpdateResponse> response); | 324 std::unique_ptr<ListUpdateResponse> response); |
| 323 | 325 |
| 324 // Processes a FULL_UPDATE |response| and updates the V4Store. If processing | 326 // Processes a FULL_UPDATE |response| and updates the V4Store. If processing |
| 325 // the |response| succeeds, it returns APPLY_UPDATE_SUCCESS. | 327 // the |response| succeeds, it returns APPLY_UPDATE_SUCCESS. |
| 326 // This method is called when we receive a FULL_UPDATE from the server, and | 328 // This method is called when we receive a FULL_UPDATE from the server, and |
| 327 // when we read a store file from disk on startup. The UMA metrics for all | 329 // when we read a store file from disk on startup. The UMA metrics for all |
| 328 // interesting sub-operations use the prefix |metric|. | 330 // interesting sub-operations use the prefix |metric|. Delays the checksum |
| 331 // check if |delay_checksum_check| is true. |
| 329 ApplyUpdateResult ProcessFullUpdate( | 332 ApplyUpdateResult ProcessFullUpdate( |
| 330 const std::string& metric, | 333 const std::string& metric, |
| 331 const std::unique_ptr<ListUpdateResponse>& response); | 334 const std::unique_ptr<ListUpdateResponse>& response, |
| 335 bool delay_checksum_check); |
| 332 | 336 |
| 333 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, updates | 337 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, updates |
| 334 // the |hash_prefix_map_| and |state_| in the V4Store, and writes the merged | 338 // the |hash_prefix_map_| and |state_| in the V4Store, and writes the merged |
| 335 // store to disk. If processing succeeds, it returns APPLY_UPDATE_SUCCESS. | 339 // store to disk. If processing succeeds, it returns APPLY_UPDATE_SUCCESS. |
| 336 // This method is only called when we receive a PARTIAL_UPDATE from the | 340 // This method is only called when we receive a PARTIAL_UPDATE from the |
| 337 // server. The UMA metrics for all interesting sub-operations use the prefix | 341 // server. The UMA metrics for all interesting sub-operations use the prefix |
| 338 // |metric|. | 342 // |metric|. |
| 339 ApplyUpdateResult ProcessPartialUpdateAndWriteToDisk( | 343 ApplyUpdateResult ProcessPartialUpdateAndWriteToDisk( |
| 340 const std::string& metric, | 344 const std::string& metric, |
| 341 const HashPrefixMap& hash_prefix_map_old, | 345 const HashPrefixMap& hash_prefix_map_old, |
| 342 std::unique_ptr<ListUpdateResponse> response); | 346 std::unique_ptr<ListUpdateResponse> response); |
| 343 | 347 |
| 344 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, and | 348 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, and |
| 345 // updates the |hash_prefix_map_| and |state_| in the V4Store. If processing | 349 // updates the |hash_prefix_map_| and |state_| in the V4Store. If processing |
| 346 // succeeds, it returns APPLY_UPDATE_SUCCESS. The UMA metrics for all | 350 // succeeds, it returns APPLY_UPDATE_SUCCESS. The UMA metrics for all |
| 347 // interesting sub-operations use the prefix |metric|. | 351 // interesting sub-operations use the prefix |metric|. Delays the checksum |
| 352 // check if |delay_checksum_check| is true. |
| 348 ApplyUpdateResult ProcessUpdate( | 353 ApplyUpdateResult ProcessUpdate( |
| 349 const std::string& metric, | 354 const std::string& metric, |
| 350 const HashPrefixMap& hash_prefix_map_old, | 355 const HashPrefixMap& hash_prefix_map_old, |
| 351 const std::unique_ptr<ListUpdateResponse>& response); | 356 const std::unique_ptr<ListUpdateResponse>& response, |
| 357 bool delay_checksum_check); |
| 352 | 358 |
| 353 // Reads the state of the store from the file on disk and returns the reason | 359 // Reads the state of the store from the file on disk and returns the reason |
| 354 // for the failure or reports success. | 360 // for the failure or reports success. |
| 355 StoreReadResult ReadFromDisk(); | 361 StoreReadResult ReadFromDisk(); |
| 356 | 362 |
| 357 // Updates the |additions_map| with the additions received in the partial | 363 // Updates the |additions_map| with the additions received in the partial |
| 358 // update from the server. The UMA metrics for all interesting sub-operations | 364 // update from the server. The UMA metrics for all interesting sub-operations |
| 359 // use the prefix |metric|. | 365 // use the prefix |metric|. |
| 360 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( | 366 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( |
| 361 const std::string& metric, | 367 const std::string& metric, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 376 const base::FilePath store_path_; | 382 const base::FilePath store_path_; |
| 377 HashPrefixMap hash_prefix_map_; | 383 HashPrefixMap hash_prefix_map_; |
| 378 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 384 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 379 }; | 385 }; |
| 380 | 386 |
| 381 std::ostream& operator<<(std::ostream& os, const V4Store& store); | 387 std::ostream& operator<<(std::ostream& os, const V4Store& store); |
| 382 | 388 |
| 383 } // namespace safe_browsing | 389 } // namespace safe_browsing |
| 384 | 390 |
| 385 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ | 391 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ |
| OLD | NEW |