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/files/file_util.h" | 7 #include "base/files/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" |
11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
12 #include "components/safe_browsing_db/prefix_set.h" | 12 #include "components/safe_browsing_db/prefix_set.h" |
13 | 13 |
| 14 namespace safe_browsing { |
| 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // NOTE(shess): kFileMagic should not be a byte-wise palindrome, so | 18 // NOTE(shess): kFileMagic should not be a byte-wise palindrome, so |
17 // that byte-order changes force corruption. | 19 // that byte-order changes force corruption. |
18 const int32 kFileMagic = 0x600D71FE; | 20 const int32 kFileMagic = 0x600D71FE; |
19 | 21 |
20 // Version history: | 22 // Version history: |
21 // Version 6: aad08754/r2814 by erikkay@google.com on 2008-10-02 (sqlite) | 23 // Version 6: aad08754/r2814 by erikkay@google.com on 2008-10-02 (sqlite) |
22 // Version 7: 6afe28a5/r37435 by shess@chromium.org on 2010-01-28 | 24 // Version 7: 6afe28a5/r37435 by shess@chromium.org on 2010-01-28 |
23 // Version 8: d3dd0715/r259791 by shess@chromium.org on 2014-03-27 | 25 // Version 8: d3dd0715/r259791 by shess@chromium.org on 2014-03-27 |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 !WriteContainer(sub_hashes_, new_file_.get(), NULL)) | 815 !WriteContainer(sub_hashes_, new_file_.get(), NULL)) |
814 return false; | 816 return false; |
815 | 817 |
816 ++chunks_written_; | 818 ++chunks_written_; |
817 | 819 |
818 // Clear everything to save memory. | 820 // Clear everything to save memory. |
819 return ClearChunkBuffers(); | 821 return ClearChunkBuffers(); |
820 } | 822 } |
821 | 823 |
822 bool SafeBrowsingStoreFile::DoUpdate( | 824 bool SafeBrowsingStoreFile::DoUpdate( |
823 safe_browsing::PrefixSetBuilder* builder, | 825 PrefixSetBuilder* builder, |
824 std::vector<SBAddFullHash>* add_full_hashes_result) { | 826 std::vector<SBAddFullHash>* add_full_hashes_result) { |
825 DCHECK(CalledOnValidThread()); | 827 DCHECK(CalledOnValidThread()); |
826 DCHECK(file_.get() || empty_); | 828 DCHECK(file_.get() || empty_); |
827 DCHECK(new_file_.get()); | 829 DCHECK(new_file_.get()); |
828 CHECK(builder); | 830 CHECK(builder); |
829 CHECK(add_full_hashes_result); | 831 CHECK(add_full_hashes_result); |
830 | 832 |
831 // Rewind the temporary storage. | 833 // Rewind the temporary storage. |
832 if (!FileRewind(new_file_.get())) | 834 if (!FileRewind(new_file_.get())) |
833 return false; | 835 return false; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 return false; | 1063 return false; |
1062 | 1064 |
1063 // Record counts before swapping to caller. | 1065 // Record counts before swapping to caller. |
1064 UMA_HISTOGRAM_COUNTS("SB2.AddPrefixes", add_prefix_count); | 1066 UMA_HISTOGRAM_COUNTS("SB2.AddPrefixes", add_prefix_count); |
1065 UMA_HISTOGRAM_COUNTS("SB2.SubPrefixes", sub_prefix_count); | 1067 UMA_HISTOGRAM_COUNTS("SB2.SubPrefixes", sub_prefix_count); |
1066 | 1068 |
1067 return true; | 1069 return true; |
1068 } | 1070 } |
1069 | 1071 |
1070 bool SafeBrowsingStoreFile::FinishUpdate( | 1072 bool SafeBrowsingStoreFile::FinishUpdate( |
1071 safe_browsing::PrefixSetBuilder* builder, | 1073 PrefixSetBuilder* builder, |
1072 std::vector<SBAddFullHash>* add_full_hashes_result) { | 1074 std::vector<SBAddFullHash>* add_full_hashes_result) { |
1073 DCHECK(CalledOnValidThread()); | 1075 DCHECK(CalledOnValidThread()); |
1074 DCHECK(builder); | 1076 DCHECK(builder); |
1075 DCHECK(add_full_hashes_result); | 1077 DCHECK(add_full_hashes_result); |
1076 | 1078 |
1077 if (!DoUpdate(builder, add_full_hashes_result)) { | 1079 if (!DoUpdate(builder, add_full_hashes_result)) { |
1078 CancelUpdate(); | 1080 CancelUpdate(); |
1079 return false; | 1081 return false; |
1080 } | 1082 } |
1081 | 1083 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 // With SQLite support gone, one way to get to this code is if the | 1158 // With SQLite support gone, one way to get to this code is if the |
1157 // existing file is a SQLite file. Make sure the journal file is | 1159 // existing file is a SQLite file. Make sure the journal file is |
1158 // also removed. | 1160 // also removed. |
1159 const base::FilePath journal_filename( | 1161 const base::FilePath journal_filename( |
1160 basename.value() + FILE_PATH_LITERAL("-journal")); | 1162 basename.value() + FILE_PATH_LITERAL("-journal")); |
1161 if (base::PathExists(journal_filename)) | 1163 if (base::PathExists(journal_filename)) |
1162 base::DeleteFile(journal_filename, false); | 1164 base::DeleteFile(journal_filename, false); |
1163 | 1165 |
1164 return true; | 1166 return true; |
1165 } | 1167 } |
| 1168 |
| 1169 } // namespace safe_browsing |
OLD | NEW |