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

Side by Side Diff: storage/browser/fileapi/copy_or_move_operation_delegate.cc

Issue 1194783002: Add fileManagerPrivate.onCopyError event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove const and rename enum. Created 5 years, 5 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
OLDNEW
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
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 ErrorBehavior error_behavior,
733 const CopyProgressCallback& progress_callback, 734 const CopyProgressCallback& progress_callback,
734 const StatusCallback& callback) 735 const StatusCallback& callback)
735 : RecursiveOperationDelegate(file_system_context), 736 : RecursiveOperationDelegate(file_system_context),
736 src_root_(src_root), 737 src_root_(src_root),
737 dest_root_(dest_root), 738 dest_root_(dest_root),
738 operation_type_(operation_type), 739 operation_type_(operation_type),
739 option_(option), 740 option_(option),
741 error_behavior_(error_behavior),
740 progress_callback_(progress_callback), 742 progress_callback_(progress_callback),
741 callback_(callback), 743 callback_(callback),
742 weak_factory_(this) { 744 weak_factory_(this) {
743 same_file_system_ = src_root_.IsInSameFileSystem(dest_root_); 745 same_file_system_ = src_root_.IsInSameFileSystem(dest_root_);
744 } 746 }
745 747
746 CopyOrMoveOperationDelegate::~CopyOrMoveOperationDelegate() { 748 CopyOrMoveOperationDelegate::~CopyOrMoveOperationDelegate() {
747 STLDeleteElements(&running_copy_set_); 749 STLDeleteElements(&running_copy_set_);
748 } 750 }
749 751
(...skipping 16 matching lines...) Expand all
766 // wants to return success and we have a code path that returns error in 768 // wants to return success and we have a code path that returns error in
767 // Blink for JS (http://crbug.com/329517). 769 // Blink for JS (http://crbug.com/329517).
768 callback_.Run(base::File::FILE_OK); 770 callback_.Run(base::File::FILE_OK);
769 return; 771 return;
770 } 772 }
771 773
772 // Start to process the source directory recursively. 774 // Start to process the source directory recursively.
773 // TODO(kinuko): This could be too expensive for same_file_system_==true 775 // 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. 776 // and operation==MOVE case, probably we can just rename the root directory.
775 // http://crbug.com/172187 777 // http://crbug.com/172187
776 StartRecursiveOperation(src_root_, callback_); 778 StartRecursiveOperation(src_root_, error_behavior_, callback_);
777 } 779 }
778 780
779 void CopyOrMoveOperationDelegate::ProcessFile( 781 void CopyOrMoveOperationDelegate::ProcessFile(
780 const FileSystemURL& src_url, 782 const FileSystemURL& src_url,
781 const StatusCallback& callback) { 783 const StatusCallback& callback) {
782 if (!progress_callback_.is_null()) { 784 if (!progress_callback_.is_null()) {
783 progress_callback_.Run( 785 progress_callback_.Run(
784 FileSystemOperation::BEGIN_COPY_ENTRY, src_url, FileSystemURL(), 0); 786 FileSystemOperation::BEGIN_COPY_ENTRY, src_url, FileSystemURL(), 0);
785 } 787 }
786 788
787 FileSystemURL dest_url = CreateDestURL(src_url); 789 FileSystemURL dest_url = CreateDestURL(src_url);
788 CopyOrMoveImpl* impl = NULL; 790 CopyOrMoveImpl* impl = NULL;
789 if (same_file_system_ && 791 if (same_file_system_ &&
790 (file_system_context() 792 (file_system_context()
791 ->GetFileSystemBackend(src_url.type()) 793 ->GetFileSystemBackend(src_url.type())
792 ->HasInplaceCopyImplementation(src_url.type()) || 794 ->HasInplaceCopyImplementation(src_url.type()) ||
793 operation_type_ == OPERATION_MOVE)) { 795 operation_type_ == OPERATION_MOVE)) {
794 impl = new CopyOrMoveOnSameFileSystemImpl( 796 impl = new CopyOrMoveOnSameFileSystemImpl(
795 operation_runner(), operation_type_, src_url, dest_url, option_, 797 operation_runner(), operation_type_, src_url, dest_url, option_,
796 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, 798 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress,
797 weak_factory_.GetWeakPtr(), src_url)); 799 weak_factory_.GetWeakPtr(), src_url));
798 } else { 800 } else {
799 // Cross filesystem case. 801 // Cross filesystem case.
800 base::File::Error error = base::File::FILE_ERROR_FAILED; 802 base::File::Error error = base::File::FILE_ERROR_FAILED;
801 CopyOrMoveFileValidatorFactory* validator_factory = 803 CopyOrMoveFileValidatorFactory* validator_factory =
802 file_system_context()->GetCopyOrMoveFileValidatorFactory( 804 file_system_context()->GetCopyOrMoveFileValidatorFactory(
803 dest_root_.type(), &error); 805 dest_root_.type(), &error);
804 if (error != base::File::FILE_OK) { 806 if (error != base::File::FILE_OK) {
807 if (!progress_callback_.is_null())
808 progress_callback_.Run(FileSystemOperation::ERROR_COPY_ENTRY, src_url,
809 dest_url, 0);
810
805 callback.Run(error); 811 callback.Run(error);
806 return; 812 return;
807 } 813 }
808 814
809 if (!validator_factory) { 815 if (!validator_factory) {
810 scoped_ptr<storage::FileStreamReader> reader = 816 scoped_ptr<storage::FileStreamReader> reader =
811 file_system_context()->CreateFileStreamReader( 817 file_system_context()->CreateFileStreamReader(
812 src_url, 0 /* offset */, storage::kMaximumLength, base::Time()); 818 src_url, 0 /* offset */, storage::kMaximumLength, base::Time());
813 scoped_ptr<FileStreamWriter> writer = 819 scoped_ptr<FileStreamWriter> writer =
814 file_system_context()->CreateFileStreamWriter(dest_url, 0); 820 file_system_context()->CreateFileStreamWriter(dest_url, 0);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 899
894 void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( 900 void CopyOrMoveOperationDelegate::DidCopyOrMoveFile(
895 const FileSystemURL& src_url, 901 const FileSystemURL& src_url,
896 const FileSystemURL& dest_url, 902 const FileSystemURL& dest_url,
897 const StatusCallback& callback, 903 const StatusCallback& callback,
898 CopyOrMoveImpl* impl, 904 CopyOrMoveImpl* impl,
899 base::File::Error error) { 905 base::File::Error error) {
900 running_copy_set_.erase(impl); 906 running_copy_set_.erase(impl);
901 delete impl; 907 delete impl;
902 908
909 if (!progress_callback_.is_null() && error != base::File::FILE_OK &&
910 error != base::File::FILE_ERROR_NOT_A_FILE)
911 progress_callback_.Run(FileSystemOperation::ERROR_COPY_ENTRY, src_url,
912 dest_url, 0);
913
903 if (!progress_callback_.is_null() && error == base::File::FILE_OK) { 914 if (!progress_callback_.is_null() && error == base::File::FILE_OK) {
904 progress_callback_.Run( 915 progress_callback_.Run(
905 FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); 916 FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0);
906 } 917 }
907 918
908 callback.Run(error); 919 callback.Run(error);
909 } 920 }
910 921
911 void CopyOrMoveOperationDelegate::DidTryRemoveDestRoot( 922 void CopyOrMoveOperationDelegate::DidTryRemoveDestRoot(
912 const StatusCallback& callback, 923 const StatusCallback& callback,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 base::FilePath relative = dest_root_.virtual_path(); 1027 base::FilePath relative = dest_root_.virtual_path();
1017 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), 1028 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(),
1018 &relative); 1029 &relative);
1019 return file_system_context()->CreateCrackedFileSystemURL( 1030 return file_system_context()->CreateCrackedFileSystemURL(
1020 dest_root_.origin(), 1031 dest_root_.origin(),
1021 dest_root_.mount_type(), 1032 dest_root_.mount_type(),
1022 relative); 1033 relative);
1023 } 1034 }
1024 1035
1025 } // namespace storage 1036 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/fileapi/copy_or_move_operation_delegate.h ('k') | storage/browser/fileapi/file_system_operation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698