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 5e0da2583ac100fb23aebd4e7aff735afd78b82e..cfc604603d4cf17a80446da0a6455d925d9e69ad 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
| @@ -2206,14 +2206,14 @@ void GDataFileSystem::OnGetDocumentEntry(const FilePath& cache_file_path, |
| scoped_ptr<base::Value> data) { |
| base::PlatformFileError error = GDataToPlatformError(status); |
| - GDataEntry* fresh_entry = NULL; |
| + scoped_ptr<GDataEntry> fresh_entry; |
| if (error == base::PLATFORM_FILE_OK) { |
| scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); |
| if (doc_entry.get()) { |
| - fresh_entry = |
| - GDataEntry::FromDocumentEntry(NULL, doc_entry.get(), root_.get()); |
| + fresh_entry.reset( |
| + GDataEntry::FromDocumentEntry(NULL, doc_entry.get(), root_.get())); |
| } |
| - if (!fresh_entry || !fresh_entry->AsGDataFile()) { |
| + if (!fresh_entry.get() || !fresh_entry->AsGDataFile()) { |
| LOG(ERROR) << "Got invalid entry from server for " << params.resource_id; |
| error = base::PLATFORM_FILE_ERROR_FAILED; |
| } |
| @@ -2234,17 +2234,8 @@ void GDataFileSystem::OnGetDocumentEntry(const FilePath& cache_file_path, |
| { |
| base::AutoLock lock(lock_); // We're accessing the root. |
| - GDataEntry* old_entry = root_->GetEntryByResourceId(params.resource_id); |
| - GDataDirectory* entry_parent = old_entry ? old_entry->parent() : NULL; |
| - |
| - if (entry_parent) { |
| - DCHECK_EQ(fresh_entry->resource_id(), old_entry->resource_id()); |
| - DCHECK(fresh_entry->AsGDataFile()); |
| - DCHECK(old_entry->AsGDataFile()); |
| - |
| - entry_parent->RemoveEntry(old_entry); |
| - entry_parent->AddEntry(fresh_entry); |
| - } |
| + DCHECK_EQ(params.resource_id, fresh_entry->resource_id()); |
| + root_->RefreshEntry(fresh_entry.Pass()); |
| } |
| bool* has_enough_space = new bool(false); |
| @@ -2904,48 +2895,55 @@ void GDataFileSystem::OnCreateDirectoryCompleted( |
| void GDataFileSystem::OnSearch(const ReadDirectoryCallback& callback, |
| GetDocumentsParams* params, |
| base::PlatformFileError error) { |
| + if (error != base::PLATFORM_FILE_OK) { |
| + if (!callback.is_null()) |
| + callback.Run(error, scoped_ptr<GDataDirectoryProto>()); |
| + return; |
| + } |
| + |
| + // We will refresh values in root for entries received in the feed. |
| + base::AutoLock lock(lock_); |
| + |
| // The search results will be returned using virtual directory. |
| // The directory is not really part of the file system, so it has no parent or |
| // root. |
| scoped_ptr<GDataDirectory> search_dir(new GDataDirectory(NULL, NULL)); |
| - base::AutoLock lock(lock_); |
| - |
| - int delta_feed_changestamp = 0; |
| - int num_regular_files = 0; |
| - int num_hosted_documents = 0; |
| - FileResourceIdMap file_map; |
| - if (error == base::PLATFORM_FILE_OK) { |
| - error = FeedToFileResourceMap(*params->feed_list, |
| - &file_map, |
| - &delta_feed_changestamp, |
| - &num_regular_files, |
| - &num_hosted_documents); |
| - } |
| + DCHECK_EQ(1u, params->feed_list->size()); |
| + DocumentFeed* feed = params->feed_list->at(0); |
| - if (error == base::PLATFORM_FILE_OK) { |
| - std::set<FilePath> ignored; |
| + // Go through all entires generated by the feed and add them to the search |
| + // result directory. |
| + for (ScopedVector<DocumentEntry>::const_iterator iter = |
| + feed->entries().begin(); |
| + iter != feed->entries().end(); ++iter) { |
|
satorux1
2012/05/31 15:56:01
nit: you can do
for (size_t i = 0; i < feed->ent
tbarzic
2012/05/31 19:25:17
I can't say they're my favorites..
Done.
|
| + DocumentEntry* doc = *iter; |
| + GDataEntry* entry = GDataEntry::FromDocumentEntry(NULL, doc, root_.get()); |
| - // Go through all entires generated by the feed and add them to the search |
| - // result directory. |
| - for (FileResourceIdMap::const_iterator it = file_map.begin(); |
| - it != file_map.end(); ++it) { |
| - scoped_ptr<GDataEntry> entry(it->second); |
| - DCHECK_EQ(it->first, entry->resource_id()); |
| - DCHECK(!entry->is_deleted()); |
| + if (!entry) |
| + continue; |
| - entry->set_title(entry->resource_id() + "." + entry->title()); |
| + DCHECK_EQ(doc->resource_id(), entry->resource_id()); |
| + DCHECK(!entry->is_deleted()); |
| - search_dir->AddEntry(entry.release()); |
| + if (entry->AsGDataFile()) { |
| + scoped_ptr<GDataEntry> entry_to_save( |
| + GDataEntry::FromDocumentEntry(NULL, doc, root_.get())); |
|
satorux1
2012/05/31 15:56:01
Could you add some comment why you have to create
tbarzic
2012/05/31 19:25:17
Done.
|
| + DCHECK(entry_to_save.get()); |
| + DCHECK_EQ(entry->resource_id(), entry_to_save->resource_id()); |
| + root_->RefreshEntry(entry_to_save.Pass()); |
| } |
| + |
| + entry->set_title(entry->resource_id() + "." + entry->title()); |
| + |
| + search_dir->AddEntry(entry); |
| } |
| scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto); |
| search_dir->ToProto(directory_proto.get()); |
| - if (!callback.is_null()) { |
| + if (!callback.is_null()) |
| callback.Run(error, directory_proto.Pass()); |
| - } |
| } |
| void GDataFileSystem::SearchAsync(const std::string& search_query, |