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 d3fdaea7fa23289a519d2b5b4bb053c68464e121..97aeb63c3cef8fcf264b079c24d94030f2dd9beb 100644 |
--- a/components/safe_browsing_db/v4_store.h |
+++ b/components/safe_browsing_db/v4_store.h |
@@ -18,6 +18,43 @@ class V4Store; |
typedef base::Callback<void(std::unique_ptr<V4Store>)> |
UpdatedStoreReadyCallback; |
+// Enumerate different failure events while parsing the file read from disk for |
+// histogramming purposes. DO NOT CHANGE THE ORDERING OF THESE VALUES. |
+enum StoreReadFailureType { |
+ // Reserved for errors in parsing this enum. |
Nathan Parker
2016/06/16 00:07:50
(if this isn't stored in a proto, it probably won'
vakh (use Gerrit instead)
2016/06/16 08:25:18
Acknowledged.
|
+ UNEXPECTED_FAILURE = 0, |
+ |
+ // No errors. |
+ SUCCESS = 1, |
+ |
+ // The contents of the file could not be read. |
+ FILE_UNREADABLE_FAILURE = 2, |
+ |
+ // The file was found to be empty. |
+ FILE_EMPTY_FAILURE = 3, |
+ |
+ // The contents of the file could not be interpreted as a valid |
+ // V4StoreFileFormat proto. |
+ PROTO_PARSING_FAILURE = 4, |
+ |
+ // The magic number didn't match. We're most likely trying to read a file |
+ // that doesn't contain hash-prefixes. |
+ UNEXPECTED_MAGIC_NUMBER_FAILURE = 5, |
+ |
+ // The version of the file is lower than expected and Chromium doesn't know |
+ // how to interpret this file anymore. |
+ FILE_VERSION_TOO_LOW_FAILURE = 6, |
+ |
+ // The rest of the file could not be parsed as a ListUpdateResponse protobuf. |
+ // The only case when this can happen is if the machine crashed before the |
+ // file was fully written to disk. |
Nathan Parker
2016/06/16 00:07:50
Or any general corruption on disk, ya?
vakh (use Gerrit instead)
2016/06/16 08:25:18
Done.
|
+ HASH_PREFIX_INFO_MISSING_FAILURE = 7, |
+ |
+ // Memory space for histograms is determined by the max. ALWAYS |
+ // ADD NEW VALUES BEFORE THIS ONE. |
+ FORMAT_FAILURE_MAX |
+}; |
+ |
// Factory for creating V4Store. Tests implement this factory to create fake |
// stores for testing. |
class V4StoreFactory { |
@@ -41,6 +78,8 @@ class V4Store { |
const std::string& state() const { return state_; } |
+ void Initialize(); |
+ |
void ApplyUpdate(const ListUpdateResponse&, |
const scoped_refptr<base::SingleThreadTaskRunner>&, |
UpdatedStoreReadyCallback); |
@@ -56,9 +95,29 @@ class V4Store { |
std::string state_; |
private: |
+ // Creates a new store from an existing one when processing an update. |
V4Store(const V4Store& other); |
+ // Reads the state of the store from the file on disk and returns the reason |
+ // for the failure or reports success. |
+ StoreReadFailureType ReadFromDisk(); |
+ |
+ // Writes the FULL_UPDATE |response| to disk as a V4StoreFileFormat proto. |
+ // Returns false if the write fails. |
+ bool WriteToDisk(const ListUpdateResponse& response) const; |
+ |
std::string GetHumanReadableState() const; |
+ |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromEmptyFile); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromAbsentFile); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromInvalidContentsFile); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromUnexpectedMagicFile); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromLowVersionFile); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromNoHashPrefixInfoFile); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestReadFromNoHashPrefixesFile); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestWriteNoResponseType); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestWritePartialResponseType); |
+ FRIEND_TEST_ALL_PREFIXES(V4StoreTest, TestWriteFullResponseType); |
}; |
inline std::ostream& operator<<(std::ostream& os, const V4Store& store) { |