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

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

Issue 2889683003: Rename TaskRunner::RunsTasksOnCurrentThread() in //components (Closed)
Patch Set: rebase Created 3 years, 6 months 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 #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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 196
197 V4Store::V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, 197 V4Store::V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner,
198 const base::FilePath& store_path, 198 const base::FilePath& store_path,
199 const int64_t old_file_size) 199 const int64_t old_file_size)
200 : file_size_(old_file_size), 200 : file_size_(old_file_size),
201 has_valid_data_(false), 201 has_valid_data_(false),
202 store_path_(store_path), 202 store_path_(store_path),
203 task_runner_(task_runner) {} 203 task_runner_(task_runner) {}
204 204
205 V4Store::~V4Store() { 205 V4Store::~V4Store() {
206 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 206 DCHECK(task_runner_->RunsTasksInCurrentSequence());
207 } 207 }
208 208
209 std::string V4Store::DebugString() const { 209 std::string V4Store::DebugString() const {
210 std::string state_base64; 210 std::string state_base64;
211 base::Base64Encode(state_, &state_base64); 211 base::Base64Encode(state_, &state_base64);
212 212
213 return base::StringPrintf("path: %" PRIsFP "; state: %s", 213 return base::StringPrintf("path: %" PRIsFP "; state: %s",
214 store_path_.value().c_str(), state_base64.c_str()); 214 store_path_.value().c_str(), state_base64.c_str());
215 } 215 }
216 216
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 521
522 (*prefix_map_to_update)[prefix_size].reserve(existing_capacity + 522 (*prefix_map_to_update)[prefix_size].reserve(existing_capacity +
523 prefix_length_to_add); 523 prefix_length_to_add);
524 } 524 }
525 } 525 }
526 526
527 ApplyUpdateResult V4Store::MergeUpdate(const HashPrefixMap& old_prefixes_map, 527 ApplyUpdateResult V4Store::MergeUpdate(const HashPrefixMap& old_prefixes_map,
528 const HashPrefixMap& additions_map, 528 const HashPrefixMap& additions_map,
529 const RepeatedField<int32>* raw_removals, 529 const RepeatedField<int32>* raw_removals,
530 const std::string& expected_checksum) { 530 const std::string& expected_checksum) {
531 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 531 DCHECK(task_runner_->RunsTasksInCurrentSequence());
532 DCHECK(hash_prefix_map_.empty()); 532 DCHECK(hash_prefix_map_.empty());
533 533
534 bool calculate_checksum = !expected_checksum.empty(); 534 bool calculate_checksum = !expected_checksum.empty();
535 if (calculate_checksum && 535 if (calculate_checksum &&
536 (expected_checksum.size() != crypto::kSHA256Length)) { 536 (expected_checksum.size() != crypto::kSHA256Length)) {
537 return CHECKSUM_MISMATCH_FAILURE; 537 return CHECKSUM_MISMATCH_FAILURE;
538 } 538 }
539 539
540 hash_prefix_map_.clear(); 540 hash_prefix_map_.clear();
541 ReserveSpaceInPrefixMap(old_prefixes_map, &hash_prefix_map_); 541 ReserveSpaceInPrefixMap(old_prefixes_map, &hash_prefix_map_);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 #endif 653 #endif
654 return CHECKSUM_MISMATCH_FAILURE; 654 return CHECKSUM_MISMATCH_FAILURE;
655 } 655 }
656 } 656 }
657 } 657 }
658 658
659 return APPLY_UPDATE_SUCCESS; 659 return APPLY_UPDATE_SUCCESS;
660 } 660 }
661 661
662 StoreReadResult V4Store::ReadFromDisk() { 662 StoreReadResult V4Store::ReadFromDisk() {
663 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 663 DCHECK(task_runner_->RunsTasksInCurrentSequence());
664 664
665 V4StoreFileFormat file_format; 665 V4StoreFileFormat file_format;
666 int64_t file_size; 666 int64_t file_size;
667 TimeTicks before = TimeTicks::Now(); 667 TimeTicks before = TimeTicks::Now();
668 { 668 {
669 // A temporary scope to make sure that |contents| get destroyed as soon as 669 // A temporary scope to make sure that |contents| get destroyed as soon as
670 // we are doing using it. 670 // we are doing using it.
671 std::string contents; 671 std::string contents;
672 bool read_success = base::ReadFileToString(store_path_, &contents); 672 bool read_success = base::ReadFileToString(store_path_, &contents);
673 if (!read_success) { 673 if (!read_success) {
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 if (result == 0) { 789 if (result == 0) {
790 return true; 790 return true;
791 } else if (result < 0) { 791 } else if (result < 0) {
792 return HashPrefixMatches(hash_prefix, begin, mid); 792 return HashPrefixMatches(hash_prefix, begin, mid);
793 } else { 793 } else {
794 return HashPrefixMatches(hash_prefix, mid + prefix_size, end); 794 return HashPrefixMatches(hash_prefix, mid + prefix_size, end);
795 } 795 }
796 } 796 }
797 797
798 bool V4Store::VerifyChecksum() { 798 bool V4Store::VerifyChecksum() {
799 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 799 DCHECK(task_runner_->RunsTasksInCurrentSequence());
800 800
801 if (expected_checksum_.empty()) { 801 if (expected_checksum_.empty()) {
802 // Nothing to check here folks! 802 // Nothing to check here folks!
803 // TODO(vakh): Do not allow empty checksums. 803 // TODO(vakh): Do not allow empty checksums.
804 return true; 804 return true;
805 } 805 }
806 806
807 IteratorMap iterator_map; 807 IteratorMap iterator_map;
808 HashPrefix next_smallest_prefix; 808 HashPrefix next_smallest_prefix;
809 InitializeIteratorMap(hash_prefix_map_, &iterator_map); 809 InitializeIteratorMap(hash_prefix_map_, &iterator_map);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 base_metric + suffix, 1, 1000000, 50, 856 base_metric + suffix, 1, 1000000, 50,
857 base::HistogramBase::kUmaTargetedHistogramFlag); 857 base::HistogramBase::kUmaTargetedHistogramFlag);
858 if (histogram) { 858 if (histogram) {
859 const int64_t file_size_kilobytes = file_size_ / 1024; 859 const int64_t file_size_kilobytes = file_size_ / 1024;
860 histogram->Add(file_size_kilobytes); 860 histogram->Add(file_size_kilobytes);
861 } 861 }
862 return file_size_; 862 return file_size_;
863 } 863 }
864 864
865 } // namespace safe_browsing 865 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_database.cc ('k') | components/sessions/core/base_session_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698