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 "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 weak_factory_.GetWeakPtr(), callback)); | 121 weak_factory_.GetWeakPtr(), callback)); |
122 } | 122 } |
123 | 123 |
124 virtual void Cancel() OVERRIDE { | 124 virtual void Cancel() OVERRIDE { |
125 cancel_requested_ = true; | 125 cancel_requested_ = true; |
126 } | 126 } |
127 | 127 |
128 private: | 128 private: |
129 void RunAfterCreateSnapshot( | 129 void RunAfterCreateSnapshot( |
130 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 130 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
131 base::PlatformFileError error, | 131 base::File::Error error, |
132 const base::PlatformFileInfo& file_info, | 132 const base::File::Info& file_info, |
133 const base::FilePath& platform_path, | 133 const base::FilePath& platform_path, |
134 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 134 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
135 if (cancel_requested_) | 135 if (cancel_requested_) |
136 error = base::PLATFORM_FILE_ERROR_ABORT; | 136 error = base::File::FILE_ERROR_ABORT; |
137 | 137 |
138 if (error != base::PLATFORM_FILE_OK) { | 138 if (error != base::File::FILE_OK) { |
139 callback.Run(error); | 139 callback.Run(error); |
140 return; | 140 return; |
141 } | 141 } |
142 | 142 |
143 // For now we assume CreateSnapshotFile always return a valid local file | 143 // For now we assume CreateSnapshotFile always return a valid local file |
144 // path. | 144 // path. |
145 DCHECK(!platform_path.empty()); | 145 DCHECK(!platform_path.empty()); |
146 | 146 |
147 if (!validator_factory_) { | 147 if (!validator_factory_) { |
148 // No validation is needed. | 148 // No validation is needed. |
149 RunAfterPreWriteValidation(platform_path, file_info, file_ref, callback, | 149 RunAfterPreWriteValidation(platform_path, file_info, file_ref, callback, |
150 base::PLATFORM_FILE_OK); | 150 base::File::FILE_OK); |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
154 // Run pre write validation. | 154 // Run pre write validation. |
155 PreWriteValidation( | 155 PreWriteValidation( |
156 platform_path, | 156 platform_path, |
157 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterPreWriteValidation, | 157 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterPreWriteValidation, |
158 weak_factory_.GetWeakPtr(), | 158 weak_factory_.GetWeakPtr(), |
159 platform_path, file_info, file_ref, callback)); | 159 platform_path, file_info, file_ref, callback)); |
160 } | 160 } |
161 | 161 |
162 void RunAfterPreWriteValidation( | 162 void RunAfterPreWriteValidation( |
163 const base::FilePath& platform_path, | 163 const base::FilePath& platform_path, |
164 const base::PlatformFileInfo& file_info, | 164 const base::File::Info& file_info, |
165 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, | 165 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, |
166 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 166 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
167 base::PlatformFileError error) { | 167 base::File::Error error) { |
168 if (cancel_requested_) | 168 if (cancel_requested_) |
169 error = base::PLATFORM_FILE_ERROR_ABORT; | 169 error = base::File::FILE_ERROR_ABORT; |
170 | 170 |
171 if (error != base::PLATFORM_FILE_OK) { | 171 if (error != base::File::FILE_OK) { |
172 callback.Run(error); | 172 callback.Run(error); |
173 return; | 173 return; |
174 } | 174 } |
175 | 175 |
176 // |file_ref| is unused but necessary to keep the file alive until | 176 // |file_ref| is unused but necessary to keep the file alive until |
177 // CopyInForeignFile() is completed. | 177 // CopyInForeignFile() is completed. |
178 operation_runner_->CopyInForeignFile( | 178 operation_runner_->CopyInForeignFile( |
179 platform_path, dest_url_, | 179 platform_path, dest_url_, |
180 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterCopyInForeignFile, | 180 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterCopyInForeignFile, |
181 weak_factory_.GetWeakPtr(), file_info, file_ref, callback)); | 181 weak_factory_.GetWeakPtr(), file_info, file_ref, callback)); |
182 } | 182 } |
183 | 183 |
184 void RunAfterCopyInForeignFile( | 184 void RunAfterCopyInForeignFile( |
185 const base::PlatformFileInfo& file_info, | 185 const base::File::Info& file_info, |
186 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, | 186 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, |
187 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 187 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
188 base::PlatformFileError error) { | 188 base::File::Error error) { |
189 if (cancel_requested_) | 189 if (cancel_requested_) |
190 error = base::PLATFORM_FILE_ERROR_ABORT; | 190 error = base::File::FILE_ERROR_ABORT; |
191 | 191 |
192 if (error != base::PLATFORM_FILE_OK) { | 192 if (error != base::File::FILE_OK) { |
193 callback.Run(error); | 193 callback.Run(error); |
194 return; | 194 return; |
195 } | 195 } |
196 | 196 |
197 file_progress_callback_.Run(file_info.size); | 197 file_progress_callback_.Run(file_info.size); |
198 | 198 |
199 if (option_ == FileSystemOperation::OPTION_NONE) { | 199 if (option_ == FileSystemOperation::OPTION_NONE) { |
200 RunAfterTouchFile(callback, base::PLATFORM_FILE_OK); | 200 RunAfterTouchFile(callback, base::File::FILE_OK); |
201 return; | 201 return; |
202 } | 202 } |
203 | 203 |
204 operation_runner_->TouchFile( | 204 operation_runner_->TouchFile( |
205 dest_url_, base::Time::Now() /* last_access */, | 205 dest_url_, base::Time::Now() /* last_access */, |
206 file_info.last_modified, | 206 file_info.last_modified, |
207 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterTouchFile, | 207 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterTouchFile, |
208 weak_factory_.GetWeakPtr(), callback)); | 208 weak_factory_.GetWeakPtr(), callback)); |
209 } | 209 } |
210 | 210 |
211 void RunAfterTouchFile( | 211 void RunAfterTouchFile( |
212 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 212 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
213 base::PlatformFileError error) { | 213 base::File::Error error) { |
214 // Even if TouchFile is failed, just ignore it. | 214 // Even if TouchFile is failed, just ignore it. |
215 | 215 |
216 if (cancel_requested_) { | 216 if (cancel_requested_) { |
217 callback.Run(base::PLATFORM_FILE_ERROR_ABORT); | 217 callback.Run(base::File::FILE_ERROR_ABORT); |
218 return; | 218 return; |
219 } | 219 } |
220 | 220 |
221 // |validator_| is NULL when the destination filesystem does not do | 221 // |validator_| is NULL when the destination filesystem does not do |
222 // validation. | 222 // validation. |
223 if (!validator_) { | 223 if (!validator_) { |
224 // No validation is needed. | 224 // No validation is needed. |
225 RunAfterPostWriteValidation(callback, base::PLATFORM_FILE_OK); | 225 RunAfterPostWriteValidation(callback, base::File::FILE_OK); |
226 return; | 226 return; |
227 } | 227 } |
228 | 228 |
229 PostWriteValidation( | 229 PostWriteValidation( |
230 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterPostWriteValidation, | 230 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterPostWriteValidation, |
231 weak_factory_.GetWeakPtr(), callback)); | 231 weak_factory_.GetWeakPtr(), callback)); |
232 } | 232 } |
233 | 233 |
234 void RunAfterPostWriteValidation( | 234 void RunAfterPostWriteValidation( |
235 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 235 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
236 base::PlatformFileError error) { | 236 base::File::Error error) { |
237 if (cancel_requested_) { | 237 if (cancel_requested_) { |
238 callback.Run(base::PLATFORM_FILE_ERROR_ABORT); | 238 callback.Run(base::File::FILE_ERROR_ABORT); |
239 return; | 239 return; |
240 } | 240 } |
241 | 241 |
242 if (error != base::PLATFORM_FILE_OK) { | 242 if (error != base::File::FILE_OK) { |
243 // Failed to validate. Remove the destination file. | 243 // Failed to validate. Remove the destination file. |
244 operation_runner_->Remove( | 244 operation_runner_->Remove( |
245 dest_url_, true /* recursive */, | 245 dest_url_, true /* recursive */, |
246 base::Bind(&SnapshotCopyOrMoveImpl::DidRemoveDestForError, | 246 base::Bind(&SnapshotCopyOrMoveImpl::DidRemoveDestForError, |
247 weak_factory_.GetWeakPtr(), error, callback)); | 247 weak_factory_.GetWeakPtr(), error, callback)); |
248 return; | 248 return; |
249 } | 249 } |
250 | 250 |
251 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_COPY) { | 251 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_COPY) { |
252 callback.Run(base::PLATFORM_FILE_OK); | 252 callback.Run(base::File::FILE_OK); |
253 return; | 253 return; |
254 } | 254 } |
255 | 255 |
256 DCHECK_EQ(CopyOrMoveOperationDelegate::OPERATION_MOVE, operation_type_); | 256 DCHECK_EQ(CopyOrMoveOperationDelegate::OPERATION_MOVE, operation_type_); |
257 | 257 |
258 // Remove the source for finalizing move operation. | 258 // Remove the source for finalizing move operation. |
259 operation_runner_->Remove( | 259 operation_runner_->Remove( |
260 src_url_, true /* recursive */, | 260 src_url_, true /* recursive */, |
261 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterRemoveSourceForMove, | 261 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterRemoveSourceForMove, |
262 weak_factory_.GetWeakPtr(), callback)); | 262 weak_factory_.GetWeakPtr(), callback)); |
263 } | 263 } |
264 | 264 |
265 void RunAfterRemoveSourceForMove( | 265 void RunAfterRemoveSourceForMove( |
266 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 266 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
267 base::PlatformFileError error) { | 267 base::File::Error error) { |
268 if (cancel_requested_) | 268 if (cancel_requested_) |
269 error = base::PLATFORM_FILE_ERROR_ABORT; | 269 error = base::File::FILE_ERROR_ABORT; |
270 | 270 |
271 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 271 if (error == base::File::FILE_ERROR_NOT_FOUND) |
272 error = base::PLATFORM_FILE_OK; | 272 error = base::File::FILE_OK; |
273 callback.Run(error); | 273 callback.Run(error); |
274 } | 274 } |
275 | 275 |
276 void DidRemoveDestForError( | 276 void DidRemoveDestForError( |
277 base::PlatformFileError prior_error, | 277 base::File::Error prior_error, |
278 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 278 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
279 base::PlatformFileError error) { | 279 base::File::Error error) { |
280 if (error != base::PLATFORM_FILE_OK) { | 280 if (error != base::File::FILE_OK) { |
281 VLOG(1) << "Error removing destination file after validation error: " | 281 VLOG(1) << "Error removing destination file after validation error: " |
282 << error; | 282 << error; |
283 } | 283 } |
284 callback.Run(prior_error); | 284 callback.Run(prior_error); |
285 } | 285 } |
286 | 286 |
287 // Runs pre-write validation. | 287 // Runs pre-write validation. |
288 void PreWriteValidation( | 288 void PreWriteValidation( |
289 const base::FilePath& platform_path, | 289 const base::FilePath& platform_path, |
290 const CopyOrMoveOperationDelegate::StatusCallback& callback) { | 290 const CopyOrMoveOperationDelegate::StatusCallback& callback) { |
291 DCHECK(validator_factory_); | 291 DCHECK(validator_factory_); |
292 validator_.reset( | 292 validator_.reset( |
293 validator_factory_->CreateCopyOrMoveFileValidator( | 293 validator_factory_->CreateCopyOrMoveFileValidator( |
294 src_url_, platform_path)); | 294 src_url_, platform_path)); |
295 validator_->StartPreWriteValidation(callback); | 295 validator_->StartPreWriteValidation(callback); |
296 } | 296 } |
297 | 297 |
298 // Runs post-write validation. | 298 // Runs post-write validation. |
299 void PostWriteValidation( | 299 void PostWriteValidation( |
300 const CopyOrMoveOperationDelegate::StatusCallback& callback) { | 300 const CopyOrMoveOperationDelegate::StatusCallback& callback) { |
301 operation_runner_->CreateSnapshotFile( | 301 operation_runner_->CreateSnapshotFile( |
302 dest_url_, | 302 dest_url_, |
303 base::Bind( | 303 base::Bind( |
304 &SnapshotCopyOrMoveImpl::PostWriteValidationAfterCreateSnapshotFile, | 304 &SnapshotCopyOrMoveImpl::PostWriteValidationAfterCreateSnapshotFile, |
305 weak_factory_.GetWeakPtr(), callback)); | 305 weak_factory_.GetWeakPtr(), callback)); |
306 } | 306 } |
307 | 307 |
308 void PostWriteValidationAfterCreateSnapshotFile( | 308 void PostWriteValidationAfterCreateSnapshotFile( |
309 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 309 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
310 base::PlatformFileError error, | 310 base::File::Error error, |
311 const base::PlatformFileInfo& file_info, | 311 const base::File::Info& file_info, |
312 const base::FilePath& platform_path, | 312 const base::FilePath& platform_path, |
313 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 313 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
314 if (cancel_requested_) | 314 if (cancel_requested_) |
315 error = base::PLATFORM_FILE_ERROR_ABORT; | 315 error = base::File::FILE_ERROR_ABORT; |
316 | 316 |
317 if (error != base::PLATFORM_FILE_OK) { | 317 if (error != base::File::FILE_OK) { |
318 callback.Run(error); | 318 callback.Run(error); |
319 return; | 319 return; |
320 } | 320 } |
321 | 321 |
322 DCHECK(validator_); | 322 DCHECK(validator_); |
323 // Note: file_ref passed here to keep the file alive until after | 323 // Note: file_ref passed here to keep the file alive until after |
324 // the StartPostWriteValidation operation finishes. | 324 // the StartPostWriteValidation operation finishes. |
325 validator_->StartPostWriteValidation( | 325 validator_->StartPostWriteValidation( |
326 platform_path, | 326 platform_path, |
327 base::Bind(&SnapshotCopyOrMoveImpl::DidPostWriteValidation, | 327 base::Bind(&SnapshotCopyOrMoveImpl::DidPostWriteValidation, |
328 weak_factory_.GetWeakPtr(), file_ref, callback)); | 328 weak_factory_.GetWeakPtr(), file_ref, callback)); |
329 } | 329 } |
330 | 330 |
331 // |file_ref| is unused; it is passed here to make sure the reference is | 331 // |file_ref| is unused; it is passed here to make sure the reference is |
332 // alive until after post-write validation is complete. | 332 // alive until after post-write validation is complete. |
333 void DidPostWriteValidation( | 333 void DidPostWriteValidation( |
334 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, | 334 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref, |
335 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 335 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
336 base::PlatformFileError error) { | 336 base::File::Error error) { |
337 callback.Run(error); | 337 callback.Run(error); |
338 } | 338 } |
339 | 339 |
340 FileSystemOperationRunner* operation_runner_; | 340 FileSystemOperationRunner* operation_runner_; |
341 CopyOrMoveOperationDelegate::OperationType operation_type_; | 341 CopyOrMoveOperationDelegate::OperationType operation_type_; |
342 FileSystemURL src_url_; | 342 FileSystemURL src_url_; |
343 FileSystemURL dest_url_; | 343 FileSystemURL dest_url_; |
344 | 344 |
345 CopyOrMoveOperationDelegate::CopyOrMoveOption option_; | 345 CopyOrMoveOperationDelegate::CopyOrMoveOption option_; |
346 CopyOrMoveFileValidatorFactory* validator_factory_; | 346 CopyOrMoveFileValidatorFactory* validator_factory_; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 399 |
400 virtual void Cancel() OVERRIDE { | 400 virtual void Cancel() OVERRIDE { |
401 cancel_requested_ = true; | 401 cancel_requested_ = true; |
402 if (copy_helper_) | 402 if (copy_helper_) |
403 copy_helper_->Cancel(); | 403 copy_helper_->Cancel(); |
404 } | 404 } |
405 | 405 |
406 private: | 406 private: |
407 void RunAfterGetMetadataForSource( | 407 void RunAfterGetMetadataForSource( |
408 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 408 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
409 base::PlatformFileError error, | 409 base::File::Error error, |
410 const base::PlatformFileInfo& file_info) { | 410 const base::File::Info& file_info) { |
411 if (cancel_requested_) | 411 if (cancel_requested_) |
412 error = base::PLATFORM_FILE_ERROR_ABORT; | 412 error = base::File::FILE_ERROR_ABORT; |
413 | 413 |
414 if (error != base::PLATFORM_FILE_OK) { | 414 if (error != base::File::FILE_OK) { |
415 callback.Run(error); | 415 callback.Run(error); |
416 return; | 416 return; |
417 } | 417 } |
418 | 418 |
419 if (file_info.is_directory) { | 419 if (file_info.is_directory) { |
420 // If not a directory, failed with appropriate error code. | 420 // If not a directory, failed with appropriate error code. |
421 callback.Run(base::PLATFORM_FILE_ERROR_NOT_A_FILE); | 421 callback.Run(base::File::FILE_ERROR_NOT_A_FILE); |
422 return; | 422 return; |
423 } | 423 } |
424 | 424 |
425 // To use FileStreamWriter, we need to ensure the destination file exists. | 425 // To use FileStreamWriter, we need to ensure the destination file exists. |
426 operation_runner_->CreateFile( | 426 operation_runner_->CreateFile( |
427 dest_url_, false /* exclusive */, | 427 dest_url_, false /* exclusive */, |
428 base::Bind(&StreamCopyOrMoveImpl::RunAfterCreateFileForDestination, | 428 base::Bind(&StreamCopyOrMoveImpl::RunAfterCreateFileForDestination, |
429 weak_factory_.GetWeakPtr(), | 429 weak_factory_.GetWeakPtr(), |
430 callback, file_info.last_modified)); | 430 callback, file_info.last_modified)); |
431 } | 431 } |
432 | 432 |
433 void RunAfterCreateFileForDestination( | 433 void RunAfterCreateFileForDestination( |
434 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 434 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
435 const base::Time& last_modified, | 435 const base::Time& last_modified, |
436 base::PlatformFileError error) { | 436 base::File::Error error) { |
437 if (cancel_requested_) | 437 if (cancel_requested_) |
438 error = base::PLATFORM_FILE_ERROR_ABORT; | 438 error = base::File::FILE_ERROR_ABORT; |
439 | 439 |
440 if (error != base::PLATFORM_FILE_OK) { | 440 if (error != base::File::FILE_OK) { |
441 callback.Run(error); | 441 callback.Run(error); |
442 return; | 442 return; |
443 } | 443 } |
444 | 444 |
445 const bool need_flush = dest_url_.mount_option().copy_sync_option() == | 445 const bool need_flush = dest_url_.mount_option().copy_sync_option() == |
446 fileapi::COPY_SYNC_OPTION_SYNC; | 446 fileapi::COPY_SYNC_OPTION_SYNC; |
447 | 447 |
448 DCHECK(!copy_helper_); | 448 DCHECK(!copy_helper_); |
449 copy_helper_.reset( | 449 copy_helper_.reset( |
450 new CopyOrMoveOperationDelegate::StreamCopyHelper( | 450 new CopyOrMoveOperationDelegate::StreamCopyHelper( |
451 reader_.Pass(), writer_.Pass(), | 451 reader_.Pass(), writer_.Pass(), |
452 need_flush, | 452 need_flush, |
453 kReadBufferSize, | 453 kReadBufferSize, |
454 file_progress_callback_, | 454 file_progress_callback_, |
455 base::TimeDelta::FromMilliseconds( | 455 base::TimeDelta::FromMilliseconds( |
456 kMinProgressCallbackInvocationSpanInMilliseconds))); | 456 kMinProgressCallbackInvocationSpanInMilliseconds))); |
457 copy_helper_->Run( | 457 copy_helper_->Run( |
458 base::Bind(&StreamCopyOrMoveImpl::RunAfterStreamCopy, | 458 base::Bind(&StreamCopyOrMoveImpl::RunAfterStreamCopy, |
459 weak_factory_.GetWeakPtr(), callback, last_modified)); | 459 weak_factory_.GetWeakPtr(), callback, last_modified)); |
460 } | 460 } |
461 | 461 |
462 void RunAfterStreamCopy( | 462 void RunAfterStreamCopy( |
463 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 463 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
464 const base::Time& last_modified, | 464 const base::Time& last_modified, |
465 base::PlatformFileError error) { | 465 base::File::Error error) { |
466 if (cancel_requested_) | 466 if (cancel_requested_) |
467 error = base::PLATFORM_FILE_ERROR_ABORT; | 467 error = base::File::FILE_ERROR_ABORT; |
468 | 468 |
469 if (error != base::PLATFORM_FILE_OK) { | 469 if (error != base::File::FILE_OK) { |
470 callback.Run(error); | 470 callback.Run(error); |
471 return; | 471 return; |
472 } | 472 } |
473 | 473 |
474 if (option_ == FileSystemOperation::OPTION_NONE) { | 474 if (option_ == FileSystemOperation::OPTION_NONE) { |
475 RunAfterTouchFile(callback, base::PLATFORM_FILE_OK); | 475 RunAfterTouchFile(callback, base::File::FILE_OK); |
476 return; | 476 return; |
477 } | 477 } |
478 | 478 |
479 operation_runner_->TouchFile( | 479 operation_runner_->TouchFile( |
480 dest_url_, base::Time::Now() /* last_access */, last_modified, | 480 dest_url_, base::Time::Now() /* last_access */, last_modified, |
481 base::Bind(&StreamCopyOrMoveImpl::RunAfterTouchFile, | 481 base::Bind(&StreamCopyOrMoveImpl::RunAfterTouchFile, |
482 weak_factory_.GetWeakPtr(), callback)); | 482 weak_factory_.GetWeakPtr(), callback)); |
483 } | 483 } |
484 | 484 |
485 void RunAfterTouchFile( | 485 void RunAfterTouchFile( |
486 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 486 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
487 base::PlatformFileError error) { | 487 base::File::Error error) { |
488 // Even if TouchFile is failed, just ignore it. | 488 // Even if TouchFile is failed, just ignore it. |
489 if (cancel_requested_) { | 489 if (cancel_requested_) { |
490 callback.Run(base::PLATFORM_FILE_ERROR_ABORT); | 490 callback.Run(base::File::FILE_ERROR_ABORT); |
491 return; | 491 return; |
492 } | 492 } |
493 | 493 |
494 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_COPY) { | 494 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_COPY) { |
495 callback.Run(base::PLATFORM_FILE_OK); | 495 callback.Run(base::File::FILE_OK); |
496 return; | 496 return; |
497 } | 497 } |
498 | 498 |
499 DCHECK_EQ(CopyOrMoveOperationDelegate::OPERATION_MOVE, operation_type_); | 499 DCHECK_EQ(CopyOrMoveOperationDelegate::OPERATION_MOVE, operation_type_); |
500 | 500 |
501 // Remove the source for finalizing move operation. | 501 // Remove the source for finalizing move operation. |
502 operation_runner_->Remove( | 502 operation_runner_->Remove( |
503 src_url_, false /* recursive */, | 503 src_url_, false /* recursive */, |
504 base::Bind(&StreamCopyOrMoveImpl::RunAfterRemoveForMove, | 504 base::Bind(&StreamCopyOrMoveImpl::RunAfterRemoveForMove, |
505 weak_factory_.GetWeakPtr(), callback)); | 505 weak_factory_.GetWeakPtr(), callback)); |
506 } | 506 } |
507 | 507 |
508 void RunAfterRemoveForMove( | 508 void RunAfterRemoveForMove( |
509 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 509 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
510 base::PlatformFileError error) { | 510 base::File::Error error) { |
511 if (cancel_requested_) | 511 if (cancel_requested_) |
512 error = base::PLATFORM_FILE_ERROR_ABORT; | 512 error = base::File::FILE_ERROR_ABORT; |
513 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 513 if (error == base::File::FILE_ERROR_NOT_FOUND) |
514 error = base::PLATFORM_FILE_OK; | 514 error = base::File::FILE_OK; |
515 callback.Run(error); | 515 callback.Run(error); |
516 } | 516 } |
517 | 517 |
518 FileSystemOperationRunner* operation_runner_; | 518 FileSystemOperationRunner* operation_runner_; |
519 CopyOrMoveOperationDelegate::OperationType operation_type_; | 519 CopyOrMoveOperationDelegate::OperationType operation_type_; |
520 FileSystemURL src_url_; | 520 FileSystemURL src_url_; |
521 FileSystemURL dest_url_; | 521 FileSystemURL dest_url_; |
522 CopyOrMoveOperationDelegate::CopyOrMoveOption option_; | 522 CopyOrMoveOperationDelegate::CopyOrMoveOption option_; |
523 scoped_ptr<webkit_blob::FileStreamReader> reader_; | 523 scoped_ptr<webkit_blob::FileStreamReader> reader_; |
524 scoped_ptr<FileStreamWriter> writer_; | 524 scoped_ptr<FileStreamWriter> writer_; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 io_buffer_.get(), io_buffer_->size(), | 572 io_buffer_.get(), io_buffer_->size(), |
573 base::Bind(&StreamCopyHelper::DidRead, | 573 base::Bind(&StreamCopyHelper::DidRead, |
574 weak_factory_.GetWeakPtr(), callback)); | 574 weak_factory_.GetWeakPtr(), callback)); |
575 if (result != net::ERR_IO_PENDING) | 575 if (result != net::ERR_IO_PENDING) |
576 DidRead(callback, result); | 576 DidRead(callback, result); |
577 } | 577 } |
578 | 578 |
579 void CopyOrMoveOperationDelegate::StreamCopyHelper::DidRead( | 579 void CopyOrMoveOperationDelegate::StreamCopyHelper::DidRead( |
580 const StatusCallback& callback, int result) { | 580 const StatusCallback& callback, int result) { |
581 if (cancel_requested_) { | 581 if (cancel_requested_) { |
582 callback.Run(base::PLATFORM_FILE_ERROR_ABORT); | 582 callback.Run(base::File::FILE_ERROR_ABORT); |
583 return; | 583 return; |
584 } | 584 } |
585 | 585 |
586 if (result < 0) { | 586 if (result < 0) { |
587 callback.Run(NetErrorToPlatformFileError(result)); | 587 callback.Run(NetErrorToFileError(result)); |
588 return; | 588 return; |
589 } | 589 } |
590 | 590 |
591 if (result == 0) { | 591 if (result == 0) { |
592 // Here is the EOF. | 592 // Here is the EOF. |
593 if (need_flush_) | 593 if (need_flush_) |
594 Flush(callback, true /* is_eof */); | 594 Flush(callback, true /* is_eof */); |
595 else | 595 else |
596 callback.Run(base::PLATFORM_FILE_OK); | 596 callback.Run(base::File::FILE_OK); |
597 return; | 597 return; |
598 } | 598 } |
599 | 599 |
600 Write(callback, new net::DrainableIOBuffer(io_buffer_.get(), result)); | 600 Write(callback, new net::DrainableIOBuffer(io_buffer_.get(), result)); |
601 } | 601 } |
602 | 602 |
603 void CopyOrMoveOperationDelegate::StreamCopyHelper::Write( | 603 void CopyOrMoveOperationDelegate::StreamCopyHelper::Write( |
604 const StatusCallback& callback, | 604 const StatusCallback& callback, |
605 scoped_refptr<net::DrainableIOBuffer> buffer) { | 605 scoped_refptr<net::DrainableIOBuffer> buffer) { |
606 DCHECK_GT(buffer->BytesRemaining(), 0); | 606 DCHECK_GT(buffer->BytesRemaining(), 0); |
607 | 607 |
608 int result = writer_->Write( | 608 int result = writer_->Write( |
609 buffer.get(), buffer->BytesRemaining(), | 609 buffer.get(), buffer->BytesRemaining(), |
610 base::Bind(&StreamCopyHelper::DidWrite, | 610 base::Bind(&StreamCopyHelper::DidWrite, |
611 weak_factory_.GetWeakPtr(), callback, buffer)); | 611 weak_factory_.GetWeakPtr(), callback, buffer)); |
612 if (result != net::ERR_IO_PENDING) | 612 if (result != net::ERR_IO_PENDING) |
613 DidWrite(callback, buffer, result); | 613 DidWrite(callback, buffer, result); |
614 } | 614 } |
615 | 615 |
616 void CopyOrMoveOperationDelegate::StreamCopyHelper::DidWrite( | 616 void CopyOrMoveOperationDelegate::StreamCopyHelper::DidWrite( |
617 const StatusCallback& callback, | 617 const StatusCallback& callback, |
618 scoped_refptr<net::DrainableIOBuffer> buffer, | 618 scoped_refptr<net::DrainableIOBuffer> buffer, |
619 int result) { | 619 int result) { |
620 if (cancel_requested_) { | 620 if (cancel_requested_) { |
621 callback.Run(base::PLATFORM_FILE_ERROR_ABORT); | 621 callback.Run(base::File::FILE_ERROR_ABORT); |
622 return; | 622 return; |
623 } | 623 } |
624 | 624 |
625 if (result < 0) { | 625 if (result < 0) { |
626 callback.Run(NetErrorToPlatformFileError(result)); | 626 callback.Run(NetErrorToFileError(result)); |
627 return; | 627 return; |
628 } | 628 } |
629 | 629 |
630 buffer->DidConsume(result); | 630 buffer->DidConsume(result); |
631 num_copied_bytes_ += result; | 631 num_copied_bytes_ += result; |
632 | 632 |
633 // Check the elapsed time since last |file_progress_callback_| invocation. | 633 // Check the elapsed time since last |file_progress_callback_| invocation. |
634 base::Time now = base::Time::Now(); | 634 base::Time now = base::Time::Now(); |
635 if (now - last_progress_callback_invocation_time_ >= | 635 if (now - last_progress_callback_invocation_time_ >= |
636 min_progress_callback_invocation_span_) { | 636 min_progress_callback_invocation_span_) { |
(...skipping 19 matching lines...) Expand all Loading... |
656 int result = writer_->Flush( | 656 int result = writer_->Flush( |
657 base::Bind(&StreamCopyHelper::DidFlush, | 657 base::Bind(&StreamCopyHelper::DidFlush, |
658 weak_factory_.GetWeakPtr(), callback, is_eof)); | 658 weak_factory_.GetWeakPtr(), callback, is_eof)); |
659 if (result != net::ERR_IO_PENDING) | 659 if (result != net::ERR_IO_PENDING) |
660 DidFlush(callback, is_eof, result); | 660 DidFlush(callback, is_eof, result); |
661 } | 661 } |
662 | 662 |
663 void CopyOrMoveOperationDelegate::StreamCopyHelper::DidFlush( | 663 void CopyOrMoveOperationDelegate::StreamCopyHelper::DidFlush( |
664 const StatusCallback& callback, bool is_eof, int result) { | 664 const StatusCallback& callback, bool is_eof, int result) { |
665 if (cancel_requested_) { | 665 if (cancel_requested_) { |
666 callback.Run(base::PLATFORM_FILE_ERROR_ABORT); | 666 callback.Run(base::File::FILE_ERROR_ABORT); |
667 return; | 667 return; |
668 } | 668 } |
669 | 669 |
670 previous_flush_offset_ = num_copied_bytes_; | 670 previous_flush_offset_ = num_copied_bytes_; |
671 if (is_eof) | 671 if (is_eof) |
672 callback.Run(NetErrorToPlatformFileError(result)); | 672 callback.Run(NetErrorToFileError(result)); |
673 else | 673 else |
674 Read(callback); | 674 Read(callback); |
675 } | 675 } |
676 | 676 |
677 CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( | 677 CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( |
678 FileSystemContext* file_system_context, | 678 FileSystemContext* file_system_context, |
679 const FileSystemURL& src_root, | 679 const FileSystemURL& src_root, |
680 const FileSystemURL& dest_root, | 680 const FileSystemURL& dest_root, |
681 OperationType operation_type, | 681 OperationType operation_type, |
682 CopyOrMoveOption option, | 682 CopyOrMoveOption option, |
(...skipping 17 matching lines...) Expand all Loading... |
700 void CopyOrMoveOperationDelegate::Run() { | 700 void CopyOrMoveOperationDelegate::Run() { |
701 // Not supported; this should never be called. | 701 // Not supported; this should never be called. |
702 NOTREACHED(); | 702 NOTREACHED(); |
703 } | 703 } |
704 | 704 |
705 void CopyOrMoveOperationDelegate::RunRecursively() { | 705 void CopyOrMoveOperationDelegate::RunRecursively() { |
706 // Perform light-weight checks first. | 706 // Perform light-weight checks first. |
707 | 707 |
708 // It is an error to try to copy/move an entry into its child. | 708 // It is an error to try to copy/move an entry into its child. |
709 if (same_file_system_ && src_root_.path().IsParent(dest_root_.path())) { | 709 if (same_file_system_ && src_root_.path().IsParent(dest_root_.path())) { |
710 callback_.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 710 callback_.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
711 return; | 711 return; |
712 } | 712 } |
713 | 713 |
714 if (same_file_system_ && src_root_.path() == dest_root_.path()) { | 714 if (same_file_system_ && src_root_.path() == dest_root_.path()) { |
715 // In JS API this should return error, but we return success because Pepper | 715 // In JS API this should return error, but we return success because Pepper |
716 // wants to return success and we have a code path that returns error in | 716 // wants to return success and we have a code path that returns error in |
717 // Blink for JS (http://crbug.com/329517). | 717 // Blink for JS (http://crbug.com/329517). |
718 callback_.Run(base::PLATFORM_FILE_OK); | 718 callback_.Run(base::File::FILE_OK); |
719 return; | 719 return; |
720 } | 720 } |
721 | 721 |
722 // Start to process the source directory recursively. | 722 // Start to process the source directory recursively. |
723 // TODO(kinuko): This could be too expensive for same_file_system_==true | 723 // TODO(kinuko): This could be too expensive for same_file_system_==true |
724 // and operation==MOVE case, probably we can just rename the root directory. | 724 // and operation==MOVE case, probably we can just rename the root directory. |
725 // http://crbug.com/172187 | 725 // http://crbug.com/172187 |
726 StartRecursiveOperation(src_root_, callback_); | 726 StartRecursiveOperation(src_root_, callback_); |
727 } | 727 } |
728 | 728 |
729 void CopyOrMoveOperationDelegate::ProcessFile( | 729 void CopyOrMoveOperationDelegate::ProcessFile( |
730 const FileSystemURL& src_url, | 730 const FileSystemURL& src_url, |
731 const StatusCallback& callback) { | 731 const StatusCallback& callback) { |
732 if (!progress_callback_.is_null()) { | 732 if (!progress_callback_.is_null()) { |
733 progress_callback_.Run( | 733 progress_callback_.Run( |
734 FileSystemOperation::BEGIN_COPY_ENTRY, src_url, FileSystemURL(), 0); | 734 FileSystemOperation::BEGIN_COPY_ENTRY, src_url, FileSystemURL(), 0); |
735 } | 735 } |
736 | 736 |
737 FileSystemURL dest_url = CreateDestURL(src_url); | 737 FileSystemURL dest_url = CreateDestURL(src_url); |
738 CopyOrMoveImpl* impl = NULL; | 738 CopyOrMoveImpl* impl = NULL; |
739 if (same_file_system_) { | 739 if (same_file_system_) { |
740 impl = new CopyOrMoveOnSameFileSystemImpl( | 740 impl = new CopyOrMoveOnSameFileSystemImpl( |
741 operation_runner(), operation_type_, src_url, dest_url, option_, | 741 operation_runner(), operation_type_, src_url, dest_url, option_, |
742 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, | 742 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, |
743 weak_factory_.GetWeakPtr(), src_url)); | 743 weak_factory_.GetWeakPtr(), src_url)); |
744 } else { | 744 } else { |
745 // Cross filesystem case. | 745 // Cross filesystem case. |
746 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; | 746 base::File::Error error = base::File::FILE_ERROR_FAILED; |
747 CopyOrMoveFileValidatorFactory* validator_factory = | 747 CopyOrMoveFileValidatorFactory* validator_factory = |
748 file_system_context()->GetCopyOrMoveFileValidatorFactory( | 748 file_system_context()->GetCopyOrMoveFileValidatorFactory( |
749 dest_root_.type(), &error); | 749 dest_root_.type(), &error); |
750 if (error != base::PLATFORM_FILE_OK) { | 750 if (error != base::File::FILE_OK) { |
751 callback.Run(error); | 751 callback.Run(error); |
752 return; | 752 return; |
753 } | 753 } |
754 | 754 |
755 if (!validator_factory) { | 755 if (!validator_factory) { |
756 scoped_ptr<webkit_blob::FileStreamReader> reader = | 756 scoped_ptr<webkit_blob::FileStreamReader> reader = |
757 file_system_context()->CreateFileStreamReader( | 757 file_system_context()->CreateFileStreamReader( |
758 src_url, 0, base::Time()); | 758 src_url, 0, base::Time()); |
759 scoped_ptr<FileStreamWriter> writer = | 759 scoped_ptr<FileStreamWriter> writer = |
760 file_system_context()->CreateFileStreamWriter(dest_url, 0); | 760 file_system_context()->CreateFileStreamWriter(dest_url, 0); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 } | 805 } |
806 | 806 |
807 ProcessDirectoryInternal(src_url, CreateDestURL(src_url), callback); | 807 ProcessDirectoryInternal(src_url, CreateDestURL(src_url), callback); |
808 } | 808 } |
809 | 809 |
810 void CopyOrMoveOperationDelegate::PostProcessDirectory( | 810 void CopyOrMoveOperationDelegate::PostProcessDirectory( |
811 const FileSystemURL& src_url, | 811 const FileSystemURL& src_url, |
812 const StatusCallback& callback) { | 812 const StatusCallback& callback) { |
813 if (option_ == FileSystemOperation::OPTION_NONE) { | 813 if (option_ == FileSystemOperation::OPTION_NONE) { |
814 PostProcessDirectoryAfterTouchFile( | 814 PostProcessDirectoryAfterTouchFile( |
815 src_url, callback, base::PLATFORM_FILE_OK); | 815 src_url, callback, base::File::FILE_OK); |
816 return; | 816 return; |
817 } | 817 } |
818 | 818 |
819 operation_runner()->GetMetadata( | 819 operation_runner()->GetMetadata( |
820 src_url, | 820 src_url, |
821 base::Bind( | 821 base::Bind( |
822 &CopyOrMoveOperationDelegate::PostProcessDirectoryAfterGetMetadata, | 822 &CopyOrMoveOperationDelegate::PostProcessDirectoryAfterGetMetadata, |
823 weak_factory_.GetWeakPtr(), src_url, callback)); | 823 weak_factory_.GetWeakPtr(), src_url, callback)); |
824 } | 824 } |
825 | 825 |
826 void CopyOrMoveOperationDelegate::OnCancel() { | 826 void CopyOrMoveOperationDelegate::OnCancel() { |
827 // Request to cancel all running Copy/Move file. | 827 // Request to cancel all running Copy/Move file. |
828 for (std::set<CopyOrMoveImpl*>::iterator iter = running_copy_set_.begin(); | 828 for (std::set<CopyOrMoveImpl*>::iterator iter = running_copy_set_.begin(); |
829 iter != running_copy_set_.end(); ++iter) | 829 iter != running_copy_set_.end(); ++iter) |
830 (*iter)->Cancel(); | 830 (*iter)->Cancel(); |
831 } | 831 } |
832 | 832 |
833 void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( | 833 void CopyOrMoveOperationDelegate::DidCopyOrMoveFile( |
834 const FileSystemURL& src_url, | 834 const FileSystemURL& src_url, |
835 const FileSystemURL& dest_url, | 835 const FileSystemURL& dest_url, |
836 const StatusCallback& callback, | 836 const StatusCallback& callback, |
837 CopyOrMoveImpl* impl, | 837 CopyOrMoveImpl* impl, |
838 base::PlatformFileError error) { | 838 base::File::Error error) { |
839 running_copy_set_.erase(impl); | 839 running_copy_set_.erase(impl); |
840 delete impl; | 840 delete impl; |
841 | 841 |
842 if (!progress_callback_.is_null() && error == base::PLATFORM_FILE_OK) { | 842 if (!progress_callback_.is_null() && error == base::File::FILE_OK) { |
843 progress_callback_.Run( | 843 progress_callback_.Run( |
844 FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); | 844 FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); |
845 } | 845 } |
846 | 846 |
847 callback.Run(error); | 847 callback.Run(error); |
848 } | 848 } |
849 | 849 |
850 void CopyOrMoveOperationDelegate::DidTryRemoveDestRoot( | 850 void CopyOrMoveOperationDelegate::DidTryRemoveDestRoot( |
851 const StatusCallback& callback, | 851 const StatusCallback& callback, |
852 base::PlatformFileError error) { | 852 base::File::Error error) { |
853 if (error == base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY) { | 853 if (error == base::File::FILE_ERROR_NOT_A_DIRECTORY) { |
854 callback_.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 854 callback_.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
855 return; | 855 return; |
856 } | 856 } |
857 if (error != base::PLATFORM_FILE_OK && | 857 if (error != base::File::FILE_OK && |
858 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) { | 858 error != base::File::FILE_ERROR_NOT_FOUND) { |
859 callback_.Run(error); | 859 callback_.Run(error); |
860 return; | 860 return; |
861 } | 861 } |
862 | 862 |
863 ProcessDirectoryInternal(src_root_, dest_root_, callback); | 863 ProcessDirectoryInternal(src_root_, dest_root_, callback); |
864 } | 864 } |
865 | 865 |
866 void CopyOrMoveOperationDelegate::ProcessDirectoryInternal( | 866 void CopyOrMoveOperationDelegate::ProcessDirectoryInternal( |
867 const FileSystemURL& src_url, | 867 const FileSystemURL& src_url, |
868 const FileSystemURL& dest_url, | 868 const FileSystemURL& dest_url, |
869 const StatusCallback& callback) { | 869 const StatusCallback& callback) { |
870 // If operation_type == Move we may need to record directories and | 870 // If operation_type == Move we may need to record directories and |
871 // restore directory timestamps in the end, though it may have | 871 // restore directory timestamps in the end, though it may have |
872 // negative performance impact. | 872 // negative performance impact. |
873 // See http://crbug.com/171284 for more details. | 873 // See http://crbug.com/171284 for more details. |
874 operation_runner()->CreateDirectory( | 874 operation_runner()->CreateDirectory( |
875 dest_url, false /* exclusive */, false /* recursive */, | 875 dest_url, false /* exclusive */, false /* recursive */, |
876 base::Bind(&CopyOrMoveOperationDelegate::DidCreateDirectory, | 876 base::Bind(&CopyOrMoveOperationDelegate::DidCreateDirectory, |
877 weak_factory_.GetWeakPtr(), src_url, dest_url, callback)); | 877 weak_factory_.GetWeakPtr(), src_url, dest_url, callback)); |
878 } | 878 } |
879 | 879 |
880 void CopyOrMoveOperationDelegate::DidCreateDirectory( | 880 void CopyOrMoveOperationDelegate::DidCreateDirectory( |
881 const FileSystemURL& src_url, | 881 const FileSystemURL& src_url, |
882 const FileSystemURL& dest_url, | 882 const FileSystemURL& dest_url, |
883 const StatusCallback& callback, | 883 const StatusCallback& callback, |
884 base::PlatformFileError error) { | 884 base::File::Error error) { |
885 if (!progress_callback_.is_null() && error == base::PLATFORM_FILE_OK) { | 885 if (!progress_callback_.is_null() && error == base::File::FILE_OK) { |
886 progress_callback_.Run( | 886 progress_callback_.Run( |
887 FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); | 887 FileSystemOperation::END_COPY_ENTRY, src_url, dest_url, 0); |
888 } | 888 } |
889 | 889 |
890 callback.Run(error); | 890 callback.Run(error); |
891 } | 891 } |
892 | 892 |
893 void CopyOrMoveOperationDelegate::PostProcessDirectoryAfterGetMetadata( | 893 void CopyOrMoveOperationDelegate::PostProcessDirectoryAfterGetMetadata( |
894 const FileSystemURL& src_url, | 894 const FileSystemURL& src_url, |
895 const StatusCallback& callback, | 895 const StatusCallback& callback, |
896 base::PlatformFileError error, | 896 base::File::Error error, |
897 const base::PlatformFileInfo& file_info) { | 897 const base::File::Info& file_info) { |
898 if (error != base::PLATFORM_FILE_OK) { | 898 if (error != base::File::FILE_OK) { |
899 // Ignore the error, and run post process which should run after TouchFile. | 899 // Ignore the error, and run post process which should run after TouchFile. |
900 PostProcessDirectoryAfterTouchFile( | 900 PostProcessDirectoryAfterTouchFile( |
901 src_url, callback, base::PLATFORM_FILE_OK); | 901 src_url, callback, base::File::FILE_OK); |
902 return; | 902 return; |
903 } | 903 } |
904 | 904 |
905 operation_runner()->TouchFile( | 905 operation_runner()->TouchFile( |
906 CreateDestURL(src_url), base::Time::Now() /* last access */, | 906 CreateDestURL(src_url), base::Time::Now() /* last access */, |
907 file_info.last_modified, | 907 file_info.last_modified, |
908 base::Bind( | 908 base::Bind( |
909 &CopyOrMoveOperationDelegate::PostProcessDirectoryAfterTouchFile, | 909 &CopyOrMoveOperationDelegate::PostProcessDirectoryAfterTouchFile, |
910 weak_factory_.GetWeakPtr(), src_url, callback)); | 910 weak_factory_.GetWeakPtr(), src_url, callback)); |
911 } | 911 } |
912 | 912 |
913 void CopyOrMoveOperationDelegate::PostProcessDirectoryAfterTouchFile( | 913 void CopyOrMoveOperationDelegate::PostProcessDirectoryAfterTouchFile( |
914 const FileSystemURL& src_url, | 914 const FileSystemURL& src_url, |
915 const StatusCallback& callback, | 915 const StatusCallback& callback, |
916 base::PlatformFileError error) { | 916 base::File::Error error) { |
917 // Even if the TouchFile is failed, just ignore it. | 917 // Even if the TouchFile is failed, just ignore it. |
918 | 918 |
919 if (operation_type_ == OPERATION_COPY) { | 919 if (operation_type_ == OPERATION_COPY) { |
920 callback.Run(base::PLATFORM_FILE_OK); | 920 callback.Run(base::File::FILE_OK); |
921 return; | 921 return; |
922 } | 922 } |
923 | 923 |
924 DCHECK_EQ(OPERATION_MOVE, operation_type_); | 924 DCHECK_EQ(OPERATION_MOVE, operation_type_); |
925 | 925 |
926 // All files and subdirectories in the directory should be moved here, | 926 // All files and subdirectories in the directory should be moved here, |
927 // so remove the source directory for finalizing move operation. | 927 // so remove the source directory for finalizing move operation. |
928 operation_runner()->Remove( | 928 operation_runner()->Remove( |
929 src_url, false /* recursive */, | 929 src_url, false /* recursive */, |
930 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, | 930 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, |
931 weak_factory_.GetWeakPtr(), callback)); | 931 weak_factory_.GetWeakPtr(), callback)); |
932 } | 932 } |
933 | 933 |
934 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( | 934 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( |
935 const StatusCallback& callback, | 935 const StatusCallback& callback, |
936 base::PlatformFileError error) { | 936 base::File::Error error) { |
937 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 937 if (error == base::File::FILE_ERROR_NOT_FOUND) |
938 error = base::PLATFORM_FILE_OK; | 938 error = base::File::FILE_OK; |
939 callback.Run(error); | 939 callback.Run(error); |
940 } | 940 } |
941 | 941 |
942 void CopyOrMoveOperationDelegate::OnCopyFileProgress( | 942 void CopyOrMoveOperationDelegate::OnCopyFileProgress( |
943 const FileSystemURL& src_url, int64 size) { | 943 const FileSystemURL& src_url, int64 size) { |
944 if (!progress_callback_.is_null()) { | 944 if (!progress_callback_.is_null()) { |
945 progress_callback_.Run( | 945 progress_callback_.Run( |
946 FileSystemOperation::PROGRESS, src_url, FileSystemURL(), size); | 946 FileSystemOperation::PROGRESS, src_url, FileSystemURL(), size); |
947 } | 947 } |
948 } | 948 } |
949 | 949 |
950 FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( | 950 FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( |
951 const FileSystemURL& src_url) const { | 951 const FileSystemURL& src_url) const { |
952 DCHECK_EQ(src_root_.type(), src_url.type()); | 952 DCHECK_EQ(src_root_.type(), src_url.type()); |
953 DCHECK_EQ(src_root_.origin(), src_url.origin()); | 953 DCHECK_EQ(src_root_.origin(), src_url.origin()); |
954 | 954 |
955 base::FilePath relative = dest_root_.virtual_path(); | 955 base::FilePath relative = dest_root_.virtual_path(); |
956 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 956 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
957 &relative); | 957 &relative); |
958 return file_system_context()->CreateCrackedFileSystemURL( | 958 return file_system_context()->CreateCrackedFileSystemURL( |
959 dest_root_.origin(), | 959 dest_root_.origin(), |
960 dest_root_.mount_type(), | 960 dest_root_.mount_type(), |
961 relative); | 961 relative); |
962 } | 962 } |
963 | 963 |
964 } // namespace fileapi | 964 } // namespace fileapi |
OLD | NEW |