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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 416 } |
417 | 417 |
418 if (file_info.is_directory) { | 418 if (file_info.is_directory) { |
419 // If not a directory, failed with appropriate error code. | 419 // If not a directory, failed with appropriate error code. |
420 callback.Run(base::File::FILE_ERROR_NOT_A_FILE); | 420 callback.Run(base::File::FILE_ERROR_NOT_A_FILE); |
421 return; | 421 return; |
422 } | 422 } |
423 | 423 |
424 // To use FileStreamWriter, we need to ensure the destination file exists. | 424 // To use FileStreamWriter, we need to ensure the destination file exists. |
425 operation_runner_->CreateFile( | 425 operation_runner_->CreateFile( |
426 dest_url_, false /* exclusive */, | 426 dest_url_, |
| 427 true /* exclusive */, |
427 base::Bind(&StreamCopyOrMoveImpl::RunAfterCreateFileForDestination, | 428 base::Bind(&StreamCopyOrMoveImpl::RunAfterCreateFileForDestination, |
428 weak_factory_.GetWeakPtr(), | 429 weak_factory_.GetWeakPtr(), |
429 callback, file_info.last_modified)); | 430 callback, |
| 431 file_info.last_modified)); |
430 } | 432 } |
431 | 433 |
432 void RunAfterCreateFileForDestination( | 434 void RunAfterCreateFileForDestination( |
433 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 435 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
434 const base::Time& last_modified, | 436 const base::Time& last_modified, |
435 base::File::Error error) { | 437 base::File::Error error) { |
436 if (cancel_requested_) | 438 if (cancel_requested_) |
437 error = base::File::FILE_ERROR_ABORT; | 439 error = base::File::FILE_ERROR_ABORT; |
438 | 440 |
| 441 if (error != base::File::FILE_OK && |
| 442 error != base::File::FILE_ERROR_EXISTS) { |
| 443 callback.Run(error); |
| 444 return; |
| 445 } |
| 446 |
| 447 if (error == base::File::FILE_ERROR_EXISTS) { |
| 448 operation_runner_->Truncate( |
| 449 dest_url_, |
| 450 0 /* length */, |
| 451 base::Bind(&StreamCopyOrMoveImpl::RunAfterTruncateForDestination, |
| 452 weak_factory_.GetWeakPtr(), |
| 453 callback, |
| 454 last_modified)); |
| 455 return; |
| 456 } |
| 457 RunAfterTruncateForDestination( |
| 458 callback, last_modified, base::File::FILE_OK); |
| 459 } |
| 460 |
| 461 void RunAfterTruncateForDestination( |
| 462 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
| 463 const base::Time& last_modified, |
| 464 base::File::Error error) { |
| 465 if (cancel_requested_) |
| 466 error = base::File::FILE_ERROR_ABORT; |
| 467 |
439 if (error != base::File::FILE_OK) { | 468 if (error != base::File::FILE_OK) { |
440 callback.Run(error); | 469 callback.Run(error); |
441 return; | 470 return; |
442 } | 471 } |
443 | 472 |
444 const bool need_flush = dest_url_.mount_option().copy_sync_option() == | 473 const bool need_flush = dest_url_.mount_option().copy_sync_option() == |
445 storage::COPY_SYNC_OPTION_SYNC; | 474 storage::COPY_SYNC_OPTION_SYNC; |
446 | 475 |
447 DCHECK(!copy_helper_); | 476 DCHECK(!copy_helper_); |
448 copy_helper_.reset( | 477 copy_helper_.reset( |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 base::FilePath relative = dest_root_.virtual_path(); | 986 base::FilePath relative = dest_root_.virtual_path(); |
958 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 987 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
959 &relative); | 988 &relative); |
960 return file_system_context()->CreateCrackedFileSystemURL( | 989 return file_system_context()->CreateCrackedFileSystemURL( |
961 dest_root_.origin(), | 990 dest_root_.origin(), |
962 dest_root_.mount_type(), | 991 dest_root_.mount_type(), |
963 relative); | 992 relative); |
964 } | 993 } |
965 | 994 |
966 } // namespace storage | 995 } // namespace storage |
OLD | NEW |