| 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 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3520 } | 3520 } |
| 3521 | 3521 |
| 3522 void GDataFileSystem::AddUploadedFileOnUIThread( | 3522 void GDataFileSystem::AddUploadedFileOnUIThread( |
| 3523 UploadMode upload_mode, | 3523 UploadMode upload_mode, |
| 3524 const FilePath& virtual_dir_path, | 3524 const FilePath& virtual_dir_path, |
| 3525 scoped_ptr<DocumentEntry> entry, | 3525 scoped_ptr<DocumentEntry> entry, |
| 3526 const FilePath& file_content_path, | 3526 const FilePath& file_content_path, |
| 3527 GDataCache::FileOperationType cache_operation, | 3527 GDataCache::FileOperationType cache_operation, |
| 3528 const base::Closure& callback) { | 3528 const base::Closure& callback) { |
| 3529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3530 DCHECK(!callback.is_null()); | 3530 |
| 3531 // ScopedClosureRunner ensures that the specified callback is always invoked |
| 3532 // upon return or passed on. |
| 3533 base::ScopedClosureRunner callback_runner(callback); |
| 3531 | 3534 |
| 3532 if (!entry.get()) { | 3535 if (!entry.get()) { |
| 3533 NOTREACHED(); | 3536 NOTREACHED(); |
| 3534 callback.Run(); | |
| 3535 return; | 3537 return; |
| 3536 } | 3538 } |
| 3537 | 3539 |
| 3538 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync( | 3540 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync( |
| 3539 virtual_dir_path); | 3541 virtual_dir_path); |
| 3540 if (!dir_entry) { | 3542 if (!dir_entry) |
| 3541 callback.Run(); | |
| 3542 return; | 3543 return; |
| 3543 } | |
| 3544 | 3544 |
| 3545 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 3545 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
| 3546 if (!parent_dir) { | 3546 if (!parent_dir) |
| 3547 callback.Run(); | |
| 3548 return; | 3547 return; |
| 3549 } | |
| 3550 | 3548 |
| 3551 scoped_ptr<GDataEntry> new_entry( | 3549 scoped_ptr<GDataEntry> new_entry( |
| 3552 GDataEntry::FromDocumentEntry( | 3550 GDataEntry::FromDocumentEntry( |
| 3553 parent_dir, entry.get(), directory_service_.get())); | 3551 parent_dir, entry.get(), directory_service_.get())); |
| 3554 if (!new_entry.get()) { | 3552 if (!new_entry.get()) |
| 3555 callback.Run(); | |
| 3556 return; | 3553 return; |
| 3557 } | |
| 3558 | 3554 |
| 3559 if (upload_mode == UPLOAD_EXISTING_FILE) { | 3555 if (upload_mode == UPLOAD_EXISTING_FILE) { |
| 3560 // Remove an existing entry, which should be present. | 3556 // Remove an existing entry, which should be present. |
| 3561 const std::string& resource_id = new_entry->resource_id(); | 3557 const std::string& resource_id = new_entry->resource_id(); |
| 3562 directory_service_->GetEntryByResourceIdAsync(resource_id, | 3558 directory_service_->GetEntryByResourceIdAsync(resource_id, |
| 3563 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); | 3559 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); |
| 3564 } | 3560 } |
| 3565 | 3561 |
| 3566 GDataFile* file = new_entry->AsGDataFile(); | 3562 GDataFile* file = new_entry->AsGDataFile(); |
| 3567 DCHECK(file); | 3563 DCHECK(file); |
| 3568 const std::string& resource_id = file->resource_id(); | 3564 const std::string& resource_id = file->resource_id(); |
| 3569 const std::string& md5 = file->file_md5(); | 3565 const std::string& md5 = file->file_md5(); |
| 3570 parent_dir->AddEntry(new_entry.release()); | 3566 parent_dir->AddEntry(new_entry.release()); |
| 3571 | 3567 |
| 3572 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 3568 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, |
| 3573 OnDirectoryChanged(virtual_dir_path)); | 3569 OnDirectoryChanged(virtual_dir_path)); |
| 3574 | 3570 |
| 3575 if (upload_mode == UPLOAD_NEW_FILE) { | 3571 if (upload_mode == UPLOAD_NEW_FILE) { |
| 3576 // Add the file to the cache if we have uploaded a new file. | 3572 // Add the file to the cache if we have uploaded a new file. |
| 3577 cache_->StoreOnUIThread(resource_id, | 3573 cache_->StoreOnUIThread(resource_id, |
| 3578 md5, | 3574 md5, |
| 3579 file_content_path, | 3575 file_content_path, |
| 3580 cache_operation, | 3576 cache_operation, |
| 3581 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 3577 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
| 3582 callback)); | 3578 callback_runner.Release())); |
| 3583 } else if (upload_mode == UPLOAD_EXISTING_FILE) { | 3579 } else if (upload_mode == UPLOAD_EXISTING_FILE) { |
| 3584 // Clear the dirty bit if we have updated an existing file. | 3580 // Clear the dirty bit if we have updated an existing file. |
| 3585 cache_->ClearDirtyOnUIThread(resource_id, | 3581 cache_->ClearDirtyOnUIThread(resource_id, |
| 3586 md5, | 3582 md5, |
| 3587 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 3583 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
| 3588 callback)); | 3584 callback_runner.Release())); |
| 3589 } else { | 3585 } else { |
| 3590 NOTREACHED() << "Unexpected upload mode: " << upload_mode; | 3586 NOTREACHED() << "Unexpected upload mode: " << upload_mode; |
| 3591 } | 3587 } |
| 3592 } | 3588 } |
| 3593 | 3589 |
| 3594 void GDataFileSystem::Observe(int type, | 3590 void GDataFileSystem::Observe(int type, |
| 3595 const content::NotificationSource& source, | 3591 const content::NotificationSource& source, |
| 3596 const content::NotificationDetails& details) { | 3592 const content::NotificationDetails& details) { |
| 3597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3598 | 3594 |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4051 } | 4047 } |
| 4052 | 4048 |
| 4053 PlatformFileInfoProto entry_file_info; | 4049 PlatformFileInfoProto entry_file_info; |
| 4054 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 4050 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 4055 *entry_proto->mutable_file_info() = entry_file_info; | 4051 *entry_proto->mutable_file_info() = entry_file_info; |
| 4056 if (!callback.is_null()) | 4052 if (!callback.is_null()) |
| 4057 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 4053 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 4058 } | 4054 } |
| 4059 | 4055 |
| 4060 } // namespace gdata | 4056 } // namespace gdata |
| OLD | NEW |