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

Side by Side Diff: base/file_util_proxy.cc

Issue 8315012: base::Bind: Convert FileUtilProxy::GetFileInfoCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pipelining. Created 9 years, 2 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 | Annotate | Revision Log
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/file_util_proxy.h" 5 #include "base/file_util_proxy.h"
6 6
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 8
9 // TODO(jianli): Move the code from anonymous namespace to base namespace so 9 // TODO(jianli): Move the code from anonymous namespace to base namespace so
10 // that all of the base:: prefixes would be unnecessary. 10 // that all of the base:: prefixes would be unnecessary.
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 462
463 private: 463 private:
464 base::FileUtilProxy::ReadDirectoryCallback* callback_; 464 base::FileUtilProxy::ReadDirectoryCallback* callback_;
465 FilePath file_path_; 465 FilePath file_path_;
466 std::vector<base::FileUtilProxy::Entry> entries_; 466 std::vector<base::FileUtilProxy::Entry> entries_;
467 }; 467 };
468 468
469 class RelayGetFileInfo : public MessageLoopRelay { 469 class RelayGetFileInfo : public MessageLoopRelay {
470 public: 470 public:
471 RelayGetFileInfo(const FilePath& file_path, 471 RelayGetFileInfo(const FilePath& file_path,
472 base::FileUtilProxy::GetFileInfoCallback* callback) 472 const base::FileUtilProxy::GetFileInfoCallback& callback)
473 : callback_(callback), 473 : callback_(callback),
474 file_path_(file_path) { 474 file_path_(file_path) {
475 DCHECK(callback); 475 DCHECK_EQ(false, callback.is_null());
476 } 476 }
477 477
478 protected: 478 protected:
479 virtual void RunWork() { 479 virtual void RunWork() {
480 if (!file_util::PathExists(file_path_)) { 480 if (!file_util::PathExists(file_path_)) {
481 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); 481 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND);
482 return; 482 return;
483 } 483 }
484 if (!file_util::GetFileInfo(file_path_, &file_info_)) 484 if (!file_util::GetFileInfo(file_path_, &file_info_))
485 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); 485 set_error_code(base::PLATFORM_FILE_ERROR_FAILED);
486 } 486 }
487 487
488 virtual void RunCallback() { 488 virtual void RunCallback() {
489 callback_->Run(error_code(), file_info_); 489 callback_.Run(error_code(), file_info_);
490 delete callback_;
491 } 490 }
492 491
493 private: 492 private:
494 base::FileUtilProxy::GetFileInfoCallback* callback_; 493 base::FileUtilProxy::GetFileInfoCallback callback_;
495 FilePath file_path_; 494 FilePath file_path_;
496 base::PlatformFileInfo file_info_; 495 base::PlatformFileInfo file_info_;
497 }; 496 };
498 497
499 class RelayGetFileInfoFromPlatformFile : public MessageLoopRelay { 498 class RelayGetFileInfoFromPlatformFile : public MessageLoopRelay {
500 public: 499 public:
501 RelayGetFileInfoFromPlatformFile( 500 RelayGetFileInfoFromPlatformFile(
502 base::PlatformFile file, 501 base::PlatformFile file,
503 base::FileUtilProxy::GetFileInfoCallback* callback) 502 const base::FileUtilProxy::GetFileInfoCallback& callback)
504 : callback_(callback), 503 : callback_(callback),
505 file_(file) { 504 file_(file) {
506 DCHECK(callback); 505 DCHECK_EQ(false, callback.is_null());
507 } 506 }
508 507
509 protected: 508 protected:
510 virtual void RunWork() { 509 virtual void RunWork() {
511 if (!base::GetPlatformFileInfo(file_, &file_info_)) 510 if (!base::GetPlatformFileInfo(file_, &file_info_))
512 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); 511 set_error_code(base::PLATFORM_FILE_ERROR_FAILED);
513 } 512 }
514 513
515 virtual void RunCallback() { 514 virtual void RunCallback() {
516 callback_->Run(error_code(), file_info_); 515 callback_.Run(error_code(), file_info_);
517 delete callback_;
518 } 516 }
519 517
520 private: 518 private:
521 base::FileUtilProxy::GetFileInfoCallback* callback_; 519 base::FileUtilProxy::GetFileInfoCallback callback_;
522 base::PlatformFile file_; 520 base::PlatformFile file_;
523 base::PlatformFileInfo file_info_; 521 base::PlatformFileInfo file_info_;
524 }; 522 };
525 523
526 class RelayRead : public MessageLoopRelay { 524 class RelayRead : public MessageLoopRelay {
527 public: 525 public:
528 RelayRead(base::PlatformFile file, 526 RelayRead(base::PlatformFile file,
529 int64 offset, 527 int64 offset,
530 int bytes_to_read, 528 int bytes_to_read,
531 base::FileUtilProxy::ReadCallback* callback) 529 base::FileUtilProxy::ReadCallback* callback)
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 const EnsureFileExistsCallback& callback) { 765 const EnsureFileExistsCallback& callback) {
768 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists( 766 return Start(FROM_HERE, message_loop_proxy, new RelayEnsureFileExists(
769 message_loop_proxy, file_path, callback)); 767 message_loop_proxy, file_path, callback));
770 } 768 }
771 769
772 // Retrieves the information about a file. It is invalid to pass NULL for the 770 // Retrieves the information about a file. It is invalid to pass NULL for the
773 // callback. 771 // callback.
774 bool FileUtilProxy::GetFileInfo( 772 bool FileUtilProxy::GetFileInfo(
775 scoped_refptr<MessageLoopProxy> message_loop_proxy, 773 scoped_refptr<MessageLoopProxy> message_loop_proxy,
776 const FilePath& file_path, 774 const FilePath& file_path,
777 GetFileInfoCallback* callback) { 775 const GetFileInfoCallback& callback) {
778 return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo( 776 return Start(FROM_HERE, message_loop_proxy, new RelayGetFileInfo(
779 file_path, callback)); 777 file_path, callback));
780 } 778 }
781 779
782 // static 780 // static
783 bool FileUtilProxy::GetFileInfoFromPlatformFile( 781 bool FileUtilProxy::GetFileInfoFromPlatformFile(
784 scoped_refptr<MessageLoopProxy> message_loop_proxy, 782 scoped_refptr<MessageLoopProxy> message_loop_proxy,
785 PlatformFile file, 783 PlatformFile file,
786 GetFileInfoCallback* callback) { 784 const GetFileInfoCallback& callback) {
787 return Start(FROM_HERE, message_loop_proxy, 785 return Start(FROM_HERE, message_loop_proxy,
788 new RelayGetFileInfoFromPlatformFile(file, callback)); 786 new RelayGetFileInfoFromPlatformFile(file, callback));
789 } 787 }
790 788
791 // static 789 // static
792 bool FileUtilProxy::ReadDirectory( 790 bool FileUtilProxy::ReadDirectory(
793 scoped_refptr<MessageLoopProxy> message_loop_proxy, 791 scoped_refptr<MessageLoopProxy> message_loop_proxy,
794 const FilePath& file_path, 792 const FilePath& file_path,
795 ReadDirectoryCallback* callback) { 793 ReadDirectoryCallback* callback) {
796 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory( 794 return Start(FROM_HERE, message_loop_proxy, new RelayReadDirectory(
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 919
922 // static 920 // static
923 bool FileUtilProxy::Flush( 921 bool FileUtilProxy::Flush(
924 scoped_refptr<MessageLoopProxy> message_loop_proxy, 922 scoped_refptr<MessageLoopProxy> message_loop_proxy,
925 PlatformFile file, 923 PlatformFile file,
926 StatusCallback* callback) { 924 StatusCallback* callback) {
927 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); 925 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback));
928 } 926 }
929 927
930 } // namespace base 928 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698