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 #include "base/base64.h" | 5 #include "base/base64.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/metrics/sparse_histogram.h" | 9 #include "base/metrics/sparse_histogram.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 void RecordStoreWriteResult(StoreWriteResult result) { | 33 void RecordStoreWriteResult(StoreWriteResult result) { |
34 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4StoreWriteResult", result, | 34 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4StoreWriteResult", result, |
35 STORE_WRITE_RESULT_MAX); | 35 STORE_WRITE_RESULT_MAX); |
36 } | 36 } |
37 | 37 |
38 void RecordApplyUpdateResult(ApplyUpdateResult result) { | 38 void RecordApplyUpdateResult(ApplyUpdateResult result) { |
39 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4ApplyUpdateResult", result, | 39 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4ApplyUpdateResult", result, |
40 APPLY_UPDATE_RESULT_MAX); | 40 APPLY_UPDATE_RESULT_MAX); |
41 } | 41 } |
42 | 42 |
43 void RecordApplyUpdateResultWhenReadingFromDisk(ApplyUpdateResult result) { | |
44 UMA_HISTOGRAM_ENUMERATION( | |
45 "SafeBrowsing.V4ApplyUpdateResultWhenReadingFromDisk", result, | |
Nathan Parker
2016/07/14 22:36:12
Is this really an update? It's more just a load.
vakh (use Gerrit instead)
2016/07/15 00:07:30
Yes, it depends on the naming strategy in the read
| |
46 APPLY_UPDATE_RESULT_MAX); | |
47 } | |
48 | |
43 // Returns the name of the temporary file used to buffer data for | 49 // Returns the name of the temporary file used to buffer data for |
44 // |filename|. Exported for unit tests. | 50 // |filename|. Exported for unit tests. |
45 const base::FilePath TemporaryFileForFilename(const base::FilePath& filename) { | 51 const base::FilePath TemporaryFileForFilename(const base::FilePath& filename) { |
46 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new")); | 52 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new")); |
47 } | 53 } |
48 | 54 |
49 } // namespace | 55 } // namespace |
50 | 56 |
51 std::ostream& operator<<(std::ostream& os, const V4Store& store) { | 57 std::ostream& operator<<(std::ostream& os, const V4Store& store) { |
52 os << store.DebugString(); | 58 os << store.DebugString(); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 if (file_format.version_number() != kFileVersion) { | 358 if (file_format.version_number() != kFileVersion) { |
353 DVLOG(1) << "File version incompatible: " << file_format.version_number() | 359 DVLOG(1) << "File version incompatible: " << file_format.version_number() |
354 << "; expected: " << kFileVersion; | 360 << "; expected: " << kFileVersion; |
355 return FILE_VERSION_INCOMPATIBLE_FAILURE; | 361 return FILE_VERSION_INCOMPATIBLE_FAILURE; |
356 } | 362 } |
357 | 363 |
358 if (!file_format.has_list_update_response()) { | 364 if (!file_format.has_list_update_response()) { |
359 return HASH_PREFIX_INFO_MISSING_FAILURE; | 365 return HASH_PREFIX_INFO_MISSING_FAILURE; |
360 } | 366 } |
361 | 367 |
362 ListUpdateResponse list_update_response = file_format.list_update_response(); | 368 const ListUpdateResponse& response = file_format.list_update_response(); |
363 state_ = list_update_response.new_client_state(); | 369 HashPrefixMap read_from_disk_map; |
364 // TODO(vakh): Do more with what's read from the disk. | 370 ApplyUpdateResult apply_update_result = UpdateHashPrefixMapFromAdditions( |
Nathan Parker
2016/07/14 22:36:12
While I think this will work, it does a lot of ext
vakh (use Gerrit instead)
2016/07/14 23:51:57
Umm, that doesn't happen. I may have misunderstood
Nathan Parker
2016/07/15 00:35:31
Blarg. Indeed, that's exactly how I was reading it
| |
371 response.additions(), &read_from_disk_map); | |
372 RecordApplyUpdateResultWhenReadingFromDisk(apply_update_result); | |
373 if (apply_update_result != APPLY_UPDATE_SUCCESS) { | |
374 return HASH_PREFIX_MAP_GENERATION_FAILURE; | |
375 } | |
365 | 376 |
377 hash_prefix_map_ = read_from_disk_map; | |
Nathan Parker
2016/07/14 22:36:12
This does a copy of the map.
vakh (use Gerrit instead)
2016/07/14 23:51:57
Done.
| |
378 state_ = response.new_client_state(); | |
366 return READ_SUCCESS; | 379 return READ_SUCCESS; |
367 } | 380 } |
368 | 381 |
369 StoreWriteResult V4Store::WriteToDisk( | 382 StoreWriteResult V4Store::WriteToDisk( |
370 std::unique_ptr<ListUpdateResponse> response) const { | 383 std::unique_ptr<ListUpdateResponse> response) const { |
371 // Do not write partial updates to the disk. | 384 // Do not write partial updates to the disk. |
372 // After merging the updates, the ListUpdateResponse passed to this method | 385 // After merging the updates, the ListUpdateResponse passed to this method |
373 // should be a FULL_UPDATE. | 386 // should be a FULL_UPDATE. |
374 if (!response->has_response_type() || | 387 if (!response->has_response_type() || |
375 response->response_type() != ListUpdateResponse::FULL_UPDATE) { | 388 response->response_type() != ListUpdateResponse::FULL_UPDATE) { |
(...skipping 20 matching lines...) Expand all Loading... | |
396 | 409 |
397 if (!base::Move(new_filename, store_path_)) { | 410 if (!base::Move(new_filename, store_path_)) { |
398 DVLOG(1) << "store_path_: " << store_path_.value(); | 411 DVLOG(1) << "store_path_: " << store_path_.value(); |
399 return UNABLE_TO_RENAME_FAILURE; | 412 return UNABLE_TO_RENAME_FAILURE; |
400 } | 413 } |
401 | 414 |
402 return WRITE_SUCCESS; | 415 return WRITE_SUCCESS; |
403 } | 416 } |
404 | 417 |
405 } // namespace safe_browsing | 418 } // namespace safe_browsing |
OLD | NEW |