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 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // Copies a file on a (same) file system. Just delegate the operation to | 42 // Copies a file on a (same) file system. Just delegate the operation to |
43 // |operation_runner|. | 43 // |operation_runner|. |
44 class CopyOrMoveOnSameFileSystemImpl | 44 class CopyOrMoveOnSameFileSystemImpl |
45 : public CopyOrMoveOperationDelegate::CopyOrMoveImpl { | 45 : public CopyOrMoveOperationDelegate::CopyOrMoveImpl { |
46 public: | 46 public: |
47 CopyOrMoveOnSameFileSystemImpl( | 47 CopyOrMoveOnSameFileSystemImpl( |
48 FileSystemOperationRunner* operation_runner, | 48 FileSystemOperationRunner* operation_runner, |
49 FileSystemContext* file_system_context, | |
49 CopyOrMoveOperationDelegate::OperationType operation_type, | 50 CopyOrMoveOperationDelegate::OperationType operation_type, |
50 const FileSystemURL& src_url, | 51 const FileSystemURL& src_url, |
51 const FileSystemURL& dest_url, | 52 const FileSystemURL& dest_url, |
52 CopyOrMoveOperationDelegate::CopyOrMoveOption option, | 53 CopyOrMoveOperationDelegate::CopyOrMoveOption option, |
53 const FileSystemOperation::CopyFileProgressCallback& | 54 const FileSystemOperation::CopyFileProgressCallback& |
54 file_progress_callback) | 55 file_progress_callback) |
55 : operation_runner_(operation_runner), | 56 : operation_runner_(operation_runner), |
57 file_system_context_(file_system_context), | |
56 operation_type_(operation_type), | 58 operation_type_(operation_type), |
57 src_url_(src_url), | 59 src_url_(src_url), |
58 dest_url_(dest_url), | 60 dest_url_(dest_url), |
59 option_(option), | 61 option_(option), |
60 file_progress_callback_(file_progress_callback) { | 62 file_progress_callback_(file_progress_callback), |
61 } | 63 weak_factory_(this) {} |
62 | 64 |
63 virtual void Run( | 65 virtual void Run( |
64 const CopyOrMoveOperationDelegate::StatusCallback& callback) OVERRIDE { | 66 const CopyOrMoveOperationDelegate::StatusCallback& callback) OVERRIDE { |
67 NotifyOnStartUpdate(dest_url_); | |
tzik
2014/09/17 04:10:19
Since the notification is already sent by FileSyst
tzik
2014/09/17 05:03:05
Sorry, I misunderstood the structure.
This notific
iseki
2014/09/17 06:21:45
Done.
iseki
2014/09/17 06:21:45
Done.
| |
65 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_MOVE) { | 68 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_MOVE) { |
66 operation_runner_->MoveFileLocal(src_url_, dest_url_, option_, callback); | 69 NotifyOnStartUpdate(src_url_); |
70 operation_runner_->MoveFileLocal( | |
71 src_url_, | |
72 dest_url_, | |
73 option_, | |
74 base::Bind(&CopyOrMoveOnSameFileSystemImpl::DidCopyOrMove, | |
75 weak_factory_.GetWeakPtr(), | |
76 callback)); | |
67 } else { | 77 } else { |
68 operation_runner_->CopyFileLocal( | 78 operation_runner_->CopyFileLocal( |
69 src_url_, dest_url_, option_, file_progress_callback_, callback); | 79 src_url_, |
80 dest_url_, | |
81 option_, | |
82 file_progress_callback_, | |
83 base::Bind(&CopyOrMoveOnSameFileSystemImpl::DidCopyOrMove, | |
84 weak_factory_.GetWeakPtr(), | |
85 callback)); | |
70 } | 86 } |
71 } | 87 } |
72 | 88 |
89 void DidCopyOrMove( | |
90 const CopyOrMoveOperationDelegate::StatusCallback& callback, | |
91 base::File::Error error) { | |
92 if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_MOVE) { | |
93 NotifyOnEndUpdate(src_url_); | |
94 } | |
95 NotifyOnEndUpdate(dest_url_); | |
96 callback.Run(error); | |
97 } | |
98 | |
73 virtual void Cancel() OVERRIDE { | 99 virtual void Cancel() OVERRIDE { |
74 // We can do nothing for the copy/move operation on a local file system. | 100 // 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 | 101 // Assuming the operation is quickly done, it should be ok to just wait |
76 // for the completion. | 102 // for the completion. |
77 } | 103 } |
78 | 104 |
79 private: | 105 private: |
106 void NotifyOnStartUpdate(const FileSystemURL& url) { | |
107 if (file_system_context_->GetUpdateObservers(url.type())) { | |
108 file_system_context_->GetUpdateObservers(url.type()) | |
109 ->Notify(&FileUpdateObserver::OnStartUpdate, MakeTuple(url)); | |
110 } | |
111 } | |
112 | |
113 void NotifyOnEndUpdate(const FileSystemURL& url) { | |
114 if (file_system_context_->GetUpdateObservers(url.type())) { | |
115 file_system_context_->GetUpdateObservers(url.type()) | |
116 ->Notify(&FileUpdateObserver::OnEndUpdate, MakeTuple(url)); | |
117 } | |
118 } | |
119 | |
80 FileSystemOperationRunner* operation_runner_; | 120 FileSystemOperationRunner* operation_runner_; |
121 scoped_refptr<FileSystemContext> file_system_context_; | |
81 CopyOrMoveOperationDelegate::OperationType operation_type_; | 122 CopyOrMoveOperationDelegate::OperationType operation_type_; |
82 FileSystemURL src_url_; | 123 FileSystemURL src_url_; |
83 FileSystemURL dest_url_; | 124 FileSystemURL dest_url_; |
84 CopyOrMoveOperationDelegate::CopyOrMoveOption option_; | 125 CopyOrMoveOperationDelegate::CopyOrMoveOption option_; |
85 FileSystemOperation::CopyFileProgressCallback file_progress_callback_; | 126 FileSystemOperation::CopyFileProgressCallback file_progress_callback_; |
127 base::WeakPtrFactory<CopyOrMoveOnSameFileSystemImpl> weak_factory_; | |
86 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOnSameFileSystemImpl); | 128 DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOnSameFileSystemImpl); |
87 }; | 129 }; |
88 | 130 |
89 // Specifically for cross file system copy/move operation, this class creates | 131 // Specifically for cross file system copy/move operation, this class creates |
90 // a snapshot file, validates it if necessary, runs copying process, | 132 // a snapshot file, validates it if necessary, runs copying process, |
91 // validates the created file, and removes source file for move (noop for | 133 // validates the created file, and removes source file for move (noop for |
92 // copy). | 134 // copy). |
93 class SnapshotCopyOrMoveImpl | 135 class SnapshotCopyOrMoveImpl |
94 : public CopyOrMoveOperationDelegate::CopyOrMoveImpl { | 136 : public CopyOrMoveOperationDelegate::CopyOrMoveImpl { |
95 public: | 137 public: |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
794 } | 836 } |
795 | 837 |
796 FileSystemURL dest_url = CreateDestURL(src_url); | 838 FileSystemURL dest_url = CreateDestURL(src_url); |
797 CopyOrMoveImpl* impl = NULL; | 839 CopyOrMoveImpl* impl = NULL; |
798 if (same_file_system_ && | 840 if (same_file_system_ && |
799 (file_system_context() | 841 (file_system_context() |
800 ->GetFileSystemBackend(src_url.type()) | 842 ->GetFileSystemBackend(src_url.type()) |
801 ->HasInplaceCopyImplementation(src_url.type()) || | 843 ->HasInplaceCopyImplementation(src_url.type()) || |
802 operation_type_ == OPERATION_MOVE)) { | 844 operation_type_ == OPERATION_MOVE)) { |
803 impl = new CopyOrMoveOnSameFileSystemImpl( | 845 impl = new CopyOrMoveOnSameFileSystemImpl( |
804 operation_runner(), operation_type_, src_url, dest_url, option_, | 846 operation_runner(), |
847 file_system_context(), | |
848 operation_type_, | |
849 src_url, | |
850 dest_url, | |
851 option_, | |
805 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, | 852 base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress, |
806 weak_factory_.GetWeakPtr(), src_url)); | 853 weak_factory_.GetWeakPtr(), |
854 src_url)); | |
807 } else { | 855 } else { |
808 // Cross filesystem case. | 856 // Cross filesystem case. |
809 base::File::Error error = base::File::FILE_ERROR_FAILED; | 857 base::File::Error error = base::File::FILE_ERROR_FAILED; |
810 CopyOrMoveFileValidatorFactory* validator_factory = | 858 CopyOrMoveFileValidatorFactory* validator_factory = |
811 file_system_context()->GetCopyOrMoveFileValidatorFactory( | 859 file_system_context()->GetCopyOrMoveFileValidatorFactory( |
812 dest_root_.type(), &error); | 860 dest_root_.type(), &error); |
813 if (error != base::File::FILE_OK) { | 861 if (error != base::File::FILE_OK) { |
814 callback.Run(error); | 862 callback.Run(error); |
815 return; | 863 return; |
816 } | 864 } |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1025 base::FilePath relative = dest_root_.virtual_path(); | 1073 base::FilePath relative = dest_root_.virtual_path(); |
1026 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 1074 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
1027 &relative); | 1075 &relative); |
1028 return file_system_context()->CreateCrackedFileSystemURL( | 1076 return file_system_context()->CreateCrackedFileSystemURL( |
1029 dest_root_.origin(), | 1077 dest_root_.origin(), |
1030 dest_root_.mount_type(), | 1078 dest_root_.mount_type(), |
1031 relative); | 1079 relative); |
1032 } | 1080 } |
1033 | 1081 |
1034 } // namespace storage | 1082 } // namespace storage |
OLD | NEW |