Chromium Code Reviews| 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..75d3ec87b964c1ebc384f1cf47e17b59fade8291 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,29 @@ void RemoveOperation::RemoveAfterGetResourceEntry( |
| entry->resource_id())); |
| } |
| +void RemoveOperation::RemoveAfterReadDirectory( |
| + const std::string& resource_id, |
| + const FileOperationCallback& callback, |
| + FileError error, |
| + scoped_ptr<ResourceEntryVector> entries) { |
|
hashimoto
2013/05/28 02:34:45
nit: How about having DCHECKs for CurrentlyOn(Brow
kinaba
2013/05/28 03:31:28
Done.
|
| + 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, |