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

Unified Diff: webkit/fileapi/local_file_system_operation.cc

Issue 12036022: Split recursive Copy/Move into async tasks and support cross operation (in local case) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed eric's comment on 12051010 Created 7 years, 11 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/fileapi/local_file_system_operation.cc
diff --git a/webkit/fileapi/local_file_system_operation.cc b/webkit/fileapi/local_file_system_operation.cc
index 80524a0d6e3fc788071bd4986fbcd582b6250655..4517dba454e53ba30239f625d7599bc606f89bab 100644
--- a/webkit/fileapi/local_file_system_operation.cc
+++ b/webkit/fileapi/local_file_system_operation.cc
@@ -11,6 +11,7 @@
#include "net/base/escape.h"
#include "net/url_request/url_request_context.h"
#include "webkit/blob/shareable_file_reference.h"
+#include "webkit/fileapi/cross_operation_delegate.h"
#include "webkit/fileapi/file_observers.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_file_util_proxy.h"
@@ -36,13 +37,6 @@ bool IsMediaFileSystemType(FileSystemType type) {
type == kFileSystemTypeDeviceMedia;
}
-bool IsCrossOperationAllowed(FileSystemType src_type,
- FileSystemType dest_type) {
- // If two types are supposed to run on different task runners we should not
- // allow cross FileUtil operations at this layer.
- return IsMediaFileSystemType(src_type) == IsMediaFileSystemType(dest_type);
-}
-
} // namespace
// LocalFileSystemOperation::ScopedUpdateNotifier -----------------------------
@@ -84,7 +78,7 @@ void LocalFileSystemOperation::CreateFile(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateFile));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -104,7 +98,7 @@ void LocalFileSystemOperation::CreateDirectory(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateDirectory));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -121,70 +115,49 @@ void LocalFileSystemOperation::Copy(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCopy));
- is_cross_operation_ = (src_url.type() != dest_url.type());
- base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_READ);
- if (result == base::PLATFORM_FILE_OK)
- result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE);
- if (result == base::PLATFORM_FILE_OK) {
- if (!IsCrossOperationAllowed(src_url.type(), dest_url.type()))
- result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- }
+ base::PlatformFileError result = SetUp(
+ dest_url, &file_util_, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
return;
}
- GetUsageAndQuotaThenRunTask(
- dest_url,
- base::Bind(&LocalFileSystemOperation::DoCopy,
- base::Unretained(this), src_url, dest_url, callback),
- base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
+ DCHECK(!recursive_operation_delegate_);
+ recursive_operation_delegate_.reset(
+ new CrossOperationDelegate(this, src_url, dest_url,
+ CrossOperationDelegate::OPERATION_COPY,
+ callback));
+ recursive_operation_delegate_->RunRecursively();
}
void LocalFileSystemOperation::Move(const FileSystemURL& src_url,
const FileSystemURL& dest_url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationMove));
- is_cross_operation_ = (src_url.type() != dest_url.type());
- scoped_ptr<LocalFileSystemOperation> deleter(this);
-
- // Temporarily disables cross-filesystem move.
- // TODO(kinuko,tzik,kinaba): This special handling must be removed once
- // we support saner cross-filesystem operation.
- // (See http://crbug.com/130055)
- if (is_cross_operation_) {
- callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION);
- return;
- }
-
- base::PlatformFileError result = SetUp(src_url, &src_util_, SETUP_FOR_WRITE);
- if (result == base::PLATFORM_FILE_OK)
- result = SetUp(dest_url, &dest_util_, SETUP_FOR_CREATE);
- if (result == base::PLATFORM_FILE_OK) {
- if (!IsCrossOperationAllowed(src_url.type(), dest_url.type()))
- result = base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
- }
+ base::PlatformFileError result = SetUp(
+ src_url, &file_util_, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
+ delete this;
return;
}
- GetUsageAndQuotaThenRunTask(
- dest_url,
- base::Bind(&LocalFileSystemOperation::DoMove,
- base::Unretained(deleter.release()),
- src_url, dest_url, callback),
- base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
+ DCHECK(!recursive_operation_delegate_);
+ recursive_operation_delegate_.reset(
+ new CrossOperationDelegate(this, src_url, dest_url,
+ CrossOperationDelegate::OPERATION_MOVE,
+ callback));
+ recursive_operation_delegate_->RunRecursively();
}
void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationDirectoryExists));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -192,7 +165,7 @@ void LocalFileSystemOperation::DirectoryExists(const FileSystemURL& url,
}
FileSystemFileUtilProxy::GetFileInfo(
- operation_context(), src_util_, url,
+ operation_context(), file_util_, url,
base::Bind(&LocalFileSystemOperation::DidDirectoryExists,
base::Owned(this), callback));
}
@@ -201,7 +174,7 @@ void LocalFileSystemOperation::FileExists(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationFileExists));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -209,7 +182,7 @@ void LocalFileSystemOperation::FileExists(const FileSystemURL& url,
}
FileSystemFileUtilProxy::GetFileInfo(
- operation_context(), src_util_, url,
+ operation_context(), file_util_, url,
base::Bind(&LocalFileSystemOperation::DidFileExists,
base::Owned(this), callback));
}
@@ -218,7 +191,7 @@ void LocalFileSystemOperation::GetMetadata(
const FileSystemURL& url, const GetMetadataCallback& callback) {
DCHECK(SetPendingOperationType(kOperationGetMetadata));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFileInfo(), FilePath());
delete this;
@@ -226,7 +199,7 @@ void LocalFileSystemOperation::GetMetadata(
}
FileSystemFileUtilProxy::GetFileInfo(
- operation_context(), src_util_, url,
+ operation_context(), file_util_, url,
base::Bind(&LocalFileSystemOperation::DidGetMetadata,
base::Owned(this), callback));
}
@@ -235,7 +208,7 @@ void LocalFileSystemOperation::ReadDirectory(
const FileSystemURL& url, const ReadDirectoryCallback& callback) {
DCHECK(SetPendingOperationType(kOperationReadDirectory));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, std::vector<base::FileUtilProxy::Entry>(), false);
delete this;
@@ -243,7 +216,7 @@ void LocalFileSystemOperation::ReadDirectory(
}
FileSystemFileUtilProxy::ReadDirectory(
- operation_context(), src_util_, url,
+ operation_context(), file_util_, url,
base::Bind(&LocalFileSystemOperation::DidReadDirectory,
base::Owned(this), callback));
}
@@ -252,12 +225,13 @@ void LocalFileSystemOperation::Remove(const FileSystemURL& url,
bool recursive,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- DCHECK(!remove_operation_delegate_);
- remove_operation_delegate_.reset(new RemoveOperationDelegate(this, callback));
+ DCHECK(!recursive_operation_delegate_);
+ recursive_operation_delegate_.reset(
+ new RemoveOperationDelegate(this, url, callback));
if (recursive)
- remove_operation_delegate_->RunRecursively(url);
+ recursive_operation_delegate_->RunRecursively();
else
- remove_operation_delegate_->Run(url);
+ recursive_operation_delegate_->Run();
}
void LocalFileSystemOperation::Write(
@@ -273,7 +247,7 @@ void LocalFileSystemOperation::Truncate(const FileSystemURL& url, int64 length,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationTruncate));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -292,7 +266,7 @@ void LocalFileSystemOperation::TouchFile(const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationTouchFile));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -300,7 +274,7 @@ void LocalFileSystemOperation::TouchFile(const FileSystemURL& url,
}
FileSystemFileUtilProxy::Touch(
- operation_context(), src_util_, url,
+ operation_context(), file_util_, url,
last_access_time, last_modified_time,
base::Bind(&LocalFileSystemOperation::DidTouchFile,
base::Owned(this), callback));
@@ -328,13 +302,13 @@ void LocalFileSystemOperation::OpenFile(const FileSystemURL& url,
base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_WRITE |
base::PLATFORM_FILE_DELETE_ON_CLOSE |
base::PLATFORM_FILE_WRITE_ATTRIBUTES)) {
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_CREATE);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFile(), base::ProcessHandle());
return;
}
} else {
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFile(), base::ProcessHandle());
return;
@@ -398,13 +372,13 @@ void LocalFileSystemOperation::SyncGetPlatformPath(const FileSystemURL& url,
FilePath* platform_path) {
DCHECK(SetPendingOperationType(kOperationGetLocalPath));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
delete this;
return;
}
- src_util_->GetLocalFilePath(operation_context(), url, platform_path);
+ file_util_->GetLocalFilePath(operation_context(), url, platform_path);
delete this;
}
@@ -414,7 +388,7 @@ void LocalFileSystemOperation::CreateSnapshotFile(
const SnapshotFileCallback& callback) {
DCHECK(SetPendingOperationType(kOperationCreateSnapshotFile));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_READ);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_READ);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result, base::PlatformFileInfo(), FilePath(), NULL);
delete this;
@@ -422,7 +396,7 @@ void LocalFileSystemOperation::CreateSnapshotFile(
}
FileSystemFileUtilProxy::CreateSnapshotFile(
- operation_context(), src_util_, url,
+ operation_context(), file_util_, url,
base::Bind(&LocalFileSystemOperation::DidCreateSnapshotFile,
base::Owned(this), callback));
}
@@ -434,7 +408,7 @@ void LocalFileSystemOperation::CopyInForeignFile(
DCHECK(SetPendingOperationType(kOperationCopyInForeignFile));
base::PlatformFileError result = SetUp(
- dest_url, &dest_util_, SETUP_FOR_CREATE);
+ dest_url, &file_util_, SETUP_FOR_CREATE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -453,7 +427,7 @@ void LocalFileSystemOperation::RemoveFile(
const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -461,7 +435,7 @@ void LocalFileSystemOperation::RemoveFile(
}
FileSystemFileUtilProxy::DeleteFile(
- operation_context(), src_util_, url,
+ operation_context(), file_util_, url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -470,7 +444,7 @@ void LocalFileSystemOperation::RemoveDirectory(
const FileSystemURL& url,
const StatusCallback& callback) {
DCHECK(SetPendingOperationType(kOperationRemove));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
callback.Run(result);
delete this;
@@ -478,20 +452,77 @@ void LocalFileSystemOperation::RemoveDirectory(
}
FileSystemFileUtilProxy::DeleteDirectory(
- operation_context(), src_util_, url,
+ operation_context(), file_util_, url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
+void LocalFileSystemOperation::CopyFileLocal(
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) {
+ DCHECK(SetPendingOperationType(kOperationCopy));
+ DCHECK_EQ(src_url.origin(), dest_url.origin());
+ DCHECK_EQ(src_url.type(), dest_url.type());
+
+ base::PlatformFileError result = SetUp(src_url, &file_util_, SETUP_FOR_READ);
+ if (result == base::PLATFORM_FILE_OK)
+ result = SetUp(dest_url, &file_util_, SETUP_FOR_CREATE);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
+ delete this;
+ return;
+ }
+
+ // Record read access for src_url.
+ operation_context()->access_observers()->Notify(
+ &FileAccessObserver::OnAccess, MakeTuple(src_url));
+ // Record update access for dest_url.
+ scoped_update_notifiers_.push_back(new ScopedUpdateNotifier(
+ operation_context(), dest_url));
+
+ GetUsageAndQuotaThenRunTask(
+ dest_url,
+ base::Bind(&LocalFileSystemOperation::DoCopyFileLocal,
+ base::Unretained(this), src_url, dest_url, callback),
+ base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
+}
+
+void LocalFileSystemOperation::MoveFileLocal(
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) {
+ DCHECK(SetPendingOperationType(kOperationMove));
+ DCHECK_EQ(src_url.origin(), dest_url.origin());
+ DCHECK_EQ(src_url.type(), dest_url.type());
+
+ base::PlatformFileError result = SetUp(src_url, &file_util_, SETUP_FOR_WRITE);
+ if (result == base::PLATFORM_FILE_OK)
+ result = SetUp(dest_url, &file_util_, SETUP_FOR_CREATE);
+ if (result != base::PLATFORM_FILE_OK) {
+ callback.Run(result);
+ delete this;
+ return;
+ }
+
+ // Record update access for dest_url.
+ scoped_update_notifiers_.push_back(new ScopedUpdateNotifier(
+ operation_context(), dest_url));
+
+ GetUsageAndQuotaThenRunTask(
+ dest_url,
+ base::Bind(&LocalFileSystemOperation::DoMoveFileLocal,
+ base::Unretained(this), src_url, dest_url, callback),
+ base::Bind(callback, base::PLATFORM_FILE_ERROR_FAILED));
+}
+
LocalFileSystemOperation::LocalFileSystemOperation(
FileSystemContext* file_system_context,
scoped_ptr<FileSystemOperationContext> operation_context)
: file_system_context_(file_system_context),
operation_context_(operation_context.Pass()),
- src_util_(NULL),
- dest_util_(NULL),
+ file_util_(NULL),
overriding_operation_context_(NULL),
- is_cross_operation_(false),
peer_handle_(base::kNullProcessHandle),
pending_operation_(kOperationNone),
weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
@@ -545,7 +576,7 @@ base::Closure LocalFileSystemOperation::GetWriteClosure(
const WriteCallback& callback) {
DCHECK(SetPendingOperationType(kOperationWrite));
- base::PlatformFileError result = SetUp(url, &src_util_, SETUP_FOR_WRITE);
+ base::PlatformFileError result = SetUp(url, &file_util_, SETUP_FOR_WRITE);
if (result != base::PLATFORM_FILE_OK) {
return base::Bind(&LocalFileSystemOperation::DidFailWrite,
base::Owned(this), callback, result);
@@ -591,7 +622,7 @@ void LocalFileSystemOperation::DoCreateFile(
bool exclusive) {
FileSystemFileUtilProxy::EnsureFileExists(
operation_context(),
- src_util_, url,
+ file_util_, url,
base::Bind(
exclusive ?
&LocalFileSystemOperation::DidEnsureFileExistsExclusive :
@@ -605,41 +636,40 @@ void LocalFileSystemOperation::DoCreateDirectory(
bool exclusive, bool recursive) {
FileSystemFileUtilProxy::CreateDirectory(
operation_context(),
- src_util_, url, exclusive, recursive,
+ file_util_, url, exclusive, recursive,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
-void LocalFileSystemOperation::DoCopy(const FileSystemURL& src_url,
- const FileSystemURL& dest_url,
- const StatusCallback& callback) {
- FileSystemFileUtilProxy::Copy(
+void LocalFileSystemOperation::DoCopyFileLocal(
+ const FileSystemURL& src_url,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) {
+ FileSystemFileUtilProxy::CopyFileLocal(
operation_context(),
- src_util_, dest_util_,
- src_url, dest_url,
+ file_util_, src_url, dest_url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
-void LocalFileSystemOperation::DoCopyInForeignFile(
- const FilePath& src_local_disk_file_path,
+void LocalFileSystemOperation::DoMoveFileLocal(
+ const FileSystemURL& src_url,
const FileSystemURL& dest_url,
const StatusCallback& callback) {
- FileSystemFileUtilProxy::CopyInForeignFile(
+ FileSystemFileUtilProxy::MoveFileLocal(
operation_context(),
- dest_util_,
- src_local_disk_file_path, dest_url,
+ file_util_, src_url, dest_url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
-void LocalFileSystemOperation::DoMove(const FileSystemURL& src_url,
- const FileSystemURL& dest_url,
- const StatusCallback& callback) {
- FileSystemFileUtilProxy::Move(
+void LocalFileSystemOperation::DoCopyInForeignFile(
+ const FilePath& src_local_disk_file_path,
+ const FileSystemURL& dest_url,
+ const StatusCallback& callback) {
+ FileSystemFileUtilProxy::CopyInForeignFile(
operation_context(),
- src_util_, dest_util_,
- src_url, dest_url,
+ file_util_, src_local_disk_file_path, dest_url,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -648,7 +678,7 @@ void LocalFileSystemOperation::DoTruncate(const FileSystemURL& url,
const StatusCallback& callback,
int64 length) {
FileSystemFileUtilProxy::Truncate(
- operation_context(), src_util_, url, length,
+ operation_context(), file_util_, url, length,
base::Bind(&LocalFileSystemOperation::DidFinishFileOperation,
base::Owned(this), callback));
}
@@ -657,7 +687,7 @@ void LocalFileSystemOperation::DoOpenFile(const FileSystemURL& url,
const OpenFileCallback& callback,
int file_flags) {
FileSystemFileUtilProxy::CreateOrOpen(
- operation_context(), src_util_, url, file_flags,
+ operation_context(), file_util_, url, file_flags,
base::Bind(&LocalFileSystemOperation::DidOpenFile,
base::Owned(this), callback));
}
@@ -812,14 +842,8 @@ base::PlatformFileError LocalFileSystemOperation::SetUp(
return base::PLATFORM_FILE_ERROR_SECURITY;
if (mode == SETUP_FOR_READ) {
- // TODO(kinuko): This doesn't work well for cross-filesystem operation
- // in the current architecture since the operation context (thus the
- // observers) is configured for the destination URL while this method
- // could be called for both src and dest URL.
- if (!is_cross_operation_) {
- operation_context()->access_observers()->Notify(
- &FileAccessObserver::OnAccess, MakeTuple(url));
- }
+ operation_context()->access_observers()->Notify(
+ &FileAccessObserver::OnAccess, MakeTuple(url));
return base::PLATFORM_FILE_OK;
}

Powered by Google App Engine
This is Rietveld 408576698