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

Side by Side Diff: components/safe_browsing_db/v4_store.h

Issue 2447443002: Log the size of each of the stores and complete DB on launch and after each (Closed)
Patch Set: git rebase Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
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
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. 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.
161 V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, 166 V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner,
162 const base::FilePath& store_path); 167 const base::FilePath& store_path,
168 const int64_t old_file_size = 0);
163 virtual ~V4Store(); 169 virtual ~V4Store();
164 170
165 const std::string& state() const { return state_; } 171 const std::string& state() const { return state_; }
166 172
167 const base::FilePath& store_path() const { return store_path_; } 173 const base::FilePath& store_path() const { return store_path_; }
168 174
169 void ApplyUpdate(std::unique_ptr<ListUpdateResponse> response, 175 void ApplyUpdate(std::unique_ptr<ListUpdateResponse> response,
170 const scoped_refptr<base::SingleThreadTaskRunner>&, 176 const scoped_refptr<base::SingleThreadTaskRunner>& runner,
171 UpdatedStoreReadyCallback); 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);
172 182
173 // If a hash prefix in this store matches |full_hash|, returns that hash 183 // If a hash prefix in this store matches |full_hash|, returns that hash
174 // prefix; otherwise returns an empty hash prefix. 184 // prefix; otherwise returns an empty hash prefix.
175 virtual HashPrefix GetMatchingHashPrefix(const FullHash& full_hash); 185 virtual HashPrefix GetMatchingHashPrefix(const FullHash& full_hash);
176 186
177 std::string DebugString() const; 187 std::string DebugString() const;
178 188
179 // Schedules the destruction of the V4Store object pointed to by |v4_store|, 189 // Schedules the destruction of the V4Store object pointed to by |v4_store|,
180 // on the task runner. 190 // on the task runner.
181 static void Destroy(std::unique_ptr<V4Store> v4_store); 191 static void Destroy(std::unique_ptr<V4Store> v4_store);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // Updates the |additions_map| with the additions received in the partial 377 // Updates the |additions_map| with the additions received in the partial
368 // update from the server. The UMA metrics for all interesting sub-operations 378 // update from the server. The UMA metrics for all interesting sub-operations
369 // use the prefix |metric|. 379 // use the prefix |metric|.
370 ApplyUpdateResult UpdateHashPrefixMapFromAdditions( 380 ApplyUpdateResult UpdateHashPrefixMapFromAdditions(
371 const std::string& metric, 381 const std::string& metric,
372 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions, 382 const ::google::protobuf::RepeatedPtrField<ThreatEntrySet>& additions,
373 HashPrefixMap* additions_map); 383 HashPrefixMap* additions_map);
374 384
375 // Writes the hash_prefix_map_ to disk as a V4StoreFileFormat proto. 385 // Writes the hash_prefix_map_ to disk as a V4StoreFileFormat proto.
376 // |checksum| is used to set the |checksum| field in the final proto. 386 // |checksum| is used to set the |checksum| field in the final proto.
377 StoreWriteResult WriteToDisk(const Checksum& checksum) const; 387 StoreWriteResult WriteToDisk(const Checksum& checksum);
378 388
379 // The checksum value as read from the disk, until it is verified. Once 389 // The checksum value as read from the disk, until it is verified. Once
380 // verified, it is cleared. 390 // verified, it is cleared.
381 std::string expected_checksum_; 391 std::string expected_checksum_;
382 392
393 // The size of the file on disk for this store.
394 int64_t file_size_;
395
383 // The state of the store as returned by the PVer4 server in the last applied 396 // The state of the store as returned by the PVer4 server in the last applied
384 // update response. 397 // update response.
385 std::string state_; 398 std::string state_;
386 const base::FilePath store_path_; 399 const base::FilePath store_path_;
387 HashPrefixMap hash_prefix_map_; 400 HashPrefixMap hash_prefix_map_;
388 const scoped_refptr<base::SequencedTaskRunner> task_runner_; 401 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
389 }; 402 };
390 403
391 std::ostream& operator<<(std::ostream& os, const V4Store& store); 404 std::ostream& operator<<(std::ostream& os, const V4Store& store);
392 405
393 } // namespace safe_browsing 406 } // namespace safe_browsing
394 407
395 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_ 408 #endif // COMPONENTS_SAFE_BROWSING_DB_V4_STORE_H_
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_local_database_manager.cc ('k') | components/safe_browsing_db/v4_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698