| 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/fileapi/cross_operation_delegate.h" | 5 #include "webkit/fileapi/cross_operation_delegate.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "webkit/blob/shareable_file_reference.h" | 8 #include "webkit/blob/shareable_file_reference.h" |
| 9 #include "webkit/fileapi/copy_or_move_file_validator.h" | 9 #include "webkit/fileapi/copy_or_move_file_validator.h" |
| 10 #include "webkit/fileapi/file_system_context.h" | 10 #include "webkit/fileapi/file_system_context.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 | 50 |
| 51 // It is an error to copy/move an entry into the same path. | 51 // It is an error to copy/move an entry into the same path. |
| 52 if (same_file_system_ && src_root_.path() == dest_root_.path()) { | 52 if (same_file_system_ && src_root_.path() == dest_root_.path()) { |
| 53 callback_.Run(base::PLATFORM_FILE_ERROR_EXISTS); | 53 callback_.Run(base::PLATFORM_FILE_ERROR_EXISTS); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // First try to copy/move it as a file. | 57 // First try to copy/move it as a file. |
| 58 CopyOrMoveFile(src_root_, dest_root_, | 58 CopyOrMoveFile(URLPair(src_root_, dest_root_), |
| 59 base::Bind(&CrossOperationDelegate::DidTryCopyOrMoveFile, | 59 base::Bind(&CrossOperationDelegate::DidTryCopyOrMoveFile, |
| 60 AsWeakPtr())); | 60 AsWeakPtr())); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void CrossOperationDelegate::ProcessFile(const FileSystemURL& src_url, | 63 void CrossOperationDelegate::ProcessFile(const FileSystemURL& src_url, |
| 64 const StatusCallback& callback) { | 64 const StatusCallback& callback) { |
| 65 CopyOrMoveFile(src_url, CreateDestURL(src_url), callback); | 65 CopyOrMoveFile(URLPair(src_url, CreateDestURL(src_url)), callback); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void CrossOperationDelegate::ProcessDirectory(const FileSystemURL& src_url, | 68 void CrossOperationDelegate::ProcessDirectory(const FileSystemURL& src_url, |
| 69 const StatusCallback& callback) { | 69 const StatusCallback& callback) { |
| 70 FileSystemURL dest_url = CreateDestURL(src_url); | 70 FileSystemURL dest_url = CreateDestURL(src_url); |
| 71 | 71 |
| 72 // If operation_type == Move we may need to record directories and | 72 // If operation_type == Move we may need to record directories and |
| 73 // restore directory timestamps in the end, though it may have | 73 // restore directory timestamps in the end, though it may have |
| 74 // negative performance impact. | 74 // negative performance impact. |
| 75 // See http://crbug.com/171284 for more details. | 75 // See http://crbug.com/171284 for more details. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(&CrossOperationDelegate::DidFinishCopy, | 113 src_root_, base::Bind(&CrossOperationDelegate::DidFinishCopy, |
| 114 AsWeakPtr(), src_root_, callback_)); | 114 AsWeakPtr(), src_root_, callback_)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void CrossOperationDelegate::CopyOrMoveFile( | 117 void CrossOperationDelegate::CopyOrMoveFile(const URLPair& url_pair, |
| 118 const FileSystemURL& src, | 118 const StatusCallback& callback) { |
| 119 const FileSystemURL& dest, | |
| 120 const StatusCallback& callback) { | |
| 121 // Same filesystem case. | 119 // Same filesystem case. |
| 122 if (same_file_system_) { | 120 if (same_file_system_) { |
| 123 if (operation_type_ == OPERATION_MOVE) | 121 if (operation_type_ == OPERATION_MOVE) { |
| 124 NewSourceOperation()->MoveFileLocal(src, dest, callback); | 122 NewSourceOperation()->MoveFileLocal(url_pair.src, url_pair.dest, |
| 125 else | 123 callback); |
| 126 NewSourceOperation()->CopyFileLocal(src, dest, callback); | 124 } else { |
| 125 NewSourceOperation()->CopyFileLocal(url_pair.src, url_pair.dest, |
| 126 callback); |
| 127 } |
| 127 return; | 128 return; |
| 128 } | 129 } |
| 129 | 130 |
| 130 // Cross filesystem case. | 131 // Cross filesystem case. |
| 131 // Perform CreateSnapshotFile, CopyInForeignFile and then calls | 132 // Perform CreateSnapshotFile, CopyInForeignFile and then calls |
| 132 // copy_callback which removes the source file if operation_type == MOVE. | 133 // copy_callback which removes the source file if operation_type == MOVE. |
| 133 StatusCallback copy_callback = | 134 StatusCallback copy_callback = |
| 134 base::Bind(&CrossOperationDelegate::DidFinishCopy, AsWeakPtr(), | 135 base::Bind(&CrossOperationDelegate::DidFinishCopy, AsWeakPtr(), |
| 135 src, callback); | 136 url_pair.src, callback); |
| 136 NewSourceOperation()->CreateSnapshotFile( | 137 NewSourceOperation()->CreateSnapshotFile( |
| 137 src, base::Bind(&CrossOperationDelegate::DidCreateSnapshot, AsWeakPtr(), | 138 url_pair.src, |
| 138 dest, copy_callback)); | 139 base::Bind(&CrossOperationDelegate::DidCreateSnapshot, AsWeakPtr(), |
| 140 url_pair, copy_callback)); |
| 139 } | 141 } |
| 140 | 142 |
| 141 void CrossOperationDelegate::DidCreateSnapshot( | 143 void CrossOperationDelegate::DidCreateSnapshot( |
| 142 const FileSystemURL& dest, | 144 const URLPair& url_pair, |
| 143 const StatusCallback& callback, | 145 const StatusCallback& callback, |
| 144 base::PlatformFileError error, | 146 base::PlatformFileError error, |
| 145 const base::PlatformFileInfo& file_info, | 147 const base::PlatformFileInfo& file_info, |
| 146 const base::FilePath& platform_path, | 148 const base::FilePath& platform_path, |
| 147 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | 149 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { |
| 148 if (error != base::PLATFORM_FILE_OK) { | 150 if (error != base::PLATFORM_FILE_OK) { |
| 149 callback.Run(error); | 151 callback.Run(error); |
| 150 return; | 152 return; |
| 151 } | 153 } |
| 152 current_file_ref_ = file_ref; | 154 current_file_ref_ = file_ref; |
| 153 | 155 |
| 154 // For now we assume CreateSnapshotFile always return a valid local file path. | 156 // For now we assume CreateSnapshotFile always return a valid local file path. |
| 155 // TODO(kinuko): Otherwise create a FileStreamReader to perform a copy/move. | 157 // TODO(kinuko): Otherwise create a FileStreamReader to perform a copy/move. |
| 156 DCHECK(!platform_path.empty()); | 158 DCHECK(!platform_path.empty()); |
| 157 | 159 |
| 158 CopyOrMoveFileValidatorFactory* factory = | 160 CopyOrMoveFileValidatorFactory* factory = |
| 159 file_system_context()->GetCopyOrMoveFileValidatorFactory( | 161 file_system_context()->GetCopyOrMoveFileValidatorFactory( |
| 160 dest_root_.type(), &error); | 162 dest_root_.type(), &error); |
| 161 if (error != base::PLATFORM_FILE_OK) { | 163 if (error != base::PLATFORM_FILE_OK) { |
| 162 callback.Run(error); | 164 callback.Run(error); |
| 163 return; | 165 return; |
| 164 } | 166 } |
| 165 if (!factory) { | 167 if (!factory) { |
| 166 DidValidateFile(dest, callback, file_info, platform_path, error); | 168 DidValidateFile(url_pair.dest, callback, file_info, platform_path, error); |
| 167 return; | 169 return; |
| 168 } | 170 } |
| 169 | 171 |
| 170 validator_.reset(factory->CreateCopyOrMoveFileValidator(platform_path)); | 172 validator_.reset( |
| 173 factory->CreateCopyOrMoveFileValidator(url_pair.src, platform_path)); |
| 171 validator_->StartValidation( | 174 validator_->StartValidation( |
| 172 base::Bind(&CrossOperationDelegate::DidValidateFile, AsWeakPtr(), | 175 base::Bind(&CrossOperationDelegate::DidValidateFile, AsWeakPtr(), |
| 173 dest, callback, file_info, platform_path)); | 176 url_pair.dest, callback, file_info, platform_path)); |
| 174 } | 177 } |
| 175 | 178 |
| 176 void CrossOperationDelegate::DidValidateFile( | 179 void CrossOperationDelegate::DidValidateFile( |
| 177 const FileSystemURL& dest, | 180 const FileSystemURL& dest, |
| 178 const StatusCallback& callback, | 181 const StatusCallback& callback, |
| 179 const base::PlatformFileInfo& file_info, | 182 const base::PlatformFileInfo& file_info, |
| 180 const base::FilePath& platform_path, | 183 const base::FilePath& platform_path, |
| 181 base::PlatformFileError error) { | 184 base::PlatformFileError error) { |
| 182 if (error != base::PLATFORM_FILE_OK) { | 185 if (error != base::PLATFORM_FILE_OK) { |
| 183 callback.Run(error); | 186 callback.Run(error); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 return NewNestedOperation(); | 235 return NewNestedOperation(); |
| 233 } | 236 } |
| 234 | 237 |
| 235 LocalFileSystemOperation* CrossOperationDelegate::NewSourceOperation() { | 238 LocalFileSystemOperation* CrossOperationDelegate::NewSourceOperation() { |
| 236 if (same_file_system_) | 239 if (same_file_system_) |
| 237 return NewDestOperation(); | 240 return NewDestOperation(); |
| 238 return src_root_operation_->CreateNestedOperation(); | 241 return src_root_operation_->CreateNestedOperation(); |
| 239 } | 242 } |
| 240 | 243 |
| 241 } // namespace fileapi | 244 } // namespace fileapi |
| OLD | NEW |