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 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 template <typename T> | 497 template <typename T> |
498 bool IsPowerOfTwo(const T& val) { | 498 bool IsPowerOfTwo(const T& val) { |
499 return val && (val & (val - 1)) == 0; | 499 return val && (val & (val - 1)) == 0; |
500 } | 500 } |
501 | 501 |
502 // Helper to read the entire database state, used by GetAddPrefixes() and | 502 // Helper to read the entire database state, used by GetAddPrefixes() and |
503 // GetAddFullHashes(). Those functions are generally used only for smaller | 503 // GetAddFullHashes(). Those functions are generally used only for smaller |
504 // files. Returns false in case of errors reading the data. | 504 // files. Returns false in case of errors reading the data. |
505 bool ReadDbStateHelper(const base::FilePath& filename, | 505 bool ReadDbStateHelper(const base::FilePath& filename, |
506 StateInternal* db_state) { | 506 StateInternal* db_state) { |
507 file_util::ScopedFILE file(base::OpenFile(filename, "rb")); | 507 base::ScopedFILE file(base::OpenFile(filename, "rb")); |
508 if (file.get() == NULL) | 508 if (file.get() == NULL) |
509 return false; | 509 return false; |
510 | 510 |
511 std::set<int32> add_chunks; | 511 std::set<int32> add_chunks; |
512 std::set<int32> sub_chunks; | 512 std::set<int32> sub_chunks; |
513 | 513 |
514 base::MD5Context context; | 514 base::MD5Context context; |
515 FileHeader header; | 515 FileHeader header; |
516 const int version = | 516 const int version = |
517 ReadAndVerifyHeader(filename, &header, &add_chunks, &sub_chunks, | 517 ReadAndVerifyHeader(filename, &header, &add_chunks, &sub_chunks, |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 // With SQLite support gone, one way to get to this code is if the | 1113 // With SQLite support gone, one way to get to this code is if the |
1114 // existing file is a SQLite file. Make sure the journal file is | 1114 // existing file is a SQLite file. Make sure the journal file is |
1115 // also removed. | 1115 // also removed. |
1116 const base::FilePath journal_filename( | 1116 const base::FilePath journal_filename( |
1117 basename.value() + FILE_PATH_LITERAL("-journal")); | 1117 basename.value() + FILE_PATH_LITERAL("-journal")); |
1118 if (base::PathExists(journal_filename)) | 1118 if (base::PathExists(journal_filename)) |
1119 base::DeleteFile(journal_filename, false); | 1119 base::DeleteFile(journal_filename, false); |
1120 | 1120 |
1121 return true; | 1121 return true; |
1122 } | 1122 } |
OLD | NEW |