| 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" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "components/safe_browsing_db/v4_rice.h" | 13 #include "components/safe_browsing_db/v4_rice.h" |
| 14 #include "components/safe_browsing_db/v4_store.h" | 14 #include "components/safe_browsing_db/v4_store.h" |
| 15 #include "components/safe_browsing_db/v4_store.pb.h" | 15 #include "components/safe_browsing_db/v4_store.pb.h" |
| 16 #include "crypto/secure_hash.h" | 16 #include "crypto/secure_hash.h" |
| 17 #include "crypto/sha2.h" | 17 #include "crypto/sha2.h" |
| 18 | 18 |
| 19 namespace safe_browsing { | 19 namespace safe_browsing { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 const uint32_t kFileMagic = 0x600D71FE; | 22 const uint32_t kFileMagic = 0x600D71FE; |
| 23 | 23 |
| 24 const uint32_t kFileVersion = 9; | 24 const uint32_t kFileVersion = 9; |
| 25 | 25 |
| 26 // The minimum expected size (in bytes) of a hash-prefix. | |
| 27 const uint32_t kMinHashPrefixLength = 4; | |
| 28 | |
| 29 // The maximum expected size (in bytes) of a hash-prefix. This represents the | |
| 30 // length of a SHA256 hash. | |
| 31 const uint32_t kMaxHashPrefixLength = 32; | |
| 32 | |
| 33 void RecordStoreReadResult(StoreReadResult result) { | 26 void RecordStoreReadResult(StoreReadResult result) { |
| 34 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4StoreReadResult", result, | 27 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4StoreReadResult", result, |
| 35 STORE_READ_RESULT_MAX); | 28 STORE_READ_RESULT_MAX); |
| 36 } | 29 } |
| 37 | 30 |
| 38 void RecordStoreWriteResult(StoreWriteResult result) { | 31 void RecordStoreWriteResult(StoreWriteResult result) { |
| 39 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4StoreWriteResult", result, | 32 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4StoreWriteResult", result, |
| 40 STORE_WRITE_RESULT_MAX); | 33 STORE_WRITE_RESULT_MAX); |
| 41 } | 34 } |
| 42 | 35 |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 if (result == 0) { | 597 if (result == 0) { |
| 605 return true; | 598 return true; |
| 606 } else if (result < 0) { | 599 } else if (result < 0) { |
| 607 return HashPrefixMatches(hash_prefix, begin, mid); | 600 return HashPrefixMatches(hash_prefix, begin, mid); |
| 608 } else { | 601 } else { |
| 609 return HashPrefixMatches(hash_prefix, mid + prefix_size, end); | 602 return HashPrefixMatches(hash_prefix, mid + prefix_size, end); |
| 610 } | 603 } |
| 611 } | 604 } |
| 612 | 605 |
| 613 } // namespace safe_browsing | 606 } // namespace safe_browsing |
| OLD | NEW |