| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <ostream> | 9 #include <ostream> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/message_loop_proxy.h" | 15 #include "base/message_loop_proxy.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_number_conversions.h" |
| 17 #include "base/task.h" | 17 #include "base/task.h" |
| 18 #include "base/thread.h" | 18 #include "base/thread.h" |
| 19 #include "base/time.h" | 19 #include "base/time.h" |
| 20 | 20 |
| 21 using base::TimeDelta; | 21 using base::TimeDelta; |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const int kDefaultCommitIntervalMs = 10000; | 25 const int kDefaultCommitIntervalMs = 10000; |
| 26 | 26 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 size_t bytes_written = fwrite(data_.data(), 1, data_.length(), tmp_file); | 47 size_t bytes_written = fwrite(data_.data(), 1, data_.length(), tmp_file); |
| 48 if (!file_util::CloseFile(tmp_file)) { | 48 if (!file_util::CloseFile(tmp_file)) { |
| 49 file_util::Delete(tmp_file_path, false); | 49 file_util::Delete(tmp_file_path, false); |
| 50 LogFailure("failed to close temporary file"); | 50 LogFailure("failed to close temporary file"); |
| 51 return; | 51 return; |
| 52 } | 52 } |
| 53 if (bytes_written < data_.length()) { | 53 if (bytes_written < data_.length()) { |
| 54 file_util::Delete(tmp_file_path, false); | 54 file_util::Delete(tmp_file_path, false); |
| 55 LogFailure("error writing, bytes_written=" + UintToString( | 55 LogFailure("error writing, bytes_written=" + |
| 56 static_cast<unsigned int>(bytes_written))); | 56 base::Uint64ToString(bytes_written)); |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 | 59 |
| 60 if (file_util::ReplaceFile(tmp_file_path, path_)) { | 60 if (file_util::ReplaceFile(tmp_file_path, path_)) { |
| 61 LogSuccess(); | 61 LogSuccess(); |
| 62 return; | 62 return; |
| 63 } | 63 } |
| 64 | 64 |
| 65 file_util::Delete(tmp_file_path, false); | 65 file_util::Delete(tmp_file_path, false); |
| 66 LogFailure("could not rename temporary file"); | 66 LogFailure("could not rename temporary file"); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 DCHECK(serializer_); | 141 DCHECK(serializer_); |
| 142 std::string data; | 142 std::string data; |
| 143 if (serializer_->SerializeData(&data)) { | 143 if (serializer_->SerializeData(&data)) { |
| 144 WriteNow(data); | 144 WriteNow(data); |
| 145 } else { | 145 } else { |
| 146 LOG(WARNING) << "failed to serialize data to be saved in " | 146 LOG(WARNING) << "failed to serialize data to be saved in " |
| 147 << path_.value(); | 147 << path_.value(); |
| 148 } | 148 } |
| 149 serializer_ = NULL; | 149 serializer_ = NULL; |
| 150 } | 150 } |
| OLD | NEW |