| 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 fdfabaf0bd4eb70e78ef2f72c6d4ec5b8f880204..6dbde2d826f5da0588005e030b8d4d2afbb58205 100644
|
| --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc
|
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc
|
| @@ -267,6 +267,28 @@ void RunGetFileFromCacheCallbackHelper(
|
| callback.Run(*error, resource_id, md5, *cache_file_path);
|
| }
|
|
|
| +// Callback for StoreToCache invoked by AddUploadedFileOnUIThread.
|
| +void OnStoreToCacheForAddUploadedFile(
|
| + const base::Closure& callback,
|
| + base::PlatformFileError /* error */,
|
| + const std::string& /* resource_id */,
|
| + const std::string& /* md5 */) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + if (!callback.is_null())
|
| + callback.Run();
|
| +}
|
| +
|
| +// Helper function called upon completion of AddUploadFile invoked by
|
| +// OnTransferCompleted.
|
| +void OnAddUploadFileCompleted(
|
| + const FileOperationCallback& callback,
|
| + base::PlatformFileError error,
|
| + scoped_ptr<UploadFileInfo> /* upload_file_info */){
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + if (!callback.is_null())
|
| + callback.Run(error);
|
| +}
|
| +
|
| void RunGetCacheStateCallbackHelper(
|
| const GetCacheStateCallback& callback,
|
| base::PlatformFileError* error,
|
| @@ -1171,26 +1193,20 @@ void GDataFileSystem::StartFileUploadOnUIThread(
|
| void GDataFileSystem::OnTransferCompleted(
|
| const FileOperationCallback& callback,
|
| base::PlatformFileError error,
|
| - UploadFileInfo* upload_file_info) {
|
| - DCHECK(upload_file_info);
|
| + scoped_ptr<UploadFileInfo> upload_file_info) {
|
| + DCHECK(upload_file_info.get());
|
| if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) {
|
| AddUploadedFile(upload_file_info->gdata_path.DirName(),
|
| upload_file_info->entry.get(),
|
| upload_file_info->file_path,
|
| - GDataCache::FILE_OPERATION_COPY);
|
| - }
|
| - if (!callback.is_null())
|
| + GDataCache::FILE_OPERATION_COPY,
|
| + base::Bind(&OnAddUploadFileCompleted,
|
| + callback,
|
| + error,
|
| + base::Passed(&upload_file_info)));
|
| + } else if (!callback.is_null()) {
|
| callback.Run(error);
|
| -
|
| - // In case of error upload_file_info will be deleted by the uploader.
|
| - if (error != base::PLATFORM_FILE_OK)
|
| - return;
|
| -
|
| - // TODO(achuith): GDataFileSystem should not have to call DeleteUpload.
|
| - GDataSystemService* service =
|
| - GDataSystemServiceFactory::GetForProfile(profile_);
|
| - if (service)
|
| - service->uploader()->DeleteUpload(upload_file_info);
|
| + }
|
| }
|
|
|
| void GDataFileSystem::Copy(const FilePath& src_file_path,
|
| @@ -3530,11 +3546,35 @@ void GDataFileSystem::AddUploadedFile(
|
| const FilePath& virtual_dir_path,
|
| DocumentEntry* entry,
|
| const FilePath& file_content_path,
|
| - GDataCache::FileOperationType cache_operation) {
|
| + GDataCache::FileOperationType cache_operation,
|
| + const base::Closure& callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| +
|
| + // Post a task to the same thread, rather than calling it here, as
|
| + // AddUploadedFile() is asynchronous.
|
| + base::MessageLoopProxy::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread,
|
| + ui_weak_ptr_,
|
| + virtual_dir_path,
|
| + entry,
|
| + file_content_path,
|
| + cache_operation,
|
| + callback));
|
| +}
|
| +
|
| +void GDataFileSystem::AddUploadedFileOnUIThread(
|
| + const FilePath& virtual_dir_path,
|
| + DocumentEntry* entry,
|
| + const FilePath& file_content_path,
|
| + GDataCache::FileOperationType cache_operation,
|
| + const base::Closure& callback) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + DCHECK(!callback.is_null());
|
|
|
| if (!entry) {
|
| NOTREACHED();
|
| + callback.Run();
|
| return;
|
| }
|
|
|
| @@ -3543,17 +3583,23 @@ void GDataFileSystem::AddUploadedFile(
|
| {
|
| base::AutoLock lock(lock_);
|
| GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path);
|
| - if (!dir_entry)
|
| + if (!dir_entry) {
|
| + callback.Run();
|
| return;
|
| + }
|
|
|
| GDataDirectory* parent_dir = dir_entry->AsGDataDirectory();
|
| - if (!parent_dir)
|
| + if (!parent_dir) {
|
| + callback.Run();
|
| return;
|
| + }
|
|
|
| scoped_ptr<GDataEntry> new_entry(
|
| GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get()));
|
| - if (!new_entry.get())
|
| + if (!new_entry.get()) {
|
| + callback.Run();
|
| return;
|
| + }
|
|
|
| GDataFile* file = new_entry->AsGDataFile();
|
| DCHECK(file);
|
| @@ -3564,7 +3610,8 @@ void GDataFileSystem::AddUploadedFile(
|
| NotifyDirectoryChanged(virtual_dir_path);
|
|
|
| StoreToCache(resource_id, md5, file_content_path, cache_operation,
|
| - CacheOperationCallback());
|
| + base::Bind(&OnStoreToCacheForAddUploadedFile,
|
| + callback));
|
| }
|
|
|
| void GDataFileSystem::Observe(int type,
|
|
|