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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 201 |
202 V4Store::V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 202 V4Store::V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
203 const base::FilePath& store_path, | 203 const base::FilePath& store_path, |
204 const int64_t old_file_size) | 204 const int64_t old_file_size) |
205 : file_size_(old_file_size), | 205 : file_size_(old_file_size), |
206 has_valid_data_(false), | 206 has_valid_data_(false), |
207 store_path_(store_path), | 207 store_path_(store_path), |
208 task_runner_(task_runner) {} | 208 task_runner_(task_runner) {} |
209 | 209 |
210 V4Store::~V4Store() { | 210 V4Store::~V4Store() { |
211 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 211 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
212 } | 212 } |
213 | 213 |
214 std::string V4Store::DebugString() const { | 214 std::string V4Store::DebugString() const { |
215 std::string state_base64; | 215 std::string state_base64; |
216 base::Base64Encode(state_, &state_base64); | 216 base::Base64Encode(state_, &state_base64); |
217 | 217 |
218 return base::StringPrintf("path: %" PRIsFP "; state: %s", | 218 return base::StringPrintf("path: %" PRIsFP "; state: %s", |
219 store_path_.value().c_str(), state_base64.c_str()); | 219 store_path_.value().c_str(), state_base64.c_str()); |
220 } | 220 } |
221 | 221 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 526 |
527 (*prefix_map_to_update)[prefix_size].reserve(existing_capacity + | 527 (*prefix_map_to_update)[prefix_size].reserve(existing_capacity + |
528 prefix_length_to_add); | 528 prefix_length_to_add); |
529 } | 529 } |
530 } | 530 } |
531 | 531 |
532 ApplyUpdateResult V4Store::MergeUpdate(const HashPrefixMap& old_prefixes_map, | 532 ApplyUpdateResult V4Store::MergeUpdate(const HashPrefixMap& old_prefixes_map, |
533 const HashPrefixMap& additions_map, | 533 const HashPrefixMap& additions_map, |
534 const RepeatedField<int32>* raw_removals, | 534 const RepeatedField<int32>* raw_removals, |
535 const std::string& expected_checksum) { | 535 const std::string& expected_checksum) { |
536 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 536 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
537 DCHECK(hash_prefix_map_.empty()); | 537 DCHECK(hash_prefix_map_.empty()); |
538 | 538 |
539 bool calculate_checksum = !expected_checksum.empty(); | 539 bool calculate_checksum = !expected_checksum.empty(); |
540 if (calculate_checksum && | 540 if (calculate_checksum && |
541 (expected_checksum.size() != crypto::kSHA256Length)) { | 541 (expected_checksum.size() != crypto::kSHA256Length)) { |
542 return CHECKSUM_MISMATCH_FAILURE; | 542 return CHECKSUM_MISMATCH_FAILURE; |
543 } | 543 } |
544 | 544 |
545 hash_prefix_map_.clear(); | 545 hash_prefix_map_.clear(); |
546 ReserveSpaceInPrefixMap(old_prefixes_map, &hash_prefix_map_); | 546 ReserveSpaceInPrefixMap(old_prefixes_map, &hash_prefix_map_); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 #endif | 658 #endif |
659 return CHECKSUM_MISMATCH_FAILURE; | 659 return CHECKSUM_MISMATCH_FAILURE; |
660 } | 660 } |
661 } | 661 } |
662 } | 662 } |
663 | 663 |
664 return APPLY_UPDATE_SUCCESS; | 664 return APPLY_UPDATE_SUCCESS; |
665 } | 665 } |
666 | 666 |
667 StoreReadResult V4Store::ReadFromDisk() { | 667 StoreReadResult V4Store::ReadFromDisk() { |
668 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 668 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
669 | 669 |
670 V4StoreFileFormat file_format; | 670 V4StoreFileFormat file_format; |
671 int64_t file_size; | 671 int64_t file_size; |
672 TimeTicks before = TimeTicks::Now(); | 672 TimeTicks before = TimeTicks::Now(); |
673 { | 673 { |
674 // A temporary scope to make sure that |contents| get destroyed as soon as | 674 // A temporary scope to make sure that |contents| get destroyed as soon as |
675 // we are doing using it. | 675 // we are doing using it. |
676 std::string contents; | 676 std::string contents; |
677 bool read_success = base::ReadFileToString(store_path_, &contents); | 677 bool read_success = base::ReadFileToString(store_path_, &contents); |
678 if (!read_success) { | 678 if (!read_success) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 if (result == 0) { | 794 if (result == 0) { |
795 return true; | 795 return true; |
796 } else if (result < 0) { | 796 } else if (result < 0) { |
797 return HashPrefixMatches(hash_prefix, begin, mid); | 797 return HashPrefixMatches(hash_prefix, begin, mid); |
798 } else { | 798 } else { |
799 return HashPrefixMatches(hash_prefix, mid + prefix_size, end); | 799 return HashPrefixMatches(hash_prefix, mid + prefix_size, end); |
800 } | 800 } |
801 } | 801 } |
802 | 802 |
803 bool V4Store::VerifyChecksum() { | 803 bool V4Store::VerifyChecksum() { |
804 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 804 DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
805 | 805 |
806 if (expected_checksum_.empty()) { | 806 if (expected_checksum_.empty()) { |
807 // Nothing to check here folks! | 807 // Nothing to check here folks! |
808 // TODO(vakh): Do not allow empty checksums. | 808 // TODO(vakh): Do not allow empty checksums. |
809 return true; | 809 return true; |
810 } | 810 } |
811 | 811 |
812 IteratorMap iterator_map; | 812 IteratorMap iterator_map; |
813 HashPrefix next_smallest_prefix; | 813 HashPrefix next_smallest_prefix; |
814 InitializeIteratorMap(hash_prefix_map_, &iterator_map); | 814 InitializeIteratorMap(hash_prefix_map_, &iterator_map); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 base_metric + suffix, 1, 1000000, 50, | 861 base_metric + suffix, 1, 1000000, 50, |
862 base::HistogramBase::kUmaTargetedHistogramFlag); | 862 base::HistogramBase::kUmaTargetedHistogramFlag); |
863 if (histogram) { | 863 if (histogram) { |
864 const int64_t file_size_kilobytes = file_size_ / 1024; | 864 const int64_t file_size_kilobytes = file_size_ / 1024; |
865 histogram->Add(file_size_kilobytes); | 865 histogram->Add(file_size_kilobytes); |
866 } | 866 } |
867 return file_size_; | 867 return file_size_; |
868 } | 868 } |
869 | 869 |
870 } // namespace safe_browsing | 870 } // namespace safe_browsing |
OLD | NEW |