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..a8aa27b297b10bc134cf98fd248f4ffa39544f02 100644 |
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc |
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
@@ -267,6 +267,16 @@ 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 */) { |
+ if (!callback.is_null()) |
achuithb
2012/06/14 22:27:18
could we add a DCHECK for UI thread here?
hshi1
2012/06/15 00:16:28
Done.
|
+ callback.Run(); |
+} |
+ |
void RunGetCacheStateCallbackHelper( |
const GetCacheStateCallback& callback, |
base::PlatformFileError* error, |
@@ -1177,8 +1187,23 @@ void GDataFileSystem::OnTransferCompleted( |
AddUploadedFile(upload_file_info->gdata_path.DirName(), |
upload_file_info->entry.get(), |
upload_file_info->file_path, |
- GDataCache::FILE_OPERATION_COPY); |
+ GDataCache::FILE_OPERATION_COPY, |
+ base::Bind(&GDataFileSystem::OnAddUploadFileCompleted, |
+ ui_weak_ptr_, |
+ callback, |
+ error, |
+ upload_file_info)); |
+ } else { |
+ OnAddUploadFileCompleted(callback, error, upload_file_info); |
} |
+} |
+ |
+void GDataFileSystem::OnAddUploadFileCompleted( |
+ const FileOperationCallback& callback, |
+ base::PlatformFileError error, |
+ UploadFileInfo* upload_file_info) { |
achuithb
2012/06/14 22:27:18
could we used scoped_ptr instead?
hshi1
2012/06/15 00:16:28
Done.
|
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
if (!callback.is_null()) |
callback.Run(error); |
@@ -1186,11 +1211,7 @@ void GDataFileSystem::OnTransferCompleted( |
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); |
+ delete upload_file_info; |
} |
void GDataFileSystem::Copy(const FilePath& src_file_path, |
@@ -3530,11 +3551,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 |
achuithb
2012/06/14 22:33:33
I'm confused. Why are we doing this?
hshi1
2012/06/15 00:16:28
This is the purpose of this CL and this bug - to m
achuithb
2012/06/15 01:27:33
I've lost sight of the big picture on why we're do
|
+ // 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 +3588,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 +3615,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, |