Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Side by Side Diff: webkit/browser/fileapi/copy_or_move_operation_delegate.cc

Issue 18565002: [FileSystem] Add another copy-or-move validation hook for post-write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify dest validation callbacks and delete dest file on error Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 if (validator_.get()) {
202 operation_runner()->CreateSnapshotFile(
203 url_pair.dest,
204 base::Bind(&CopyOrMoveOperationDelegate::DoPostWriteValidation,
205 AsWeakPtr(), url_pair, callback));
206 } else {
207 DidPostWriteValidation(url_pair, callback, base::PLATFORM_FILE_OK);
208 }
209 }
210
211 void CopyOrMoveOperationDelegate::DoPostWriteValidation(
212 const URLPair& url_pair,
213 const StatusCallback& callback,
214 base::PlatformFileError error,
215 const base::PlatformFileInfo& file_info,
216 const base::FilePath& platform_path,
217 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
218 // TODO(gbillock): need to check here that file_ref is null or anything?
219 if (error != base::PLATFORM_FILE_OK) {
220 operation_runner()->Remove(
221 url_pair.dest, true,
222 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError,
vandebo (ex-Chrome) 2013/07/02 20:15:02 Shouldn't this take the callback and invoke it aft
Greg Billock 2013/07/03 16:08:27 I want to return the validation error, not the rem
223 AsWeakPtr()));
224 callback.Run(error);
225 return;
226 }
227
228 DCHECK(validator_.get());
229 validator_->StartPostWriteValidation(
230 platform_path,
231 base::Bind(&CopyOrMoveOperationDelegate::DidPostWriteValidation,
232 AsWeakPtr(), url_pair, callback));
233 }
234
235 void CopyOrMoveOperationDelegate::DidPostWriteValidation(
236 const URLPair& url_pair,
237 const StatusCallback& callback,
238 base::PlatformFileError error) {
239 if (error != base::PLATFORM_FILE_OK) {
240 operation_runner()->Remove(
241 url_pair.dest, true,
242 base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError,
243 AsWeakPtr()));
244 callback.Run(error);
vandebo (ex-Chrome) 2013/07/02 20:15:02 Same here
Greg Billock 2013/07/03 16:08:27 ditto
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 error) {
286 // TODO(gbillock): What to do here? Currently nothing....
vandebo (ex-Chrome) 2013/07/02 20:15:02 Remove it if you don't need it... but you do. You
Greg Billock 2013/07/03 16:08:27 That's basically what's happening now. I should wa
287 }
288
232 } // namespace fileapi 289 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698