OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "storage/browser/fileapi/copy_or_move_operation_delegate.h" | 5 #include "storage/browser/fileapi/copy_or_move_operation_delegate.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
723 else | 723 else |
724 Read(callback); | 724 Read(callback); |
725 } | 725 } |
726 | 726 |
727 CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( | 727 CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( |
728 FileSystemContext* file_system_context, | 728 FileSystemContext* file_system_context, |
729 const FileSystemURL& src_root, | 729 const FileSystemURL& src_root, |
730 const FileSystemURL& dest_root, | 730 const FileSystemURL& dest_root, |
731 OperationType operation_type, | 731 OperationType operation_type, |
732 CopyOrMoveOption option, | 732 CopyOrMoveOption option, |
733 const bool continue_with_error, | |
mtomasz
2015/06/20 02:42:56
Bools are hard to read. Can we made an enum, like
| |
734 const CopyOrMoveErrorCallback& error_callback, | |
733 const CopyProgressCallback& progress_callback, | 735 const CopyProgressCallback& progress_callback, |
734 const StatusCallback& callback) | 736 const StatusCallback& callback) |
735 : RecursiveOperationDelegate(file_system_context), | 737 : RecursiveOperationDelegate(file_system_context), |
736 src_root_(src_root), | 738 src_root_(src_root), |
737 dest_root_(dest_root), | 739 dest_root_(dest_root), |
738 operation_type_(operation_type), | 740 operation_type_(operation_type), |
739 option_(option), | 741 option_(option), |
742 continue_with_error_(continue_with_error), | |
743 error_callback_(error_callback), | |
740 progress_callback_(progress_callback), | 744 progress_callback_(progress_callback), |
741 callback_(callback), | 745 callback_(callback), |
742 weak_factory_(this) { | 746 weak_factory_(this) { |
743 same_file_system_ = src_root_.IsInSameFileSystem(dest_root_); | 747 same_file_system_ = src_root_.IsInSameFileSystem(dest_root_); |
744 } | 748 } |
745 | 749 |
746 CopyOrMoveOperationDelegate::~CopyOrMoveOperationDelegate() { | 750 CopyOrMoveOperationDelegate::~CopyOrMoveOperationDelegate() { |
747 STLDeleteElements(&running_copy_set_); | 751 STLDeleteElements(&running_copy_set_); |
748 } | 752 } |
749 | 753 |
(...skipping 16 matching lines...) Expand all Loading... | |
766 // wants to return success and we have a code path that returns error in | 770 // wants to return success and we have a code path that returns error in |
767 // Blink for JS (http://crbug.com/329517). | 771 // Blink for JS (http://crbug.com/329517). |
768 callback_.Run(base::File::FILE_OK); | 772 callback_.Run(base::File::FILE_OK); |
769 return; | 773 return; |
770 } | 774 } |
771 | 775 |
772 // Start to process the source directory recursively. | 776 // Start to process the source directory recursively. |
773 // TODO(kinuko): This could be too expensive for same_file_system_==true | 777 // TODO(kinuko): This could be too expensive for same_file_system_==true |
774 // and operation==MOVE case, probably we can just rename the root directory. | 778 // and operation==MOVE case, probably we can just rename the root directory. |
775 // http://crbug.com/172187 | 779 // http://crbug.com/172187 |
776 StartRecursiveOperation(src_root_, callback_); | 780 if (continue_with_error_) |
781 StartRecursiveOperationWithIgnoringError(src_root_, ErrorCallback(), | |
mtomasz
2015/06/20 02:42:56
I'm thinking whether we can simplify this logic. I
yawano
2015/06/22 02:28:27
I don't like the idea that the progress callback r
mtomasz
2015/06/22 02:31:41
SGTM
| |
782 callback_); | |
783 else | |
784 StartRecursiveOperation(src_root_, callback_); | |
777 } | 785 } |
778 | 786 |
779 void CopyOrMoveOperationDelegate::ProcessFile( | 787 void CopyOrMoveOperationDelegate::ProcessFile( |
780 const FileSystemURL& src_url, | 788 const FileSystemURL& src_url, |
781 const StatusCallback& callback) { | 789 const StatusCallback& callback) { |
782 if (!progress_callback_.is_null()) { | 790 if (!progress_callback_.is_null()) { |
783 progress_callback_.Run( | 791 progress_callback_.Run( |
784 FileSystemOperation::BEGIN_COPY_ENTRY, src_url, FileSystemURL(), 0); | 792 FileSystemOperation::BEGIN_COPY_ENTRY, src_url, FileSystemURL(), 0); |
785 } | 793 } |
786 | 794 |
787 FileSystemURL dest_url = CreateDestURL(src_url); | 795 FileSystemURL dest_url = CreateDestURL(src_url); |
788 CopyOrMoveImpl* impl = NULL; | 796 CopyOrMoveImpl* impl = NULL; |
789 if (same_file_system_ && | 797 if (same_file_system_ && |
790 (file_system_context() | 798 (file_system_context() |
791 ->GetFileSystemBackend(src_url.type()) | 799 ->GetFileSystemBackend(src_url.type()) |
792 ->HasInplaceCopyImplementation(src_url.type()) || | 800 ->HasInplaceCopyImplementation(src_url.type()) || |
793 operation_type_ == OPERATION_MOVE)) { | 801 operation_type_ == OPERATION_MOVE)) { |
794 impl = new CopyOrMoveOnSameFileSystemImpl( | 802 impl = new CopyOrMoveOnSameFileSystemImpl( |
795 operation_runner(), operation_type_, src_url, dest_url, option_, | 803 operation_runner(), operation_type_, src_url, dest_url, option_, |
796 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, | 804 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, |
797 weak_factory_.GetWeakPtr(), src_url)); | 805 weak_factory_.GetWeakPtr(), src_url)); |
798 } else { | 806 } else { |
799 // Cross filesystem case. | 807 // Cross filesystem case. |
800 base::File::Error error = base::File::FILE_ERROR_FAILED; | 808 base::File::Error error = base::File::FILE_ERROR_FAILED; |
801 CopyOrMoveFileValidatorFactory* validator_factory = | 809 CopyOrMoveFileValidatorFactory* validator_factory = |
802 file_system_context()->GetCopyOrMoveFileValidatorFactory( | 810 file_system_context()->GetCopyOrMoveFileValidatorFactory( |
803 dest_root_.type(), &error); | 811 dest_root_.type(), &error); |
804 if (error != base::File::FILE_OK) { | 812 if (error != base::File::FILE_OK) { |
813 if (!error_callback_.is_null()) | |
814 error_callback_.Run(error, src_url, dest_url); | |
815 | |
805 callback.Run(error); | 816 callback.Run(error); |
806 return; | 817 return; |
807 } | 818 } |
808 | 819 |
809 if (!validator_factory) { | 820 if (!validator_factory) { |
810 scoped_ptr<storage::FileStreamReader> reader = | 821 scoped_ptr<storage::FileStreamReader> reader = |
811 file_system_context()->CreateFileStreamReader( | 822 file_system_context()->CreateFileStreamReader( |
812 src_url, 0 /* offset */, storage::kMaximumLength, base::Time()); | 823 src_url, 0 /* offset */, storage::kMaximumLength, base::Time()); |
813 scoped_ptr<FileStreamWriter> writer = | 824 scoped_ptr<FileStreamWriter> writer = |
814 file_system_context()->CreateFileStreamWriter(dest_url, 0); | 825 file_system_context()->CreateFileStreamWriter(dest_url, 0); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 | 904 |
894 void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( | 905 void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( |
895 const FileSystemURL& src_url, | 906 const FileSystemURL& src_url, |
896 const FileSystemURL& dest_url, | 907 const FileSystemURL& dest_url, |
897 const StatusCallback& callback, | 908 const StatusCallback& callback, |
898 CopyOrMoveImpl* impl, | 909 CopyOrMoveImpl* impl, |
899 base::File::Error error) { | 910 base::File::Error error) { |
900 running_copy_set_.erase(impl); | 911 running_copy_set_.erase(impl); |
901 delete impl; | 912 delete impl; |
902 | 913 |
914 if (!error_callback_.is_null() && error != base::File::FILE_OK && | |
915 error != base::File::FILE_ERROR_NOT_A_FILE) | |
916 error_callback_.Run(error, src_url, dest_url); | |
917 | |
903 if (!progress_callback_.is_null() && error == base::File::FILE_OK) { | 918 if (!progress_callback_.is_null() && error == base::File::FILE_OK) { |
904 progress_callback_.Run( | 919 progress_callback_.Run( |
905 FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); | 920 FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); |
906 } | 921 } |
907 | 922 |
908 callback.Run(error); | 923 callback.Run(error); |
909 } | 924 } |
910 | 925 |
911 void CopyOrMoveOperationDelegate::DidTryRemoveDestRoot( | 926 void CopyOrMoveOperationDelegate::DidTryRemoveDestRoot( |
912 const StatusCallback& callback, | 927 const StatusCallback& callback, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1016 base::FilePath relative = dest_root_.virtual_path(); | 1031 base::FilePath relative = dest_root_.virtual_path(); |
1017 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 1032 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
1018 &relative); | 1033 &relative); |
1019 return file_system_context()->CreateCrackedFileSystemURL( | 1034 return file_system_context()->CreateCrackedFileSystemURL( |
1020 dest_root_.origin(), | 1035 dest_root_.origin(), |
1021 dest_root_.mount_type(), | 1036 dest_root_.mount_type(), |
1022 relative); | 1037 relative); |
1023 } | 1038 } |
1024 | 1039 |
1025 } // namespace storage | 1040 } // namespace storage |
OLD | NEW |