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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 // Ditto for FileOperationCallback | 227 // Ditto for FileOperationCallback |
228 void RunFileOperationCallbackHelper( | 228 void RunFileOperationCallbackHelper( |
229 const FileOperationCallback& callback, | 229 const FileOperationCallback& callback, |
230 base::PlatformFileError* error) { | 230 base::PlatformFileError* error) { |
231 DCHECK(error); | 231 DCHECK(error); |
232 | 232 |
233 if (!callback.is_null()) | 233 if (!callback.is_null()) |
234 callback.Run(*error); | 234 callback.Run(*error); |
235 } | 235 } |
236 | 236 |
237 // Callback for StoreToCache invoked by AddUploadedFileOnUIThread. | |
238 void OnStoreToCacheForAddUploadedFile( | |
239 const base::Closure& callback, | |
240 base::PlatformFileError /* error */, | |
241 const std::string& /* resource_id */, | |
242 const std::string& /* md5 */) { | |
243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
244 if (!callback.is_null()) | |
245 callback.Run(); | |
246 } | |
247 | |
248 // Helper function called upon completion of AddUploadFile invoked by | |
249 // OnTransferCompleted. | |
250 void OnAddUploadFileCompleted( | |
251 const FileOperationCallback& callback, | |
252 base::PlatformFileError error, | |
253 scoped_ptr<UploadFileInfo> /* upload_file_info */){ | |
254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
255 if (!callback.is_null()) | |
256 callback.Run(error); | |
257 } | |
258 | |
237 // Used to implement GetCacheState. | 259 // Used to implement GetCacheState. |
238 void RunGetCacheStateCallbackHelper( | 260 void RunGetCacheStateCallbackHelper( |
239 const GetCacheStateCallback& callback, | 261 const GetCacheStateCallback& callback, |
240 GDataCache::CacheEntry* cache_entry, | 262 GDataCache::CacheEntry* cache_entry, |
241 bool* success) { | 263 bool* success) { |
242 DCHECK(cache_entry); | 264 DCHECK(cache_entry); |
243 DCHECK(success); | 265 DCHECK(success); |
244 if (callback.is_null()) | 266 if (callback.is_null()) |
245 return; | 267 return; |
246 | 268 |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1144 base::Bind(&GDataFileSystem::OnTransferCompleted, | 1166 base::Bind(&GDataFileSystem::OnTransferCompleted, |
1145 ui_weak_ptr_, | 1167 ui_weak_ptr_, |
1146 callback); | 1168 callback); |
1147 | 1169 |
1148 service->uploader()->UploadFile(scoped_ptr<UploadFileInfo>(upload_file_info)); | 1170 service->uploader()->UploadFile(scoped_ptr<UploadFileInfo>(upload_file_info)); |
1149 } | 1171 } |
1150 | 1172 |
1151 void GDataFileSystem::OnTransferCompleted( | 1173 void GDataFileSystem::OnTransferCompleted( |
1152 const FileOperationCallback& callback, | 1174 const FileOperationCallback& callback, |
1153 base::PlatformFileError error, | 1175 base::PlatformFileError error, |
1154 UploadFileInfo* upload_file_info) { | 1176 scoped_ptr<UploadFileInfo> upload_file_info) { |
1155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1156 DCHECK(upload_file_info); | 1178 DCHECK(upload_file_info.get()); |
1157 | 1179 |
1158 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { | 1180 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { |
1159 AddUploadedFile(upload_file_info->gdata_path.DirName(), | 1181 const UploadFileInfo* upload_file_info_ptr = upload_file_info.get(); |
achuithb
2012/06/15 21:53:58
Please add a comment.
satorux1
2012/06/15 21:59:15
yeah, this is subtle. glad you caught this before
hshi1
2012/06/15 22:05:48
Done.
hshi1
2012/06/15 22:05:48
Yes, thanks for mentioning a similar issue before
| |
1160 upload_file_info->entry.get(), | 1182 AddUploadedFile(upload_file_info_ptr->gdata_path.DirName(), |
1161 upload_file_info->file_path, | 1183 upload_file_info_ptr->entry.get(), |
1162 GDataCache::FILE_OPERATION_COPY); | 1184 upload_file_info_ptr->file_path, |
1185 GDataCache::FILE_OPERATION_COPY, | |
1186 base::Bind(&OnAddUploadFileCompleted, | |
1187 callback, | |
1188 error, | |
1189 base::Passed(&upload_file_info))); | |
1190 } else if (!callback.is_null()) { | |
1191 callback.Run(error); | |
1163 } | 1192 } |
1164 if (!callback.is_null()) | |
1165 callback.Run(error); | |
1166 | |
1167 // In case of error upload_file_info will be deleted by the uploader. | |
1168 if (error != base::PLATFORM_FILE_OK) | |
1169 return; | |
1170 | |
1171 // TODO(achuith): GDataFileSystem should not have to call DeleteUpload. | |
1172 GDataSystemService* service = | |
1173 GDataSystemServiceFactory::GetForProfile(profile_); | |
1174 if (service) | |
1175 service->uploader()->DeleteUpload(upload_file_info); | |
1176 } | 1193 } |
1177 | 1194 |
1178 void GDataFileSystem::Copy(const FilePath& src_file_path, | 1195 void GDataFileSystem::Copy(const FilePath& src_file_path, |
1179 const FilePath& dest_file_path, | 1196 const FilePath& dest_file_path, |
1180 const FileOperationCallback& callback) { | 1197 const FileOperationCallback& callback) { |
1181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1182 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1199 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1183 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, | 1200 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, |
1184 ui_weak_ptr_, | 1201 ui_weak_ptr_, |
1185 src_file_path, | 1202 src_file_path, |
(...skipping 2290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3476 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 3493 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
3477 | 3494 |
3478 NotifyDirectoryChanged(parent_dir->GetFilePath()); | 3495 NotifyDirectoryChanged(parent_dir->GetFilePath()); |
3479 return base::PLATFORM_FILE_OK; | 3496 return base::PLATFORM_FILE_OK; |
3480 } | 3497 } |
3481 | 3498 |
3482 void GDataFileSystem::AddUploadedFile( | 3499 void GDataFileSystem::AddUploadedFile( |
3483 const FilePath& virtual_dir_path, | 3500 const FilePath& virtual_dir_path, |
3484 DocumentEntry* entry, | 3501 DocumentEntry* entry, |
3485 const FilePath& file_content_path, | 3502 const FilePath& file_content_path, |
3486 GDataCache::FileOperationType cache_operation) { | 3503 GDataCache::FileOperationType cache_operation, |
3504 const base::Closure& callback) { | |
3487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3505 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3488 | 3506 |
3507 // Post a task to the same thread, rather than calling it here, as | |
3508 // AddUploadedFile() is asynchronous. | |
3509 base::MessageLoopProxy::current()->PostTask( | |
3510 FROM_HERE, | |
3511 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, | |
3512 ui_weak_ptr_, | |
3513 virtual_dir_path, | |
3514 entry, | |
3515 file_content_path, | |
3516 cache_operation, | |
3517 callback)); | |
3518 } | |
3519 | |
3520 void GDataFileSystem::AddUploadedFileOnUIThread( | |
3521 const FilePath& virtual_dir_path, | |
3522 DocumentEntry* entry, | |
3523 const FilePath& file_content_path, | |
3524 GDataCache::FileOperationType cache_operation, | |
3525 const base::Closure& callback) { | |
3526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
3527 DCHECK(!callback.is_null()); | |
3528 | |
3489 if (!entry) { | 3529 if (!entry) { |
3490 NOTREACHED(); | 3530 NOTREACHED(); |
3531 callback.Run(); | |
3491 return; | 3532 return; |
3492 } | 3533 } |
3493 | 3534 |
3494 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); | 3535 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); |
3495 if (!dir_entry) | 3536 if (!dir_entry) { |
3537 callback.Run(); | |
3496 return; | 3538 return; |
3539 } | |
3497 | 3540 |
3498 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 3541 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
3499 if (!parent_dir) | 3542 if (!parent_dir) { |
3543 callback.Run(); | |
3500 return; | 3544 return; |
3545 } | |
3501 | 3546 |
3502 scoped_ptr<GDataEntry> new_entry( | 3547 scoped_ptr<GDataEntry> new_entry( |
3503 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); | 3548 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); |
3504 if (!new_entry.get()) | 3549 if (!new_entry.get()) { |
3550 callback.Run(); | |
3505 return; | 3551 return; |
3552 } | |
3506 | 3553 |
3507 GDataFile* file = new_entry->AsGDataFile(); | 3554 GDataFile* file = new_entry->AsGDataFile(); |
3508 DCHECK(file); | 3555 DCHECK(file); |
3509 const std::string& resource_id = file->resource_id(); | 3556 const std::string& resource_id = file->resource_id(); |
3510 const std::string& md5 = file->file_md5(); | 3557 const std::string& md5 = file->file_md5(); |
3511 parent_dir->AddEntry(new_entry.release()); | 3558 parent_dir->AddEntry(new_entry.release()); |
3512 | 3559 |
3513 NotifyDirectoryChanged(virtual_dir_path); | 3560 NotifyDirectoryChanged(virtual_dir_path); |
3514 | 3561 |
3515 cache_->StoreOnUIThread(resource_id, md5, file_content_path, cache_operation, | 3562 cache_->StoreOnUIThread(resource_id, md5, file_content_path, cache_operation, |
3516 CacheOperationCallback()); | 3563 base::Bind(&OnStoreToCacheForAddUploadedFile, |
3564 callback)); | |
3517 } | 3565 } |
3518 | 3566 |
3519 void GDataFileSystem::Observe(int type, | 3567 void GDataFileSystem::Observe(int type, |
3520 const content::NotificationSource& source, | 3568 const content::NotificationSource& source, |
3521 const content::NotificationDetails& details) { | 3569 const content::NotificationDetails& details) { |
3522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3523 | 3571 |
3524 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 3572 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
3525 PrefService* pref_service = profile_->GetPrefs(); | 3573 PrefService* pref_service = profile_->GetPrefs(); |
3526 std::string* pref_name = content::Details<std::string>(details).ptr(); | 3574 std::string* pref_name = content::Details<std::string>(details).ptr(); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3777 base::PlatformFileError error, | 3825 base::PlatformFileError error, |
3778 const std::string& resource_id, | 3826 const std::string& resource_id, |
3779 const std::string& md5) { | 3827 const std::string& md5) { |
3780 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3828 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3781 | 3829 |
3782 if (!callback.is_null()) | 3830 if (!callback.is_null()) |
3783 callback.Run(error); | 3831 callback.Run(error); |
3784 } | 3832 } |
3785 | 3833 |
3786 } // namespace gdata | 3834 } // namespace gdata |
OLD | NEW |