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 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.
| |
277 callback.Run(); | |
278 } | |
279 | |
270 void RunGetCacheStateCallbackHelper( | 280 void RunGetCacheStateCallbackHelper( |
271 const GetCacheStateCallback& callback, | 281 const GetCacheStateCallback& callback, |
272 base::PlatformFileError* error, | 282 base::PlatformFileError* error, |
273 int* cache_state) { | 283 int* cache_state) { |
274 DCHECK(error); | 284 DCHECK(error); |
275 DCHECK(cache_state); | 285 DCHECK(cache_state); |
276 | 286 |
277 if (!callback.is_null()) | 287 if (!callback.is_null()) |
278 callback.Run(*error, *cache_state); | 288 callback.Run(*error, *cache_state); |
279 } | 289 } |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1164 base::Bind(&GDataFileSystem::OnTransferCompleted, | 1174 base::Bind(&GDataFileSystem::OnTransferCompleted, |
1165 ui_weak_ptr_, | 1175 ui_weak_ptr_, |
1166 callback); | 1176 callback); |
1167 | 1177 |
1168 service->uploader()->UploadFile(scoped_ptr<UploadFileInfo>(upload_file_info)); | 1178 service->uploader()->UploadFile(scoped_ptr<UploadFileInfo>(upload_file_info)); |
1169 } | 1179 } |
1170 | 1180 |
1171 void GDataFileSystem::OnTransferCompleted( | 1181 void GDataFileSystem::OnTransferCompleted( |
1172 const FileOperationCallback& callback, | 1182 const FileOperationCallback& callback, |
1173 base::PlatformFileError error, | 1183 base::PlatformFileError error, |
1174 UploadFileInfo* upload_file_info) { | 1184 UploadFileInfo* upload_file_info) { |
achuithb
2012/06/14 22:27:18
We are getting ownership of upload_file_info here.
hshi1
2012/06/15 00:16:28
Done.
| |
1175 DCHECK(upload_file_info); | 1185 DCHECK(upload_file_info); |
1176 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { | 1186 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { |
1177 AddUploadedFile(upload_file_info->gdata_path.DirName(), | 1187 AddUploadedFile(upload_file_info->gdata_path.DirName(), |
1178 upload_file_info->entry.get(), | 1188 upload_file_info->entry.get(), |
1179 upload_file_info->file_path, | 1189 upload_file_info->file_path, |
1180 GDataCache::FILE_OPERATION_COPY); | 1190 GDataCache::FILE_OPERATION_COPY, |
1191 base::Bind(&GDataFileSystem::OnAddUploadFileCompleted, | |
1192 ui_weak_ptr_, | |
1193 callback, | |
1194 error, | |
1195 upload_file_info)); | |
1196 } else { | |
1197 OnAddUploadFileCompleted(callback, error, upload_file_info); | |
1181 } | 1198 } |
1199 } | |
1200 | |
1201 void GDataFileSystem::OnAddUploadFileCompleted( | |
1202 const FileOperationCallback& callback, | |
1203 base::PlatformFileError error, | |
1204 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.
| |
1205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1206 | |
1182 if (!callback.is_null()) | 1207 if (!callback.is_null()) |
1183 callback.Run(error); | 1208 callback.Run(error); |
1184 | 1209 |
1185 // In case of error upload_file_info will be deleted by the uploader. | 1210 // In case of error upload_file_info will be deleted by the uploader. |
achuithb
2012/06/14 22:27:18
This is really weird (deletion by uploader in case
hshi1
2012/06/15 00:16:28
This is no longer necessary as the pointer gets au
| |
1186 if (error != base::PLATFORM_FILE_OK) | 1211 if (error != base::PLATFORM_FILE_OK) |
1187 return; | 1212 return; |
1188 | 1213 |
1189 // TODO(achuith): GDataFileSystem should not have to call DeleteUpload. | 1214 delete upload_file_info; |
1190 GDataSystemService* service = | |
1191 GDataSystemServiceFactory::GetForProfile(profile_); | |
1192 if (service) | |
1193 service->uploader()->DeleteUpload(upload_file_info); | |
1194 } | 1215 } |
1195 | 1216 |
1196 void GDataFileSystem::Copy(const FilePath& src_file_path, | 1217 void GDataFileSystem::Copy(const FilePath& src_file_path, |
1197 const FilePath& dest_file_path, | 1218 const FilePath& dest_file_path, |
1198 const FileOperationCallback& callback) { | 1219 const FileOperationCallback& callback) { |
1199 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1200 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1221 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1201 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, | 1222 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, |
1202 ui_weak_ptr_, | 1223 ui_weak_ptr_, |
1203 src_file_path, | 1224 src_file_path, |
(...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3523 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 3544 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
3524 | 3545 |
3525 NotifyDirectoryChanged(parent_dir->GetFilePath()); | 3546 NotifyDirectoryChanged(parent_dir->GetFilePath()); |
3526 return base::PLATFORM_FILE_OK; | 3547 return base::PLATFORM_FILE_OK; |
3527 } | 3548 } |
3528 | 3549 |
3529 void GDataFileSystem::AddUploadedFile( | 3550 void GDataFileSystem::AddUploadedFile( |
3530 const FilePath& virtual_dir_path, | 3551 const FilePath& virtual_dir_path, |
3531 DocumentEntry* entry, | 3552 DocumentEntry* entry, |
3532 const FilePath& file_content_path, | 3553 const FilePath& file_content_path, |
3533 GDataCache::FileOperationType cache_operation) { | 3554 GDataCache::FileOperationType cache_operation, |
3555 const base::Closure& callback) { | |
3534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3535 | 3557 |
3558 // 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
| |
3559 // AddUploadedFile() is asynchronous. | |
3560 base::MessageLoopProxy::current()->PostTask( | |
3561 FROM_HERE, | |
3562 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, | |
3563 ui_weak_ptr_, | |
3564 virtual_dir_path, | |
3565 entry, | |
3566 file_content_path, | |
3567 cache_operation, | |
3568 callback)); | |
3569 } | |
3570 | |
3571 void GDataFileSystem::AddUploadedFileOnUIThread( | |
3572 const FilePath& virtual_dir_path, | |
3573 DocumentEntry* entry, | |
3574 const FilePath& file_content_path, | |
3575 GDataCache::FileOperationType cache_operation, | |
3576 const base::Closure& callback) { | |
3577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
3578 DCHECK(!callback.is_null()); | |
3579 | |
3536 if (!entry) { | 3580 if (!entry) { |
3537 NOTREACHED(); | 3581 NOTREACHED(); |
3582 callback.Run(); | |
3538 return; | 3583 return; |
3539 } | 3584 } |
3540 | 3585 |
3541 std::string resource_id; | 3586 std::string resource_id; |
3542 std::string md5; | 3587 std::string md5; |
3543 { | 3588 { |
3544 base::AutoLock lock(lock_); | 3589 base::AutoLock lock(lock_); |
3545 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); | 3590 GDataEntry* dir_entry = GetGDataEntryByPath(virtual_dir_path); |
3546 if (!dir_entry) | 3591 if (!dir_entry) { |
3592 callback.Run(); | |
3547 return; | 3593 return; |
3594 } | |
3548 | 3595 |
3549 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 3596 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
3550 if (!parent_dir) | 3597 if (!parent_dir) { |
3598 callback.Run(); | |
3551 return; | 3599 return; |
3600 } | |
3552 | 3601 |
3553 scoped_ptr<GDataEntry> new_entry( | 3602 scoped_ptr<GDataEntry> new_entry( |
3554 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); | 3603 GDataEntry::FromDocumentEntry(parent_dir, entry, root_.get())); |
3555 if (!new_entry.get()) | 3604 if (!new_entry.get()) { |
3605 callback.Run(); | |
3556 return; | 3606 return; |
3607 } | |
3557 | 3608 |
3558 GDataFile* file = new_entry->AsGDataFile(); | 3609 GDataFile* file = new_entry->AsGDataFile(); |
3559 DCHECK(file); | 3610 DCHECK(file); |
3560 resource_id = file->resource_id(); | 3611 resource_id = file->resource_id(); |
3561 md5 = file->file_md5(); | 3612 md5 = file->file_md5(); |
3562 parent_dir->AddEntry(new_entry.release()); | 3613 parent_dir->AddEntry(new_entry.release()); |
3563 } | 3614 } |
3564 NotifyDirectoryChanged(virtual_dir_path); | 3615 NotifyDirectoryChanged(virtual_dir_path); |
3565 | 3616 |
3566 StoreToCache(resource_id, md5, file_content_path, cache_operation, | 3617 StoreToCache(resource_id, md5, file_content_path, cache_operation, |
3567 CacheOperationCallback()); | 3618 base::Bind(&OnStoreToCacheForAddUploadedFile, |
3619 callback)); | |
3568 } | 3620 } |
3569 | 3621 |
3570 void GDataFileSystem::Observe(int type, | 3622 void GDataFileSystem::Observe(int type, |
3571 const content::NotificationSource& source, | 3623 const content::NotificationSource& source, |
3572 const content::NotificationDetails& details) { | 3624 const content::NotificationDetails& details) { |
3573 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 3625 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
3574 PrefService* pref_service = profile_->GetPrefs(); | 3626 PrefService* pref_service = profile_->GetPrefs(); |
3575 std::string* pref_name = content::Details<std::string>(details).ptr(); | 3627 std::string* pref_name = content::Details<std::string>(details).ptr(); |
3576 if (*pref_name == prefs::kDisableGDataHostedFiles) { | 3628 if (*pref_name == prefs::kDisableGDataHostedFiles) { |
3577 SetHideHostedDocuments( | 3629 SetHideHostedDocuments( |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4152 base::PlatformFileError error, | 4204 base::PlatformFileError error, |
4153 const std::string& resource_id, | 4205 const std::string& resource_id, |
4154 const std::string& md5) { | 4206 const std::string& md5) { |
4155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 4207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
4156 | 4208 |
4157 if (!callback.is_null()) | 4209 if (!callback.is_null()) |
4158 callback.Run(error); | 4210 callback.Run(error); |
4159 } | 4211 } |
4160 | 4212 |
4161 } // namespace gdata | 4213 } // namespace gdata |
OLD | NEW |