Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: components/safe_browsing_db/v4_store.cc

Issue 2598733002: Fix handling of store-write failures in Pver4 (Closed)
Patch Set: Change the way I generate a non-writable file, for Windows Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_store_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 731
732 // Attempt writing to a temporary file first and at the end, swap the files. 732 // Attempt writing to a temporary file first and at the end, swap the files.
733 const base::FilePath new_filename = TemporaryFileForFilename(store_path_); 733 const base::FilePath new_filename = TemporaryFileForFilename(store_path_);
734 734
735 file_format.set_magic_number(kFileMagic); 735 file_format.set_magic_number(kFileMagic);
736 file_format.set_version_number(kFileVersion); 736 file_format.set_version_number(kFileVersion);
737 std::string file_format_string; 737 std::string file_format_string;
738 file_format.SerializeToString(&file_format_string); 738 file_format.SerializeToString(&file_format_string);
739 size_t written = base::WriteFile(new_filename, file_format_string.data(), 739 size_t written = base::WriteFile(new_filename, file_format_string.data(),
740 file_format_string.size()); 740 file_format_string.size());
741 DCHECK_EQ(file_format_string.size(), written); 741
742 if (file_format_string.size() != written) {
743 return UNEXPECTED_BYTES_WRITTEN_FAILURE;
744 }
742 745
743 if (!base::Move(new_filename, store_path_)) { 746 if (!base::Move(new_filename, store_path_)) {
744 return UNABLE_TO_RENAME_FAILURE; 747 return UNABLE_TO_RENAME_FAILURE;
745 } 748 }
746 749
747 // Update |file_size_| now because we wrote the file correctly. 750 // Update |file_size_| now because we wrote the file correctly.
748 file_size_ = static_cast<int64_t>(written); 751 file_size_ = static_cast<int64_t>(written);
749 752
750 return WRITE_SUCCESS; 753 return WRITE_SUCCESS;
751 } 754 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 base_metric + suffix, 1, 1000000, 50, 854 base_metric + suffix, 1, 1000000, 50,
852 base::HistogramBase::kUmaTargetedHistogramFlag); 855 base::HistogramBase::kUmaTargetedHistogramFlag);
853 if (histogram) { 856 if (histogram) {
854 const int64_t file_size_kilobytes = file_size_ / 1024; 857 const int64_t file_size_kilobytes = file_size_ / 1024;
855 histogram->Add(file_size_kilobytes); 858 histogram->Add(file_size_kilobytes);
856 } 859 }
857 return file_size_; 860 return file_size_;
858 } 861 }
859 862
860 } // namespace safe_browsing 863 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | components/safe_browsing_db/v4_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698