Commit 744ec5b2 authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Remove use of GetGDataEntryByPath() from StartFileUploadOnUIThread

The number of calles of GetGDataEntryByPath() is reduced from 19 to 18.
StartFileUploadParams is introduced to overcome the limitation of Bind.

BUG=137694
TEST=out/Release/unit_tests --gtest_filter=GData*; confirm uploading to drive works as before by "save image as" to Drive.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147964 0039d316-1c4b-4281-b951-d872f2087c98
parent b17f430b
...@@ -753,6 +753,19 @@ struct GDataFileSystem::FeedToFileResourceMapUmaStats { ...@@ -753,6 +753,19 @@ struct GDataFileSystem::FeedToFileResourceMapUmaStats {
EntryKindToCountMap num_files_with_entry_kind; EntryKindToCountMap num_files_with_entry_kind;
}; };
// GDataFileSystem::StartFileUploadParams implementation.
struct GDataFileSystem::StartFileUploadParams {
StartFileUploadParams(const FilePath& in_local_file_path,
const FilePath& in_remote_file_path,
const FileOperationCallback& in_callback)
: local_file_path(in_local_file_path),
remote_file_path(in_remote_file_path),
callback(in_callback) {}
const FilePath local_file_path;
const FilePath remote_file_path;
const FileOperationCallback callback;
};
// GDataFileSystem class implementation. // GDataFileSystem class implementation.
...@@ -1229,18 +1242,16 @@ void GDataFileSystem::TransferRegularFile( ...@@ -1229,18 +1242,16 @@ void GDataFileSystem::TransferRegularFile(
content_type), content_type),
base::Bind(&GDataFileSystem::StartFileUploadOnUIThread, base::Bind(&GDataFileSystem::StartFileUploadOnUIThread,
ui_weak_ptr_, ui_weak_ptr_,
local_file_path, StartFileUploadParams(local_file_path,
remote_dest_file_path, remote_dest_file_path,
callback, callback),
base::Owned(error), base::Owned(error),
base::Owned(file_size), base::Owned(file_size),
base::Owned(content_type))); base::Owned(content_type)));
} }
void GDataFileSystem::StartFileUploadOnUIThread( void GDataFileSystem::StartFileUploadOnUIThread(
const FilePath& local_file, const StartFileUploadParams& params,
const FilePath& remote_dest_file,
const FileOperationCallback& callback,
GDataFileError* error, GDataFileError* error,
int64* file_size, int64* file_size,
std::string* content_type) { std::string* content_type) {
...@@ -1252,38 +1263,57 @@ void GDataFileSystem::StartFileUploadOnUIThread( ...@@ -1252,38 +1263,57 @@ void GDataFileSystem::StartFileUploadOnUIThread(
DCHECK(content_type); DCHECK(content_type);
if (*error != GDATA_FILE_OK) { if (*error != GDATA_FILE_OK) {
if (!callback.is_null()) if (!params.callback.is_null())
callback.Run(*error); params.callback.Run(*error);
return; return;
} }
// Make sure the destination directory exists. // Make sure the destination directory exists.
GDataEntry* dest_dir = GetGDataEntryByPath(remote_dest_file.DirName()); GetEntryInfoByPath(
if (!dest_dir || !dest_dir->AsGDataDirectory()) { params.remote_file_path.DirName(),
if (!callback.is_null()) base::Bind(
callback.Run(GDATA_FILE_ERROR_NOT_FOUND); &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo,
NOTREACHED(); ui_weak_ptr_,
params,
*file_size,
*content_type));
}
void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo(
const StartFileUploadParams& params,
int64 file_size,
std::string content_type,
GDataFileError error,
scoped_ptr<GDataEntryProto> entry_proto) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (entry_proto.get() && !entry_proto->file_info().is_directory())
error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
if (error != GDATA_FILE_OK) {
if (!params.callback.is_null())
params.callback.Run(error);
return; return;
} }
DCHECK(entry_proto.get());
// Fill in values of UploadFileInfo. // Fill in values of UploadFileInfo.
scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo);
upload_file_info->file_path = local_file; upload_file_info->file_path = params.local_file_path;
upload_file_info->file_size = *file_size; upload_file_info->file_size = file_size;
upload_file_info->gdata_path = remote_dest_file; upload_file_info->gdata_path = params.remote_file_path;
// Use the file name as the title. // Use the file name as the title.
upload_file_info->title = remote_dest_file.BaseName().value(); upload_file_info->title = params.remote_file_path.BaseName().value();
upload_file_info->content_length = *file_size; upload_file_info->content_length = file_size;
upload_file_info->all_bytes_present = true; upload_file_info->all_bytes_present = true;
upload_file_info->content_type = *content_type; upload_file_info->content_type = content_type;
upload_file_info->initial_upload_location = upload_file_info->initial_upload_location = GURL(entry_proto->upload_url());
dest_dir->AsGDataDirectory()->upload_url();
upload_file_info->completion_callback = upload_file_info->completion_callback =
base::Bind(&GDataFileSystem::OnTransferCompleted, base::Bind(&GDataFileSystem::OnTransferCompleted,
ui_weak_ptr_, ui_weak_ptr_,
callback); params.callback);
uploader_->UploadNewFile(upload_file_info.Pass()); uploader_->UploadNewFile(upload_file_info.Pass());
} }
......
...@@ -172,6 +172,9 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -172,6 +172,9 @@ class GDataFileSystem : public GDataFileSystemInterface,
// Struct used to record UMA stats with FeedToFileResourceMap(). // Struct used to record UMA stats with FeedToFileResourceMap().
struct FeedToFileResourceMapUmaStats; struct FeedToFileResourceMapUmaStats;
// Struct used for StartFileUploadOnUIThread().
struct StartFileUploadParams;
// Finds entry object by |file_path| and returns the entry object. // Finds entry object by |file_path| and returns the entry object.
// Returns NULL if it does not find the entry. // Returns NULL if it does not find the entry.
GDataEntry* GetGDataEntryByPath(const FilePath& file_path); GDataEntry* GetGDataEntryByPath(const FilePath& file_path);
...@@ -648,13 +651,20 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -648,13 +651,20 @@ class GDataFileSystem : public GDataFileSystemInterface,
// Kicks off file upload once it receives |file_size| and |content_type|. // Kicks off file upload once it receives |file_size| and |content_type|.
void StartFileUploadOnUIThread( void StartFileUploadOnUIThread(
const FilePath& local_file, const StartFileUploadParams& params,
const FilePath& remote_dest_file,
const FileOperationCallback& callback,
GDataFileError* error, GDataFileError* error,
int64* file_size, int64* file_size,
std::string* content_type); std::string* content_type);
// Part of StartFileUploadOnUIThread(). Called after GetEntryInfoByPath()
// is complete.
void StartFileUploadOnUIThreadAfterGetEntryInfo(
const StartFileUploadParams& params,
int64 file_size,
std::string content_type,
GDataFileError error,
scoped_ptr<GDataEntryProto> entry_proto);
// Cache intermediate callbacks, that run on calling thread, for above cache // Cache intermediate callbacks, that run on calling thread, for above cache
// tasks that were run on blocking pool. // tasks that were run on blocking pool.
......
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