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 long long offset, | 501 int64 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 RelayTruncate : public RelayWithStatusCallback { | 585 class RelayTruncatePlatformFile : public RelayWithStatusCallback { |
586 public: | 586 public: |
587 RelayTruncate(base::PlatformFile file, | 587 RelayTruncatePlatformFile(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 |
606 class RelayFlush : public RelayWithStatusCallback { | 639 class RelayFlush : public RelayWithStatusCallback { |
607 public: | 640 public: |
608 RelayFlush(base::PlatformFile file, | 641 RelayFlush(base::PlatformFile file, |
609 base::FileUtilProxy::StatusCallback* callback) | 642 base::FileUtilProxy::StatusCallback* callback) |
610 : RelayWithStatusCallback(callback), | 643 : RelayWithStatusCallback(callback), |
611 file_(file) { | 644 file_(file) { |
612 } | 645 } |
613 | 646 |
614 protected: | 647 protected: |
615 virtual void RunWork() { | 648 virtual void RunWork() { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 StatusCallback* callback) { | 808 StatusCallback* callback) { |
776 return Start(FROM_HERE, message_loop_proxy, | 809 return Start(FROM_HERE, message_loop_proxy, |
777 new RelayTouchFilePath(file_path, last_access_time, | 810 new RelayTouchFilePath(file_path, last_access_time, |
778 last_modified_time, callback)); | 811 last_modified_time, callback)); |
779 } | 812 } |
780 | 813 |
781 // static | 814 // static |
782 bool FileUtilProxy::Truncate( | 815 bool FileUtilProxy::Truncate( |
783 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 816 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
784 PlatformFile file, | 817 PlatformFile file, |
785 long long length, | 818 int64 length, |
786 StatusCallback* callback) { | 819 StatusCallback* callback) { |
787 return Start(FROM_HERE, message_loop_proxy, | 820 return Start(FROM_HERE, message_loop_proxy, |
788 new RelayTruncate(file, length, callback)); | 821 new RelayTruncatePlatformFile(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)); |
789 } | 832 } |
790 | 833 |
791 // static | 834 // static |
792 bool FileUtilProxy::Flush( | 835 bool FileUtilProxy::Flush( |
793 scoped_refptr<MessageLoopProxy> message_loop_proxy, | 836 scoped_refptr<MessageLoopProxy> message_loop_proxy, |
794 PlatformFile file, | 837 PlatformFile file, |
795 StatusCallback* callback) { | 838 StatusCallback* callback) { |
796 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); | 839 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); |
797 } | 840 } |
798 | 841 |
799 } // namespace base | 842 } // namespace base |
OLD | NEW |