Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Unified Diff: components/safe_browsing_db/v4_store.h

Issue 2384893002: PVer4: Test checksum on startup outside the hotpath of DB load (Closed)
Patch Set: Verify that the checksum check happens async Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/safe_browsing_db/v4_store.h
diff --git a/components/safe_browsing_db/v4_store.h b/components/safe_browsing_db/v4_store.h
index f0172808c8f92d8b0df83b25a174801190c2ac8a..a2a89be440fbc1d185afb96838179dc31fdb80c6 100644
--- a/components/safe_browsing_db/v4_store.h
+++ b/components/safe_browsing_db/v4_store.h
@@ -180,8 +180,16 @@ class V4Store {
// of the hash prefixes.
void Initialize();
- // Reset internal state and delete the backing file.
- virtual bool Reset();
+ // Reset internal state.
+ void Reset();
+
+ // Scheduled after reading the store file from disk on startup. When run, it
+ // ensures that the checksum of the hash prefixes in lexicographical sorted
+ // order matches the expected value in |expected_checksum_|. Returns true if
+ // it matches; false otherwise. Checksum verification can take a long time,
+ // so it is performed outside of the hotpath of loading SafeBrowsing database,
+ // which blocks resource loads.
+ bool VerifyChecksum();
private:
FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromEmptyFile);
@@ -246,6 +254,7 @@ class V4Store {
FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds);
FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds);
FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesFailsChecksum);
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestChecksumErrorOnStartup);
friend class V4StoreTest;
// If |prefix_size| is within expected range, and |raw_hashes_length| is a
@@ -293,8 +302,9 @@ class V4Store {
// Merges the prefix map from the old store (|old_hash_prefix_map|) and the
// update (additions_map) to populate the prefix map for the current store.
// The indices in the |raw_removals| list, which may be NULL, are not merged.
- // The SHA256 checksum of the final list of hash prefixes, in lexographically
- // sorted order, must match |expected_checksum| (if it's not empty).
+ // The SHA256 checksum of the final list of hash prefixes, in
+ // lexicographically sorted order, must match |expected_checksum| (if it's not
+ // empty).
ApplyUpdateResult MergeUpdate(const HashPrefixMap& old_hash_prefix_map,
const HashPrefixMap& additions_map,
const ::google::protobuf::RepeatedField<
@@ -345,6 +355,10 @@ class V4Store {
StoreWriteResult WriteToDisk(
std::unique_ptr<ListUpdateResponse> response) const;
+ // The checksum value as read from the disk, until it is verified. Once
+ // verified, it is cleared.
+ std::string expected_checksum_;
+
// The state of the store as returned by the PVer4 server in the last applied
// update response.
std::string state_;
« no previous file with comments | « components/safe_browsing_db/v4_local_database_manager_unittest.cc ('k') | components/safe_browsing_db/v4_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698