Chromium Code Reviews| 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" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "components/safe_browsing_db/v4_protocol_manager_util.h" | 12 #include "components/safe_browsing_db/v4_protocol_manager_util.h" |
| 13 | 13 |
| 14 namespace safe_browsing { | 14 namespace safe_browsing { |
| 15 | 15 |
| 16 class V4Store; | 16 class V4Store; |
| 17 | 17 |
| 18 typedef base::Callback<void(std::unique_ptr<V4Store>)> | 18 typedef base::Callback<void(std::unique_ptr<V4Store> new_store)> |
| 19 UpdatedStoreReadyCallback; | 19 UpdatedStoreReadyCallback; |
| 20 | 20 |
| 21 // The sorted list of hash prefixes. | 21 // The sorted list of hash prefixes. |
| 22 typedef std::string HashPrefixes; | 22 typedef std::string HashPrefixes; |
| 23 | 23 |
| 24 // Stores the list of sorted hash prefixes, by size. | 24 // Stores the list of sorted hash prefixes, by size. |
| 25 // For instance: {4: ["abcd", "bcde", "cdef", "gggg"], 5: ["fffff"]} | 25 // For instance: {4: ["abcd", "bcde", "cdef", "gggg"], 5: ["fffff"]} |
| 26 typedef base::hash_map<PrefixSize, HashPrefixes> HashPrefixMap; | 26 typedef base::hash_map<PrefixSize, HashPrefixes> HashPrefixMap; |
| 27 | 27 |
| 28 // Stores the iterator to the last element merged from the HashPrefixMap for a | 28 // Stores the iterator to the last element merged from the HashPrefixMap for a |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 virtual V4Store* CreateV4Store( | 151 virtual V4Store* CreateV4Store( |
| 152 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 152 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 153 const base::FilePath& store_path); | 153 const base::FilePath& store_path); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 class V4Store { | 156 class V4Store { |
| 157 public: | 157 public: |
| 158 // The |task_runner| is used to ensure that the operations in this file are | 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 | 159 // performed on the correct thread. |store_path| specifies the location on |
| 160 // disk for this file. The constructor doesn't read the store file from disk. | 160 // disk for this file. The constructor doesn't read the store file from disk. |
| 161 // 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. | |
| 161 V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 164 V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 162 const base::FilePath& store_path); | 165 const base::FilePath& store_path, |
| 166 const uint64_t old_file_size = 0); | |
|
Nathan Parker
2016/10/24 20:33:55
I'm not clear on why you need the old_file_size. E
vakh (use Gerrit instead)
2016/10/24 21:32:41
Yes, except what do we want to report if the updat
| |
| 163 virtual ~V4Store(); | 167 virtual ~V4Store(); |
| 164 | 168 |
| 165 const std::string& state() const { return state_; } | 169 const std::string& state() const { return state_; } |
| 166 | 170 |
| 167 const base::FilePath& store_path() const { return store_path_; } | 171 const base::FilePath& store_path() const { return store_path_; } |
| 168 | 172 |
| 169 void ApplyUpdate(std::unique_ptr<ListUpdateResponse> response, | 173 void ApplyUpdate(std::unique_ptr<ListUpdateResponse> response, |
| 170 const scoped_refptr<base::SingleThreadTaskRunner>&, | 174 const scoped_refptr<base::SingleThreadTaskRunner>& runner, |
| 171 UpdatedStoreReadyCallback); | 175 UpdatedStoreReadyCallback callback); |
| 176 | |
| 177 // Records (in kilobytes) and returns the size of the file on disk for this | |
| 178 // store using |base_metric| as prefix and the filename as suffix. | |
| 179 uint64_t RecordAndReturnFileSize(const std::string& base_metric); | |
| 172 | 180 |
| 173 // If a hash prefix in this store matches |full_hash|, returns that hash | 181 // If a hash prefix in this store matches |full_hash|, returns that hash |
| 174 // prefix; otherwise returns an empty hash prefix. | 182 // prefix; otherwise returns an empty hash prefix. |
| 175 virtual HashPrefix GetMatchingHashPrefix(const FullHash& full_hash); | 183 virtual HashPrefix GetMatchingHashPrefix(const FullHash& full_hash); |
| 176 | 184 |
| 177 std::string DebugString() const; | 185 std::string DebugString() const; |
| 178 | 186 |
| 179 // Schedules the destruction of the V4Store object pointed to by |v4_store|, | 187 // Schedules the destruction of the V4Store object pointed to by |v4_store|, |
| 180 // on the task runner. | 188 // on the task runner. |
| 181 static void Destroy(std::unique_ptr<V4Store> v4_store); | 189 static void Destroy(std::unique_ptr<V4Store> v4_store); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 // Updates the |additions_map| with the additions received in the partial | 375 // Updates the |additions_map| with the additions received in the partial |
| 368 // update from the server. The UMA metrics for all interesting sub-operations | 376 // update from the server. The UMA metrics for all interesting sub-operations |
| 369 // use the prefix |metric|. | 377 // use the prefix |metric|. |
| 370 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( | 378 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( |
| 371 const std::string& metric, | 379 const std::string& metric, |
| 372 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, | 380 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, |
| 373 HashPrefixMap* additions_map); | 381 HashPrefixMap* additions_map); |
| 374 | 382 |
| 375 // Writes the hash_prefix_map_ to disk as a V4StoreFileFormat proto. | 383 // Writes the hash_prefix_map_ to disk as a V4StoreFileFormat proto. |
| 376 // |checksum| is used to set the |checksum| field in the final proto. | 384 // |checksum| is used to set the |checksum| field in the final proto. |
| 377 StoreWriteResult WriteToDisk(const Checksum& checksum) const; | 385 StoreWriteResult WriteToDisk(const Checksum& checksum); |
| 378 | 386 |
| 379 // The checksum value as read from the disk, until it is verified. Once | 387 // The checksum value as read from the disk, until it is verified. Once |
| 380 // verified, it is cleared. | 388 // verified, it is cleared. |
| 381 std::string expected_checksum_; | 389 std::string expected_checksum_; |
| 382 | 390 |
| 391 // The size of the file on disk for this store. | |
| 392 uint64_t file_size_; | |
| 393 | |
| 383 // The state of the store as returned by the PVer4 server in the last applied | 394 // The state of the store as returned by the PVer4 server in the last applied |
| 384 // update response. | 395 // update response. |
| 385 std::string state_; | 396 std::string state_; |
| 386 const base::FilePath store_path_; | 397 const base::FilePath store_path_; |
| 387 HashPrefixMap hash_prefix_map_; | 398 HashPrefixMap hash_prefix_map_; |
| 388 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 399 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 389 }; | 400 }; |
| 390 | 401 |
| 391 std::ostream& operator<<(std::ostream& os, const V4Store& store); | 402 std::ostream& operator<<(std::ostream& os, const V4Store& store); |
| 392 | 403 |
| 393 } // namespace safe_browsing | 404 } // namespace safe_browsing |
| 394 | 405 |
| 395 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ | 406 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ |
| OLD | NEW |