Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10809054: gdata: Remove use of GetGDataEntryByPath() from StartFileUploadOnUIThread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/gdata/gdata_file_system.cc
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc
index bf441df31f4bad2b6249e5036a95cb525e178ff4..a5ee0cb3bb02a3c3628ac8bd9a6235b71fe491a2 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc
@@ -753,6 +753,19 @@ struct GDataFileSystem::FeedToFileResourceMapUmaStats {
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.
@@ -1229,18 +1242,16 @@ void GDataFileSystem::TransferRegularFile(
content_type),
base::Bind(&GDataFileSystem::StartFileUploadOnUIThread,
ui_weak_ptr_,
- local_file_path,
- remote_dest_file_path,
- callback,
+ StartFileUploadParams(local_file_path,
+ remote_dest_file_path,
+ callback),
base::Owned(error),
base::Owned(file_size),
base::Owned(content_type)));
}
void GDataFileSystem::StartFileUploadOnUIThread(
- const FilePath& local_file,
- const FilePath& remote_dest_file,
- const FileOperationCallback& callback,
+ const StartFileUploadParams& params,
GDataFileError* error,
int64* file_size,
std::string* content_type) {
@@ -1252,38 +1263,57 @@ void GDataFileSystem::StartFileUploadOnUIThread(
DCHECK(content_type);
if (*error != GDATA_FILE_OK) {
- if (!callback.is_null())
- callback.Run(*error);
+ if (!params.callback.is_null())
+ params.callback.Run(*error);
return;
}
// Make sure the destination directory exists.
- GDataEntry* dest_dir = GetGDataEntryByPath(remote_dest_file.DirName());
- if (!dest_dir || !dest_dir->AsGDataDirectory()) {
- if (!callback.is_null())
- callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
- NOTREACHED();
+ GetEntryInfoByPath(
+ params.remote_file_path.DirName(),
+ base::Bind(
+ &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo,
+ 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;
}
+ DCHECK(entry_proto.get());
// Fill in values of UploadFileInfo.
scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo);
- upload_file_info->file_path = local_file;
- upload_file_info->file_size = *file_size;
- upload_file_info->gdata_path = remote_dest_file;
+ upload_file_info->file_path = params.local_file_path;
+ upload_file_info->file_size = file_size;
+ upload_file_info->gdata_path = params.remote_file_path;
// Use the file name as the title.
- upload_file_info->title = remote_dest_file.BaseName().value();
- upload_file_info->content_length = *file_size;
+ upload_file_info->title = params.remote_file_path.BaseName().value();
+ upload_file_info->content_length = file_size;
upload_file_info->all_bytes_present = true;
- upload_file_info->content_type = *content_type;
- upload_file_info->initial_upload_location =
- dest_dir->AsGDataDirectory()->upload_url();
+ upload_file_info->content_type = content_type;
+ upload_file_info->initial_upload_location = GURL(entry_proto->upload_url());
upload_file_info->completion_callback =
base::Bind(&GDataFileSystem::OnTransferCompleted,
ui_weak_ptr_,
- callback);
+ params.callback);
uploader_->UploadNewFile(upload_file_info.Pass());
}

Powered by Google App Engine
This is Rietveld 408576698