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

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

Issue 1194783002: Add fileManagerPrivate.onCopyError event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/file_system_operation_runner.h" 5 #include "storage/browser/fileapi/file_system_operation_runner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "net/url_request/url_request_context.h" 10 #include "net/url_request/url_request_context.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 url, exclusive, recursive, 79 url, exclusive, recursive,
80 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 80 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(),
81 handle, callback)); 81 handle, callback));
82 return handle.id; 82 return handle.id;
83 } 83 }
84 84
85 OperationID FileSystemOperationRunner::Copy( 85 OperationID FileSystemOperationRunner::Copy(
86 const FileSystemURL& src_url, 86 const FileSystemURL& src_url,
87 const FileSystemURL& dest_url, 87 const FileSystemURL& dest_url,
88 CopyOrMoveOption option, 88 CopyOrMoveOption option,
89 const bool continue_with_error,
90 const CopyOrMoveErrorCallback& error_callback,
89 const CopyProgressCallback& progress_callback, 91 const CopyProgressCallback& progress_callback,
90 const StatusCallback& callback) { 92 const StatusCallback& callback) {
91 base::File::Error error = base::File::FILE_OK; 93 base::File::Error error = base::File::FILE_OK;
92 FileSystemOperation* operation = 94 FileSystemOperation* operation =
93 file_system_context_->CreateFileSystemOperation(dest_url, &error); 95 file_system_context_->CreateFileSystemOperation(dest_url, &error);
94 BeginOperationScoper scope; 96 BeginOperationScoper scope;
95 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); 97 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr());
96 if (!operation) { 98 if (!operation) {
97 DidFinish(handle, callback, error); 99 DidFinish(handle, callback, error);
98 return handle.id; 100 return handle.id;
99 } 101 }
100 PrepareForWrite(handle.id, dest_url); 102 PrepareForWrite(handle.id, dest_url);
101 PrepareForRead(handle.id, src_url); 103 PrepareForRead(handle.id, src_url);
102 operation->Copy( 104 operation->Copy(
103 src_url, dest_url, option, 105 src_url, dest_url, option, continue_with_error,
104 progress_callback.is_null() ? 106 error_callback.is_null()
105 CopyProgressCallback() : 107 ? CopyOrMoveErrorCallback()
106 base::Bind(&FileSystemOperationRunner::OnCopyProgress, AsWeakPtr(), 108 : base::Bind(&FileSystemOperationRunner::OnCopyOrMoveError,
107 handle, progress_callback), 109 AsWeakPtr(), handle, error_callback),
108 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), 110 progress_callback.is_null()
109 handle, callback)); 111 ? CopyProgressCallback()
112 : base::Bind(&FileSystemOperationRunner::OnCopyProgress, AsWeakPtr(),
113 handle, progress_callback),
114 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), handle,
115 callback));
110 return handle.id; 116 return handle.id;
111 } 117 }
112 118
113 OperationID FileSystemOperationRunner::Move( 119 OperationID FileSystemOperationRunner::Move(
114 const FileSystemURL& src_url, 120 const FileSystemURL& src_url,
115 const FileSystemURL& dest_url, 121 const FileSystemURL& dest_url,
116 CopyOrMoveOption option, 122 CopyOrMoveOption option,
117 const StatusCallback& callback) { 123 const StatusCallback& callback) {
118 base::File::Error error = base::File::FILE_OK; 124 base::File::Error error = base::File::FILE_OK;
119 FileSystemOperation* operation = 125 FileSystemOperation* operation =
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 base::ThreadTaskRunnerHandle::Get()->PostTask( 610 base::ThreadTaskRunnerHandle::Get()->PostTask(
605 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidCreateSnapshot, 611 FROM_HERE, base::Bind(&FileSystemOperationRunner::DidCreateSnapshot,
606 AsWeakPtr(), handle, callback, rv, file_info, 612 AsWeakPtr(), handle, callback, rv, file_info,
607 platform_path, file_ref)); 613 platform_path, file_ref));
608 return; 614 return;
609 } 615 }
610 callback.Run(rv, file_info, platform_path, file_ref); 616 callback.Run(rv, file_info, platform_path, file_ref);
611 FinishOperation(handle.id); 617 FinishOperation(handle.id);
612 } 618 }
613 619
620 void FileSystemOperationRunner::OnCopyOrMoveError(
621 const OperationHandle& handle,
622 const CopyOrMoveErrorCallback& callback,
623 base::File::Error error,
624 const FileSystemURL& source_url,
625 const FileSystemURL& dest_url) {
626 if (handle.scope) {
627 base::ThreadTaskRunnerHandle::Get()->PostTask(
628 FROM_HERE,
629 base::Bind(&FileSystemOperationRunner::OnCopyOrMoveError, AsWeakPtr(),
630 handle, callback, error, source_url, dest_url));
631 return;
632 }
633 callback.Run(error, source_url, dest_url);
634 }
635
614 void FileSystemOperationRunner::OnCopyProgress( 636 void FileSystemOperationRunner::OnCopyProgress(
615 const OperationHandle& handle, 637 const OperationHandle& handle,
616 const CopyProgressCallback& callback, 638 const CopyProgressCallback& callback,
617 FileSystemOperation::CopyProgressType type, 639 FileSystemOperation::CopyProgressType type,
618 const FileSystemURL& source_url, 640 const FileSystemURL& source_url,
619 const FileSystemURL& dest_url, 641 const FileSystemURL& dest_url,
620 int64 size) { 642 int64 size) {
621 if (handle.scope) { 643 if (handle.scope) {
622 base::ThreadTaskRunnerHandle::Get()->PostTask( 644 base::ThreadTaskRunnerHandle::Get()->PostTask(
623 FROM_HERE, base::Bind( 645 FROM_HERE, base::Bind(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 stray_cancel_callbacks_.find(id); 702 stray_cancel_callbacks_.find(id);
681 if (found_cancel != stray_cancel_callbacks_.end()) { 703 if (found_cancel != stray_cancel_callbacks_.end()) {
682 // This cancel has been requested after the operation has finished, 704 // This cancel has been requested after the operation has finished,
683 // so report that we failed to stop it. 705 // so report that we failed to stop it.
684 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); 706 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION);
685 stray_cancel_callbacks_.erase(found_cancel); 707 stray_cancel_callbacks_.erase(found_cancel);
686 } 708 }
687 } 709 }
688 710
689 } // namespace storage 711 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698