| OLD | NEW |
| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 const std::string& resource_id, | 260 const std::string& resource_id, |
| 261 const std::string& md5, | 261 const std::string& md5, |
| 262 FilePath* cache_file_path) { | 262 FilePath* cache_file_path) { |
| 263 DCHECK(error); | 263 DCHECK(error); |
| 264 DCHECK(cache_file_path); | 264 DCHECK(cache_file_path); |
| 265 | 265 |
| 266 if (!callback.is_null()) | 266 if (!callback.is_null()) |
| 267 callback.Run(*error, resource_id, md5, *cache_file_path); | 267 callback.Run(*error, resource_id, md5, *cache_file_path); |
| 268 } | 268 } |
| 269 | 269 |
| 270 // Callback for StoreToCache invoked by AddUploadedFileOnUIThread. |
| 271 void OnStoreToCacheForAddUploadedFile( |
| 272 const base::Closure& callback, |
| 273 base::PlatformFileError /* error */, |
| 274 const std::string& /* resource_id */, |
| 275 const std::string& /* md5 */) { |
| 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 277 if (!callback.is_null()) |
| 278 callback.Run(); |
| 279 } |
| 280 |
| 281 // Helper function called upon completion of AddUploadFile invoked by |
| 282 // OnTransferCompleted. |
| 283 void OnAddUploadFileCompleted( |
| 284 const FileOperationCallback& callback, |
| 285 base::PlatformFileError error, |
| 286 scoped_ptr<UploadFileInfo> /* upload_file_info */){ |
| 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 288 if (!callback.is_null()) |
| 289 callback.Run(error); |
| 290 } |
| 291 |
| 270 void RunGetCacheStateCallbackHelper( | 292 void RunGetCacheStateCallbackHelper( |
| 271 const GetCacheStateCallback& callback, | 293 const GetCacheStateCallback& callback, |
| 272 base::PlatformFileError* error, | 294 base::PlatformFileError* error, |
| 273 int* cache_state) { | 295 int* cache_state) { |
| 274 DCHECK(error); | 296 DCHECK(error); |
| 275 DCHECK(cache_state); | 297 DCHECK(cache_state); |
| 276 | 298 |
| 277 if (!callback.is_null()) | 299 if (!callback.is_null()) |
| 278 callback.Run(*error, *cache_state); | 300 callback.Run(*error, *cache_state); |
| 279 } | 301 } |
| (...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 base::Bind(&GDataFileSystem::OnTransferCompleted, | 1186 base::Bind(&GDataFileSystem::OnTransferCompleted, |
| 1165 ui_weak_ptr_, | 1187 ui_weak_ptr_, |
| 1166 callback); | 1188 callback); |
| 1167 | 1189 |
| 1168 service->uploader()->UploadFile(scoped_ptr<UploadFileInfo>(upload_file_info)); | 1190 service->uploader()->UploadFile(scoped_ptr<UploadFileInfo>(upload_file_info)); |
| 1169 } | 1191 } |
| 1170 | 1192 |
| 1171 void GDataFileSystem::OnTransferCompleted( | 1193 void GDataFileSystem::OnTransferCompleted( |
| 1172 const FileOperationCallback& callback, | 1194 const FileOperationCallback& callback, |
| 1173 base::PlatformFileError error, | 1195 base::PlatformFileError error, |
| 1174 UploadFileInfo* upload_file_info) { | 1196 scoped_ptr<UploadFileInfo> upload_file_info) { |
| 1175 DCHECK(upload_file_info); | 1197 DCHECK(upload_file_info.get()); |
| 1176 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { | 1198 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { |
| 1177 AddUploadedFile(upload_file_info->gdata_path.DirName(), | 1199 AddUploadedFile(upload_file_info->gdata_path.DirName(), |
| 1178 upload_file_info->entry.get(), | 1200 upload_file_info->entry.get(), |
| 1179 upload_file_info->file_path, | 1201 upload_file_info->file_path, |
| 1180 GDataCache::FILE_OPERATION_COPY); | 1202 GDataCache::FILE_OPERATION_COPY, |
| 1203 base::Bind(&OnAddUploadFileCompleted, |
| 1204 callback, |
| 1205 error, |
| 1206 base::Passed(&upload_file_info))); |
| 1207 } else if (!callback.is_null()) { |
| 1208 callback.Run(error); |
| 1181 } | 1209 } |
| 1182 if (!callback.is_null()) | |
| 1183 callback.Run(error); | |
| 1184 | |
| 1185 // In case of error upload_file_info will be deleted by the uploader. | |
| 1186 if (error != base::PLATFORM_FILE_OK) | |
| 1187 return; | |
| 1188 | |
| 1189 // TODO(achuith): GDataFileSystem should not have to call DeleteUpload. | |
| 1190 GDataSystemService* service = | |
| 1191 GDataSystemServiceFactory::GetForProfile(profile_); | |
| 1192 if (service) | |
| 1193 service->uploader()->DeleteUpload(upload_file_info); | |
| 1194 } | 1210 } |
| 1195 | 1211 |
| 1196 void GDataFileSystem::Copy(const FilePath& src_file_path, | 1212 void GDataFileSystem::Copy(const FilePath& src_file_path, |
| 1197 const FilePath& dest_file_path, | 1213 const FilePath& dest_file_path, |
| 1198 const FileOperationCallback& callback) { | 1214 const FileOperationCallback& callback) { |
| 1199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 1200 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1216 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 1201 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, | 1217 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, |
| 1202 ui_weak_ptr_, | 1218 ui_weak_ptr_, |
| 1203 src_file_path, | 1219 src_file_path, |
| (...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3523 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 3539 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 3524 | 3540 |
| 3525 NotifyDirectoryChanged(parent_dir->GetFilePath()); | 3541 NotifyDirectoryChanged(parent_dir->GetFilePath()); |
| 3526 return base::PLATFORM_FILE_OK; | 3542 return base::PLATFORM_FILE_OK; |
| 3527 } | 3543 } |
| 3528 | 3544 |
| 3529 void GDataFileSystem::AddUploadedFile( | 3545 void GDataFileSystem::AddUploadedFile( |
| 3530 const FilePath& virtual_dir_path, | 3546 const FilePath& virtual_dir_path, |
| 3531 DocumentEntry* entry, | 3547 DocumentEntry* entry, |
| 3532 const FilePath& file_content_path, | 3548 const FilePath& file_content_path, |
| 3533 GDataCache::FileOperationType cache_operation) { | 3549 GDataCache::FileOperationType cache_operation, |
| 3550 const base::Closure& callback) { |
| 3534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3535 | 3552 |
| 3553 // Post a task to the same thread, rather than calling it here, as |
| 3554 // AddUploadedFile() is asynchronous. |
| 3555 base::MessageLoopProxy::current()->PostTask( |
| 3556 FROM_HERE, |
| 3557 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, |
| 3558 ui_weak_ptr_, |
| 3559 virtual_dir_path, |
| 3560 entry, |
| 3561 file_content_path, |
| 3562 cache_operation, |
| 3563 callback)); |
| 3564 } |
| 3565 |
| 3566 void GDataFileSystem::AddUploadedFileOnUIThread( |
| 3567 const FilePath& virtual_dir_path, |
| 3568 DocumentEntry* entry, |
| 3569 const FilePath& file_content_path, |
| 3570 GDataCache::FileOperationType cache_operation, |
| 3571 const base::Closure& callback) { |
| 3572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3573 DCHECK(!callback.is_null()); |
| 3574 |
| 3536 if (!entry) { | 3575 if (!entry) { |
| 3537 NOTREACHED(); | 3576 NOTREACHED(); |
| 3577 callback.Run(); |
| 3538 return; | 3578 return; |
| 3539 } | 3579 } |
| 3540 | 3580 |
| 3541 std::string resource_id; | 3581 std::string resource_id; |
| 3542 std::string md5; | 3582 std::string md5; |
| 3543 { | 3583 { |
| 3544 base::AutoLock lock(lock_); | 3584 base::AutoLock lock(lock_); |
| 3545 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); | 3585 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); |
| 3546 if (!dir_entry) | 3586 if (!dir_entry) { |
| 3587 callback.Run(); |
| 3547 return; | 3588 return; |
| 3589 } |
| 3548 | 3590 |
| 3549 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 3591 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
| 3550 if (!parent_dir) | 3592 if (!parent_dir) { |
| 3593 callback.Run(); |
| 3551 return; | 3594 return; |
| 3595 } |
| 3552 | 3596 |
| 3553 scoped_ptr<GDataEntry> new_entry( | 3597 scoped_ptr<GDataEntry> new_entry( |
| 3554 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); | 3598 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); |
| 3555 if (!new_entry.get()) | 3599 if (!new_entry.get()) { |
| 3600 callback.Run(); |
| 3556 return; | 3601 return; |
| 3602 } |
| 3557 | 3603 |
| 3558 GDataFile* file = new_entry->AsGDataFile(); | 3604 GDataFile* file = new_entry->AsGDataFile(); |
| 3559 DCHECK(file); | 3605 DCHECK(file); |
| 3560 resource_id = file->resource_id(); | 3606 resource_id = file->resource_id(); |
| 3561 md5 = file->file_md5(); | 3607 md5 = file->file_md5(); |
| 3562 parent_dir->AddEntry(new_entry.release()); | 3608 parent_dir->AddEntry(new_entry.release()); |
| 3563 } | 3609 } |
| 3564 NotifyDirectoryChanged(virtual_dir_path); | 3610 NotifyDirectoryChanged(virtual_dir_path); |
| 3565 | 3611 |
| 3566 StoreToCache(resource_id, md5, file_content_path, cache_operation, | 3612 StoreToCache(resource_id, md5, file_content_path, cache_operation, |
| 3567 CacheOperationCallback()); | 3613 base::Bind(&OnStoreToCacheForAddUploadedFile, |
| 3614 callback)); |
| 3568 } | 3615 } |
| 3569 | 3616 |
| 3570 void GDataFileSystem::Observe(int type, | 3617 void GDataFileSystem::Observe(int type, |
| 3571 const content::NotificationSource& source, | 3618 const content::NotificationSource& source, |
| 3572 const content::NotificationDetails& details) { | 3619 const content::NotificationDetails& details) { |
| 3573 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 3620 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 3574 PrefService* pref_service = profile_->GetPrefs(); | 3621 PrefService* pref_service = profile_->GetPrefs(); |
| 3575 std::string* pref_name = content::Details<std::string>(details).ptr(); | 3622 std::string* pref_name = content::Details<std::string>(details).ptr(); |
| 3576 if (*pref_name == prefs::kDisableGDataHostedFiles) { | 3623 if (*pref_name == prefs::kDisableGDataHostedFiles) { |
| 3577 SetHideHostedDocuments( | 3624 SetHideHostedDocuments( |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4152 base::PlatformFileError error, | 4199 base::PlatformFileError error, |
| 4153 const std::string& resource_id, | 4200 const std::string& resource_id, |
| 4154 const std::string& md5) { | 4201 const std::string& md5) { |
| 4155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 4202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 4156 | 4203 |
| 4157 if (!callback.is_null()) | 4204 if (!callback.is_null()) |
| 4158 callback.Run(error); | 4205 callback.Run(error); |
| 4159 } | 4206 } |
| 4160 | 4207 |
| 4161 } // namespace gdata | 4208 } // namespace gdata |
| OLD | NEW |