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 { | 14 namespace safe_browsing { |
15 | 15 |
16 // NOTE(shess): kFileMagic should not be a byte-wise palindrome, so | 16 // NOTE(shess): kFileMagic should not be a byte-wise palindrome, so |
Nathan Parker
2015/11/05 22:00:53
anon-namespace
vakh (old account. dont use)
2015/11/07 01:22:56
Done.
| |
17 // that byte-order changes force corruption. | 17 // that byte-order changes force corruption. |
18 const int32 kFileMagic = 0x600D71FE; | 18 const int32 kFileMagic = 0x600D71FE; |
19 | 19 |
20 // Version history: | 20 // Version history: |
21 // Version 6: aad08754/r2814 by erikkay@google.com on 2008-10-02 (sqlite) | 21 // 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 | 22 // 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 | 23 // Version 8: d3dd0715/r259791 by shess@chromium.org on 2014-03-27 |
24 const int32 kFileVersion = 8; | 24 const int32 kFileVersion = 8; |
25 | 25 |
26 // ReadAndVerifyHeader() returns this in case of error. | 26 // ReadAndVerifyHeader() returns this in case of error. |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 if (!ReadAndVerifyChecksum(file.get(), &context)) | 546 if (!ReadAndVerifyChecksum(file.get(), &context)) |
547 return false; | 547 return false; |
548 | 548 |
549 int64 size = 0; | 549 int64 size = 0; |
550 if (!base::GetFileSize(filename, &size)) | 550 if (!base::GetFileSize(filename, &size)) |
551 return false; | 551 return false; |
552 | 552 |
553 return static_cast<int64>(ftell(file.get())) == size; | 553 return static_cast<int64>(ftell(file.get())) == size; |
554 } | 554 } |
555 | 555 |
556 } // namespace | |
557 | |
558 SafeBrowsingStoreFile::SafeBrowsingStoreFile( | 556 SafeBrowsingStoreFile::SafeBrowsingStoreFile( |
559 const scoped_refptr<const base::SequencedTaskRunner>& task_runner) | 557 const scoped_refptr<const base::SequencedTaskRunner>& task_runner) |
560 : task_runner_(task_runner), | 558 : task_runner_(task_runner), |
561 chunks_written_(0), | 559 chunks_written_(0), |
562 empty_(false), | 560 empty_(false), |
563 corruption_seen_(false) { | 561 corruption_seen_(false) { |
564 } | 562 } |
565 | 563 |
566 SafeBrowsingStoreFile::~SafeBrowsingStoreFile() { | 564 SafeBrowsingStoreFile::~SafeBrowsingStoreFile() { |
567 // Thread-checking is disabled in the destructor due to crbug.com/338486. | 565 // Thread-checking is disabled in the destructor due to crbug.com/338486. |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
813 !WriteContainer(sub_hashes_, new_file_.get(), NULL)) | 811 !WriteContainer(sub_hashes_, new_file_.get(), NULL)) |
814 return false; | 812 return false; |
815 | 813 |
816 ++chunks_written_; | 814 ++chunks_written_; |
817 | 815 |
818 // Clear everything to save memory. | 816 // Clear everything to save memory. |
819 return ClearChunkBuffers(); | 817 return ClearChunkBuffers(); |
820 } | 818 } |
821 | 819 |
822 bool SafeBrowsingStoreFile::DoUpdate( | 820 bool SafeBrowsingStoreFile::DoUpdate( |
823 safe_browsing::PrefixSetBuilder* builder, | 821 PrefixSetBuilder* builder, |
824 std::vector<SBAddFullHash>* add_full_hashes_result) { | 822 std::vector<SBAddFullHash>* add_full_hashes_result) { |
825 DCHECK(CalledOnValidThread()); | 823 DCHECK(CalledOnValidThread()); |
826 DCHECK(file_.get() || empty_); | 824 DCHECK(file_.get() || empty_); |
827 DCHECK(new_file_.get()); | 825 DCHECK(new_file_.get()); |
828 CHECK(builder); | 826 CHECK(builder); |
829 CHECK(add_full_hashes_result); | 827 CHECK(add_full_hashes_result); |
830 | 828 |
831 // Rewind the temporary storage. | 829 // Rewind the temporary storage. |
832 if (!FileRewind(new_file_.get())) | 830 if (!FileRewind(new_file_.get())) |
833 return false; | 831 return false; |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1061 return false; | 1059 return false; |
1062 | 1060 |
1063 // Record counts before swapping to caller. | 1061 // Record counts before swapping to caller. |
1064 UMA_HISTOGRAM_COUNTS("SB2.AddPrefixes", add_prefix_count); | 1062 UMA_HISTOGRAM_COUNTS("SB2.AddPrefixes", add_prefix_count); |
1065 UMA_HISTOGRAM_COUNTS("SB2.SubPrefixes", sub_prefix_count); | 1063 UMA_HISTOGRAM_COUNTS("SB2.SubPrefixes", sub_prefix_count); |
1066 | 1064 |
1067 return true; | 1065 return true; |
1068 } | 1066 } |
1069 | 1067 |
1070 bool SafeBrowsingStoreFile::FinishUpdate( | 1068 bool SafeBrowsingStoreFile::FinishUpdate( |
1071 safe_browsing::PrefixSetBuilder* builder, | 1069 PrefixSetBuilder* builder, |
1072 std::vector<SBAddFullHash>* add_full_hashes_result) { | 1070 std::vector<SBAddFullHash>* add_full_hashes_result) { |
1073 DCHECK(CalledOnValidThread()); | 1071 DCHECK(CalledOnValidThread()); |
1074 DCHECK(builder); | 1072 DCHECK(builder); |
1075 DCHECK(add_full_hashes_result); | 1073 DCHECK(add_full_hashes_result); |
1076 | 1074 |
1077 if (!DoUpdate(builder, add_full_hashes_result)) { | 1075 if (!DoUpdate(builder, add_full_hashes_result)) { |
1078 CancelUpdate(); | 1076 CancelUpdate(); |
1079 return false; | 1077 return false; |
1080 } | 1078 } |
1081 | 1079 |
(...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 | 1154 // 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 | 1155 // existing file is a SQLite file. Make sure the journal file is |
1158 // also removed. | 1156 // also removed. |
1159 const base::FilePath journal_filename( | 1157 const base::FilePath journal_filename( |
1160 basename.value() + FILE_PATH_LITERAL("-journal")); | 1158 basename.value() + FILE_PATH_LITERAL("-journal")); |
1161 if (base::PathExists(journal_filename)) | 1159 if (base::PathExists(journal_filename)) |
1162 base::DeleteFile(journal_filename, false); | 1160 base::DeleteFile(journal_filename, false); |
1163 | 1161 |
1164 return true; | 1162 return true; |
1165 } | 1163 } |
1164 | |
1165 } // namespace safe_browsing | |
OLD | NEW |