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 "webkit/browser/fileapi/copy_or_move_operation_delegate.h" | 5 #include "webkit/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 "webkit/browser/fileapi/copy_or_move_file_validator.h" | 9 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
10 #include "webkit/browser/fileapi/file_system_context.h" | 10 #include "webkit/browser/fileapi/file_system_context.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 callback_.Run(error); | 104 callback_.Run(error); |
105 return; | 105 return; |
106 } | 106 } |
107 | 107 |
108 // Start to process the source directory recursively. | 108 // Start to process the source directory recursively. |
109 // TODO(kinuko): This could be too expensive for same_file_system_==true | 109 // TODO(kinuko): This could be too expensive for same_file_system_==true |
110 // and operation==MOVE case, probably we can just rename the root directory. | 110 // and operation==MOVE case, probably we can just rename the root directory. |
111 // http://crbug.com/172187 | 111 // http://crbug.com/172187 |
112 StartRecursiveOperation( | 112 StartRecursiveOperation( |
113 src_root_, base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, | 113 src_root_, base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, |
114 AsWeakPtr(), src_root_, callback_)); | 114 AsWeakPtr(), URLPair(src_root_, dest_root_), |
115 callback_)); | |
115 } | 116 } |
116 | 117 |
117 void CopyOrMoveOperationDelegate::CopyOrMoveFile(const URLPair& url_pair, | 118 void CopyOrMoveOperationDelegate::CopyOrMoveFile(const URLPair& url_pair, |
118 const StatusCallback& callback) { | 119 const StatusCallback& callback) { |
119 // Same filesystem case. | 120 // Same filesystem case. |
120 if (same_file_system_) { | 121 if (same_file_system_) { |
121 if (operation_type_ == OPERATION_MOVE) { | 122 if (operation_type_ == OPERATION_MOVE) { |
122 operation_runner()->MoveFileLocal(url_pair.src, url_pair.dest, callback); | 123 operation_runner()->MoveFileLocal(url_pair.src, url_pair.dest, callback); |
123 } else { | 124 } else { |
124 operation_runner()->CopyFileLocal(url_pair.src, url_pair.dest, callback); | 125 operation_runner()->CopyFileLocal(url_pair.src, url_pair.dest, callback); |
125 } | 126 } |
126 return; | 127 return; |
127 } | 128 } |
128 | 129 |
129 // Cross filesystem case. | 130 // Cross filesystem case. |
130 // Perform CreateSnapshotFile, CopyInForeignFile and then calls | 131 // Perform CreateSnapshotFile, CopyInForeignFile and then calls |
131 // copy_callback which removes the source file if operation_type == MOVE. | 132 // copy_callback which removes the source file if operation_type == MOVE. |
132 StatusCallback copy_callback = | 133 StatusCallback copy_callback = |
133 base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, AsWeakPtr(), | 134 base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, AsWeakPtr(), |
134 url_pair.src, callback); | 135 url_pair, callback); |
135 operation_runner()->CreateSnapshotFile( | 136 operation_runner()->CreateSnapshotFile( |
136 url_pair.src, | 137 url_pair.src, |
137 base::Bind(&CopyOrMoveOperationDelegate::DidCreateSnapshot, AsWeakPtr(), | 138 base::Bind(&CopyOrMoveOperationDelegate::DidCreateSnapshot, AsWeakPtr(), |
138 url_pair, copy_callback)); | 139 url_pair, copy_callback)); |
139 } | 140 } |
140 | 141 |
141 void CopyOrMoveOperationDelegate::DidCreateSnapshot( | 142 void CopyOrMoveOperationDelegate::DidCreateSnapshot( |
142 const URLPair& url_pair, | 143 const URLPair& url_pair, |
143 const StatusCallback& callback, | 144 const StatusCallback& callback, |
144 base::PlatformFileError error, | 145 base::PlatformFileError error, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 base::PlatformFileError error) { | 183 base::PlatformFileError error) { |
183 if (error != base::PLATFORM_FILE_OK) { | 184 if (error != base::PLATFORM_FILE_OK) { |
184 callback.Run(error); | 185 callback.Run(error); |
185 return; | 186 return; |
186 } | 187 } |
187 | 188 |
188 operation_runner()->CopyInForeignFile(platform_path, dest, callback); | 189 operation_runner()->CopyInForeignFile(platform_path, dest, callback); |
189 } | 190 } |
190 | 191 |
191 void CopyOrMoveOperationDelegate::DidFinishCopy( | 192 void CopyOrMoveOperationDelegate::DidFinishCopy( |
192 const FileSystemURL& src, | 193 const URLPair& url_pair, |
193 const StatusCallback& callback, | 194 const StatusCallback& callback, |
194 base::PlatformFileError error) { | 195 base::PlatformFileError error) { |
195 if (error != base::PLATFORM_FILE_OK || | 196 if (error != base::PLATFORM_FILE_OK) { |
196 operation_type_ == OPERATION_COPY) { | |
197 callback.Run(error); | 197 callback.Run(error); |
198 return; | 198 return; |
199 } | 199 } |
200 | |
201 if (validator_.get()) { | |
kinuko
2013/07/04 03:10:12
nit: Can you add a comment here to clarify that va
Greg Billock
2013/07/08 20:01:53
Done.
| |
202 operation_runner()->CreateSnapshotFile( | |
203 url_pair.dest, | |
204 base::Bind(&CopyOrMoveOperationDelegate::DoPostWriteValidation, | |
205 AsWeakPtr(), url_pair, callback)); | |
206 } else { | |
207 DidPostWriteValidation(url_pair, callback, base::PLATFORM_FILE_OK); | |
208 } | |
209 } | |
210 | |
211 void CopyOrMoveOperationDelegate::DoPostWriteValidation( | |
212 const URLPair& url_pair, | |
213 const StatusCallback& callback, | |
214 base::PlatformFileError error, | |
215 const base::PlatformFileInfo& file_info, | |
216 const base::FilePath& platform_path, | |
217 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | |
218 // TODO(gbillock): need to check here that file_ref is null or anything? | |
kinuko
2013/07/04 03:10:12
I think you can just bind the ref to the callback
Greg Billock
2013/07/08 20:01:53
Yeah. Steve and I figured this out I think. I'm ju
| |
219 if (error != base::PLATFORM_FILE_OK) { | |
220 operation_runner()->Remove( | |
221 url_pair.dest, true, | |
222 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError, | |
223 AsWeakPtr(), error, callback)); | |
224 return; | |
225 } | |
226 | |
227 DCHECK(validator_.get()); | |
228 validator_->StartPostWriteValidation( | |
229 platform_path, file_ref, | |
230 base::Bind(&CopyOrMoveOperationDelegate::DidPostWriteValidation, | |
231 AsWeakPtr(), url_pair, callback)); | |
232 } | |
233 | |
234 void CopyOrMoveOperationDelegate::DidPostWriteValidation( | |
235 const URLPair& url_pair, | |
236 const StatusCallback& callback, | |
237 base::PlatformFileError error) { | |
238 if (error != base::PLATFORM_FILE_OK) { | |
239 operation_runner()->Remove( | |
240 url_pair.dest, true, | |
241 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError, | |
242 AsWeakPtr(), error, callback)); | |
243 return; | |
244 } | |
245 | |
246 if (operation_type_ == OPERATION_COPY) { | |
247 callback.Run(error); | |
248 return; | |
249 } | |
200 | 250 |
201 DCHECK_EQ(OPERATION_MOVE, operation_type_); | 251 DCHECK_EQ(OPERATION_MOVE, operation_type_); |
202 | 252 |
203 // Remove the source for finalizing move operation. | 253 // Remove the source for finalizing move operation. |
204 operation_runner()->Remove( | 254 operation_runner()->Remove( |
205 src, true /* recursive */, | 255 url_pair.src, true /* recursive */, |
206 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, | 256 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, |
207 AsWeakPtr(), callback)); | 257 AsWeakPtr(), callback)); |
208 } | 258 } |
209 | 259 |
210 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( | 260 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( |
211 const StatusCallback& callback, | 261 const StatusCallback& callback, |
212 base::PlatformFileError error) { | 262 base::PlatformFileError error) { |
213 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 263 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) |
214 error = base::PLATFORM_FILE_OK; | 264 error = base::PLATFORM_FILE_OK; |
215 callback.Run(error); | 265 callback.Run(error); |
216 } | 266 } |
217 | 267 |
218 FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( | 268 FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( |
219 const FileSystemURL& src_url) const { | 269 const FileSystemURL& src_url) const { |
220 DCHECK_EQ(src_root_.type(), src_url.type()); | 270 DCHECK_EQ(src_root_.type(), src_url.type()); |
221 DCHECK_EQ(src_root_.origin(), src_url.origin()); | 271 DCHECK_EQ(src_root_.origin(), src_url.origin()); |
222 | 272 |
223 base::FilePath relative = dest_root_.virtual_path(); | 273 base::FilePath relative = dest_root_.virtual_path(); |
224 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 274 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
225 &relative); | 275 &relative); |
226 return file_system_context()->CreateCrackedFileSystemURL( | 276 return file_system_context()->CreateCrackedFileSystemURL( |
227 dest_root_.origin(), | 277 dest_root_.origin(), |
228 dest_root_.mount_type(), | 278 dest_root_.mount_type(), |
229 relative); | 279 relative); |
230 } | 280 } |
231 | 281 |
282 void CopyOrMoveOperationDelegate::DidRemoveDestForError( | |
283 base::PlatformFileError prior_error, | |
284 const StatusCallback& callback, | |
285 base::PlatformFileError error) { | |
286 callback.Run(prior_error); | |
287 } | |
288 | |
232 } // namespace fileapi | 289 } // namespace fileapi |
OLD | NEW |