Chromium Code Reviews| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) { | 103 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) { |
| 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, |
|
kinuko
2013/07/12 05:00:19
I overlooked this in my previous review, but when
Greg Billock
2013/07/12 18:02:19
OK. I'll add a directory-specific handler for this
vandebo (ex-Chrome)
2013/07/12 18:51:48
Probably want a complementary test that fails veri
Greg Billock
2013/07/12 20:36:46
validation is per-file at present, so you'd expect
vandebo (ex-Chrome)
2013/07/12 21:06:58
We only get one result code, so do you say it work
Greg Billock
2013/07/12 22:06:32
Yeah, the test shows this: it deletes the entire d
| |
| 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 // |validator_| must not exist in the same-filesystem case. | |
| 202 if (!validator_.get()) { | |
| 203 scoped_refptr<webkit_blob::ShareableFileReference> file_ref; | |
| 204 DidPostWriteValidation(url_pair, callback, file_ref, | |
| 205 base::PLATFORM_FILE_OK); | |
| 206 return; | |
| 207 } | |
| 208 | |
| 209 DCHECK(!same_file_system_); | |
| 210 operation_runner()->CreateSnapshotFile( | |
| 211 url_pair.dest, | |
| 212 base::Bind(&CopyOrMoveOperationDelegate::DoPostWriteValidation, | |
| 213 AsWeakPtr(), url_pair, callback)); | |
| 214 } | |
| 215 | |
| 216 void CopyOrMoveOperationDelegate::DoPostWriteValidation( | |
| 217 const URLPair& url_pair, | |
| 218 const StatusCallback& callback, | |
| 219 base::PlatformFileError error, | |
| 220 const base::PlatformFileInfo& file_info, | |
| 221 const base::FilePath& platform_path, | |
| 222 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | |
| 223 if (error != base::PLATFORM_FILE_OK) { | |
| 224 operation_runner()->Remove( | |
| 225 url_pair.dest, true, | |
| 226 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError, | |
| 227 AsWeakPtr(), error, callback)); | |
| 228 return; | |
| 229 } | |
| 230 | |
| 231 DCHECK(validator_.get()); | |
| 232 validator_->StartPostWriteValidation( | |
|
vandebo (ex-Chrome)
2013/07/12 15:08:15
Probably should add a comment about keeping file_r
Greg Billock
2013/07/12 18:02:19
Done.
| |
| 233 platform_path, | |
| 234 base::Bind(&CopyOrMoveOperationDelegate::DidPostWriteValidation, | |
| 235 AsWeakPtr(), url_pair, callback, file_ref)); | |
| 236 } | |
| 237 | |
| 238 void CopyOrMoveOperationDelegate::DidPostWriteValidation( | |
| 239 const URLPair& url_pair, | |
| 240 const StatusCallback& callback, | |
| 241 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, | |
|
vandebo (ex-Chrome)
2013/07/12 15:08:15
nit: file_ref isn't used in this context, so /*fil
Greg Billock
2013/07/12 18:02:19
Done.
| |
| 242 base::PlatformFileError error) { | |
| 243 if (error != base::PLATFORM_FILE_OK) { | |
| 244 operation_runner()->Remove( | |
| 245 url_pair.dest, true, | |
| 246 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError, | |
| 247 AsWeakPtr(), error, callback)); | |
| 248 return; | |
| 249 } | |
| 250 | |
| 251 if (operation_type_ == OPERATION_COPY) { | |
| 252 callback.Run(error); | |
| 253 return; | |
| 254 } | |
| 200 | 255 |
| 201 DCHECK_EQ(OPERATION_MOVE, operation_type_); | 256 DCHECK_EQ(OPERATION_MOVE, operation_type_); |
| 202 | 257 |
| 203 // Remove the source for finalizing move operation. | 258 // Remove the source for finalizing move operation. |
| 204 operation_runner()->Remove( | 259 operation_runner()->Remove( |
| 205 src, true /* recursive */, | 260 url_pair.src, true /* recursive */, |
| 206 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, | 261 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, |
| 207 AsWeakPtr(), callback)); | 262 AsWeakPtr(), callback)); |
| 208 } | 263 } |
| 209 | 264 |
| 210 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( | 265 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( |
| 211 const StatusCallback& callback, | 266 const StatusCallback& callback, |
| 212 base::PlatformFileError error) { | 267 base::PlatformFileError error) { |
| 213 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 268 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) |
| 214 error = base::PLATFORM_FILE_OK; | 269 error = base::PLATFORM_FILE_OK; |
| 215 callback.Run(error); | 270 callback.Run(error); |
| 216 } | 271 } |
| 217 | 272 |
| 218 FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( | 273 FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( |
| 219 const FileSystemURL& src_url) const { | 274 const FileSystemURL& src_url) const { |
| 220 DCHECK_EQ(src_root_.type(), src_url.type()); | 275 DCHECK_EQ(src_root_.type(), src_url.type()); |
| 221 DCHECK_EQ(src_root_.origin(), src_url.origin()); | 276 DCHECK_EQ(src_root_.origin(), src_url.origin()); |
| 222 | 277 |
| 223 base::FilePath relative = dest_root_.virtual_path(); | 278 base::FilePath relative = dest_root_.virtual_path(); |
| 224 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 279 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
| 225 &relative); | 280 &relative); |
| 226 return file_system_context()->CreateCrackedFileSystemURL( | 281 return file_system_context()->CreateCrackedFileSystemURL( |
| 227 dest_root_.origin(), | 282 dest_root_.origin(), |
| 228 dest_root_.mount_type(), | 283 dest_root_.mount_type(), |
| 229 relative); | 284 relative); |
| 230 } | 285 } |
| 231 | 286 |
| 287 void CopyOrMoveOperationDelegate::DidRemoveDestForError( | |
| 288 base::PlatformFileError prior_error, | |
| 289 const StatusCallback& callback, | |
| 290 base::PlatformFileError error) { | |
| 291 callback.Run(prior_error); | |
|
vandebo (ex-Chrome)
2013/07/12 15:08:15
nit: VLOG if error != OK ?
Greg Billock
2013/07/12 18:02:19
Done.
| |
| 292 } | |
| 293 | |
| 232 } // namespace fileapi | 294 } // namespace fileapi |
| OLD | NEW |