| 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 8c6296a7979445dbacafb541ea365a0d0a02cf88..7327efa1685265d4ddc35b9381d772000b1f2f47 100644
|
| --- a/chrome/browser/chromeos/drive/file_system/remove_operation.cc
|
| +++ b/chrome/browser/chromeos/drive/file_system/remove_operation.cc
|
| @@ -9,7 +9,7 @@
|
| #include "chrome/browser/chromeos/drive/file_cache.h"
|
| #include "chrome/browser/chromeos/drive/file_system/operation_observer.h"
|
| #include "chrome/browser/chromeos/drive/file_system_util.h"
|
| -#include "chrome/browser/chromeos/drive/job_scheduler.h"
|
| +#include "chrome/browser/chromeos/drive/resource_metadata.h"
|
| #include "content/public/browser/browser_thread.h"
|
|
|
| using content::BrowserThread;
|
| @@ -19,25 +19,23 @@ namespace file_system {
|
|
|
| namespace {
|
|
|
| -// Checks local metadata state before requesting remote delete.
|
| -// |parent_resource_id| is set to the resource ID of the parent directory of
|
| -// |path|. If it is a special folder like drive/other, empty string is set.
|
| -// |entry| is the resource entry for the |path|.
|
| -FileError CheckLocalState(internal::ResourceMetadata* metadata,
|
| - const base::FilePath& path,
|
| - bool is_recursive,
|
| - std::string* parent_resource_id,
|
| - ResourceEntry* entry) {
|
| - std::string local_id;
|
| - FileError error = metadata->GetIdByPath(path, &local_id);
|
| +// Removes cache file and moves the metadata entry to the trash.
|
| +FileError UpdateLocalState(internal::ResourceMetadata* metadata,
|
| + internal::FileCache* cache,
|
| + const base::FilePath& path,
|
| + bool is_recursive,
|
| + std::string* local_id,
|
| + base::FilePath* changed_directory_path) {
|
| + FileError error = metadata->GetIdByPath(path, local_id);
|
| if (error != FILE_ERROR_OK)
|
| return error;
|
|
|
| - error = metadata->GetResourceEntryById(local_id, entry);
|
| + ResourceEntry entry;
|
| + error = metadata->GetResourceEntryById(*local_id, &entry);
|
| if (error != FILE_ERROR_OK)
|
| return error;
|
|
|
| - if (entry->file_info().is_directory() && !is_recursive) {
|
| + if (entry.file_info().is_directory() && !is_recursive) {
|
| // Check emptiness of the directory.
|
| ResourceEntryVector entries;
|
| error = metadata->ReadDirectoryByPath(path, &entries);
|
| @@ -47,51 +45,15 @@ FileError CheckLocalState(internal::ResourceMetadata* metadata,
|
| return FILE_ERROR_NOT_EMPTY;
|
| }
|
|
|
| - // Get the resource_id of the parent folder. If it is a special folder that
|
| - // does not have the server side ID, returns an empty string (not an error).
|
| - if (util::IsSpecialResourceId(entry->parent_local_id())) {
|
| - *parent_resource_id = "";
|
| - } else {
|
| - ResourceEntry parent_entry;
|
| - error = metadata->GetResourceEntryById(entry->parent_local_id(),
|
| - &parent_entry);
|
| - if (error != FILE_ERROR_OK)
|
| - return error;
|
| - *parent_resource_id = parent_entry.resource_id();
|
| - }
|
| -
|
| - return FILE_ERROR_OK;
|
| -}
|
| + *changed_directory_path = metadata->GetFilePath(*local_id).DirName();
|
|
|
| -// Updates local metadata and cache state after remote delete.
|
| -FileError UpdateLocalStateAfterDelete(internal::ResourceMetadata* metadata,
|
| - internal::FileCache* cache,
|
| - const std::string& local_id,
|
| - base::FilePath* changed_directory_path) {
|
| - *changed_directory_path = metadata->GetFilePath(local_id).DirName();
|
| - FileError error = metadata->RemoveEntry(local_id);
|
| + // Move to the trash.
|
| + entry.set_parent_local_id(util::kDriveTrashDirLocalId);
|
| + error = metadata->RefreshEntry(entry);
|
| if (error != FILE_ERROR_OK)
|
| return error;
|
|
|
| - error = cache->Remove(local_id);
|
| - DLOG_IF(ERROR, error != FILE_ERROR_OK) << "Failed to remove: " << local_id;
|
| -
|
| - return FILE_ERROR_OK;
|
| -}
|
| -
|
| -// Updates local metadata and after remote unparenting.
|
| -FileError UpdateLocalStateAfterUnparent(
|
| - internal::ResourceMetadata* metadata,
|
| - const std::string& local_id,
|
| - base::FilePath* changed_directory_path) {
|
| - *changed_directory_path = metadata->GetFilePath(local_id).DirName();
|
| -
|
| - ResourceEntry entry;
|
| - FileError error = metadata->GetResourceEntryById(local_id, &entry);
|
| - if (error != FILE_ERROR_OK)
|
| - return error;
|
| - entry.set_parent_local_id(util::kDriveOtherDirLocalId);
|
| - return metadata->RefreshEntry(entry);
|
| + return cache->Remove(*local_id);
|
| }
|
|
|
| } // namespace
|
| @@ -99,12 +61,10 @@ FileError UpdateLocalStateAfterUnparent(
|
| RemoveOperation::RemoveOperation(
|
| base::SequencedTaskRunner* blocking_task_runner,
|
| OperationObserver* observer,
|
| - JobScheduler* scheduler,
|
| internal::ResourceMetadata* metadata,
|
| internal::FileCache* cache)
|
| : blocking_task_runner_(blocking_task_runner),
|
| observer_(observer),
|
| - scheduler_(scheduler),
|
| metadata_(metadata),
|
| cache_(cache),
|
| weak_ptr_factory_(this) {
|
| @@ -121,103 +81,37 @@ void RemoveOperation::Remove(const base::FilePath& path,
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| DCHECK(!callback.is_null());
|
|
|
| - std::string* parent_resource_id = new std::string;
|
| - ResourceEntry* entry = new ResourceEntry;
|
| + std::string* local_id = new std::string;
|
| + base::FilePath* changed_directory_path = new base::FilePath;
|
| base::PostTaskAndReplyWithResult(
|
| blocking_task_runner_.get(),
|
| FROM_HERE,
|
| - base::Bind(&CheckLocalState,
|
| + base::Bind(&UpdateLocalState,
|
| metadata_,
|
| + cache_,
|
| path,
|
| is_recursive,
|
| - parent_resource_id,
|
| - entry),
|
| - base::Bind(&RemoveOperation::RemoveAfterCheckLocalState,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - callback,
|
| - base::Owned(parent_resource_id),
|
| - base::Owned(entry)));
|
| -}
|
| -
|
| -void RemoveOperation::RemoveAfterCheckLocalState(
|
| - const FileOperationCallback& callback,
|
| - const std::string* parent_resource_id,
|
| - const ResourceEntry* entry,
|
| - FileError error) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(!callback.is_null());
|
| -
|
| - if (error != FILE_ERROR_OK) {
|
| - callback.Run(error);
|
| - return;
|
| - }
|
| -
|
| - // To match with the behavior of drive.google.com:
|
| - // Removal of shared entries under MyDrive is just removing from the parent.
|
| - // The entry will stay in shared-with-me (in other words, in "drive/other".)
|
| - //
|
| - // TODO(kinaba): to be more precise, we might be better to branch by whether
|
| - // or not the current account is an owner of the file. The code below is
|
| - // written under the assumption that |shared_with_me| coincides with that.
|
| - if (entry->shared_with_me() && !parent_resource_id->empty()) {
|
| - scheduler_->RemoveResourceFromDirectory(
|
| - *parent_resource_id,
|
| - entry->resource_id(),
|
| - ClientContext(USER_INITIATED),
|
| - base::Bind(&RemoveOperation::RemoveAfterUpdateRemoteState,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - callback,
|
| - base::Bind(&UpdateLocalStateAfterUnparent,
|
| - metadata_,
|
| - entry->local_id())));
|
| - } else {
|
| - // Otherwise try sending the entry to trash.
|
| - scheduler_->DeleteResource(
|
| - entry->resource_id(),
|
| - ClientContext(USER_INITIATED),
|
| - base::Bind(&RemoveOperation::RemoveAfterUpdateRemoteState,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - callback,
|
| - base::Bind(&UpdateLocalStateAfterDelete,
|
| - metadata_,
|
| - cache_,
|
| - entry->local_id())));
|
| - }
|
| -}
|
| -
|
| -void RemoveOperation::RemoveAfterUpdateRemoteState(
|
| - const FileOperationCallback& callback,
|
| - const base::Callback<FileError(base::FilePath*)>& local_update_task,
|
| - google_apis::GDataErrorCode status) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| - DCHECK(!callback.is_null());
|
| -
|
| - FileError error = GDataToFileError(status);
|
| - if (error != FILE_ERROR_OK) {
|
| - callback.Run(error);
|
| - return;
|
| - }
|
| -
|
| - base::FilePath* changed_directory_path = new base::FilePath;
|
| - base::PostTaskAndReplyWithResult(
|
| - blocking_task_runner_.get(),
|
| - FROM_HERE,
|
| - base::Bind(local_update_task, changed_directory_path),
|
| + local_id,
|
| + changed_directory_path),
|
| base::Bind(&RemoveOperation::RemoveAfterUpdateLocalState,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| + base::Owned(local_id),
|
| base::Owned(changed_directory_path)));
|
| }
|
|
|
| void RemoveOperation::RemoveAfterUpdateLocalState(
|
| const FileOperationCallback& callback,
|
| + const std::string* local_id,
|
| const base::FilePath* changed_directory_path,
|
| FileError error) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| DCHECK(!callback.is_null());
|
|
|
| - if (error == FILE_ERROR_OK)
|
| + if (error == FILE_ERROR_OK) {
|
| observer_->OnDirectoryChangedByOperation(*changed_directory_path);
|
| + observer_->OnEntryRemovedByOperation(*local_id);
|
| + }
|
|
|
| callback.Run(error);
|
| }
|
|
|