OLD | NEW |
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 Loading... |
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 ErrorBehavior error_behavior, |
89 const CopyProgressCallback& progress_callback, | 90 const CopyProgressCallback& progress_callback, |
90 const StatusCallback& callback) { | 91 const StatusCallback& callback) { |
91 base::File::Error error = base::File::FILE_OK; | 92 base::File::Error error = base::File::FILE_OK; |
92 FileSystemOperation* operation = | 93 FileSystemOperation* operation = |
93 file_system_context_->CreateFileSystemOperation(dest_url, &error); | 94 file_system_context_->CreateFileSystemOperation(dest_url, &error); |
94 BeginOperationScoper scope; | 95 BeginOperationScoper scope; |
95 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); | 96 OperationHandle handle = BeginOperation(operation, scope.AsWeakPtr()); |
96 if (!operation) { | 97 if (!operation) { |
97 DidFinish(handle, callback, error); | 98 DidFinish(handle, callback, error); |
98 return handle.id; | 99 return handle.id; |
99 } | 100 } |
100 PrepareForWrite(handle.id, dest_url); | 101 PrepareForWrite(handle.id, dest_url); |
101 PrepareForRead(handle.id, src_url); | 102 PrepareForRead(handle.id, src_url); |
102 operation->Copy( | 103 operation->Copy(src_url, dest_url, option, error_behavior, |
103 src_url, dest_url, option, | 104 progress_callback.is_null() |
104 progress_callback.is_null() ? | 105 ? CopyProgressCallback() |
105 CopyProgressCallback() : | 106 : base::Bind(&FileSystemOperationRunner::OnCopyProgress, |
106 base::Bind(&FileSystemOperationRunner::OnCopyProgress, AsWeakPtr(), | 107 AsWeakPtr(), handle, progress_callback), |
107 handle, progress_callback), | 108 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
108 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 109 handle, callback)); |
109 handle, callback)); | |
110 return handle.id; | 110 return handle.id; |
111 } | 111 } |
112 | 112 |
113 OperationID FileSystemOperationRunner::Move( | 113 OperationID FileSystemOperationRunner::Move( |
114 const FileSystemURL& src_url, | 114 const FileSystemURL& src_url, |
115 const FileSystemURL& dest_url, | 115 const FileSystemURL& dest_url, |
116 CopyOrMoveOption option, | 116 CopyOrMoveOption option, |
117 const StatusCallback& callback) { | 117 const StatusCallback& callback) { |
118 base::File::Error error = base::File::FILE_OK; | 118 base::File::Error error = base::File::FILE_OK; |
119 FileSystemOperation* operation = | 119 FileSystemOperation* operation = |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 stray_cancel_callbacks_.find(id); | 680 stray_cancel_callbacks_.find(id); |
681 if (found_cancel != stray_cancel_callbacks_.end()) { | 681 if (found_cancel != stray_cancel_callbacks_.end()) { |
682 // This cancel has been requested after the operation has finished, | 682 // This cancel has been requested after the operation has finished, |
683 // so report that we failed to stop it. | 683 // so report that we failed to stop it. |
684 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); | 684 found_cancel->second.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
685 stray_cancel_callbacks_.erase(found_cancel); | 685 stray_cancel_callbacks_.erase(found_cancel); |
686 } | 686 } |
687 } | 687 } |
688 | 688 |
689 } // namespace storage | 689 } // namespace storage |
OLD | NEW |