| 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..2e3167bf6a8481085cff812e9f1235fd05711e65 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,10 @@ 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());
|
| + scoped_ptr<GDataFile> fresh_entry_as_file(
|
| + fresh_entry.release()->AsGDataFile());
|
| + root_->RefreshFile(fresh_entry_as_file.Pass());
|
| }
|
|
|
| bool* has_enough_space = new bool(false);
|
| @@ -2904,48 +2897,56 @@ 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_);
|
| + DCHECK_EQ(1u, params->feed_list->size());
|
| + DocumentFeed* feed = params->feed_list->at(0);
|
|
|
| - 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);
|
| - }
|
| + // Go through all entires generated by the feed and add them to the search
|
| + // result directory.
|
| + for (size_t i = 0; i < feed->entries().size(); ++i){
|
| + DocumentEntry* doc = feed->entries()->at(i);
|
| + GDataEntry* entry = GDataEntry::FromDocumentEntry(NULL, doc, root_.get());
|
|
|
| - if (error == base::PLATFORM_FILE_OK) {
|
| - std::set<FilePath> ignored;
|
| + if (!entry)
|
| + continue;
|
|
|
| - // 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());
|
| + DCHECK_EQ(doc->resource_id(), entry->resource_id());
|
| + DCHECK(!entry->is_deleted());
|
| +
|
| + if (entry->AsGDataFile()) {
|
| + // We have to make a new copy of the entry because |search_dir| will later
|
| + // take ownership of |entry|.
|
| + GDataEntry* entry_to_save =
|
| + GDataEntry::FromDocumentEntry(NULL, doc, root_.get());
|
| + DCHECK(entry_to_save && entry_to_save->AsGDataFile());
|
| + DCHECK_EQ(entry->resource_id(), entry_to_save->resource_id());
|
| + scoped_ptr<GDataFile>entry_to_save_as_file(entry_to_save->AsGDataFile());
|
| + root_->RefreshFile(entry_to_save_as_file.Pass());
|
| + }
|
|
|
| - entry->set_title(entry->resource_id() + "." + entry->title());
|
| + entry->set_title(entry->resource_id() + "." + entry->title());
|
|
|
| - search_dir->AddEntry(entry.release());
|
| - }
|
| + 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,
|
|
|