summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-26 18:06:26 +0000
committerhidehiko@chromium.org <hidehiko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-26 18:06:26 +0000
commit39a7337981191d10da0843b0e33c65797f51fca5 (patch)
treeb7cffdcb00862814175da8a65abd5fda8dc5f83a /webkit
parent615bbbfdd7b9be41bdf33b60fbed2ad9a02d2352 (diff)
downloadchromium_src-39a7337981191d10da0843b0e33c65797f51fca5.zip
chromium_src-39a7337981191d10da0843b0e33c65797f51fca5.tar.gz
chromium_src-39a7337981191d10da0843b0e33c65797f51fca5.tar.bz2
Implement "preserving last modified" for Copy() and Move() on cross file system.
This CL implements "preserving last modified" feature for Copy() and Move() on cross file system. As specification says, the failing of TouchFile shouldn't be an error, so errors are just ignored. BUG=282107 TEST=Ran unit_tests and content_unittests Review URL: https://codereview.chromium.org/24593002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225504 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/browser/fileapi/copy_or_move_operation_delegate.cc103
-rw-r--r--webkit/browser/fileapi/copy_or_move_operation_delegate.h8
2 files changed, 98 insertions, 13 deletions
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc
index fed1abd..83a5333 100644
--- a/webkit/browser/fileapi/copy_or_move_operation_delegate.cc
+++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.cc
@@ -170,6 +170,23 @@ class SnapshotCopyOrMoveImpl
file_progress_callback_.Run(file_info.size);
+ if (option_ == FileSystemOperation::OPTION_NONE) {
+ RunAfterTouchFile(callback, base::PLATFORM_FILE_OK);
+ return;
+ }
+
+ operation_runner_->TouchFile(
+ dest_url_, base::Time::Now() /* last_access */,
+ file_info.last_modified,
+ base::Bind(&SnapshotCopyOrMoveImpl::RunAfterTouchFile,
+ weak_factory_.GetWeakPtr(), callback));
+ }
+
+ void RunAfterTouchFile(
+ const CopyOrMoveOperationDelegate::StatusCallback& callback,
+ base::PlatformFileError error) {
+ // Even if TouchFile is failed, just ignore it.
+
// |validator_| is NULL when the destination filesystem does not do
// validation.
if (!validator_) {
@@ -311,6 +328,7 @@ class StreamCopyOrMoveImpl
CopyOrMoveOperationDelegate::OperationType operation_type,
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
+ CopyOrMoveOperationDelegate::CopyOrMoveOption option,
scoped_ptr<webkit_blob::FileStreamReader> reader,
scoped_ptr<FileStreamWriter> writer,
const FileSystemOperation::CopyFileProgressCallback&
@@ -319,6 +337,7 @@ class StreamCopyOrMoveImpl
operation_type_(operation_type),
src_url_(src_url),
dest_url_(dest_url),
+ option_(option),
reader_(reader.Pass()),
writer_(writer.Pass()),
file_progress_callback_(file_progress_callback),
@@ -355,11 +374,13 @@ class StreamCopyOrMoveImpl
operation_runner_->CreateFile(
dest_url_, false /* exclusive */,
base::Bind(&StreamCopyOrMoveImpl::RunAfterCreateFileForDestination,
- weak_factory_.GetWeakPtr(), callback));
+ weak_factory_.GetWeakPtr(),
+ callback, file_info.last_modified));
}
void RunAfterCreateFileForDestination(
const CopyOrMoveOperationDelegate::StatusCallback& callback,
+ const base::Time& last_modified,
base::PlatformFileError error) {
if (error != base::PLATFORM_FILE_OK) {
callback.Run(error);
@@ -376,17 +397,33 @@ class StreamCopyOrMoveImpl
kMinProgressCallbackInvocationSpanInMilliseconds)));
copy_helper_->Run(
base::Bind(&StreamCopyOrMoveImpl::RunAfterStreamCopy,
- weak_factory_.GetWeakPtr(), callback));
+ weak_factory_.GetWeakPtr(), callback, last_modified));
}
void RunAfterStreamCopy(
const CopyOrMoveOperationDelegate::StatusCallback& callback,
+ const base::Time& last_modified,
base::PlatformFileError error) {
if (error != base::PLATFORM_FILE_OK) {
callback.Run(error);
return;
}
+ if (option_ == FileSystemOperation::OPTION_NONE) {
+ RunAfterTouchFile(callback, base::PLATFORM_FILE_OK);
+ return;
+ }
+
+ operation_runner_->TouchFile(
+ dest_url_, base::Time::Now() /* last_access */, last_modified,
+ base::Bind(&StreamCopyOrMoveImpl::RunAfterTouchFile,
+ weak_factory_.GetWeakPtr(), callback));
+ }
+
+ void RunAfterTouchFile(
+ const CopyOrMoveOperationDelegate::StatusCallback& callback,
+ base::PlatformFileError error) {
+ // Even if TouchFile is failed, just ignore it.
if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_COPY) {
callback.Run(base::PLATFORM_FILE_OK);
return;
@@ -413,6 +450,7 @@ class StreamCopyOrMoveImpl
CopyOrMoveOperationDelegate::OperationType operation_type_;
FileSystemURL src_url_;
FileSystemURL dest_url_;
+ CopyOrMoveOperationDelegate::CopyOrMoveOption option_;
scoped_ptr<webkit_blob::FileStreamReader> reader_;
scoped_ptr<FileStreamWriter> writer_;
FileSystemOperation::CopyFileProgressCallback file_progress_callback_;
@@ -602,7 +640,7 @@ void CopyOrMoveOperationDelegate::ProcessFile(
file_system_context()->CreateFileStreamWriter(dest_url, 0);
if (reader && writer) {
impl = new StreamCopyOrMoveImpl(
- operation_runner(), operation_type_, src_url, dest_url,
+ operation_runner(), operation_type_, src_url, dest_url, option_,
reader.Pass(), writer.Pass(),
base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress,
weak_factory_.GetWeakPtr(), src_url));
@@ -652,19 +690,17 @@ void CopyOrMoveOperationDelegate::ProcessDirectory(
void CopyOrMoveOperationDelegate::PostProcessDirectory(
const FileSystemURL& src_url,
const StatusCallback& callback) {
- if (operation_type_ == OPERATION_COPY) {
- callback.Run(base::PLATFORM_FILE_OK);
+ if (option_ == FileSystemOperation::OPTION_NONE) {
+ PostProcessDirectoryAfterTouchFile(
+ src_url, callback, base::PLATFORM_FILE_OK);
return;
}
- DCHECK_EQ(OPERATION_MOVE, operation_type_);
-
- // All files and subdirectories in the directory should be moved here,
- // so remove the source directory for finalizing move operation.
- operation_runner()->Remove(
- src_url, false /* recursive */,
- base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove,
- weak_factory_.GetWeakPtr(), callback));
+ operation_runner()->GetMetadata(
+ src_url,
+ base::Bind(
+ &CopyOrMoveOperationDelegate::PostProcessDirectoryAfterGetMetadata,
+ weak_factory_.GetWeakPtr(), src_url, callback));
}
void CopyOrMoveOperationDelegate::DidCopyOrMoveFile(
@@ -727,6 +763,47 @@ void CopyOrMoveOperationDelegate::DidCreateDirectory(
callback.Run(error);
}
+void CopyOrMoveOperationDelegate::PostProcessDirectoryAfterGetMetadata(
+ const FileSystemURL& src_url,
+ const StatusCallback& callback,
+ base::PlatformFileError error,
+ const base::PlatformFileInfo& file_info) {
+ if (error != base::PLATFORM_FILE_OK) {
+ // Ignore the error, and run post process which should run after TouchFile.
+ PostProcessDirectoryAfterTouchFile(
+ src_url, callback, base::PLATFORM_FILE_OK);
+ return;
+ }
+
+ operation_runner()->TouchFile(
+ CreateDestURL(src_url), base::Time::Now() /* last access */,
+ file_info.last_modified,
+ base::Bind(
+ &CopyOrMoveOperationDelegate::PostProcessDirectoryAfterTouchFile,
+ weak_factory_.GetWeakPtr(), src_url, callback));
+}
+
+void CopyOrMoveOperationDelegate::PostProcessDirectoryAfterTouchFile(
+ const FileSystemURL& src_url,
+ const StatusCallback& callback,
+ base::PlatformFileError error) {
+ // Even if the TouchFile is failed, just ignore it.
+
+ if (operation_type_ == OPERATION_COPY) {
+ callback.Run(base::PLATFORM_FILE_OK);
+ return;
+ }
+
+ DCHECK_EQ(OPERATION_MOVE, operation_type_);
+
+ // All files and subdirectories in the directory should be moved here,
+ // so remove the source directory for finalizing move operation.
+ operation_runner()->Remove(
+ src_url, false /* recursive */,
+ base::Bind(&CopyOrMoveOperationDelegate::DidRemoveSourceForMove,
+ weak_factory_.GetWeakPtr(), callback));
+}
+
void CopyOrMoveOperationDelegate::DidRemoveSourceForMove(
const StatusCallback& callback,
base::PlatformFileError error) {
diff --git a/webkit/browser/fileapi/copy_or_move_operation_delegate.h b/webkit/browser/fileapi/copy_or_move_operation_delegate.h
index 597e05e..3a0205c 100644
--- a/webkit/browser/fileapi/copy_or_move_operation_delegate.h
+++ b/webkit/browser/fileapi/copy_or_move_operation_delegate.h
@@ -112,6 +112,14 @@ class CopyOrMoveOperationDelegate
const FileSystemURL& dest_url,
const StatusCallback& callback,
base::PlatformFileError error);
+ void PostProcessDirectoryAfterGetMetadata(
+ const FileSystemURL& src_url,
+ const StatusCallback& callback,
+ base::PlatformFileError error,
+ const base::PlatformFileInfo& file_info);
+ void PostProcessDirectoryAfterTouchFile(const FileSystemURL& src_url,
+ const StatusCallback& callback,
+ base::PlatformFileError error);
void DidRemoveSourceForMove(const StatusCallback& callback,
base::PlatformFileError error);