| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/safe_browsing/safe_browsing_store_file.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_file.h" | 8 #include "base/files/scoped_file.h" |
| 9 #include "base/md5.h" | 9 #include "base/md5.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // Prevent excessive sharding by setting a lower limit on the shard stride. | 42 // Prevent excessive sharding by setting a lower limit on the shard stride. |
| 43 // Smaller values should work fine, but very small values will probably lead to | 43 // Smaller values should work fine, but very small values will probably lead to |
| 44 // poor performance. Shard stride is indirectly related to | 44 // poor performance. Shard stride is indirectly related to |
| 45 // |kUpdateStorageBytes|, setting that very small will bump against this. | 45 // |kUpdateStorageBytes|, setting that very small will bump against this. |
| 46 const uint32 kMinShardStride = 1 << 24; | 46 const uint32 kMinShardStride = 1 << 24; |
| 47 | 47 |
| 48 // Strides over the entire SBPrefix space. | 48 // Strides over the entire SBPrefix space. |
| 49 const uint64 kMaxShardStride = 1ULL << 32; | 49 const uint64 kMaxShardStride = 1ULL << 32; |
| 50 | 50 |
| 51 // Maximum SBPrefix value. | 51 // Maximum SBPrefix value. |
| 52 const SBPrefix kMaxSBPrefix = ~0; | 52 const SBPrefix kMaxSBPrefix = 0xFFFFFFFF; |
| 53 | 53 |
| 54 // Header at the front of the main database file. | 54 // Header at the front of the main database file. |
| 55 struct FileHeaderV8 { | 55 struct FileHeaderV8 { |
| 56 int32 magic, version; | 56 int32 magic, version; |
| 57 uint32 add_chunk_count, sub_chunk_count; | 57 uint32 add_chunk_count, sub_chunk_count; |
| 58 uint32 shard_stride; | 58 uint32 shard_stride; |
| 59 // TODO(shess): Is this where 64-bit will bite me? Perhaps write a | 59 // TODO(shess): Is this where 64-bit will bite me? Perhaps write a |
| 60 // specialized read/write? | 60 // specialized read/write? |
| 61 }; | 61 }; |
| 62 | 62 |
| (...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 // input file. |out_stride| will be derived from an estimate of the resulting | 961 // input file. |out_stride| will be derived from an estimate of the resulting |
| 962 // file's size. |process_stride| will be the max of both. | 962 // file's size. |process_stride| will be the max of both. |
| 963 uint64 in_stride = kMaxShardStride; | 963 uint64 in_stride = kMaxShardStride; |
| 964 uint64 out_stride = kMaxShardStride; | 964 uint64 out_stride = kMaxShardStride; |
| 965 uint64 process_stride = 0; | 965 uint64 process_stride = 0; |
| 966 | 966 |
| 967 // The header info is only used later if |!empty_|. The v8 read loop only | 967 // The header info is only used later if |!empty_|. The v8 read loop only |
| 968 // needs |in_stride|, while v7 needs to refer to header information. | 968 // needs |in_stride|, while v7 needs to refer to header information. |
| 969 base::MD5Context in_context; | 969 base::MD5Context in_context; |
| 970 int version = kInvalidVersion; | 970 int version = kInvalidVersion; |
| 971 FileHeader header; | 971 FileHeader header = {0}; |
| 972 | 972 |
| 973 if (!empty_) { | 973 if (!empty_) { |
| 974 DCHECK(file_.get()); | 974 DCHECK(file_.get()); |
| 975 | 975 |
| 976 version = ReadAndVerifyHeader(filename_, &header, | 976 version = ReadAndVerifyHeader(filename_, &header, |
| 977 &add_chunks_cache_, &sub_chunks_cache_, | 977 &add_chunks_cache_, &sub_chunks_cache_, |
| 978 file_.get(), &in_context); | 978 file_.get(), &in_context); |
| 979 if (version == kInvalidVersion) | 979 if (version == kInvalidVersion) |
| 980 return OnCorruptDatabase(); | 980 return OnCorruptDatabase(); |
| 981 | 981 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 // With SQLite support gone, one way to get to this code is if the | 1237 // With SQLite support gone, one way to get to this code is if the |
| 1238 // existing file is a SQLite file. Make sure the journal file is | 1238 // existing file is a SQLite file. Make sure the journal file is |
| 1239 // also removed. | 1239 // also removed. |
| 1240 const base::FilePath journal_filename( | 1240 const base::FilePath journal_filename( |
| 1241 basename.value() + FILE_PATH_LITERAL("-journal")); | 1241 basename.value() + FILE_PATH_LITERAL("-journal")); |
| 1242 if (base::PathExists(journal_filename)) | 1242 if (base::PathExists(journal_filename)) |
| 1243 base::DeleteFile(journal_filename, false); | 1243 base::DeleteFile(journal_filename, false); |
| 1244 | 1244 |
| 1245 return true; | 1245 return true; |
| 1246 } | 1246 } |
| OLD | NEW |