Commit 2ce52afb authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Remove use of FindEntryByPathSync() from RemoveEntryFromNonRootDirectory()

The number of callers of FindEntryByPathSync() is reduced from 9 to 7.

BUG=137694, 126634, 139446
TEST=Moving a file to another directory and renaming in the same directory work as before from file manager.

Review URL: https://chromiumcodereview.appspot.com/10832254

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151369 0039d316-1c4b-4281-b951-d872f2087c98
parent 4b255792
...@@ -1292,28 +1292,50 @@ void GDataFileSystem::RemoveEntryFromNonRootDirectory( ...@@ -1292,28 +1292,50 @@ void GDataFileSystem::RemoveEntryFromNonRootDirectory(
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
const FilePath dir_path = file_path.DirName(); const FilePath dir_path = file_path.DirName();
GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); // Return if there is an error or |dir_path| is the root directory.
GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); if (error != GDATA_FILE_OK || dir_path == FilePath(kGDataRootDirectory)) {
if (error == GDATA_FILE_OK) { callback.Run(error, file_path);
if (!entry || !dir) { return;
error = GDATA_FILE_ERROR_NOT_FOUND;
} else {
if (!dir->AsGDataDirectory())
error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
}
} }
// Returns if there is an error or |dir_path| is the root directory. directory_service_->GetEntryInfoPairByPaths(
if (error != GDATA_FILE_OK || file_path,
dir->resource_id() == kGDataRootDirectoryResourceId) { dir_path,
callback.Run(error, file_path); base::Bind(
&GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair,
ui_weak_ptr_,
callback));
}
void GDataFileSystem::RemoveEntryFromNonRootDirectoryAfterEntryInfoPair(
const FileMoveCallback& callback,
scoped_ptr<EntryInfoPairResult> result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
DCHECK(result.get());
const FilePath& file_path = result->first.path;
const FilePath& dir_path = result->second.path;
if (result->first.error != GDATA_FILE_OK) {
callback.Run(result->first.error, file_path);
return;
} else if (result->second.error != GDATA_FILE_OK) {
callback.Run(result->second.error, file_path);
return;
}
scoped_ptr<GDataEntryProto> entry_proto = result->first.proto.Pass();
scoped_ptr<GDataEntryProto> dir_proto = result->second.proto.Pass();
if (!dir_proto->file_info().is_directory()) {
callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY, file_path);
return; return;
} }
documents_service_->RemoveResourceFromDirectory( documents_service_->RemoveResourceFromDirectory(
dir->content_url(), GURL(dir_proto->content_url()),
entry->edit_url(), GURL(entry_proto->edit_url()),
entry->resource_id(), entry_proto->resource_id(),
base::Bind(&GDataFileSystem::MoveEntryToRootDirectoryLocally, base::Bind(&GDataFileSystem::MoveEntryToRootDirectoryLocally,
ui_weak_ptr_, ui_weak_ptr_,
callback, callback,
......
...@@ -391,6 +391,12 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -391,6 +391,12 @@ class GDataFileSystem : public GDataFileSystemInterface,
const FileOperationCallback& callback, const FileOperationCallback& callback,
scoped_ptr<EntryInfoPairResult> result); scoped_ptr<EntryInfoPairResult> result);
// Part of RemoveEntryFromNonRootDirectory(). Called after
// GetEntryInfoPairByPaths() is complete. |callback| must not be null.
void RemoveEntryFromNonRootDirectoryAfterEntryInfoPair(
const FileMoveCallback& callback,
scoped_ptr<EntryInfoPairResult> result);
// Removes a file or directory at |file_path| from the current directory if // Removes a file or directory at |file_path| from the current directory if
// it's not in the root directory. This essentially moves an entry to the // it's not in the root directory. This essentially moves an entry to the
// root directory on the server side. // root directory on the server side.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment