| 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/md5.h" | 7 #include "base/md5.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 const base::FilePath& current_filename) { | 179 const base::FilePath& current_filename) { |
| 180 const base::FilePath original_filename( | 180 const base::FilePath original_filename( |
| 181 current_filename.DirName().AppendASCII("Safe Browsing")); | 181 current_filename.DirName().AppendASCII("Safe Browsing")); |
| 182 if (file_util::PathExists(original_filename)) { | 182 if (file_util::PathExists(original_filename)) { |
| 183 int64 size = 0; | 183 int64 size = 0; |
| 184 if (file_util::GetFileSize(original_filename, &size)) { | 184 if (file_util::GetFileSize(original_filename, &size)) { |
| 185 UMA_HISTOGRAM_COUNTS("SB2.OldDatabaseKilobytes", | 185 UMA_HISTOGRAM_COUNTS("SB2.OldDatabaseKilobytes", |
| 186 static_cast<int>(size / 1024)); | 186 static_cast<int>(size / 1024)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 if (file_util::Delete(original_filename, false)) { | 189 if (base::Delete(original_filename, false)) { |
| 190 RecordFormatEvent(FORMAT_EVENT_DELETED_ORIGINAL); | 190 RecordFormatEvent(FORMAT_EVENT_DELETED_ORIGINAL); |
| 191 } else { | 191 } else { |
| 192 RecordFormatEvent(FORMAT_EVENT_DELETED_ORIGINAL_FAILED); | 192 RecordFormatEvent(FORMAT_EVENT_DELETED_ORIGINAL_FAILED); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Just best-effort on the journal file, don't want to get lost in | 195 // Just best-effort on the journal file, don't want to get lost in |
| 196 // the weeds. | 196 // the weeds. |
| 197 const base::FilePath journal_filename( | 197 const base::FilePath journal_filename( |
| 198 current_filename.DirName().AppendASCII("Safe Browsing-journal")); | 198 current_filename.DirName().AppendASCII("Safe Browsing-journal")); |
| 199 file_util::Delete(journal_filename, false); | 199 base::Delete(journal_filename, false); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 SafeBrowsingStoreFile::SafeBrowsingStoreFile() | 203 SafeBrowsingStoreFile::SafeBrowsingStoreFile() |
| 204 : chunks_written_(0), empty_(false), corruption_seen_(false) {} | 204 : chunks_written_(0), empty_(false), corruption_seen_(false) {} |
| 205 | 205 |
| 206 SafeBrowsingStoreFile::~SafeBrowsingStoreFile() { | 206 SafeBrowsingStoreFile::~SafeBrowsingStoreFile() { |
| 207 Close(); | 207 Close(); |
| 208 } | 208 } |
| 209 | 209 |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 base::MD5Final(&digest, &context); | 647 base::MD5Final(&digest, &context); |
| 648 if (!WriteItem(digest, new_file_.get(), NULL)) | 648 if (!WriteItem(digest, new_file_.get(), NULL)) |
| 649 return false; | 649 return false; |
| 650 | 650 |
| 651 // Trim any excess left over from the temporary chunk data. | 651 // Trim any excess left over from the temporary chunk data. |
| 652 if (!file_util::TruncateFile(new_file_.get())) | 652 if (!file_util::TruncateFile(new_file_.get())) |
| 653 return false; | 653 return false; |
| 654 | 654 |
| 655 // Close the file handle and swizzle the file into place. | 655 // Close the file handle and swizzle the file into place. |
| 656 new_file_.reset(); | 656 new_file_.reset(); |
| 657 if (!file_util::Delete(filename_, false) && | 657 if (!base::Delete(filename_, false) && |
| 658 file_util::PathExists(filename_)) | 658 file_util::PathExists(filename_)) |
| 659 return false; | 659 return false; |
| 660 | 660 |
| 661 const base::FilePath new_filename = TemporaryFileForFilename(filename_); | 661 const base::FilePath new_filename = TemporaryFileForFilename(filename_); |
| 662 if (!file_util::Move(new_filename, filename_)) | 662 if (!file_util::Move(new_filename, filename_)) |
| 663 return false; | 663 return false; |
| 664 | 664 |
| 665 // Record counts before swapping to caller. | 665 // Record counts before swapping to caller. |
| 666 UMA_HISTOGRAM_COUNTS("SB2.AddPrefixes", add_prefixes.size()); | 666 UMA_HISTOGRAM_COUNTS("SB2.AddPrefixes", add_prefixes.size()); |
| 667 UMA_HISTOGRAM_COUNTS("SB2.SubPrefixes", sub_prefixes.size()); | 667 UMA_HISTOGRAM_COUNTS("SB2.SubPrefixes", sub_prefixes.size()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 void SafeBrowsingStoreFile::DeleteAddChunk(int32 chunk_id) { | 728 void SafeBrowsingStoreFile::DeleteAddChunk(int32 chunk_id) { |
| 729 add_del_cache_.insert(chunk_id); | 729 add_del_cache_.insert(chunk_id); |
| 730 } | 730 } |
| 731 | 731 |
| 732 void SafeBrowsingStoreFile::DeleteSubChunk(int32 chunk_id) { | 732 void SafeBrowsingStoreFile::DeleteSubChunk(int32 chunk_id) { |
| 733 sub_del_cache_.insert(chunk_id); | 733 sub_del_cache_.insert(chunk_id); |
| 734 } | 734 } |
| 735 | 735 |
| 736 // static | 736 // static |
| 737 bool SafeBrowsingStoreFile::DeleteStore(const base::FilePath& basename) { | 737 bool SafeBrowsingStoreFile::DeleteStore(const base::FilePath& basename) { |
| 738 if (!file_util::Delete(basename, false) && | 738 if (!base::Delete(basename, false) && |
| 739 file_util::PathExists(basename)) { | 739 file_util::PathExists(basename)) { |
| 740 NOTREACHED(); | 740 NOTREACHED(); |
| 741 return false; | 741 return false; |
| 742 } | 742 } |
| 743 | 743 |
| 744 const base::FilePath new_filename = TemporaryFileForFilename(basename); | 744 const base::FilePath new_filename = TemporaryFileForFilename(basename); |
| 745 if (!file_util::Delete(new_filename, false) && | 745 if (!base::Delete(new_filename, false) && |
| 746 file_util::PathExists(new_filename)) { | 746 file_util::PathExists(new_filename)) { |
| 747 NOTREACHED(); | 747 NOTREACHED(); |
| 748 return false; | 748 return false; |
| 749 } | 749 } |
| 750 | 750 |
| 751 // With SQLite support gone, one way to get to this code is if the | 751 // With SQLite support gone, one way to get to this code is if the |
| 752 // existing file is a SQLite file. Make sure the journal file is | 752 // existing file is a SQLite file. Make sure the journal file is |
| 753 // also removed. | 753 // also removed. |
| 754 const base::FilePath journal_filename( | 754 const base::FilePath journal_filename( |
| 755 basename.value() + FILE_PATH_LITERAL("-journal")); | 755 basename.value() + FILE_PATH_LITERAL("-journal")); |
| 756 if (file_util::PathExists(journal_filename)) | 756 if (file_util::PathExists(journal_filename)) |
| 757 file_util::Delete(journal_filename, false); | 757 base::Delete(journal_filename, false); |
| 758 | 758 |
| 759 return true; | 759 return true; |
| 760 } | 760 } |
| OLD | NEW |