Chromium Code Reviews| 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 { |
| 15 | 15 |
| 16 using safe_browsing::SBAddFullHash; | |
| 17 using safe_browsing::SBAddPrefix; | |
| 18 using safe_browsing::SBAddPrefixes; | |
| 19 using safe_browsing::SBAddPrefixHashLess; | |
| 20 using safe_browsing::SBAddPrefixLess; | |
| 21 using safe_browsing::SBPrefix; | |
| 22 using safe_browsing::SBSubFullHash; | |
| 23 using safe_browsing::SBSubPrefix; | |
| 24 using safe_browsing::SBSubPrefixes; | |
|
mattm
2015/11/11 01:10:16
Put this namespace inside the namespace safe_brows
vakh (old account. dont use)
2015/11/11 18:59:53
Done.
| |
| 25 | |
| 16 // NOTE(shess): kFileMagic should not be a byte-wise palindrome, so | 26 // NOTE(shess): kFileMagic should not be a byte-wise palindrome, so |
| 17 // that byte-order changes force corruption. | 27 // that byte-order changes force corruption. |
| 18 const int32 kFileMagic = 0x600D71FE; | 28 const int32 kFileMagic = 0x600D71FE; |
| 19 | 29 |
| 20 // Version history: | 30 // Version history: |
| 21 // Version 6: aad08754/r2814 by erikkay@google.com on 2008-10-02 (sqlite) | 31 // 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 | 32 // 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 | 33 // Version 8: d3dd0715/r259791 by shess@chromium.org on 2014-03-27 |
| 24 const int32 kFileVersion = 8; | 34 const int32 kFileVersion = 8; |
| 25 | 35 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 | 558 |
| 549 int64 size = 0; | 559 int64 size = 0; |
| 550 if (!base::GetFileSize(filename, &size)) | 560 if (!base::GetFileSize(filename, &size)) |
| 551 return false; | 561 return false; |
| 552 | 562 |
| 553 return static_cast<int64>(ftell(file.get())) == size; | 563 return static_cast<int64>(ftell(file.get())) == size; |
| 554 } | 564 } |
| 555 | 565 |
| 556 } // namespace | 566 } // namespace |
| 557 | 567 |
| 568 namespace safe_browsing { | |
| 569 | |
| 558 SafeBrowsingStoreFile::SafeBrowsingStoreFile( | 570 SafeBrowsingStoreFile::SafeBrowsingStoreFile( |
| 559 const scoped_refptr<const base::SequencedTaskRunner>& task_runner) | 571 const scoped_refptr<const base::SequencedTaskRunner>& task_runner) |
| 560 : task_runner_(task_runner), | 572 : task_runner_(task_runner), |
| 561 chunks_written_(0), | 573 chunks_written_(0), |
| 562 empty_(false), | 574 empty_(false), |
| 563 corruption_seen_(false) { | 575 corruption_seen_(false) { |
| 564 } | 576 } |
| 565 | 577 |
| 566 SafeBrowsingStoreFile::~SafeBrowsingStoreFile() { | 578 SafeBrowsingStoreFile::~SafeBrowsingStoreFile() { |
| 567 // Thread-checking is disabled in the destructor due to crbug.com/338486. | 579 // 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)) | 825 !WriteContainer(sub_hashes_, new_file_.get(), NULL)) |
| 814 return false; | 826 return false; |
| 815 | 827 |
| 816 ++chunks_written_; | 828 ++chunks_written_; |
| 817 | 829 |
| 818 // Clear everything to save memory. | 830 // Clear everything to save memory. |
| 819 return ClearChunkBuffers(); | 831 return ClearChunkBuffers(); |
| 820 } | 832 } |
| 821 | 833 |
| 822 bool SafeBrowsingStoreFile::DoUpdate( | 834 bool SafeBrowsingStoreFile::DoUpdate( |
| 823 safe_browsing::PrefixSetBuilder* builder, | 835 PrefixSetBuilder* builder, |
| 824 std::vector<SBAddFullHash>* add_full_hashes_result) { | 836 std::vector<SBAddFullHash>* add_full_hashes_result) { |
| 825 DCHECK(CalledOnValidThread()); | 837 DCHECK(CalledOnValidThread()); |
| 826 DCHECK(file_.get() || empty_); | 838 DCHECK(file_.get() || empty_); |
| 827 DCHECK(new_file_.get()); | 839 DCHECK(new_file_.get()); |
| 828 CHECK(builder); | 840 CHECK(builder); |
| 829 CHECK(add_full_hashes_result); | 841 CHECK(add_full_hashes_result); |
| 830 | 842 |
| 831 // Rewind the temporary storage. | 843 // Rewind the temporary storage. |
| 832 if (!FileRewind(new_file_.get())) | 844 if (!FileRewind(new_file_.get())) |
| 833 return false; | 845 return false; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 return false; | 1073 return false; |
| 1062 | 1074 |
| 1063 // Record counts before swapping to caller. | 1075 // Record counts before swapping to caller. |
| 1064 UMA_HISTOGRAM_COUNTS("SB2.AddPrefixes", add_prefix_count); | 1076 UMA_HISTOGRAM_COUNTS("SB2.AddPrefixes", add_prefix_count); |
| 1065 UMA_HISTOGRAM_COUNTS("SB2.SubPrefixes", sub_prefix_count); | 1077 UMA_HISTOGRAM_COUNTS("SB2.SubPrefixes", sub_prefix_count); |
| 1066 | 1078 |
| 1067 return true; | 1079 return true; |
| 1068 } | 1080 } |
| 1069 | 1081 |
| 1070 bool SafeBrowsingStoreFile::FinishUpdate( | 1082 bool SafeBrowsingStoreFile::FinishUpdate( |
| 1071 safe_browsing::PrefixSetBuilder* builder, | 1083 PrefixSetBuilder* builder, |
| 1072 std::vector<SBAddFullHash>* add_full_hashes_result) { | 1084 std::vector<SBAddFullHash>* add_full_hashes_result) { |
| 1073 DCHECK(CalledOnValidThread()); | 1085 DCHECK(CalledOnValidThread()); |
| 1074 DCHECK(builder); | 1086 DCHECK(builder); |
| 1075 DCHECK(add_full_hashes_result); | 1087 DCHECK(add_full_hashes_result); |
| 1076 | 1088 |
| 1077 if (!DoUpdate(builder, add_full_hashes_result)) { | 1089 if (!DoUpdate(builder, add_full_hashes_result)) { |
| 1078 CancelUpdate(); | 1090 CancelUpdate(); |
| 1079 return false; | 1091 return false; |
| 1080 } | 1092 } |
| 1081 | 1093 |
| (...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 | 1168 // 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 | 1169 // existing file is a SQLite file. Make sure the journal file is |
| 1158 // also removed. | 1170 // also removed. |
| 1159 const base::FilePath journal_filename( | 1171 const base::FilePath journal_filename( |
| 1160 basename.value() + FILE_PATH_LITERAL("-journal")); | 1172 basename.value() + FILE_PATH_LITERAL("-journal")); |
| 1161 if (base::PathExists(journal_filename)) | 1173 if (base::PathExists(journal_filename)) |
| 1162 base::DeleteFile(journal_filename, false); | 1174 base::DeleteFile(journal_filename, false); |
| 1163 | 1175 |
| 1164 return true; | 1176 return true; |
| 1165 } | 1177 } |
| 1178 | |
| 1179 } // namespace safe_browsing | |
| OLD | NEW |