Commit e50c6ad8 authored by satorux@chromium.org's avatar satorux@chromium.org

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

The number of calles of FindEntryByPathSync() is reduced from 17 to 15.

BUG=10831212,126634
TEST=Copying a file (and a hosted document) on Drive works before from file manager

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150824 0039d316-1c4b-4281-b951-d872f2087c98
parent 938fe9e3
...@@ -922,6 +922,8 @@ void GDataFileSystem::Copy(const FilePath& src_file_path, ...@@ -922,6 +922,8 @@ void GDataFileSystem::Copy(const FilePath& src_file_path,
const FileOperationCallback& callback) { const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::IO)); BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(!callback.is_null());
RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread,
ui_weak_ptr_, ui_weak_ptr_,
src_file_path, src_file_path,
...@@ -933,41 +935,50 @@ void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, ...@@ -933,41 +935,50 @@ void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path,
const FilePath& dest_file_path, const FilePath& dest_file_path,
const FileOperationCallback& callback) { const FileOperationCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
GDataFileError error = GDATA_FILE_OK; directory_service_->GetEntryInfoPairByPaths(
FilePath dest_parent_path = dest_file_path.DirName(); src_file_path,
dest_file_path.DirName(),
base::Bind(&GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair,
ui_weak_ptr_,
dest_file_path,
callback));
}
std::string src_file_resource_id; void GDataFileSystem::CopyOnUIThreadAfterGetEntryInfoPair(
bool src_file_is_hosted_document = false; const FilePath& dest_file_path,
const FileOperationCallback& callback,
scoped_ptr<EntryInfoPairResult> result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
DCHECK(result.get());
GDataEntry* src_entry = directory_service_->FindEntryByPathSync( if (result->first.error != GDATA_FILE_OK) {
src_file_path); callback.Run(result->first.error);
GDataEntry* dest_parent = directory_service_->FindEntryByPathSync( return;
dest_parent_path); } else if (result->second.error != GDATA_FILE_OK) {
if (!src_entry || !dest_parent) { callback.Run(result->second.error);
error = GDATA_FILE_ERROR_NOT_FOUND; return;
} else if (!dest_parent->AsGDataDirectory()) {
error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
} else if (!src_entry->AsGDataFile()) {
// TODO(benchan): Implement copy for directories. In the interim,
// we handle recursive directory copy in the file manager.
error = GDATA_FILE_ERROR_INVALID_OPERATION;
} else {
src_file_resource_id = src_entry->resource_id();
src_file_is_hosted_document =
src_entry->AsGDataFile()->is_hosted_document();
} }
if (error != GDATA_FILE_OK) { scoped_ptr<GDataEntryProto> src_file_proto = result->first.proto.Pass();
if (!callback.is_null()) scoped_ptr<GDataEntryProto> dest_parent_proto = result->second.proto.Pass();
MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error));
if (!dest_parent_proto->file_info().is_directory()) {
callback.Run(GDATA_FILE_ERROR_NOT_A_DIRECTORY);
return;
} else if (src_file_proto->file_info().is_directory()) {
// TODO(kochi): Implement copy for directories. In the interim,
// we handle recursive directory copy in the file manager.
// crbug.com/141596
callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION);
return; return;
} }
if (src_file_is_hosted_document) { if (src_file_proto->file_specific_info().is_hosted_document()) {
CopyDocumentToDirectory(dest_parent_path, CopyDocumentToDirectory(dest_file_path.DirName(),
src_file_resource_id, src_file_proto->resource_id(),
// Drop the document extension, which should not be // Drop the document extension, which should not be
// in the document title. // in the document title.
dest_file_path.BaseName().RemoveExtension().value(), dest_file_path.BaseName().RemoveExtension().value(),
...@@ -975,8 +986,9 @@ void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, ...@@ -975,8 +986,9 @@ void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path,
return; return;
} }
// TODO(benchan): Reimplement this once the server API supports // TODO(kochi): Reimplement this once the server API supports
// copying of regular files directly on the server side. // copying of regular files directly on the server side. crbug.com/138273
const FilePath& src_file_path = result->first.path;
GetFileByPath(src_file_path, GetFileByPath(src_file_path,
base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy,
ui_weak_ptr_, ui_weak_ptr_,
...@@ -993,11 +1005,10 @@ void GDataFileSystem::OnGetFileCompleteForCopy( ...@@ -993,11 +1005,10 @@ void GDataFileSystem::OnGetFileCompleteForCopy(
const std::string& unused_mime_type, const std::string& unused_mime_type,
GDataFileType file_type) { GDataFileType file_type) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
if (error != GDATA_FILE_OK) { if (error != GDATA_FILE_OK) {
if (!callback.is_null()) callback.Run(error);
callback.Run(error);
return; return;
} }
......
...@@ -740,6 +740,13 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -740,6 +740,13 @@ class GDataFileSystem : public GDataFileSystemInterface,
GDataCache::FileOperationType cache_operation, GDataCache::FileOperationType cache_operation,
const base::Closure& callback); const base::Closure& callback);
// Part of CopyOnUIThread(). Called after GetEntryInfoPairByPaths() is
// complete.
void CopyOnUIThreadAfterGetEntryInfoPair(
const FilePath& dest_file_path,
const FileOperationCallback& callback,
scoped_ptr<EntryInfoPairResult> result);
// Part of RemoveOnUIThread(). Called after GetEntryInfoByPath() is // Part of RemoveOnUIThread(). Called after GetEntryInfoByPath() is
// complete. // complete.
void RemoveOnUIThreadAfterGetEntryInfo( void RemoveOnUIThreadAfterGetEntryInfo(
......
...@@ -199,6 +199,7 @@ class GDataFileSystemInterface { ...@@ -199,6 +199,7 @@ class GDataFileSystemInterface {
// of the file system. // of the file system.
// //
// Can be called from UI/IO thread. |callback| is run on the calling thread. // Can be called from UI/IO thread. |callback| is run on the calling thread.
// |callback| must not be null.
virtual void Copy(const FilePath& src_file_path, virtual void Copy(const FilePath& src_file_path,
const FilePath& dest_file_path, const FilePath& dest_file_path,
const FileOperationCallback& callback) = 0; const FileOperationCallback& callback) = 0;
......
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