Commit 20013054 authored by hshi@chromium.org's avatar hshi@chromium.org

gdata: Cleanup GDataFileSystem::AddUploadedFileOnUIThread().

Use ScopedClosureRunner to simplify callback invocation. This ensures
the callback is always either invoked or passed on, and eliminates
the need to DCHECK(!callback.is_null()).

BUG=none
TEST=unit_tests, manual upload tests.


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149706 0039d316-1c4b-4281-b951-d872f2087c98
parent 81404cac
......@@ -3527,34 +3527,30 @@ void GDataFileSystem::AddUploadedFileOnUIThread(
GDataCache::FileOperationType cache_operation,
const base::Closure& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
// ScopedClosureRunner ensures that the specified callback is always invoked
// upon return or passed on.
base::ScopedClosureRunner callback_runner(callback);
if (!entry.get()) {
NOTREACHED();
callback.Run();
return;
}
GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(
virtual_dir_path);
if (!dir_entry) {
callback.Run();
if (!dir_entry)
return;
}
GDataDirectory* parent_dir = dir_entry->AsGDataDirectory();
if (!parent_dir) {
callback.Run();
if (!parent_dir)
return;
}
scoped_ptr<GDataEntry> new_entry(
GDataEntry::FromDocumentEntry(
parent_dir, entry.get(), directory_service_.get()));
if (!new_entry.get()) {
callback.Run();
if (!new_entry.get())
return;
}
if (upload_mode == UPLOAD_EXISTING_FILE) {
// Remove an existing entry, which should be present.
......@@ -3579,13 +3575,13 @@ void GDataFileSystem::AddUploadedFileOnUIThread(
file_content_path,
cache_operation,
base::Bind(&OnCacheUpdatedForAddUploadedFile,
callback));
callback_runner.Release()));
} else if (upload_mode == UPLOAD_EXISTING_FILE) {
// Clear the dirty bit if we have updated an existing file.
cache_->ClearDirtyOnUIThread(resource_id,
md5,
base::Bind(&OnCacheUpdatedForAddUploadedFile,
callback));
callback_runner.Release()));
} else {
NOTREACHED() << "Unexpected upload mode: " << upload_mode;
}
......
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