OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common/important_file_writer.h" | 5 #include "chrome/common/important_file_writer.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 | 44 |
45 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE; | 45 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE; |
46 base::PlatformFile tmp_file = | 46 base::PlatformFile tmp_file = |
47 base::CreatePlatformFile(tmp_file_path, flags, NULL, NULL); | 47 base::CreatePlatformFile(tmp_file_path, flags, NULL, NULL); |
48 if (tmp_file == base::kInvalidPlatformFileValue) { | 48 if (tmp_file == base::kInvalidPlatformFileValue) { |
49 LogFailure(FAILED_OPENING, "could not open temporary file"); | 49 LogFailure(FAILED_OPENING, "could not open temporary file"); |
50 return; | 50 return; |
51 } | 51 } |
52 | 52 |
53 CHECK_LE(data_.length(), static_cast<size_t>(kint32max)); | 53 DCHECK_LE(data_.length(), static_cast<size_t>(kint32max)); |
54 int bytes_written = base::WritePlatformFile( | 54 int bytes_written = base::WritePlatformFile( |
55 tmp_file, 0, data_.data(), static_cast<int>(data_.length())); | 55 tmp_file, 0, data_.data(), static_cast<int>(data_.length())); |
56 base::FlushPlatformFile(tmp_file); // Ignore return value. | 56 base::FlushPlatformFile(tmp_file); // Ignore return value. |
57 | 57 |
58 if (!base::ClosePlatformFile(tmp_file)) { | 58 if (!base::ClosePlatformFile(tmp_file)) { |
59 LogFailure(FAILED_CLOSING, "failed to close temporary file"); | 59 LogFailure(FAILED_CLOSING, "failed to close temporary file"); |
60 file_util::Delete(tmp_file_path, false); | 60 file_util::Delete(tmp_file_path, false); |
61 return; | 61 return; |
62 } | 62 } |
63 | 63 |
(...skipping 17 matching lines...) Expand all Loading... |
81 FAILED_OPENING, | 81 FAILED_OPENING, |
82 FAILED_CLOSING, | 82 FAILED_CLOSING, |
83 FAILED_WRITING, | 83 FAILED_WRITING, |
84 FAILED_RENAMING, | 84 FAILED_RENAMING, |
85 TEMP_FILE_FAILURE_MAX | 85 TEMP_FILE_FAILURE_MAX |
86 }; | 86 }; |
87 | 87 |
88 void LogFailure(TempFileFailure failure_code, const std::string& message) { | 88 void LogFailure(TempFileFailure failure_code, const std::string& message) { |
89 UMA_HISTOGRAM_ENUMERATION("ImportantFile.TempFileFailures", failure_code, | 89 UMA_HISTOGRAM_ENUMERATION("ImportantFile.TempFileFailures", failure_code, |
90 TEMP_FILE_FAILURE_MAX); | 90 TEMP_FILE_FAILURE_MAX); |
91 PLOG(WARNING) << "temp file failure: " << path_.value() | 91 DPLOG(WARNING) << "temp file failure: " << path_.value() |
92 << " : " << message; | 92 << " : " << message; |
93 } | 93 } |
94 | 94 |
95 const FilePath path_; | 95 const FilePath path_; |
96 const std::string data_; | 96 const std::string data_; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(WriteToDiskTask); | 98 DISALLOW_COPY_AND_ASSIGN(WriteToDiskTask); |
99 }; | 99 }; |
100 | 100 |
101 } // namespace | 101 } // namespace |
102 | 102 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 &ImportantFileWriter::DoScheduledWrite); | 156 &ImportantFileWriter::DoScheduledWrite); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 void ImportantFileWriter::DoScheduledWrite() { | 160 void ImportantFileWriter::DoScheduledWrite() { |
161 DCHECK(serializer_); | 161 DCHECK(serializer_); |
162 std::string data; | 162 std::string data; |
163 if (serializer_->SerializeData(&data)) { | 163 if (serializer_->SerializeData(&data)) { |
164 WriteNow(data); | 164 WriteNow(data); |
165 } else { | 165 } else { |
166 LOG(WARNING) << "failed to serialize data to be saved in " | 166 DLOG(WARNING) << "failed to serialize data to be saved in " |
167 << path_.value(); | 167 << path_.value(); |
168 } | 168 } |
169 serializer_ = NULL; | 169 serializer_ = NULL; |
170 } | 170 } |
OLD | NEW |