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

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

Issue 2791243002: Rewrite base::Bind into base::BindOnce on trivial cases in base (Closed)
Patch Set: rebase 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/files/file_path_watcher_unittest.cc ('k') | base/files/file_util_proxy.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/file_proxy.h" 5 #include "base/files/file_proxy.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 19 matching lines...) Expand all
30 : file_(std::move(file)), 30 : file_(std::move(file)),
31 error_(File::FILE_ERROR_FAILED), 31 error_(File::FILE_ERROR_FAILED),
32 task_runner_(proxy->task_runner()), 32 task_runner_(proxy->task_runner()),
33 proxy_(AsWeakPtr(proxy)) { 33 proxy_(AsWeakPtr(proxy)) {
34 } 34 }
35 35
36 void PassFile() { 36 void PassFile() {
37 if (proxy_) 37 if (proxy_)
38 proxy_->SetFile(std::move(file_)); 38 proxy_->SetFile(std::move(file_));
39 else if (file_.IsValid()) 39 else if (file_.IsValid())
40 task_runner_->PostTask(FROM_HERE, Bind(&FileDeleter, Passed(&file_))); 40 task_runner_->PostTask(FROM_HERE,
41 BindOnce(&FileDeleter, Passed(&file_)));
41 } 42 }
42 43
43 protected: 44 protected:
44 File file_; 45 File file_;
45 File::Error error_; 46 File::Error error_;
46 47
47 private: 48 private:
48 scoped_refptr<TaskRunner> task_runner_; 49 scoped_refptr<TaskRunner> task_runner_;
49 WeakPtr<FileProxy> proxy_; 50 WeakPtr<FileProxy> proxy_;
50 DISALLOW_COPY_AND_ASSIGN(FileHelper); 51 DISALLOW_COPY_AND_ASSIGN(FileHelper);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 DISALLOW_COPY_AND_ASSIGN(WriteHelper); 229 DISALLOW_COPY_AND_ASSIGN(WriteHelper);
229 }; 230 };
230 231
231 } // namespace 232 } // namespace
232 233
233 FileProxy::FileProxy(TaskRunner* task_runner) : task_runner_(task_runner) { 234 FileProxy::FileProxy(TaskRunner* task_runner) : task_runner_(task_runner) {
234 } 235 }
235 236
236 FileProxy::~FileProxy() { 237 FileProxy::~FileProxy() {
237 if (file_.IsValid()) 238 if (file_.IsValid())
238 task_runner_->PostTask(FROM_HERE, Bind(&FileDeleter, Passed(&file_))); 239 task_runner_->PostTask(FROM_HERE, BindOnce(&FileDeleter, Passed(&file_)));
239 } 240 }
240 241
241 bool FileProxy::CreateOrOpen(const FilePath& file_path, 242 bool FileProxy::CreateOrOpen(const FilePath& file_path,
242 uint32_t file_flags, 243 uint32_t file_flags,
243 const StatusCallback& callback) { 244 const StatusCallback& callback) {
244 DCHECK(!file_.IsValid()); 245 DCHECK(!file_.IsValid());
245 CreateOrOpenHelper* helper = new CreateOrOpenHelper(this, File()); 246 CreateOrOpenHelper* helper = new CreateOrOpenHelper(this, File());
246 return task_runner_->PostTaskAndReply( 247 return task_runner_->PostTaskAndReply(
247 FROM_HERE, 248 FROM_HERE,
248 Bind(&CreateOrOpenHelper::RunWork, Unretained(helper), file_path, 249 BindOnce(&CreateOrOpenHelper::RunWork, Unretained(helper), file_path,
249 file_flags), 250 file_flags),
250 Bind(&CreateOrOpenHelper::Reply, Owned(helper), callback)); 251 BindOnce(&CreateOrOpenHelper::Reply, Owned(helper), callback));
251 } 252 }
252 253
253 bool FileProxy::CreateTemporary(uint32_t additional_file_flags, 254 bool FileProxy::CreateTemporary(uint32_t additional_file_flags,
254 const CreateTemporaryCallback& callback) { 255 const CreateTemporaryCallback& callback) {
255 DCHECK(!file_.IsValid()); 256 DCHECK(!file_.IsValid());
256 CreateTemporaryHelper* helper = new CreateTemporaryHelper(this, File()); 257 CreateTemporaryHelper* helper = new CreateTemporaryHelper(this, File());
257 return task_runner_->PostTaskAndReply( 258 return task_runner_->PostTaskAndReply(
258 FROM_HERE, 259 FROM_HERE,
259 Bind(&CreateTemporaryHelper::RunWork, Unretained(helper), 260 BindOnce(&CreateTemporaryHelper::RunWork, Unretained(helper),
260 additional_file_flags), 261 additional_file_flags),
261 Bind(&CreateTemporaryHelper::Reply, Owned(helper), callback)); 262 BindOnce(&CreateTemporaryHelper::Reply, Owned(helper), callback));
262 } 263 }
263 264
264 bool FileProxy::IsValid() const { 265 bool FileProxy::IsValid() const {
265 return file_.IsValid(); 266 return file_.IsValid();
266 } 267 }
267 268
268 void FileProxy::SetFile(File file) { 269 void FileProxy::SetFile(File file) {
269 DCHECK(!file_.IsValid()); 270 DCHECK(!file_.IsValid());
270 file_ = std::move(file); 271 file_ = std::move(file);
271 } 272 }
272 273
273 File FileProxy::TakeFile() { 274 File FileProxy::TakeFile() {
274 return std::move(file_); 275 return std::move(file_);
275 } 276 }
276 277
277 File FileProxy::DuplicateFile() { 278 File FileProxy::DuplicateFile() {
278 return file_.Duplicate(); 279 return file_.Duplicate();
279 } 280 }
280 281
281 PlatformFile FileProxy::GetPlatformFile() const { 282 PlatformFile FileProxy::GetPlatformFile() const {
282 return file_.GetPlatformFile(); 283 return file_.GetPlatformFile();
283 } 284 }
284 285
285 bool FileProxy::Close(const StatusCallback& callback) { 286 bool FileProxy::Close(const StatusCallback& callback) {
286 DCHECK(file_.IsValid()); 287 DCHECK(file_.IsValid());
287 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); 288 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_));
288 return task_runner_->PostTaskAndReply( 289 return task_runner_->PostTaskAndReply(
289 FROM_HERE, 290 FROM_HERE, BindOnce(&GenericFileHelper::Close, Unretained(helper)),
290 Bind(&GenericFileHelper::Close, Unretained(helper)), 291 BindOnce(&GenericFileHelper::Reply, Owned(helper), callback));
291 Bind(&GenericFileHelper::Reply, Owned(helper), callback));
292 } 292 }
293 293
294 bool FileProxy::GetInfo(const GetFileInfoCallback& callback) { 294 bool FileProxy::GetInfo(const GetFileInfoCallback& callback) {
295 DCHECK(file_.IsValid()); 295 DCHECK(file_.IsValid());
296 GetInfoHelper* helper = new GetInfoHelper(this, std::move(file_)); 296 GetInfoHelper* helper = new GetInfoHelper(this, std::move(file_));
297 return task_runner_->PostTaskAndReply( 297 return task_runner_->PostTaskAndReply(
298 FROM_HERE, 298 FROM_HERE, BindOnce(&GetInfoHelper::RunWork, Unretained(helper)),
299 Bind(&GetInfoHelper::RunWork, Unretained(helper)), 299 BindOnce(&GetInfoHelper::Reply, Owned(helper), callback));
300 Bind(&GetInfoHelper::Reply, Owned(helper), callback));
301 } 300 }
302 301
303 bool FileProxy::Read(int64_t offset, 302 bool FileProxy::Read(int64_t offset,
304 int bytes_to_read, 303 int bytes_to_read,
305 const ReadCallback& callback) { 304 const ReadCallback& callback) {
306 DCHECK(file_.IsValid()); 305 DCHECK(file_.IsValid());
307 if (bytes_to_read < 0) 306 if (bytes_to_read < 0)
308 return false; 307 return false;
309 308
310 ReadHelper* helper = new ReadHelper(this, std::move(file_), bytes_to_read); 309 ReadHelper* helper = new ReadHelper(this, std::move(file_), bytes_to_read);
311 return task_runner_->PostTaskAndReply( 310 return task_runner_->PostTaskAndReply(
312 FROM_HERE, 311 FROM_HERE, BindOnce(&ReadHelper::RunWork, Unretained(helper), offset),
313 Bind(&ReadHelper::RunWork, Unretained(helper), offset), 312 BindOnce(&ReadHelper::Reply, Owned(helper), callback));
314 Bind(&ReadHelper::Reply, Owned(helper), callback));
315 } 313 }
316 314
317 bool FileProxy::Write(int64_t offset, 315 bool FileProxy::Write(int64_t offset,
318 const char* buffer, 316 const char* buffer,
319 int bytes_to_write, 317 int bytes_to_write,
320 const WriteCallback& callback) { 318 const WriteCallback& callback) {
321 DCHECK(file_.IsValid()); 319 DCHECK(file_.IsValid());
322 if (bytes_to_write <= 0 || buffer == NULL) 320 if (bytes_to_write <= 0 || buffer == NULL)
323 return false; 321 return false;
324 322
325 WriteHelper* helper = 323 WriteHelper* helper =
326 new WriteHelper(this, std::move(file_), buffer, bytes_to_write); 324 new WriteHelper(this, std::move(file_), buffer, bytes_to_write);
327 return task_runner_->PostTaskAndReply( 325 return task_runner_->PostTaskAndReply(
328 FROM_HERE, 326 FROM_HERE, BindOnce(&WriteHelper::RunWork, Unretained(helper), offset),
329 Bind(&WriteHelper::RunWork, Unretained(helper), offset), 327 BindOnce(&WriteHelper::Reply, Owned(helper), callback));
330 Bind(&WriteHelper::Reply, Owned(helper), callback));
331 } 328 }
332 329
333 bool FileProxy::SetTimes(Time last_access_time, 330 bool FileProxy::SetTimes(Time last_access_time,
334 Time last_modified_time, 331 Time last_modified_time,
335 const StatusCallback& callback) { 332 const StatusCallback& callback) {
336 DCHECK(file_.IsValid()); 333 DCHECK(file_.IsValid());
337 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); 334 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_));
338 return task_runner_->PostTaskAndReply( 335 return task_runner_->PostTaskAndReply(
339 FROM_HERE, 336 FROM_HERE,
340 Bind(&GenericFileHelper::SetTimes, Unretained(helper), last_access_time, 337 BindOnce(&GenericFileHelper::SetTimes, Unretained(helper),
341 last_modified_time), 338 last_access_time, last_modified_time),
342 Bind(&GenericFileHelper::Reply, Owned(helper), callback)); 339 BindOnce(&GenericFileHelper::Reply, Owned(helper), callback));
343 } 340 }
344 341
345 bool FileProxy::SetLength(int64_t length, const StatusCallback& callback) { 342 bool FileProxy::SetLength(int64_t length, const StatusCallback& callback) {
346 DCHECK(file_.IsValid()); 343 DCHECK(file_.IsValid());
347 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); 344 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_));
348 return task_runner_->PostTaskAndReply( 345 return task_runner_->PostTaskAndReply(
349 FROM_HERE, 346 FROM_HERE,
350 Bind(&GenericFileHelper::SetLength, Unretained(helper), length), 347 BindOnce(&GenericFileHelper::SetLength, Unretained(helper), length),
351 Bind(&GenericFileHelper::Reply, Owned(helper), callback)); 348 BindOnce(&GenericFileHelper::Reply, Owned(helper), callback));
352 } 349 }
353 350
354 bool FileProxy::Flush(const StatusCallback& callback) { 351 bool FileProxy::Flush(const StatusCallback& callback) {
355 DCHECK(file_.IsValid()); 352 DCHECK(file_.IsValid());
356 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_)); 353 GenericFileHelper* helper = new GenericFileHelper(this, std::move(file_));
357 return task_runner_->PostTaskAndReply( 354 return task_runner_->PostTaskAndReply(
358 FROM_HERE, 355 FROM_HERE, BindOnce(&GenericFileHelper::Flush, Unretained(helper)),
359 Bind(&GenericFileHelper::Flush, Unretained(helper)), 356 BindOnce(&GenericFileHelper::Reply, Owned(helper), callback));
360 Bind(&GenericFileHelper::Reply, Owned(helper), callback));
361 } 357 }
362 358
363 } // namespace base 359 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_path_watcher_unittest.cc ('k') | base/files/file_util_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698