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

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

Issue 2614763002: DCHECK that full hash must be 21 bytes or 32 bytes long. (Closed)
Patch Set: Change DCHECK to accept 32 or 21 size. Add unit test. Created 3 years, 11 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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 // Update |file_size_| now because we wrote the file correctly. 757 // Update |file_size_| now because we wrote the file correctly.
758 file_size_ = static_cast<int64_t>(written); 758 file_size_ = static_cast<int64_t>(written);
759 759
760 return WRITE_SUCCESS; 760 return WRITE_SUCCESS;
761 } 761 }
762 762
763 HashPrefix V4Store::GetMatchingHashPrefix(const FullHash& full_hash) { 763 HashPrefix V4Store::GetMatchingHashPrefix(const FullHash& full_hash) {
764 // It should never be the case that more than one hash prefixes match a given 764 // It should never be the case that more than one hash prefixes match a given
765 // full hash. However, if that happens, this method returns any one of them. 765 // full hash. However, if that happens, this method returns any one of them.
766 // It does not guarantee which one of those will be returned. 766 // It does not guarantee which one of those will be returned.
767 DCHECK_EQ(32u, full_hash.size()); 767 DCHECK(full_hash.size() == 32u || full_hash.size() == 21u);
768 for (const auto& pair : hash_prefix_map_) { 768 for (const auto& pair : hash_prefix_map_) {
769 const PrefixSize& prefix_size = pair.first; 769 const PrefixSize& prefix_size = pair.first;
770 const HashPrefixes& hash_prefixes = pair.second; 770 const HashPrefixes& hash_prefixes = pair.second;
771 HashPrefix hash_prefix = full_hash.substr(0, prefix_size); 771 HashPrefix hash_prefix = full_hash.substr(0, prefix_size);
772 if (HashPrefixMatches(hash_prefix, hash_prefixes.begin(), 772 if (HashPrefixMatches(hash_prefix, hash_prefixes.begin(),
773 hash_prefixes.end())) { 773 hash_prefixes.end())) {
774 return hash_prefix; 774 return hash_prefix;
775 } 775 }
776 } 776 }
777 return HashPrefix(); 777 return HashPrefix();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_store.h ('k') | components/safe_browsing_db/v4_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698