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

Unified Diff: webkit/fileapi/remove_operation_delegate.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: rebase 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/remove_operation_delegate.cc
diff --git a/webkit/fileapi/remove_operation_delegate.cc b/webkit/fileapi/remove_operation_delegate.cc
index 3dafbdb04e08840513582e1525a06e8b6dd9bad3..5504025288aa015140e38b87472dbf0f3d804768 100644
--- a/webkit/fileapi/remove_operation_delegate.cc
+++ b/webkit/fileapi/remove_operation_delegate.cc
@@ -13,122 +13,81 @@ namespace fileapi {
RemoveOperationDelegate::RemoveOperationDelegate(
LocalFileSystemOperation* original_operation,
+ const FileSystemURL& url,
const StatusCallback& callback)
- : original_operation_(original_operation),
- callback_(callback),
- inflight_operations_(0) {
+ : RecursiveOperationDelegate(original_operation),
+ url_(url),
+ callback_(callback) {
}
RemoveOperationDelegate::~RemoveOperationDelegate() {}
-void RemoveOperationDelegate::Run(const FileSystemURL& url) {
- LocalFileSystemOperation* operation = NewOperation(url);
- if (!operation)
+void RemoveOperationDelegate::Run() {
+ base::PlatformFileError error;
+ LocalFileSystemOperation* operation = NewOperation(url_, &error);
+ if (!operation) {
+ callback_.Run(error);
return;
- operation->RemoveFile(url, base::Bind(
- &RemoveOperationDelegate::DidTryRemoveFile, AsWeakPtr(), url));
+ }
+ operation->RemoveFile(url_, base::Bind(
+ &RemoveOperationDelegate::DidTryRemoveFile, AsWeakPtr()));
}
-void RemoveOperationDelegate::RunRecursively(const FileSystemURL& url) {
- DCHECK(pending_directories_.empty());
- pending_directories_.push(url);
- ProcessNextDirectory(base::PLATFORM_FILE_OK);
+void RemoveOperationDelegate::RunRecursively() {
+ StartRecursiveOperation(
+ url_,
+ base::Bind(&RemoveOperationDelegate::RemoveNextDirectory, AsWeakPtr()));
}
-void RemoveOperationDelegate::DidTryRemoveFile(
- const FileSystemURL& url,
- base::PlatformFileError error) {
- if (error == base::PLATFORM_FILE_OK ||
- error != base::PLATFORM_FILE_ERROR_NOT_A_FILE) {
- callback_.Run(error);
+void RemoveOperationDelegate::ProcessFile(const FileSystemURL& url,
+ const StatusCallback& callback) {
+ base::PlatformFileError error;
+ LocalFileSystemOperation* operation = NewOperation(url, &error);
+ if (!operation) {
+ callback.Run(error);
return;
}
- LocalFileSystemOperation* operation = NewOperation(url);
- if (!operation)
- return;
- operation->RemoveDirectory(url, callback_);
+ if (to_remove_directories_.size() == 1u &&
+ to_remove_directories_.top() == url) {
+ // We seem to have been re-directed from ProcessDirectory.
+ to_remove_directories_.pop();
+ }
+ operation->RemoveFile(url, base::Bind(
+ &RemoveOperationDelegate::DidRemoveFile, AsWeakPtr(), callback));
+}
+
+void RemoveOperationDelegate::ProcessDirectory(const FileSystemURL& url,
+ const StatusCallback& callback) {
+ to_remove_directories_.push(url);
+ callback.Run(base::PLATFORM_FILE_OK);
}
-void RemoveOperationDelegate::ProcessNextDirectory(
+void RemoveOperationDelegate::DidTryRemoveFile(
base::PlatformFileError error) {
- if (error != base::PLATFORM_FILE_OK) {
+ if (error == base::PLATFORM_FILE_OK ||
+ error != base::PLATFORM_FILE_ERROR_NOT_A_FILE) {
callback_.Run(error);
return;
}
- if (inflight_operations_ > 0)
- return;
- if (pending_directories_.empty()) {
- RemoveNextDirectory(error);
- return;
- }
- FileSystemURL url = pending_directories_.front();
- pending_directories_.pop();
- LocalFileSystemOperation* operation = NewOperation(url);
- if (!operation)
- return;
- inflight_operations_++;
- operation->ReadDirectory(
- url, base::Bind(&RemoveOperationDelegate::DidReadDirectory,
- AsWeakPtr(), url));
-}
-
-void RemoveOperationDelegate::DidReadDirectory(
- const FileSystemURL& parent,
- base::PlatformFileError error,
- const FileEntryList& entries,
- bool has_more) {
- if (error != base::PLATFORM_FILE_OK) {
- if (error == base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY) {
- // The given path may have been a file, so try RemoveFile.
- inflight_operations_--;
- DCHECK_GE(inflight_operations_, 0);
- RemoveFile(parent);
- return;
- }
+ LocalFileSystemOperation* operation = NewOperation(url_, &error);
+ if (!operation) {
callback_.Run(error);
return;
}
- for (size_t i = 0; i < entries.size(); i++) {
- FileSystemURL url = parent.WithPath(parent.path().Append(entries[i].name));
- if (entries[i].is_directory) {
- pending_directories_.push(url);
- continue;
- }
- RemoveFile(url);
- }
- if (has_more)
- return;
-
- to_remove_directories_.push(parent);
- inflight_operations_--;
- DCHECK_GE(inflight_operations_, 0);
- ProcessNextDirectory(base::PLATFORM_FILE_OK);
+ operation->RemoveDirectory(url_, callback_);
}
-void RemoveOperationDelegate::RemoveFile(const FileSystemURL& url) {
- LocalFileSystemOperation* operation = NewOperation(url);
- if (!operation)
- return;
- inflight_operations_++;
- operation->RemoveFile(url, base::Bind(
- &RemoveOperationDelegate::DidRemoveFile, AsWeakPtr()));
-}
-
-void RemoveOperationDelegate::DidRemoveFile(base::PlatformFileError error) {
- inflight_operations_--;
- DCHECK_GE(inflight_operations_, 0);
- if (error != base::PLATFORM_FILE_OK &&
- error != base::PLATFORM_FILE_ERROR_NOT_FOUND) {
- callback_.Run(error);
+void RemoveOperationDelegate::DidRemoveFile(const StatusCallback& callback,
+ base::PlatformFileError error) {
+ if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND) {
+ callback.Run(base::PLATFORM_FILE_OK);
return;
}
- ProcessNextDirectory(error);
+ callback.Run(error);
}
void RemoveOperationDelegate::RemoveNextDirectory(
base::PlatformFileError error) {
- DCHECK_EQ(0, inflight_operations_);
- DCHECK(pending_directories_.empty());
if (error != base::PLATFORM_FILE_OK ||
to_remove_directories_.empty()) {
callback_.Run(error);
@@ -136,31 +95,14 @@ void RemoveOperationDelegate::RemoveNextDirectory(
}
FileSystemURL url = to_remove_directories_.top();
to_remove_directories_.pop();
- LocalFileSystemOperation* operation = NewOperation(url);
- if (!operation)
+ LocalFileSystemOperation* operation = NewOperation(url, &error);
+ if (!operation) {
+ callback_.Run(error);
return;
+ }
operation->RemoveDirectory(url, base::Bind(
&RemoveOperationDelegate::RemoveNextDirectory,
AsWeakPtr()));
}
-LocalFileSystemOperation* RemoveOperationDelegate::NewOperation(
- const FileSystemURL& url) {
- base::PlatformFileError error;
- FileSystemOperation* operation = original_operation_->file_system_context()->
- CreateFileSystemOperation(url, &error);
- if (error != base::PLATFORM_FILE_OK) {
- callback_.Run(error);
- return NULL;
- }
- LocalFileSystemOperation* local_operation =
- operation->AsLocalFileSystemOperation();
- DCHECK(local_operation);
-
- // Let the new operation inherit from the original operation.
- local_operation->set_overriding_operation_context(
- original_operation_->operation_context());
- return local_operation;
-}
-
} // namespace fileapi
« no previous file with comments | « webkit/fileapi/remove_operation_delegate.h ('k') | webkit/fileapi/syncable/syncable_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698