| 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 "base/files/important_file_writer.h" | 5 #include "base/files/important_file_writer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/callback_helpers.h" |
| 14 #include "base/critical_closure.h" | 15 #include "base/critical_closure.h" |
| 15 #include "base/debug/alias.h" | 16 #include "base/debug/alias.h" |
| 16 #include "base/files/file.h" | 17 #include "base/files/file.h" |
| 17 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
| 18 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
| 19 #include "base/logging.h" | 20 #include "base/logging.h" |
| 20 #include "base/macros.h" | 21 #include "base/macros.h" |
| 21 #include "base/metrics/histogram_macros.h" | 22 #include "base/metrics/histogram_macros.h" |
| 22 #include "base/numerics/safe_conversions.h" | 23 #include "base/numerics/safe_conversions.h" |
| 23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 void ImportantFileWriter::WriteNow(std::unique_ptr<std::string> data) { | 172 void ImportantFileWriter::WriteNow(std::unique_ptr<std::string> data) { |
| 172 DCHECK(CalledOnValidThread()); | 173 DCHECK(CalledOnValidThread()); |
| 173 if (!IsValueInRangeForNumericType<int32_t>(data->length())) { | 174 if (!IsValueInRangeForNumericType<int32_t>(data->length())) { |
| 174 NOTREACHED(); | 175 NOTREACHED(); |
| 175 return; | 176 return; |
| 176 } | 177 } |
| 177 | 178 |
| 178 if (HasPendingWrite()) | 179 if (HasPendingWrite()) |
| 179 timer_.Stop(); | 180 timer_.Stop(); |
| 180 | 181 |
| 181 Closure task = Bind(&WriteScopedStringToFileAtomically, path_, Passed(&data), | 182 Closure task = AdaptCallbackForRepeating( |
| 182 Passed(&before_next_write_callback_), | 183 BindOnce(&WriteScopedStringToFileAtomically, path_, std::move(data), |
| 183 Passed(&after_next_write_callback_)); | 184 std::move(before_next_write_callback_), |
| 185 std::move(after_next_write_callback_))); |
| 184 | 186 |
| 185 if (!task_runner_->PostTask(FROM_HERE, MakeCriticalClosure(task))) { | 187 if (!task_runner_->PostTask(FROM_HERE, MakeCriticalClosure(task))) { |
| 186 // Posting the task to background message loop is not expected | 188 // Posting the task to background message loop is not expected |
| 187 // to fail, but if it does, avoid losing data and just hit the disk | 189 // to fail, but if it does, avoid losing data and just hit the disk |
| 188 // on the current thread. | 190 // on the current thread. |
| 189 NOTREACHED(); | 191 NOTREACHED(); |
| 190 | 192 |
| 191 task.Run(); | 193 task.Run(); |
| 192 } | 194 } |
| 193 } | 195 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 217 } | 219 } |
| 218 | 220 |
| 219 void ImportantFileWriter::RegisterOnNextWriteCallbacks( | 221 void ImportantFileWriter::RegisterOnNextWriteCallbacks( |
| 220 const Closure& before_next_write_callback, | 222 const Closure& before_next_write_callback, |
| 221 const Callback<void(bool success)>& after_next_write_callback) { | 223 const Callback<void(bool success)>& after_next_write_callback) { |
| 222 before_next_write_callback_ = before_next_write_callback; | 224 before_next_write_callback_ = before_next_write_callback; |
| 223 after_next_write_callback_ = after_next_write_callback; | 225 after_next_write_callback_ = after_next_write_callback; |
| 224 } | 226 } |
| 225 | 227 |
| 226 } // namespace base | 228 } // namespace base |
| OLD | NEW |