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

Side by Side Diff: base/files/important_file_writer.cc

Issue 2820993002: Introduce base::IgnoreReuse() to wrap OnceCallback into RepeatingCallback (Closed)
Patch Set: fix Created 3 years, 8 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 | « base/callback_helpers_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/callback_helpers_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698