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

Unified Diff: chrome/browser/chromeos/drive/file_system/remove_operation.cc

Issue 16094003: drive: Respect is_recursive parameter in RemoveOperation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DriveFileSystemExtensionApiTest Created 7 years, 7 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: chrome/browser/chromeos/drive/file_system/remove_operation.cc
diff --git a/chrome/browser/chromeos/drive/file_system/remove_operation.cc b/chrome/browser/chromeos/drive/file_system/remove_operation.cc
index 27904df1c6122e4498781cd1c47e6993c70f9806..d27bdbba274c604d6b139ede6f27cfdb8c276ee8 100644
--- a/chrome/browser/chromeos/drive/file_system/remove_operation.cc
+++ b/chrome/browser/chromeos/drive/file_system/remove_operation.cc
@@ -32,22 +32,26 @@ RemoveOperation::~RemoveOperation() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
-void RemoveOperation::Remove(const base::FilePath& file_path,
+void RemoveOperation::Remove(const base::FilePath& path,
bool is_recursive,
const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
- // Get the edit URL of an entry at |file_path|.
+ // Get the edit URL of an entry at |path|.
metadata_->GetResourceEntryByPathOnUIThread(
- file_path,
+ path,
base::Bind(
&RemoveOperation::RemoveAfterGetResourceEntry,
weak_ptr_factory_.GetWeakPtr(),
+ path,
+ is_recursive,
callback));
}
void RemoveOperation::RemoveAfterGetResourceEntry(
+ const base::FilePath& path,
+ bool is_recursive,
const FileOperationCallback& callback,
FileError error,
scoped_ptr<ResourceEntry> entry) {
@@ -58,7 +62,17 @@ void RemoveOperation::RemoveAfterGetResourceEntry(
callback.Run(error);
return;
}
- DCHECK(entry);
+
+ if (entry->file_info().is_directory() && !is_recursive) {
+ // Check emptiness of the directory.
+ metadata_->ReadDirectoryByPathOnUIThread(
+ path,
+ base::Bind(&RemoveOperation::RemoveAfterReadDirectory,
+ weak_ptr_factory_.GetWeakPtr(),
+ entry->resource_id(),
+ callback));
+ return;
+ }
scheduler_->DeleteResource(
entry->resource_id(),
@@ -68,6 +82,32 @@ void RemoveOperation::RemoveAfterGetResourceEntry(
entry->resource_id()));
}
+void RemoveOperation::RemoveAfterReadDirectory(
+ const std::string& resource_id,
+ const FileOperationCallback& callback,
+ FileError error,
+ scoped_ptr<ResourceEntryVector> entries) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ if (error != FILE_ERROR_OK) {
+ callback.Run(error);
+ return;
+ }
+
+ if (!entries->empty()) {
+ callback.Run(FILE_ERROR_NOT_EMPTY);
+ return;
+ }
+
+ scheduler_->DeleteResource(
+ resource_id,
+ base::Bind(&RemoveOperation::RemoveResourceLocally,
+ weak_ptr_factory_.GetWeakPtr(),
+ callback,
+ resource_id));
+}
+
void RemoveOperation::RemoveResourceLocally(
const FileOperationCallback& callback,
const std::string& resource_id,

Powered by Google App Engine
This is Rietveld 408576698