Commit 9a5a4cd0 authored by satorux@chromium.org's avatar satorux@chromium.org

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

The number of calles of FindEntryByPathSync() is reduced from 13 to 11.

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151040 0039d316-1c4b-4281-b951-d872f2087c98
parent 2ed2ea2a
......@@ -1235,27 +1235,49 @@ void GDataFileSystem::MoveEntryFromRootDirectory(
DCHECK(!callback.is_null());
DCHECK_EQ(kGDataRootDirectory, file_path.DirName().value());
GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path);
GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path);
if (error == GDATA_FILE_OK) {
if (!entry || !dir_entry) {
error = GDATA_FILE_ERROR_NOT_FOUND;
} else {
if (!dir_entry->AsGDataDirectory())
error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
}
// Return if there is an error or |dir_path| is the root directory.
if (error != GDATA_FILE_OK || dir_path == FilePath(kGDataRootDirectory)) {
callback.Run(error);
return;
}
// Returns if there is an error or |dir_path| is the root directory.
if (error != GDATA_FILE_OK ||
dir_entry->resource_id() == kGDataRootDirectoryResourceId) {
callback.Run(error);
directory_service_->GetEntryInfoPairByPaths(
file_path,
dir_path,
base::Bind(
&GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair,
ui_weak_ptr_,
callback));
}
void GDataFileSystem::MoveEntryFromRootDirectoryAfterGetEntryInfoPair(
const FileOperationCallback& callback,
scoped_ptr<EntryInfoPairResult> result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
DCHECK(result.get());
if (result->first.error != GDATA_FILE_OK) {
callback.Run(result->first.error);
return;
} else if (result->second.error != GDATA_FILE_OK) {
callback.Run(result->second.error);
return;
}
scoped_ptr<GDataEntryProto> src_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);
return;
}
const FilePath& file_path = result->first.path;
const FilePath& dir_path = result->second.path;
documents_service_->AddResourceToDirectory(
dir_entry->content_url(),
entry->edit_url(),
GURL(dir_proto->content_url()),
GURL(src_proto->edit_url()),
base::Bind(&GDataFileSystem::OnMoveEntryFromRootDirectoryCompleted,
ui_weak_ptr_,
callback,
......
......@@ -384,6 +384,12 @@ class GDataFileSystem : public GDataFileSystemInterface,
GDataFileError error,
const FilePath& file_path);
// Part of MoveEntryFromRootDirectory(). Called after
// GetEntryInfoPairByPaths() is complete. |callback| must not be null.
void MoveEntryFromRootDirectoryAfterGetEntryInfoPair(
const FileOperationCallback& callback,
scoped_ptr<EntryInfoPairResult> result);
// Removes a file or directory at |file_path| from the directory at
// |dir_path| and moves it to the root directory.
//
......
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