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

Unified 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: Add test 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 side-by-side diff with in-line comments
Download patch
Index: webkit/browser/fileapi/copy_or_move_operation_delegate.cc
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc
index 8b706902b5c84396c675b884a01422d75f638b4b..4546ba3e4d6439e0db39e6bd97262c3442a112d7 100644
--- a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc
+++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc
@@ -111,7 +111,8 @@ void CopyOrMoveOperationDelegate::DidTryRemoveDestRoot(
// http://crbug.com/172187
StartRecursiveOperation(
src_root_, base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy,
- AsWeakPtr(), src_root_, callback_));
+ AsWeakPtr(), URLPair(src_root_, dest_root_),
+ callback_));
}
void CopyOrMoveOperationDelegate::CopyOrMoveFile(const URLPair& url_pair,
@@ -131,7 +132,7 @@ void CopyOrMoveOperationDelegate::CopyOrMoveFile(const URLPair& url_pair,
// copy_callback which removes the source file if operation_type == MOVE.
StatusCallback copy_callback =
base::Bind(&CopyOrMoveOperationDelegate::DidFinishCopy, AsWeakPtr(),
- url_pair.src, callback);
+ url_pair, callback);
operation_runner()->CreateSnapshotFile(
url_pair.src,
base::Bind(&CopyOrMoveOperationDelegate::DidCreateSnapshot, AsWeakPtr(),
@@ -189,11 +190,62 @@ void CopyOrMoveOperationDelegate::DidValidateFile(
}
void CopyOrMoveOperationDelegate::DidFinishCopy(
- const FileSystemURL& src,
+ const URLPair& url_pair,
const StatusCallback& callback,
base::PlatformFileError error) {
- if (error != base::PLATFORM_FILE_OK ||
- operation_type_ == OPERATION_COPY) {
+ if (error != base::PLATFORM_FILE_OK) {
+ callback.Run(error);
+ return;
+ }
+
+ // |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.
+ if (!validator_.get()) {
+ DidPostWriteValidation(url_pair, callback, base::PLATFORM_FILE_OK);
+ return;
+ }
+
+ DCHECK(!same_file_system_);
+ operation_runner()->CreateSnapshotFile(
+ url_pair.dest,
+ base::Bind(&CopyOrMoveOperationDelegate::DoPostWriteValidation,
+ AsWeakPtr(), url_pair, callback));
+}
+
+void CopyOrMoveOperationDelegate::DoPostWriteValidation(
+ const URLPair& url_pair,
+ const StatusCallback& callback,
+ base::PlatformFileError error,
+ const base::PlatformFileInfo& file_info,
+ const base::FilePath& platform_path,
+ const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
+ if (error != base::PLATFORM_FILE_OK) {
+ operation_runner()->Remove(
+ url_pair.dest, true,
+ base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError,
+ 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
+ return;
+ }
+
+ DCHECK(validator_.get());
+ validator_->StartPostWriteValidation(
+ platform_path, file_ref,
+ base::Bind(&CopyOrMoveOperationDelegate::DidPostWriteValidation,
+ 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.
+}
+
+void CopyOrMoveOperationDelegate::DidPostWriteValidation(
+ const URLPair& url_pair,
+ const StatusCallback& callback,
+ base::PlatformFileError error) {
+ if (error != base::PLATFORM_FILE_OK) {
+ operation_runner()->Remove(
+ url_pair.dest, true,
+ base::Bind(&CopyOrMoveOperationDelegate::DidRemoveDestForError,
+ AsWeakPtr(), error, callback));
+ return;
+ }
+
+ if (operation_type_ == OPERATION_COPY) {
callback.Run(error);
return;
}
@@ -202,7 +254,7 @@ void CopyOrMoveOperationDelegate::DidFinishCopy(
// Remove the source for finalizing move operation.
operation_runner()->Remove(
- src, true /* recursive */,
+ url_pair.src, true /* recursive */,
base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove,
AsWeakPtr(), callback));
}
@@ -229,4 +281,11 @@ FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL(
relative);
}
+void CopyOrMoveOperationDelegate::DidRemoveDestForError(
+ base::PlatformFileError prior_error,
+ const StatusCallback& callback,
+ base::PlatformFileError error) {
+ callback.Run(prior_error);
+}
+
} // namespace fileapi

Powered by Google App Engine
This is Rietveld 408576698