| 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 "storage/browser/fileapi/copy_or_move_operation_delegate.h" | 5 #include "storage/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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 file_progress_callback) | 54 file_progress_callback) |
| 55 : operation_runner_(operation_runner), | 55 : operation_runner_(operation_runner), |
| 56 operation_type_(operation_type), | 56 operation_type_(operation_type), |
| 57 src_url_(src_url), | 57 src_url_(src_url), |
| 58 dest_url_(dest_url), | 58 dest_url_(dest_url), |
| 59 option_(option), | 59 option_(option), |
| 60 file_progress_callback_(file_progress_callback) { | 60 file_progress_callback_(file_progress_callback) { |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual void Run( | 63 virtual void Run( |
| 64 const CopyOrMoveOperationDelegate::StatusCallback& callback) OVERRIDE { | 64 const CopyOrMoveOperationDelegate::StatusCallback& callback) override { |
| 65 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_MOVE) { | 65 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_MOVE) { |
| 66 operation_runner_->MoveFileLocal(src_url_, dest_url_, option_, callback); | 66 operation_runner_->MoveFileLocal(src_url_, dest_url_, option_, callback); |
| 67 } else { | 67 } else { |
| 68 operation_runner_->CopyFileLocal( | 68 operation_runner_->CopyFileLocal( |
| 69 src_url_, dest_url_, option_, file_progress_callback_, callback); | 69 src_url_, dest_url_, option_, file_progress_callback_, callback); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 virtual void Cancel() OVERRIDE { | 73 virtual void Cancel() override { |
| 74 // We can do nothing for the copy/move operation on a local file system. | 74 // We can do nothing for the copy/move operation on a local file system. |
| 75 // Assuming the operation is quickly done, it should be ok to just wait | 75 // Assuming the operation is quickly done, it should be ok to just wait |
| 76 // for the completion. | 76 // for the completion. |
| 77 } | 77 } |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 FileSystemOperationRunner* operation_runner_; | 80 FileSystemOperationRunner* operation_runner_; |
| 81 CopyOrMoveOperationDelegate::OperationType operation_type_; | 81 CopyOrMoveOperationDelegate::OperationType operation_type_; |
| 82 FileSystemURL src_url_; | 82 FileSystemURL src_url_; |
| 83 FileSystemURL dest_url_; | 83 FileSystemURL dest_url_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 107 src_url_(src_url), | 107 src_url_(src_url), |
| 108 dest_url_(dest_url), | 108 dest_url_(dest_url), |
| 109 option_(option), | 109 option_(option), |
| 110 validator_factory_(validator_factory), | 110 validator_factory_(validator_factory), |
| 111 file_progress_callback_(file_progress_callback), | 111 file_progress_callback_(file_progress_callback), |
| 112 cancel_requested_(false), | 112 cancel_requested_(false), |
| 113 weak_factory_(this) { | 113 weak_factory_(this) { |
| 114 } | 114 } |
| 115 | 115 |
| 116 virtual void Run( | 116 virtual void Run( |
| 117 const CopyOrMoveOperationDelegate::StatusCallback& callback) OVERRIDE { | 117 const CopyOrMoveOperationDelegate::StatusCallback& callback) override { |
| 118 file_progress_callback_.Run(0); | 118 file_progress_callback_.Run(0); |
| 119 operation_runner_->CreateSnapshotFile( | 119 operation_runner_->CreateSnapshotFile( |
| 120 src_url_, | 120 src_url_, |
| 121 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterCreateSnapshot, | 121 base::Bind(&SnapshotCopyOrMoveImpl::RunAfterCreateSnapshot, |
| 122 weak_factory_.GetWeakPtr(), callback)); | 122 weak_factory_.GetWeakPtr(), callback)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 virtual void Cancel() OVERRIDE { | 125 virtual void Cancel() override { |
| 126 cancel_requested_ = true; | 126 cancel_requested_ = true; |
| 127 } | 127 } |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 void RunAfterCreateSnapshot( | 130 void RunAfterCreateSnapshot( |
| 131 const CopyOrMoveOperationDelegate::StatusCallback& callback, | 131 const CopyOrMoveOperationDelegate::StatusCallback& callback, |
| 132 base::File::Error error, | 132 base::File::Error error, |
| 133 const base::File::Info& file_info, | 133 const base::File::Info& file_info, |
| 134 const base::FilePath& platform_path, | 134 const base::FilePath& platform_path, |
| 135 const scoped_refptr<storage::ShareableFileReference>& file_ref) { | 135 const scoped_refptr<storage::ShareableFileReference>& file_ref) { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 src_url_(src_url), | 382 src_url_(src_url), |
| 383 dest_url_(dest_url), | 383 dest_url_(dest_url), |
| 384 option_(option), | 384 option_(option), |
| 385 reader_(reader.Pass()), | 385 reader_(reader.Pass()), |
| 386 writer_(writer.Pass()), | 386 writer_(writer.Pass()), |
| 387 file_progress_callback_(file_progress_callback), | 387 file_progress_callback_(file_progress_callback), |
| 388 cancel_requested_(false), | 388 cancel_requested_(false), |
| 389 weak_factory_(this) {} | 389 weak_factory_(this) {} |
| 390 | 390 |
| 391 virtual void Run( | 391 virtual void Run( |
| 392 const CopyOrMoveOperationDelegate::StatusCallback& callback) OVERRIDE { | 392 const CopyOrMoveOperationDelegate::StatusCallback& callback) override { |
| 393 // Reader can be created even if the entry does not exist or the entry is | 393 // Reader can be created even if the entry does not exist or the entry is |
| 394 // a directory. To check errors before destination file creation, | 394 // a directory. To check errors before destination file creation, |
| 395 // check metadata first. | 395 // check metadata first. |
| 396 operation_runner_->GetMetadata( | 396 operation_runner_->GetMetadata( |
| 397 src_url_, | 397 src_url_, |
| 398 base::Bind(&StreamCopyOrMoveImpl::RunAfterGetMetadataForSource, | 398 base::Bind(&StreamCopyOrMoveImpl::RunAfterGetMetadataForSource, |
| 399 weak_factory_.GetWeakPtr(), callback)); | 399 weak_factory_.GetWeakPtr(), callback)); |
| 400 } | 400 } |
| 401 | 401 |
| 402 virtual void Cancel() OVERRIDE { | 402 virtual void Cancel() override { |
| 403 cancel_requested_ = true; | 403 cancel_requested_ = true; |
| 404 if (copy_helper_) | 404 if (copy_helper_) |
| 405 copy_helper_->Cancel(); | 405 copy_helper_->Cancel(); |
| 406 } | 406 } |
| 407 | 407 |
| 408 private: | 408 private: |
| 409 void NotifyOnStartUpdate(const FileSystemURL& url) { | 409 void NotifyOnStartUpdate(const FileSystemURL& url) { |
| 410 if (file_system_context_->GetUpdateObservers(url.type())) { | 410 if (file_system_context_->GetUpdateObservers(url.type())) { |
| 411 file_system_context_->GetUpdateObservers(url.type()) | 411 file_system_context_->GetUpdateObservers(url.type()) |
| 412 ->Notify(&FileUpdateObserver::OnStartUpdate, MakeTuple(url)); | 412 ->Notify(&FileUpdateObserver::OnStartUpdate, MakeTuple(url)); |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 base::FilePath relative = dest_root_.virtual_path(); | 1025 base::FilePath relative = dest_root_.virtual_path(); |
| 1026 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 1026 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
| 1027 &relative); | 1027 &relative); |
| 1028 return file_system_context()->CreateCrackedFileSystemURL( | 1028 return file_system_context()->CreateCrackedFileSystemURL( |
| 1029 dest_root_.origin(), | 1029 dest_root_.origin(), |
| 1030 dest_root_.mount_type(), | 1030 dest_root_.mount_type(), |
| 1031 relative); | 1031 relative); |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 } // namespace storage | 1034 } // namespace storage |
| OLD | NEW |