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 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(), src_root_, dest_root_, callback_)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void CopyOrMoveOperationDelegate::CopyOrMoveFile(const URLPair& url_pair, | 117 void CopyOrMoveOperationDelegate::CopyOrMoveFile(const URLPair& url_pair, |
| 118 const StatusCallback& callback) { | 118 const StatusCallback& callback) { |
| 119 // Same filesystem case. | 119 // Same filesystem case. |
| 120 if (same_file_system_) { | 120 if (same_file_system_) { |
| 121 if (operation_type_ == OPERATION_MOVE) { | 121 if (operation_type_ == OPERATION_MOVE) { |
| 122 operation_runner()->MoveFileLocal(url_pair.src, url_pair.dest, callback); | 122 operation_runner()->MoveFileLocal(url_pair.src, url_pair.dest, callback); |
| 123 } else { | 123 } else { |
| 124 operation_runner()->CopyFileLocal(url_pair.src, url_pair.dest, callback); | 124 operation_runner()->CopyFileLocal(url_pair.src, url_pair.dest, callback); |
| 125 } | 125 } |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Cross filesystem case. | 129 // Cross filesystem case. |
| 130 // Perform CreateSnapshotFile, CopyInForeignFile and then calls | 130 // Perform CreateSnapshotFile, CopyInForeignFile and then calls |
| 131 // copy_callback which removes the source file if operation_type == MOVE. | 131 // copy_callback which removes the source file if operation_type == MOVE. |
| 132 StatusCallback copy_callback = | 132 StatusCallback copy_callback = |
| 133 base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, AsWeakPtr(), | 133 base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, AsWeakPtr(), |
| 134 url_pair.src, callback); | 134 url_pair.src, url_pair.dest, callback); |
| 135 operation_runner()->CreateSnapshotFile( | 135 operation_runner()->CreateSnapshotFile( |
| 136 url_pair.src, | 136 url_pair.src, |
| 137 base::Bind(&CopyOrMoveOperationDelegate::DidCreateSnapshot, AsWeakPtr(), | 137 base::Bind(&CopyOrMoveOperationDelegate::DidCreateSnapshot, AsWeakPtr(), |
| 138 url_pair, copy_callback)); | 138 url_pair, copy_callback)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void CopyOrMoveOperationDelegate::DidCreateSnapshot( | 141 void CopyOrMoveOperationDelegate::DidCreateSnapshot( |
| 142 const URLPair& url_pair, | 142 const URLPair& url_pair, |
| 143 const StatusCallback& callback, | 143 const StatusCallback& callback, |
| 144 base::PlatformFileError error, | 144 base::PlatformFileError error, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 if (error != base::PLATFORM_FILE_OK) { | 183 if (error != base::PLATFORM_FILE_OK) { |
| 184 callback.Run(error); | 184 callback.Run(error); |
| 185 return; | 185 return; |
| 186 } | 186 } |
| 187 | 187 |
| 188 operation_runner()->CopyInForeignFile(platform_path, dest, callback); | 188 operation_runner()->CopyInForeignFile(platform_path, dest, callback); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void CopyOrMoveOperationDelegate::DidFinishCopy( | 191 void CopyOrMoveOperationDelegate::DidFinishCopy( |
| 192 const FileSystemURL& src, | 192 const FileSystemURL& src, |
| 193 const FileSystemURL& dest, | |
| 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 | 200 |
| 201 if (operation_type_ == OPERATION_COPY) { | |
|
vandebo (ex-Chrome)
2013/07/02 18:43:05
Code is basically the same in both cases, combine.
Greg Billock
2013/07/02 19:17:39
I see what you mean below. Yeah, that's a good pla
| |
| 202 if (validator_.get()) { | |
| 203 PostWriteValidate( | |
| 204 dest, base::Bind(&CopyOrMoveOperationDelegate::DidPostCopyValidation, | |
| 205 AsWeakPtr(), callback)); | |
| 206 } else { | |
| 207 DidPostCopyValidation(callback, base::PLATFORM_FILE_OK); | |
| 208 } | |
| 209 return; | |
| 210 } | |
| 211 | |
| 201 DCHECK_EQ(OPERATION_MOVE, operation_type_); | 212 DCHECK_EQ(OPERATION_MOVE, operation_type_); |
| 202 | 213 |
| 214 if (validator_.get()) { | |
| 215 PostWriteValidate( | |
| 216 dest, base::Bind(&CopyOrMoveOperationDelegate::DidPostMoveValidation, | |
| 217 AsWeakPtr(), src, callback)); | |
| 218 } else { | |
| 219 DidPostMoveValidation(src, callback, base::PLATFORM_FILE_OK); | |
| 220 } | |
| 221 } | |
| 222 | |
| 223 void CopyOrMoveOperationDelegate::PostWriteValidate( | |
| 224 const FileSystemURL& dest, | |
| 225 const StatusCallback& callback) { | |
| 226 operation_runner()->CreateSnapshotFile( | |
| 227 dest, base::Bind(&CopyOrMoveOperationDelegate::DoPostWriteValidation, | |
| 228 AsWeakPtr(), callback)); | |
| 229 } | |
| 230 | |
| 231 void CopyOrMoveOperationDelegate::DoPostWriteValidation( | |
| 232 const StatusCallback& callback, | |
| 233 base::PlatformFileError error, | |
| 234 const base::PlatformFileInfo& file_info, | |
| 235 const base::FilePath& platform_path, | |
| 236 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | |
|
vandebo (ex-Chrome)
2013/07/02 18:43:05
You probably need to pass file_ref down so that th
Greg Billock
2013/07/02 19:17:39
So the file_ref is what keeps the snapshot alive?
vandebo (ex-Chrome)
2013/07/02 20:15:02
We don't want to validate files that need snapshot
| |
| 237 // TODO(gbillock): need to check here that file_ref is null or anything? | |
| 238 if (error != base::PLATFORM_FILE_OK) { | |
| 239 callback.Run(error); | |
| 240 return; | |
| 241 } | |
| 242 | |
| 243 DCHECK(validator_.get()); | |
| 244 validator_->StartPostWriteValidation(platform_path, callback); | |
|
vandebo (ex-Chrome)
2013/07/02 18:43:05
Instead of passing |callback| down to this point,
Greg Billock
2013/07/02 19:17:39
Done.
| |
| 245 } | |
| 246 | |
| 247 void CopyOrMoveOperationDelegate::DidPostCopyValidation( | |
| 248 const StatusCallback& callback, | |
| 249 base::PlatformFileError error) { | |
| 250 callback.Run(error); | |
| 251 } | |
| 252 | |
| 253 void CopyOrMoveOperationDelegate::DidPostMoveValidation( | |
| 254 const FileSystemURL& src, | |
| 255 const StatusCallback& callback, | |
| 256 base::PlatformFileError error) { | |
| 257 if (error != base::PLATFORM_FILE_OK) { | |
| 258 // TODO(gbillock): Need to remove the destination file here? | |
|
vandebo (ex-Chrome)
2013/07/02 18:43:05
Yes
Greg Billock
2013/07/02 19:17:39
Added the call, but I'm not sure what to do with e
vandebo (ex-Chrome)
2013/07/02 20:15:02
Yea, send back the validation error.
| |
| 259 callback.Run(error); | |
| 260 return; | |
| 261 } | |
| 262 | |
| 203 // Remove the source for finalizing move operation. | 263 // Remove the source for finalizing move operation. |
| 204 operation_runner()->Remove( | 264 operation_runner()->Remove( |
| 205 src, true /* recursive */, | 265 src, true /* recursive */, |
| 206 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, | 266 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, |
| 207 AsWeakPtr(), callback)); | 267 AsWeakPtr(), callback)); |
| 208 } | 268 } |
| 209 | 269 |
| 210 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( | 270 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( |
| 211 const StatusCallback& callback, | 271 const StatusCallback& callback, |
| 212 base::PlatformFileError error) { | 272 base::PlatformFileError error) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 223 base::FilePath relative = dest_root_.virtual_path(); | 283 base::FilePath relative = dest_root_.virtual_path(); |
| 224 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 284 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
| 225 &relative); | 285 &relative); |
| 226 return file_system_context()->CreateCrackedFileSystemURL( | 286 return file_system_context()->CreateCrackedFileSystemURL( |
| 227 dest_root_.origin(), | 287 dest_root_.origin(), |
| 228 dest_root_.mount_type(), | 288 dest_root_.mount_type(), |
| 229 relative); | 289 relative); |
| 230 } | 290 } |
| 231 | 291 |
| 232 } // namespace fileapi | 292 } // namespace fileapi |
| OLD | NEW |