| 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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, | 248 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, |
| 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 class V4StoreTest; | 259 friend class V4StoreTest; |
| 259 | 260 |
| 260 // If |prefix_size| is within expected range, and |raw_hashes_length| is a | 261 // If |prefix_size| is within expected range, and |raw_hashes_length| is a |
| 261 // multiple of prefix_size, then it sets the string of length | 262 // multiple of prefix_size, then it sets the string of length |
| 262 // |raw_hashes_length| starting at |raw_hashes_begin| as the value at key | 263 // |raw_hashes_length| starting at |raw_hashes_begin| as the value at key |
| 263 // |prefix_size| in |additions_map| | 264 // |prefix_size| in |additions_map| |
| 264 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, | 265 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size, |
| 265 const char* raw_hashes_begin, | 266 const char* raw_hashes_begin, |
| 266 const size_t raw_hashes_length, | 267 const size_t raw_hashes_length, |
| 267 HashPrefixMap* additions_map); | 268 HashPrefixMap* additions_map); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 StoreReadResult ReadFromDisk(); | 355 StoreReadResult ReadFromDisk(); |
| 355 | 356 |
| 356 // Updates the |additions_map| with the additions received in the partial | 357 // Updates the |additions_map| with the additions received in the partial |
| 357 // update from the server. The UMA metrics for all interesting sub-operations | 358 // update from the server. The UMA metrics for all interesting sub-operations |
| 358 // use the prefix |metric|. | 359 // use the prefix |metric|. |
| 359 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( | 360 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( |
| 360 const std::string& metric, | 361 const std::string& metric, |
| 361 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, | 362 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, |
| 362 HashPrefixMap* additions_map); | 363 HashPrefixMap* additions_map); |
| 363 | 364 |
| 364 // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. | 365 // Writes the hash_prefix_map_ to disk as a V4StoreFileFormat proto. |
| 365 StoreWriteResult WriteToDisk( | 366 // |checksum| is used to set the |checksum| field in the final proto. |
| 366 std::unique_ptr<ListUpdateResponse> response) const; | 367 StoreWriteResult WriteToDisk(const Checksum& checksum) const; |
| 367 | 368 |
| 368 // The checksum value as read from the disk, until it is verified. Once | 369 // The checksum value as read from the disk, until it is verified. Once |
| 369 // verified, it is cleared. | 370 // verified, it is cleared. |
| 370 std::string expected_checksum_; | 371 std::string expected_checksum_; |
| 371 | 372 |
| 372 // The state of the store as returned by the PVer4 server in the last applied | 373 // The state of the store as returned by the PVer4 server in the last applied |
| 373 // update response. | 374 // update response. |
| 374 std::string state_; | 375 std::string state_; |
| 375 const base::FilePath store_path_; | 376 const base::FilePath store_path_; |
| 376 HashPrefixMap hash_prefix_map_; | 377 HashPrefixMap hash_prefix_map_; |
| 377 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 378 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 378 }; | 379 }; |
| 379 | 380 |
| 380 std::ostream& operator<<(std::ostream& os, const V4Store& store); | 381 std::ostream& operator<<(std::ostream& os, const V4Store& store); |
| 381 | 382 |
| 382 } // namespace safe_browsing | 383 } // namespace safe_browsing |
| 383 | 384 |
| 384 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ | 385 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ |
| OLD | NEW |