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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10540132: gdata: Convert GDataFileSystem::AddUploadFile() to asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase svn:trunk/src@142185 and resolve conflicts. Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 1170
1171 void GDataFileSystem::OnTransferCompleted( 1171 void GDataFileSystem::OnTransferCompleted(
1172 const FileOperationCallback& callback, 1172 const FileOperationCallback& callback,
1173 base::PlatformFileError error, 1173 base::PlatformFileError error,
1174 UploadFileInfo* upload_file_info) { 1174 UploadFileInfo* upload_file_info) {
1175 DCHECK(upload_file_info); 1175 DCHECK(upload_file_info);
1176 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { 1176 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) {
1177 AddUploadedFile(upload_file_info->gdata_path.DirName(), 1177 AddUploadedFile(upload_file_info->gdata_path.DirName(),
1178 upload_file_info->entry.get(), 1178 upload_file_info->entry.get(),
1179 upload_file_info->file_path, 1179 upload_file_info->file_path,
1180 GDataCache::FILE_OPERATION_COPY); 1180 GDataCache::FILE_OPERATION_COPY,
1181 base::Bind(&GDataFileSystem::OnAddUploadFileCompleted,
1182 ui_weak_ptr_,
1183 callback,
1184 error,
1185 upload_file_info));
1186 } else {
satorux1 2012/06/14 20:30:06 maybe: else if (upload_file_info->entry.get()) {
hshi1 2012/06/14 20:47:27 In the original code there is no such check; even
1187 OnAddUploadFileCompleted(callback, error, upload_file_info);
1181 } 1188 }
1189 }
1190
1191 void GDataFileSystem::OnAddUploadFileCompleted(
1192 const FileOperationCallback& callback,
1193 base::PlatformFileError error,
1194 UploadFileInfo* upload_file_info) {
1195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1196
1182 if (!callback.is_null()) 1197 if (!callback.is_null())
1183 callback.Run(error); 1198 callback.Run(error);
1184 1199
1185 // In case of error upload_file_info will be deleted by the uploader. 1200 // In case of error upload_file_info will be deleted by the uploader.
1186 if (error != base::PLATFORM_FILE_OK) 1201 if (error != base::PLATFORM_FILE_OK)
1187 return; 1202 return;
1188 1203
1189 // TODO(achuith): GDataFileSystem should not have to call DeleteUpload. 1204 delete upload_file_info;
1190 GDataSystemService* service =
1191 GDataSystemServiceFactory::GetForProfile(profile_);
1192 if (service)
1193 service->uploader()->DeleteUpload(upload_file_info);
1194 } 1205 }
1195 1206
1196 void GDataFileSystem::Copy(const FilePath& src_file_path, 1207 void GDataFileSystem::Copy(const FilePath& src_file_path,
1197 const FilePath& dest_file_path, 1208 const FilePath& dest_file_path,
1198 const FileOperationCallback& callback) { 1209 const FileOperationCallback& callback) {
1199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1200 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1211 BrowserThread::CurrentlyOn(BrowserThread::IO));
1201 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, 1212 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread,
1202 ui_weak_ptr_, 1213 ui_weak_ptr_,
1203 src_file_path, 1214 src_file_path,
(...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after
3523 return base::PLATFORM_FILE_ERROR_NOT_FOUND; 3534 return base::PLATFORM_FILE_ERROR_NOT_FOUND;
3524 3535
3525 NotifyDirectoryChanged(parent_dir->GetFilePath()); 3536 NotifyDirectoryChanged(parent_dir->GetFilePath());
3526 return base::PLATFORM_FILE_OK; 3537 return base::PLATFORM_FILE_OK;
3527 } 3538 }
3528 3539
3529 void GDataFileSystem::AddUploadedFile( 3540 void GDataFileSystem::AddUploadedFile(
3530 const FilePath& virtual_dir_path, 3541 const FilePath& virtual_dir_path,
3531 DocumentEntry* entry, 3542 DocumentEntry* entry,
3532 const FilePath& file_content_path, 3543 const FilePath& file_content_path,
3533 GDataCache::FileOperationType cache_operation) { 3544 GDataCache::FileOperationType cache_operation,
3545 const base::Closure& callback) {
3534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3535 3547
3548 // Post a task to the same thread, rather than calling it here, as
3549 // AddUploadedFile() is asynchronous.
3550 base::MessageLoopProxy::current()->PostTask(
3551 FROM_HERE,
3552 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread,
3553 ui_weak_ptr_,
3554 virtual_dir_path,
3555 entry,
3556 file_content_path,
3557 cache_operation,
3558 callback));
3559 }
3560
3561 void GDataFileSystem::AddUploadedFileOnUIThread(
3562 const FilePath& virtual_dir_path,
3563 DocumentEntry* entry,
3564 const FilePath& file_content_path,
3565 GDataCache::FileOperationType cache_operation,
3566 const base::Closure& callback) {
3567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3568 DCHECK(!callback.is_null());
3569
3536 if (!entry) { 3570 if (!entry) {
3537 NOTREACHED(); 3571 NOTREACHED();
3572 callback.Run();
3538 return; 3573 return;
3539 } 3574 }
3540 3575
3541 std::string resource_id; 3576 std::string resource_id;
3542 std::string md5; 3577 std::string md5;
3543 { 3578 {
3544 base::AutoLock lock(lock_); 3579 base::AutoLock lock(lock_);
3545 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); 3580 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path);
3546 if (!dir_entry) 3581 if (!dir_entry) {
3582 callback.Run();
3547 return; 3583 return;
3584 }
3548 3585
3549 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); 3586 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory();
3550 if (!parent_dir) 3587 if (!parent_dir) {
3588 callback.Run();
3551 return; 3589 return;
3590 }
3552 3591
3553 scoped_ptr<GDataEntry> new_entry( 3592 scoped_ptr<GDataEntry> new_entry(
3554 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); 3593 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get()));
3555 if (!new_entry.get()) 3594 if (!new_entry.get()) {
3595 callback.Run();
3556 return; 3596 return;
3597 }
3557 3598
3558 GDataFile* file = new_entry->AsGDataFile(); 3599 GDataFile* file = new_entry->AsGDataFile();
3559 DCHECK(file); 3600 DCHECK(file);
3560 resource_id = file->resource_id(); 3601 resource_id = file->resource_id();
3561 md5 = file->file_md5(); 3602 md5 = file->file_md5();
3562 parent_dir->AddEntry(new_entry.release()); 3603 parent_dir->AddEntry(new_entry.release());
3563 } 3604 }
3564 NotifyDirectoryChanged(virtual_dir_path); 3605 NotifyDirectoryChanged(virtual_dir_path);
3565 3606
3566 StoreToCache(resource_id, md5, file_content_path, cache_operation, 3607 StoreToCache(resource_id, md5, file_content_path, cache_operation,
3567 CacheOperationCallback()); 3608 CacheOperationCallback());
3609 callback.Run();
satorux1 2012/06/14 20:30:06 Should we run the callback here? StoreToCache() is
hshi1 2012/06/14 20:47:27 You're right, does the new patch set work? On 201
3568 } 3610 }
3569 3611
3570 void GDataFileSystem::Observe(int type, 3612 void GDataFileSystem::Observe(int type,
3571 const content::NotificationSource& source, 3613 const content::NotificationSource& source,
3572 const content::NotificationDetails& details) { 3614 const content::NotificationDetails& details) {
3573 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 3615 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
3574 PrefService* pref_service = profile_->GetPrefs(); 3616 PrefService* pref_service = profile_->GetPrefs();
3575 std::string* pref_name = content::Details<std::string>(details).ptr(); 3617 std::string* pref_name = content::Details<std::string>(details).ptr();
3576 if (*pref_name == prefs::kDisableGDataHostedFiles) { 3618 if (*pref_name == prefs::kDisableGDataHostedFiles) {
3577 SetHideHostedDocuments( 3619 SetHideHostedDocuments(
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
4152 base::PlatformFileError error, 4194 base::PlatformFileError error,
4153 const std::string& resource_id, 4195 const std::string& resource_id,
4154 const std::string& md5) { 4196 const std::string& md5) {
4155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 4197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4156 4198
4157 if (!callback.is_null()) 4199 if (!callback.is_null())
4158 callback.Run(error); 4200 callback.Run(error);
4159 } 4201 }
4160 4202
4161 } // namespace gdata 4203 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698