| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 // lexicographically sorted order, must match |expected_checksum| (if it's not | 306 // lexicographically sorted order, must match |expected_checksum| (if it's not |
| 307 // empty). | 307 // empty). |
| 308 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map, | 308 ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map, |
| 309 const HashPrefixMap& additions_map, | 309 const HashPrefixMap& additions_map, |
| 310 const ::google::protobuf::RepeatedField< | 310 const ::google::protobuf::RepeatedField< |
| 311 ::google::protobuf::int32>* raw_removals, | 311 ::google::protobuf::int32>* raw_removals, |
| 312 const std::string& expected_checksum); | 312 const std::string& expected_checksum); |
| 313 | 313 |
| 314 // Processes the FULL_UPDATE |response| from the server, and writes the | 314 // Processes the FULL_UPDATE |response| from the server, and writes the |
| 315 // merged V4Store to disk. If processing the |response| succeeds, it returns | 315 // merged V4Store to disk. If processing the |response| succeeds, it returns |
| 316 // APPLY_UPDATE_SUCCESS. | 316 // APPLY_UPDATE_SUCCESS. The UMA metrics for all interesting sub-operations |
| 317 // use the prefix |metric|. |
| 317 // This method is only called when we receive a FULL_UPDATE from the server. | 318 // This method is only called when we receive a FULL_UPDATE from the server. |
| 318 ApplyUpdateResult ProcessFullUpdateAndWriteToDisk( | 319 ApplyUpdateResult ProcessFullUpdateAndWriteToDisk( |
| 320 const std::string& metric, |
| 319 std::unique_ptr<ListUpdateResponse> response); | 321 std::unique_ptr<ListUpdateResponse> response); |
| 320 | 322 |
| 321 // Processes a FULL_UPDATE |response| and updates the V4Store. If processing | 323 // Processes a FULL_UPDATE |response| and updates the V4Store. If processing |
| 322 // the |response| succeeds, it returns APPLY_UPDATE_SUCCESS. | 324 // the |response| succeeds, it returns APPLY_UPDATE_SUCCESS. |
| 323 // This method is called when we receive a FULL_UPDATE from the server, and | 325 // This method is called when we receive a FULL_UPDATE from the server, and |
| 324 // when we read a store file from disk on startup. | 326 // when we read a store file from disk on startup. The UMA metrics for all |
| 327 // interesting sub-operations use the prefix |metric|. |
| 325 ApplyUpdateResult ProcessFullUpdate( | 328 ApplyUpdateResult ProcessFullUpdate( |
| 329 const std::string& metric, |
| 326 const std::unique_ptr<ListUpdateResponse>& response); | 330 const std::unique_ptr<ListUpdateResponse>& response); |
| 327 | 331 |
| 328 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, updates | 332 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, updates |
| 329 // the |hash_prefix_map_| and |state_| in the V4Store, and writes the merged | 333 // the |hash_prefix_map_| and |state_| in the V4Store, and writes the merged |
| 330 // store to disk. If processing succeeds, it returns APPLY_UPDATE_SUCCESS. | 334 // store to disk. If processing succeeds, it returns APPLY_UPDATE_SUCCESS. |
| 331 // This method is only called when we receive a PARTIAL_UPDATE from the | 335 // This method is only called when we receive a PARTIAL_UPDATE from the |
| 332 // server. | 336 // server. The UMA metrics for all interesting sub-operations use the prefix |
| 337 // |metric|. |
| 333 ApplyUpdateResult ProcessPartialUpdateAndWriteToDisk( | 338 ApplyUpdateResult ProcessPartialUpdateAndWriteToDisk( |
| 339 const std::string& metric, |
| 334 const HashPrefixMap& hash_prefix_map_old, | 340 const HashPrefixMap& hash_prefix_map_old, |
| 335 std::unique_ptr<ListUpdateResponse> response); | 341 std::unique_ptr<ListUpdateResponse> response); |
| 336 | 342 |
| 337 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, and | 343 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, and |
| 338 // updates the |hash_prefix_map_| and |state_| in the V4Store. If processing | 344 // updates the |hash_prefix_map_| and |state_| in the V4Store. If processing |
| 339 // succeeds, it returns APPLY_UPDATE_SUCCESS. | 345 // succeeds, it returns APPLY_UPDATE_SUCCESS. The UMA metrics for all |
| 346 // interesting sub-operations use the prefix |metric|. |
| 340 ApplyUpdateResult ProcessUpdate( | 347 ApplyUpdateResult ProcessUpdate( |
| 348 const std::string& metric, |
| 341 const HashPrefixMap& hash_prefix_map_old, | 349 const HashPrefixMap& hash_prefix_map_old, |
| 342 const std::unique_ptr<ListUpdateResponse>& response); | 350 const std::unique_ptr<ListUpdateResponse>& response); |
| 343 | 351 |
| 344 // Reads the state of the store from the file on disk and returns the reason | 352 // Reads the state of the store from the file on disk and returns the reason |
| 345 // for the failure or reports success. | 353 // for the failure or reports success. |
| 346 StoreReadResult ReadFromDisk(); | 354 StoreReadResult ReadFromDisk(); |
| 347 | 355 |
| 348 // Updates the |additions_map| with the additions received in the partial | 356 // Updates the |additions_map| with the additions received in the partial |
| 349 // update from the server. | 357 // update from the server. The UMA metrics for all interesting sub-operations |
| 358 // use the prefix |metric|. |
| 350 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( | 359 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( |
| 360 const std::string& metric, |
| 351 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, | 361 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, |
| 352 HashPrefixMap* additions_map); | 362 HashPrefixMap* additions_map); |
| 353 | 363 |
| 354 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. | 364 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. |
| 355 StoreWriteResult WriteToDisk( | 365 StoreWriteResult WriteToDisk( |
| 356 std::unique_ptr<ListUpdateResponse> response) const; | 366 std::unique_ptr<ListUpdateResponse> response) const; |
| 357 | 367 |
| 358 // The checksum value as read from the disk, until it is verified. Once | 368 // The checksum value as read from the disk, until it is verified. Once |
| 359 // verified, it is cleared. | 369 // verified, it is cleared. |
| 360 std::string expected_checksum_; | 370 std::string expected_checksum_; |
| 361 | 371 |
| 362 // The state of the store as returned by the PVer4 server in the last applied | 372 // The state of the store as returned by the PVer4 server in the last applied |
| 363 // update response. | 373 // update response. |
| 364 std::string state_; | 374 std::string state_; |
| 365 const base::FilePath store_path_; | 375 const base::FilePath store_path_; |
| 366 HashPrefixMap hash_prefix_map_; | 376 HashPrefixMap hash_prefix_map_; |
| 367 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 377 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 368 }; | 378 }; |
| 369 | 379 |
| 370 std::ostream& operator<<(std::ostream& os, const V4Store& store); | 380 std::ostream& operator<<(std::ostream& os, const V4Store& store); |
| 371 | 381 |
| 372 } // namespace safe_browsing | 382 } // namespace safe_browsing |
| 373 | 383 |
| 374 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ | 384 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ |
| OLD | NEW |