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 "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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 int64 offset_; | 491 int64 offset_; |
492 char* buffer_; | 492 char* buffer_; |
493 int bytes_to_read_; | 493 int bytes_to_read_; |
494 base::FileUtilProxy::ReadWriteCallback* callback_; | 494 base::FileUtilProxy::ReadWriteCallback* callback_; |
495 int bytes_read_; | 495 int bytes_read_; |
496 }; | 496 }; |
497 | 497 |
498 class RelayWrite : public MessageLoopRelay { | 498 class RelayWrite : public MessageLoopRelay { |
499 public: | 499 public: |
500 RelayWrite(base::PlatformFile file, | 500 RelayWrite(base::PlatformFile file, |
501 int64 offset, | 501 long long offset, |
502 const char* buffer, | 502 const char* buffer, |
503 int bytes_to_write, | 503 int bytes_to_write, |
504 base::FileUtilProxy::ReadWriteCallback* callback) | 504 base::FileUtilProxy::ReadWriteCallback* callback) |
505 : file_(file), | 505 : file_(file), |
506 offset_(offset), | 506 offset_(offset), |
507 buffer_(buffer), | 507 buffer_(buffer), |
508 bytes_to_write_(bytes_to_write), | 508 bytes_to_write_(bytes_to_write), |
509 callback_(callback) { | 509 callback_(callback) { |
510 } | 510 } |
511 | 511 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 file_path_, last_access_time_, last_modified_time_)) | 575 file_path_, last_access_time_, last_modified_time_)) |
576 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | 576 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
577 } | 577 } |
578 | 578 |
579 private: | 579 private: |
580 FilePath file_path_; | 580 FilePath file_path_; |
581 base::Time last_access_time_; | 581 base::Time last_access_time_; |
582 base::Time last_modified_time_; | 582 base::Time last_modified_time_; |
583 }; | 583 }; |
584 | 584 |
585 class RelayTruncatePlatformFile : public RelayWithStatusCallback { | 585 class RelayTruncate : public RelayWithStatusCallback { |
586 public: | 586 public: |
587 RelayTruncatePlatformFile(base::PlatformFile file, | 587 RelayTruncate(base::PlatformFile file, |
588 int64 length, | 588 int64 length, |
589 base::FileUtilProxy::StatusCallback* callback) | 589 base::FileUtilProxy::StatusCallback* callback) |
590 : RelayWithStatusCallback(callback), | 590 : RelayWithStatusCallback(callback), |
591 file_(file), | 591 file_(file), |
592 length_(length) { | 592 length_(length) { |
593 } | 593 } |
594 | 594 |
595 protected: | 595 protected: |
596 virtual void RunWork() { | 596 virtual void RunWork() { |
597 if (!base::TruncatePlatformFile(file_, length_)) | 597 if (!base::TruncatePlatformFile(file_, length_)) |
598 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | 598 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); |
599 } | 599 } |
600 | 600 |
601 private: | 601 private: |
602 base::PlatformFile file_; | 602 base::PlatformFile file_; |
603 int64 length_; | 603 int64 length_; |
604 }; | 604 }; |
605 | 605 |
606 class RelayTruncate : public RelayWithStatusCallback { | |
607 public: | |
608 RelayTruncate(const FilePath& path, | |
609 int64 length, | |
610 base::FileUtilProxy::StatusCallback* callback) | |
611 : RelayWithStatusCallback(callback), | |
612 path_(path), | |
613 length_(length) { | |
614 } | |
615 | |
616 protected: | |
617 virtual void RunWork() { | |
618 base::PlatformFileError error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
619 base::PlatformFile file = | |
620 base::CreatePlatformFile( | |
621 path_, | |
622 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE, | |
623 NULL, | |
624 &error_code); | |
625 if (error_code != base::PLATFORM_FILE_OK) { | |
626 set_error_code(error_code); | |
627 return; | |
628 } | |
629 if (!base::TruncatePlatformFile(file, length_)) | |
630 set_error_code(base::PLATFORM_FILE_ERROR_FAILED); | |
631 base::ClosePlatformFile(file); | |
632 } | |
633 | |
634 private: | |
635 FilePath path_; | |
636 int64 length_; | |
637 }; | |
638 | |
639 class RelayFlush : public RelayWithStatusCallback { | 606 class RelayFlush : public RelayWithStatusCallback { |
640 public: | 607 public: |
641 RelayFlush(base::PlatformFile file, | 608 RelayFlush(base::PlatformFile file, |
642 base::FileUtilProxy::StatusCallback* callback) | 609 base::FileUtilProxy::StatusCallback* callback) |
643 : RelayWithStatusCallback(callback), | 610 : RelayWithStatusCallback(callback), |
644 file_(file) { | 611 file_(file) { |
645 } | 612 } |
646 | 613 |
647 protected: | 614 protected: |
648 virtual void RunWork() { | 615 virtual void RunWork() { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 StatusCallback* callback) { | 775 StatusCallback* callback) { |
809 return Start(FROM_HERE, message_loop_proxy, | 776 return Start(FROM_HERE, message_loop_proxy, |
810 new RelayTouchFilePath(file_path, last_access_time, | 777 new RelayTouchFilePath(file_path, last_access_time, |
811 last_modified_time, callback)); | 778 last_modified_time, callback)); |
812 } | 779 } |
813 | 780 |
814 // static | 781 // static |
815 bool FileUtilProxy::Truncate( | 782 bool FileUtilProxy::Truncate( |
816 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 783 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
817 PlatformFile file, | 784 PlatformFile file, |
818 int64 length, | 785 long long length, |
819 StatusCallback* callback) { | 786 StatusCallback* callback) { |
820 return Start(FROM_HERE, message_loop_proxy, | 787 return Start(FROM_HERE, message_loop_proxy, |
821 new RelayTruncatePlatformFile(file, length, callback)); | 788 new RelayTruncate(file, length, callback)); |
822 } | |
823 | |
824 // static | |
825 bool FileUtilProxy::Truncate( | |
826 scoped_refptr<MessageLoopProxy> message_loop_proxy, | |
827 const FilePath& path, | |
828 int64 length, | |
829 StatusCallback* callback) { | |
830 return Start(FROM_HERE, message_loop_proxy, | |
831 new RelayTruncate(path, length, callback)); | |
832 } | 789 } |
833 | 790 |
834 // static | 791 // static |
835 bool FileUtilProxy::Flush( | 792 bool FileUtilProxy::Flush( |
836 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 793 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
837 PlatformFile file, | 794 PlatformFile file, |
838 StatusCallback* callback) { | 795 StatusCallback* callback) { |
839 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); | 796 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); |
840 } | 797 } |
841 | 798 |
842 } // namespace base | 799 } // namespace base |
OLD | NEW |