blob: ac990b3ddcab44b4dc8753a6babb3a2c984085f7 [file] [log] [blame]
thakis91351e6f2016-05-07 19:30:531// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_
6#define COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_
7
vakh5c9644b2016-05-24 22:33:428#include "base/files/file_path.h"
9#include "base/memory/ref_counted.h"
10#include "base/sequenced_task_runner.h"
vakh370e9322016-06-28 22:11:1911#include "base/single_thread_task_runner.h"
12#include "components/safe_browsing_db/v4_protocol_manager_util.h"
vakh5c9644b2016-05-24 22:33:4213
thakis91351e6f2016-05-07 19:30:5314namespace safe_browsing {
15
vakh3deb8da2016-06-02 21:37:4416class V4Store;
17
vakh8ca75272016-10-27 18:45:4518typedef base::Callback<void(std::unique_ptr<V4Store> new_store)>
vakh370e9322016-06-28 22:11:1919 UpdatedStoreReadyCallback;
20
vakh2eb43a62016-07-13 22:55:3621// The sorted list of hash prefixes.
22typedef std::string HashPrefixes;
23
24// Stores the list of sorted hash prefixes, by size.
25// For instance: {4: ["abcd", "bcde", "cdef", "gggg"], 5: ["fffff"]}
26typedef base::hash_map<PrefixSize, HashPrefixes> HashPrefixMap;
27
vakh92377d22016-07-18 17:21:0428// Stores the iterator to the last element merged from the HashPrefixMap for a
29// given prefix size.
30// For instance: {4:iter(3), 5:iter(1)} means that we have already merged
vakh2eb43a62016-07-13 22:55:3631// 3 hash prefixes of length 4, and 1 hash prefix of length 5.
vakh92377d22016-07-18 17:21:0432typedef base::hash_map<PrefixSize, HashPrefixes::const_iterator> IteratorMap;
vakh2eb43a62016-07-13 22:55:3633
vakh2d092db2016-06-29 00:44:5134// Enumerate different failure events while parsing the file read from disk for
35// histogramming purposes. DO NOT CHANGE THE ORDERING OF THESE VALUES.
36enum StoreReadResult {
37 // No errors.
38 READ_SUCCESS = 0,
39
40 // Reserved for errors in parsing this enum.
41 UNEXPECTED_READ_FAILURE = 1,
42
43 // The contents of the file could not be read.
44 FILE_UNREADABLE_FAILURE = 2,
45
46 // The file was found to be empty.
47 FILE_EMPTY_FAILURE = 3,
48
49 // The contents of the file could not be interpreted as a valid
50 // V4StoreFileFormat proto.
51 PROTO_PARSING_FAILURE = 4,
52
53 // The magic number didn't match. We're most likely trying to read a file
vakh3f60e9592016-07-20 07:00:0654 // that doesn't contain hash prefixes.
vakh2d092db2016-06-29 00:44:5155 UNEXPECTED_MAGIC_NUMBER_FAILURE = 5,
56
57 // The version of the file is different from expected and Chromium doesn't
58 // know how to interpret this version of the file.
59 FILE_VERSION_INCOMPATIBLE_FAILURE = 6,
60
61 // The rest of the file could not be parsed as a ListUpdateResponse protobuf.
62 // This can happen if the machine crashed before the file was fully written to
63 // disk or if there was disk corruption.
64 HASH_PREFIX_INFO_MISSING_FAILURE = 7,
65
vakhbeda83d2016-07-15 00:57:2966 // Unable to generate the hash prefix map from the updates on disk.
67 HASH_PREFIX_MAP_GENERATION_FAILURE = 8,
68
vakh2d092db2016-06-29 00:44:5169 // Memory space for histograms is determined by the max. ALWAYS
70 // ADD NEW VALUES BEFORE THIS ONE.
71 STORE_READ_RESULT_MAX
72};
73
74// Enumerate different failure events while writing the file to disk after
75// applying updates for histogramming purposes.
76// DO NOT CHANGE THE ORDERING OF THESE VALUES.
77enum StoreWriteResult {
78 // No errors.
79 WRITE_SUCCESS = 0,
80
81 // Reserved for errors in parsing this enum.
82 UNEXPECTED_WRITE_FAILURE = 1,
83
84 // The proto being written to disk wasn't a FULL_UPDATE proto.
85 INVALID_RESPONSE_TYPE_FAILURE = 2,
86
87 // Number of bytes written to disk was different from the size of the proto.
88 UNEXPECTED_BYTES_WRITTEN_FAILURE = 3,
89
90 // Renaming the temporary file to store file failed.
91 UNABLE_TO_RENAME_FAILURE = 4,
92
93 // Memory space for histograms is determined by the max. ALWAYS
94 // ADD NEW VALUES BEFORE THIS ONE.
95 STORE_WRITE_RESULT_MAX
96};
97
vakh2eb43a62016-07-13 22:55:3698// Enumerate different events while applying the update fetched fom the server
99// for histogramming purposes.
100// DO NOT CHANGE THE ORDERING OF THESE VALUES.
101enum ApplyUpdateResult {
102 // No errors.
103 APPLY_UPDATE_SUCCESS = 0,
104
105 // Reserved for errors in parsing this enum.
106 UNEXPECTED_APPLY_UPDATE_FAILURE = 1,
107
108 // Prefix size smaller than 4 (which is the lowest expected).
109 PREFIX_SIZE_TOO_SMALL_FAILURE = 2,
110
111 // Prefix size larger than 32 (length of a full SHA256 hash).
112 PREFIX_SIZE_TOO_LARGE_FAILURE = 3,
113
114 // The number of bytes in additions isn't a multiple of prefix size.
115 ADDITIONS_SIZE_UNEXPECTED_FAILURE = 4,
116
117 // The update received from the server contains a prefix that's already
118 // present in the map.
119 ADDITIONS_HAS_EXISTING_PREFIX_FAILURE = 5,
120
121 // The server sent a response_type that the client did not expect.
122 UNEXPECTED_RESPONSE_TYPE_FAILURE = 6,
123
vakhfe520542016-07-18 21:59:31124 // One of more index(es) in removals field of the response is greater than
125 // the number of hash prefixes currently in the (old) store.
vakh605ab1c2016-08-04 18:37:40126 REMOVALS_INDEX_TOO_LARGE_FAILURE = 7,
127
128 // Failed to decode the Rice-encoded additions/removals field.
129 RICE_DECODING_FAILURE = 8,
130
131 // Compression type other than RAW and RICE for additions.
132 UNEXPECTED_COMPRESSION_TYPE_ADDITIONS_FAILURE = 9,
133
134 // Compression type other than RAW and RICE for removals.
135 UNEXPECTED_COMPRESSION_TYPE_REMOVALS_FAILURE = 10,
vakhfe520542016-07-18 21:59:31136
vakh0facbb7c2016-08-11 02:15:12137 // The state of the store did not match the expected checksum sent by the
138 // server.
139 CHECKSUM_MISMATCH_FAILURE = 11,
140
vakh2eb43a62016-07-13 22:55:36141 // Memory space for histograms is determined by the max. ALWAYS
142 // ADD NEW VALUES BEFORE THIS ONE.
143 APPLY_UPDATE_RESULT_MAX
144};
145
vakh3deb8da2016-06-02 21:37:44146// Factory for creating V4Store. Tests implement this factory to create fake
147// stores for testing.
148class V4StoreFactory {
149 public:
150 virtual ~V4StoreFactory() {}
151 virtual V4Store* CreateV4Store(
152 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
153 const base::FilePath& store_path);
154};
155
thakis91351e6f2016-05-07 19:30:53156class V4Store {
vakh5c9644b2016-05-24 22:33:42157 public:
158 // The |task_runner| is used to ensure that the operations in this file are
159 // performed on the correct thread. |store_path| specifies the location on
vakh2d092db2016-06-29 00:44:51160 // disk for this file. The constructor doesn't read the store file from disk.
vakh8ca75272016-10-27 18:45:45161 // If the store is being created to apply an update to the old store, then
162 // |old_file_size| is the size of the existing file on disk for this store;
163 // 0 otherwise. This is needed so that we can correctly report the size of
164 // store file on disk, even if writing the new file fails after successfully
165 // applying an update.
vakh5c9644b2016-05-24 22:33:42166 V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner,
vakh8ca75272016-10-27 18:45:45167 const base::FilePath& store_path,
168 const int64_t old_file_size = 0);
vakh5c9644b2016-05-24 22:33:42169 virtual ~V4Store();
170
vakh370e9322016-06-28 22:11:19171 const std::string& state() const { return state_; }
172
173 const base::FilePath& store_path() const { return store_path_; }
174
vakhad9b4f42016-06-29 21:37:02175 void ApplyUpdate(std::unique_ptr<ListUpdateResponse> response,
vakh8ca75272016-10-27 18:45:45176 const scoped_refptr<base::SingleThreadTaskRunner>& runner,
177 UpdatedStoreReadyCallback callback);
178
179 // Records (in kilobytes) and returns the size of the file on disk for this
180 // store using |base_metric| as prefix and the filename as suffix.
181 int64_t RecordAndReturnFileSize(const std::string& base_metric);
vakh370e9322016-06-28 22:11:19182
vakh3f60e9592016-07-20 07:00:06183 // If a hash prefix in this store matches |full_hash|, returns that hash
184 // prefix; otherwise returns an empty hash prefix.
vakh84307af2016-07-20 22:12:43185 virtual HashPrefix GetMatchingHashPrefix(const FullHash& full_hash);
vakh3f60e9592016-07-20 07:00:06186
vakh370e9322016-06-28 22:11:19187 std::string DebugString() const;
188
vakhb8eecb02016-10-18 23:04:37189 // Schedules the destruction of the V4Store object pointed to by |v4_store|,
190 // on the task runner.
191 static void Destroy(std::unique_ptr<V4Store> v4_store);
192
vakh2d092db2016-06-29 00:44:51193 // Reads the store file from disk and populates the in-memory representation
194 // of the hash prefixes.
195 void Initialize();
196
nparker518b14312016-12-21 22:42:42197 // True if this store has valid contents, either from a successful read
198 // from disk or a full update. This does not mean the checksum was verified.
199 virtual bool HasValidData() const;
200
vakhcb8c22f2016-10-10 18:26:20201 // Reset internal state.
202 void Reset();
203
204 // Scheduled after reading the store file from disk on startup. When run, it
205 // ensures that the checksum of the hash prefixes in lexicographical sorted
206 // order matches the expected value in |expected_checksum_|. Returns true if
207 // it matches; false otherwise. Checksum verification can take a long time,
208 // so it is performed outside of the hotpath of loading SafeBrowsing database,
209 // which blocks resource loads.
210 bool VerifyChecksum();
vakh5c9644b2016-05-24 22:33:42211
vakh370e9322016-06-28 22:11:19212 private:
vakh2d092db2016-06-29 00:44:51213 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromEmptyFile);
214 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromAbsentFile);
215 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromInvalidContentsFile);
216 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromUnexpectedMagicFile);
217 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromLowVersionFile);
218 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromNoHashPrefixInfoFile);
219 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromNoHashPrefixesFile);
220 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestWriteNoResponseType);
221 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestWritePartialResponseType);
222 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestWriteFullResponseType);
223 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromFileWithUnknownProto);
vakh2eb43a62016-07-13 22:55:36224 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
225 TestAddUnlumpedHashesWithInvalidAddition);
226 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAddUnlumpedHashes);
227 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAddUnlumpedHashesWithEmptyString);
228 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
vakh92377d22016-07-18 17:21:04229 TestGetNextSmallestUnmergedPrefixWithEmptyPrefixMap);
230 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestGetNextSmallestUnmergedPrefix);
vakh2eb43a62016-07-13 22:55:36231 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesWithSameSizesInEachMap);
232 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
233 TestMergeUpdatesWithDifferentSizesInEachMap);
234 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesOldMapRunsOutFirst);
235 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
236 TestMergeUpdatesAdditionsMapRunsOutFirst);
237 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
vakhbeda83d2016-07-15 00:57:29238 TestMergeUpdatesFailsForRepeatedHashPrefix);
239 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
vakhfe520542016-07-18 21:59:31240 TestMergeUpdatesFailsWhenRemovalsIndexTooLarge);
241 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesRemovesOnlyElement);
242 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesRemovesFirstElement);
243 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesRemovesMiddleElement);
244 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesRemovesLastElement);
245 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
246 TestMergeUpdatesRemovesWhenOldHasDifferentSizes);
247 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
248 TestMergeUpdatesRemovesMultipleAcrossDifferentSizes);
249 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
vakhbeda83d2016-07-15 00:57:29250 TestReadFullResponseWithValidHashPrefixMap);
251 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
252 TestReadFullResponseWithInvalidHashPrefixMap);
vakh3f60e9592016-07-20 07:00:06253 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestHashPrefixExistsAtTheBeginning);
254 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestHashPrefixExistsInTheMiddle);
255 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestHashPrefixExistsAtTheEnd);
256 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
257 TestHashPrefixExistsAtTheBeginningOfEven);
258 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestHashPrefixExistsAtTheEndOfEven);
259 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
260 TestHashPrefixDoesNotExistInConcatenatedList);
261 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestFullHashExistsInMapWithSingleSize);
262 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
263 TestFullHashExistsInMapWithDifferentSizes);
264 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
265 TestHashPrefixExistsInMapWithSingleSize);
266 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
267 TestHashPrefixExistsInMapWithDifferentSizes);
268 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
269 TestHashPrefixDoesNotExistInMapWithDifferentSizes);
vakh605ab1c2016-08-04 18:37:40270 FRIEND_TEST_ALL_PREFIXES(V4StoreTest,
271 TestAdditionsWithRiceEncodingFailsWithInvalidInput);
272 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds);
273 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds);
vakh0facbb7c2016-08-11 02:15:12274 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestMergeUpdatesFailsChecksum);
vakhcb8c22f2016-10-10 18:26:20275 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestChecksumErrorOnStartup);
vakh9f1266e2016-10-14 01:57:07276 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, WriteToDiskFails);
vakhcfa3d922016-10-15 01:44:00277 FRIEND_TEST_ALL_PREFIXES(V4StoreTest, FullUpdateFailsChecksumSynchronously);
vakh605ab1c2016-08-04 18:37:40278 friend class V4StoreTest;
vakh2eb43a62016-07-13 22:55:36279
vakh1670eb02016-08-19 02:18:13280 // If |prefix_size| is within expected range, and |raw_hashes_length| is a
281 // multiple of prefix_size, then it sets the string of length
282 // |raw_hashes_length| starting at |raw_hashes_begin| as the value at key
283 // |prefix_size| in |additions_map|
284 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size,
285 const char* raw_hashes_begin,
286 const size_t raw_hashes_length,
287 HashPrefixMap* additions_map);
288
289 // An overloaded version of AddUnlumpedHashes that allows passing in a
290 // std::string object.
vakh2eb43a62016-07-13 22:55:36291 static ApplyUpdateResult AddUnlumpedHashes(PrefixSize prefix_size,
292 const std::string& raw_hashes,
293 HashPrefixMap* additions_map);
294
vakh92377d22016-07-18 17:21:04295 // Get the next unmerged hash prefix in dictionary order from
296 // |hash_prefix_map|. |iterator_map| is used to determine which hash prefixes
vakh2eb43a62016-07-13 22:55:36297 // have been merged already. Returns true if there are any unmerged hash
298 // prefixes in the list.
vakh92377d22016-07-18 17:21:04299 static bool GetNextSmallestUnmergedPrefix(
henrikae63d7262016-07-15 07:53:56300 const HashPrefixMap& hash_prefix_map,
vakh92377d22016-07-18 17:21:04301 const IteratorMap& iterator_map,
302 HashPrefix* smallest_hash_prefix);
henrikae63d7262016-07-15 07:53:56303
vakh3f60e9592016-07-20 07:00:06304 // Returns true if |hash_prefix| exists between |begin| and |end| iterators.
305 static bool HashPrefixMatches(const HashPrefix& hash_prefix,
306 const HashPrefixes::const_iterator& begin,
307 const HashPrefixes::const_iterator& end);
308
vakh92377d22016-07-18 17:21:04309 // For each key in |hash_prefix_map|, sets the iterator at that key
310 // |iterator_map| to hash_prefix_map[key].begin().
311 static void InitializeIteratorMap(const HashPrefixMap& hash_prefix_map,
312 IteratorMap* iterator_map);
vakh2eb43a62016-07-13 22:55:36313
314 // Reserve the appropriate string size so that the string size of the merged
315 // list is exact. This ignores the space that would otherwise be released by
316 // deletions specified in the update because it is non-trivial to calculate
317 // those deletions upfront. This isn't so bad since deletions are supposed to
318 // be small and infrequent.
319 static void ReserveSpaceInPrefixMap(const HashPrefixMap& other_prefixes_map,
320 HashPrefixMap* prefix_map_to_update);
321
vakh2eb43a62016-07-13 22:55:36322 // Merges the prefix map from the old store (|old_hash_prefix_map|) and the
323 // update (additions_map) to populate the prefix map for the current store.
vakhfe520542016-07-18 21:59:31324 // The indices in the |raw_removals| list, which may be NULL, are not merged.
vakhcb8c22f2016-10-10 18:26:20325 // The SHA256 checksum of the final list of hash prefixes, in
326 // lexicographically sorted order, must match |expected_checksum| (if it's not
327 // empty).
vakhcfa3d922016-10-15 01:44:00328 ApplyUpdateResult MergeUpdate(
329 const HashPrefixMap& old_hash_prefix_map,
330 const HashPrefixMap& additions_map,
331 const ::google::protobuf::RepeatedField<::google::protobuf::int32>*
332 raw_removals,
333 const std::string& expected_checksum);
vakh2d092db2016-06-29 00:44:51334
vakh0facbb7c2016-08-11 02:15:12335 // Processes the FULL_UPDATE |response| from the server, and writes the
336 // merged V4Store to disk. If processing the |response| succeeds, it returns
vakh36a98c52016-10-13 03:21:20337 // APPLY_UPDATE_SUCCESS. The UMA metrics for all interesting sub-operations
338 // use the prefix |metric|.
vakh0facbb7c2016-08-11 02:15:12339 // This method is only called when we receive a FULL_UPDATE from the server.
340 ApplyUpdateResult ProcessFullUpdateAndWriteToDisk(
vakh36a98c52016-10-13 03:21:20341 const std::string& metric,
vakh0facbb7c2016-08-11 02:15:12342 std::unique_ptr<ListUpdateResponse> response);
343
344 // Processes a FULL_UPDATE |response| and updates the V4Store. If processing
345 // the |response| succeeds, it returns APPLY_UPDATE_SUCCESS.
346 // This method is called when we receive a FULL_UPDATE from the server, and
vakh36a98c52016-10-13 03:21:20347 // when we read a store file from disk on startup. The UMA metrics for all
vakhcfa3d922016-10-15 01:44:00348 // interesting sub-operations use the prefix |metric|. Delays the checksum
349 // check if |delay_checksum_check| is true.
vakh0facbb7c2016-08-11 02:15:12350 ApplyUpdateResult ProcessFullUpdate(
vakh36a98c52016-10-13 03:21:20351 const std::string& metric,
vakhcfa3d922016-10-15 01:44:00352 const std::unique_ptr<ListUpdateResponse>& response,
353 bool delay_checksum_check);
vakh0facbb7c2016-08-11 02:15:12354
355 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, updates
356 // the |hash_prefix_map_| and |state_| in the V4Store, and writes the merged
357 // store to disk. If processing succeeds, it returns APPLY_UPDATE_SUCCESS.
358 // This method is only called when we receive a PARTIAL_UPDATE from the
vakh36a98c52016-10-13 03:21:20359 // server. The UMA metrics for all interesting sub-operations use the prefix
360 // |metric|.
vakh0facbb7c2016-08-11 02:15:12361 ApplyUpdateResult ProcessPartialUpdateAndWriteToDisk(
vakh36a98c52016-10-13 03:21:20362 const std::string& metric,
vakh0facbb7c2016-08-11 02:15:12363 const HashPrefixMap& hash_prefix_map_old,
364 std::unique_ptr<ListUpdateResponse> response);
365
366 // Merges the hash prefixes in |hash_prefix_map_old| and |response|, and
367 // updates the |hash_prefix_map_| and |state_| in the V4Store. If processing
vakh36a98c52016-10-13 03:21:20368 // succeeds, it returns APPLY_UPDATE_SUCCESS. The UMA metrics for all
vakhcfa3d922016-10-15 01:44:00369 // interesting sub-operations use the prefix |metric|. Delays the checksum
370 // check if |delay_checksum_check| is true.
vakh0facbb7c2016-08-11 02:15:12371 ApplyUpdateResult ProcessUpdate(
vakh36a98c52016-10-13 03:21:20372 const std::string& metric,
vakh0facbb7c2016-08-11 02:15:12373 const HashPrefixMap& hash_prefix_map_old,
vakhcfa3d922016-10-15 01:44:00374 const std::unique_ptr<ListUpdateResponse>& response,
375 bool delay_checksum_check);
vakh605ab1c2016-08-04 18:37:40376
vakh2d092db2016-06-29 00:44:51377 // Reads the state of the store from the file on disk and returns the reason
378 // for the failure or reports success.
379 StoreReadResult ReadFromDisk();
380
vakh8ccfe9a2016-10-04 22:25:20381 // Updates the |additions_map| with the additions received in the partial
vakh36a98c52016-10-13 03:21:20382 // update from the server. The UMA metrics for all interesting sub-operations
383 // use the prefix |metric|.
vakh8ccfe9a2016-10-04 22:25:20384 ApplyUpdateResult UpdateHashPrefixMapFromAdditions(
vakh36a98c52016-10-13 03:21:20385 const std::string& metric,
vakh8ccfe9a2016-10-04 22:25:20386 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions,
387 HashPrefixMap* additions_map);
388
vakh9f1266e2016-10-14 01:57:07389 // Writes the hash_prefix_map_ to disk as a V4StoreFileFormat proto.
390 // |checksum| is used to set the |checksum| field in the final proto.
vakh8ca75272016-10-27 18:45:45391 StoreWriteResult WriteToDisk(const Checksum& checksum);
vakh2d092db2016-06-29 00:44:51392
vakhcb8c22f2016-10-10 18:26:20393 // The checksum value as read from the disk, until it is verified. Once
394 // verified, it is cleared.
395 std::string expected_checksum_;
396
vakh8ca75272016-10-27 18:45:45397 // The size of the file on disk for this store.
398 int64_t file_size_;
399
nparker518b14312016-12-21 22:42:42400 // True if the file was successfully read+parsed or was populated from
401 // a full update.
402 bool has_valid_data_;
403
vakh370e9322016-06-28 22:11:19404 // The state of the store as returned by the PVer4 server in the last applied
405 // update response.
406 std::string state_;
vakh3deb8da2016-06-02 21:37:44407 const base::FilePath store_path_;
vakh2eb43a62016-07-13 22:55:36408 HashPrefixMap hash_prefix_map_;
vakh370e9322016-06-28 22:11:19409 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
thakis91351e6f2016-05-07 19:30:53410};
411
vakh370e9322016-06-28 22:11:19412std::ostream& operator<<(std::ostream& os, const V4Store& store);
413
thakis91351e6f2016-05-07 19:30:53414} // namespace safe_browsing
415
416#endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_