Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_file_system.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| index 48b3d12a4a28c3ad061c9bc48164ead19bcd7432..3a1c812d5f6e20218013621336dafefd4a4e85f2 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| @@ -2551,6 +2551,101 @@ void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback, |
| callback.Run(base::PLATFORM_FILE_OK, directory_proto.Pass()); |
| } |
| +void GDataFileSystem::RequestDirectoryRefresh( |
| + const FilePath& file_path) { |
| + if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + const bool posted = BrowserThread::PostTask( |
| + BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, |
| + ui_weak_ptr_, |
| + file_path)); |
| + DCHECK(posted); |
| + return; |
| + } |
| + |
| + RequestDirectoryRefreshOnUIThread(file_path); |
| +} |
| + |
| +void GDataFileSystem::RequestDirectoryRefreshOnUIThread( |
| + const FilePath& file_path) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + GDataEntry* entry = GetGDataEntryByPath(file_path); |
| + if (!entry) { |
|
tbarzic
2012/05/18 22:51:12
we may want to check that entry is really a direct
satorux1
2012/05/18 23:42:19
Done.
|
| + LOG(ERROR) << "Directory entry not found: " << file_path.value(); |
| + return; |
| + } |
| + |
| + base::AutoLock lock(lock_); // To access root_. |
| + LoadFeedFromServer(root_->origin(), |
| + 0, // Not delta feed. |
| + 0, // Not used. |
| + true, // multiple feeds |
| + file_path, |
| + std::string(), // No search query |
| + entry->resource_id(), |
| + FindEntryCallback(), // Not used. |
| + base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, |
| + ui_weak_ptr_)); |
| +} |
| + |
| +void GDataFileSystem::OnRequestDirectoryRefresh( |
| + GetDocumentsParams* params, |
| + base::PlatformFileError error) { |
| + DCHECK(params); |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + const FilePath& directory_path = params->search_file_path; |
| + if (error != base::PLATFORM_FILE_OK) { |
| + LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() |
| + << ": " << error; |
| + return; |
| + } |
| + |
| + int unused_delta_feed_changestamp = 0; |
| + int unused_num_regular_files = 0; |
| + int unused_num_hosted_documents = 0; |
| + FileResourceIdMap file_map; |
| + error = FeedToFileResourceMap(*params->feed_list, |
| + &file_map, |
| + &unused_delta_feed_changestamp, |
| + &unused_num_regular_files, |
| + &unused_num_hosted_documents); |
| + if (error != base::PLATFORM_FILE_OK) { |
| + LOG(ERROR) << "Failed to convert feed: " << directory_path.value() |
| + << ": " << error; |
| + return; |
| + } |
| + |
| + base::AutoLock lock(lock_); // To access root_. |
| + |
| + GDataEntry* directory_entry = root_->GetEntryByResourceId( |
| + params->directory_resource_id); |
| + if (!directory_entry || !directory_entry->AsGDataDirectory()) { |
| + LOG(ERROR) << "Directory entry is gone: " << directory_path.value() |
| + << ": " << params->directory_resource_id; |
| + return; |
| + } |
| + GDataDirectory* directory = directory_entry->AsGDataDirectory(); |
| + |
| + // Remove the existing files. |
| + directory->RemoveChildFiles(); |
| + // Go through all entires generated by the feed and add files. |
| + for (FileResourceIdMap::const_iterator it = file_map.begin(); |
| + it != file_map.end(); ++it) { |
| + scoped_ptr<GDataEntry> entry(it->second); |
| + // Skip if it's not a file (i.e. directory). |
| + if (!entry->AsGDataFile()) |
| + continue; |
| + directory->AddEntry(entry.release()); |
| + } |
| + |
| + NotifyDirectoryChanged(directory_path); |
| + DVLOG(1) << "Directory refreshed: " << directory_path.value(); |
| +} |
| + |
| bool GDataFileSystem::GetFileInfoByPath( |
| const FilePath& file_path, GDataFileProperties* properties) { |
| DCHECK(properties); |