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 "webkit/browser/fileapi/copy_or_move_file_validator.h" | 9 #include "webkit/browser/fileapi/copy_or_move_file_validator.h" |
10 #include "webkit/browser/fileapi/file_system_context.h" | 10 #include "webkit/browser/fileapi/file_system_context.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 callback_.Run(error); | 104 callback_.Run(error); |
105 return; | 105 return; |
106 } | 106 } |
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(&CopyOrMoveOperationDelegate::DidFinishCopy, | 113 src_root_, base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, |
114 AsWeakPtr(), src_root_, callback_)); | 114 AsWeakPtr(), URLPair(src_root_, dest_root_), |
115 callback_)); | |
115 } | 116 } |
116 | 117 |
117 void CopyOrMoveOperationDelegate::CopyOrMoveFile(const URLPair& url_pair, | 118 void CopyOrMoveOperationDelegate::CopyOrMoveFile(const URLPair& url_pair, |
118 const StatusCallback& callback) { | 119 const StatusCallback& callback) { |
119 // Same filesystem case. | 120 // Same filesystem case. |
120 if (same_file_system_) { | 121 if (same_file_system_) { |
121 if (operation_type_ == OPERATION_MOVE) { | 122 if (operation_type_ == OPERATION_MOVE) { |
122 operation_runner()->MoveFileLocal(url_pair.src, url_pair.dest, callback); | 123 operation_runner()->MoveFileLocal(url_pair.src, url_pair.dest, callback); |
123 } else { | 124 } else { |
124 operation_runner()->CopyFileLocal(url_pair.src, url_pair.dest, callback); | 125 operation_runner()->CopyFileLocal(url_pair.src, url_pair.dest, callback); |
125 } | 126 } |
126 return; | 127 return; |
127 } | 128 } |
128 | 129 |
129 // Cross filesystem case. | 130 // Cross filesystem case. |
130 // Perform CreateSnapshotFile, CopyInForeignFile and then calls | 131 // Perform CreateSnapshotFile, CopyInForeignFile and then calls |
131 // copy_callback which removes the source file if operation_type == MOVE. | 132 // copy_callback which removes the source file if operation_type == MOVE. |
132 StatusCallback copy_callback = | 133 StatusCallback copy_callback = |
133 base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, AsWeakPtr(), | 134 base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, AsWeakPtr(), |
134 url_pair.src, callback); | 135 url_pair, callback); |
135 operation_runner()->CreateSnapshotFile( | 136 operation_runner()->CreateSnapshotFile( |
136 url_pair.src, | 137 url_pair.src, |
137 base::Bind(&CopyOrMoveOperationDelegate::DidCreateSnapshot, AsWeakPtr(), | 138 base::Bind(&CopyOrMoveOperationDelegate::DidCreateSnapshot, AsWeakPtr(), |
138 url_pair, copy_callback)); | 139 url_pair, copy_callback)); |
139 } | 140 } |
140 | 141 |
141 void CopyOrMoveOperationDelegate::DidCreateSnapshot( | 142 void CopyOrMoveOperationDelegate::DidCreateSnapshot( |
142 const URLPair& url_pair, | 143 const URLPair& url_pair, |
143 const StatusCallback& callback, | 144 const StatusCallback& callback, |
144 base::PlatformFileError error, | 145 base::PlatformFileError error, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 base::PlatformFileError error) { | 183 base::PlatformFileError error) { |
183 if (error != base::PLATFORM_FILE_OK) { | 184 if (error != base::PLATFORM_FILE_OK) { |
184 callback.Run(error); | 185 callback.Run(error); |
185 return; | 186 return; |
186 } | 187 } |
187 | 188 |
188 operation_runner()->CopyInForeignFile(platform_path, dest, callback); | 189 operation_runner()->CopyInForeignFile(platform_path, dest, callback); |
189 } | 190 } |
190 | 191 |
191 void CopyOrMoveOperationDelegate::DidFinishCopy( | 192 void CopyOrMoveOperationDelegate::DidFinishCopy( |
192 const FileSystemURL& src, | 193 const URLPair& url_pair, |
193 const StatusCallback& callback, | 194 const StatusCallback& callback, |
194 base::PlatformFileError error) { | 195 base::PlatformFileError error) { |
195 if (error != base::PLATFORM_FILE_OK || | 196 if (error != base::PLATFORM_FILE_OK) { |
196 operation_type_ == OPERATION_COPY) { | |
197 callback.Run(error); | 197 callback.Run(error); |
198 return; | 198 return; |
199 } | 199 } |
200 | |
201 // |validator_| must not exist in the same-filesystem case. | |
vandebo (ex-Chrome)
2013/07/10 15:52:46
This comment is odd. I think it means |validator_
Greg Billock
2013/07/11 22:54:35
Yes, we can hit it same-filesystem, but we won't h
vandebo (ex-Chrome)
2013/07/12 15:08:15
validator_ would work in the same filesystem case,
Greg Billock
2013/07/12 18:02:19
Done.
| |
202 if (!validator_.get()) { | |
203 DidPostWriteValidation(url_pair, callback, base::PLATFORM_FILE_OK); | |
204 return; | |
205 } | |
206 | |
207 DCHECK(!same_file_system_); | |
208 operation_runner()->CreateSnapshotFile( | |
209 url_pair.dest, | |
210 base::Bind(&CopyOrMoveOperationDelegate::DoPostWriteValidation, | |
211 AsWeakPtr(), url_pair, callback)); | |
212 } | |
213 | |
214 void CopyOrMoveOperationDelegate::DoPostWriteValidation( | |
215 const URLPair& url_pair, | |
216 const StatusCallback& callback, | |
217 base::PlatformFileError error, | |
218 const base::PlatformFileInfo& file_info, | |
219 const base::FilePath& platform_path, | |
220 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { | |
221 if (error != base::PLATFORM_FILE_OK) { | |
222 operation_runner()->Remove( | |
223 url_pair.dest, true, | |
224 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError, | |
225 AsWeakPtr(), error, callback)); | |
vandebo (ex-Chrome)
2013/07/10 15:52:46
nit: you could bind error to callback and pass it
Greg Billock
2013/07/11 22:54:35
Yeah. I don't think that'd improve this, though.
vandebo (ex-Chrome)
2013/07/12 15:08:15
I think it makes DidRemoveDestForError a bit more
| |
226 return; | |
227 } | |
228 | |
229 DCHECK(validator_.get()); | |
230 validator_->StartPostWriteValidation( | |
231 platform_path, file_ref, | |
232 base::Bind(&CopyOrMoveOperationDelegate::DidPostWriteValidation, | |
233 AsWeakPtr(), url_pair, callback)); | |
vandebo (ex-Chrome)
2013/07/10 15:52:46
Yea, pass file_ref to DidPostWriteValidation so th
Greg Billock
2013/07/11 22:54:35
I see. That's a good point.
| |
234 } | |
235 | |
236 void CopyOrMoveOperationDelegate::DidPostWriteValidation( | |
237 const URLPair& url_pair, | |
238 const StatusCallback& callback, | |
239 base::PlatformFileError error) { | |
240 if (error != base::PLATFORM_FILE_OK) { | |
241 operation_runner()->Remove( | |
242 url_pair.dest, true, | |
243 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError, | |
244 AsWeakPtr(), error, callback)); | |
245 return; | |
246 } | |
247 | |
248 if (operation_type_ == OPERATION_COPY) { | |
249 callback.Run(error); | |
250 return; | |
251 } | |
200 | 252 |
201 DCHECK_EQ(OPERATION_MOVE, operation_type_); | 253 DCHECK_EQ(OPERATION_MOVE, operation_type_); |
202 | 254 |
203 // Remove the source for finalizing move operation. | 255 // Remove the source for finalizing move operation. |
204 operation_runner()->Remove( | 256 operation_runner()->Remove( |
205 src, true /* recursive */, | 257 url_pair.src, true /* recursive */, |
206 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, | 258 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove, |
207 AsWeakPtr(), callback)); | 259 AsWeakPtr(), callback)); |
208 } | 260 } |
209 | 261 |
210 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( | 262 void CopyOrMoveOperationDelegate::DidRemoveSourceForMove( |
211 const StatusCallback& callback, | 263 const StatusCallback& callback, |
212 base::PlatformFileError error) { | 264 base::PlatformFileError error) { |
213 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) | 265 if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) |
214 error = base::PLATFORM_FILE_OK; | 266 error = base::PLATFORM_FILE_OK; |
215 callback.Run(error); | 267 callback.Run(error); |
216 } | 268 } |
217 | 269 |
218 FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( | 270 FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL( |
219 const FileSystemURL& src_url) const { | 271 const FileSystemURL& src_url) const { |
220 DCHECK_EQ(src_root_.type(), src_url.type()); | 272 DCHECK_EQ(src_root_.type(), src_url.type()); |
221 DCHECK_EQ(src_root_.origin(), src_url.origin()); | 273 DCHECK_EQ(src_root_.origin(), src_url.origin()); |
222 | 274 |
223 base::FilePath relative = dest_root_.virtual_path(); | 275 base::FilePath relative = dest_root_.virtual_path(); |
224 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), | 276 src_root_.virtual_path().AppendRelativePath(src_url.virtual_path(), |
225 &relative); | 277 &relative); |
226 return file_system_context()->CreateCrackedFileSystemURL( | 278 return file_system_context()->CreateCrackedFileSystemURL( |
227 dest_root_.origin(), | 279 dest_root_.origin(), |
228 dest_root_.mount_type(), | 280 dest_root_.mount_type(), |
229 relative); | 281 relative); |
230 } | 282 } |
231 | 283 |
284 void CopyOrMoveOperationDelegate::DidRemoveDestForError( | |
285 base::PlatformFileError prior_error, | |
286 const StatusCallback& callback, | |
287 base::PlatformFileError error) { | |
288 callback.Run(prior_error); | |
289 } | |
290 | |
232 } // namespace fileapi | 291 } // namespace fileapi |
OLD | NEW |