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 d2d5c9a40b772453413c1faff5b1da338f89c940..33f5005ba54db05866dfcdf6aa8039b3d450830f 100644 |
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc |
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
@@ -3643,7 +3643,7 @@ base::PlatformFileError GDataFileSystem::UpdateFromFeed( |
ApplyFeedFromFileUrlMap( |
is_delta_feed, |
is_delta_feed ? delta_feed_changestamp : root_feed_changestamp, |
- file_map); |
+ &file_map); |
if (should_notify_initial_load) |
NotifyInitialLoadFinished(); |
@@ -3659,7 +3659,7 @@ base::PlatformFileError GDataFileSystem::UpdateFromFeed( |
void GDataFileSystem::ApplyFeedFromFileUrlMap( |
bool is_delta_feed, |
int feed_changestamp, |
- const FileResourceIdMap& file_map) { |
+ FileResourceIdMap* file_map) { |
lock_.AssertAcquired(); |
// Don't send directory content change notification while performing |
// the initial content retrieval. |
@@ -3677,10 +3677,15 @@ void GDataFileSystem::ApplyFeedFromFileUrlMap( |
new GDataRootDirectory); |
// Go through all entires generated by the feed and apply them to the local |
// snapshot of the file system. |
- for (FileResourceIdMap::const_iterator it = file_map.begin(); |
- it != file_map.end(); ++it) { |
+ for (FileResourceIdMap::iterator it = file_map->begin(); |
+ it != file_map->end();) { |
+ // Ensure that the entry is deleted, unless the ownership is explicitly |
+ // transferred by entry.release(). |
scoped_ptr<GDataEntry> entry(it->second); |
DCHECK_EQ(it->first, entry->resource_id()); |
+ // Erase the entry so the deleted entry won't be referenced. |
+ file_map->erase(it++); |
+ |
GDataEntry* old_entry = root_->GetEntryByResourceId(entry->resource_id()); |
GDataDirectory* dest_dir = NULL; |
if (entry->is_deleted()) { // Deleted file/directory. |
@@ -3716,7 +3721,7 @@ void GDataFileSystem::ApplyFeedFromFileUrlMap( |
if (dest_dir->resource_id() != entry->parent_resource_id()) { |
changed_dirs.insert(dest_dir->GetFilePath()); |
dest_dir = FindDirectoryForNewEntry(entry.get(), |
- file_map, |
+ *file_map, |
orphaned_entries_dir.get()); |
} |
DCHECK(dest_dir); |
@@ -3727,7 +3732,7 @@ void GDataFileSystem::ApplyFeedFromFileUrlMap( |
&changed_dirs); |
} else { // Adding a new file. |
dest_dir = FindDirectoryForNewEntry(entry.get(), |
- file_map, |
+ *file_map, |
orphaned_entries_dir.get()); |
DCHECK(dest_dir); |
AddEntryToDirectoryAndCollectChangedDirectories( |
@@ -3744,6 +3749,8 @@ void GDataFileSystem::ApplyFeedFromFileUrlMap( |
changed_dirs.insert(dest_dir->GetFilePath()); |
} |
} |
+ // All entry must be erased from the map. |
+ DCHECK(file_map->empty()); |
if (should_notify_directory_changed) { |
for (std::set<FilePath>::iterator dir_iter = changed_dirs.begin(); |
@@ -3773,9 +3780,10 @@ GDataDirectory* GDataFileSystem::FindDirectoryForNewEntry( |
dir = (find_iter != file_map.end() && |
find_iter->second) ? |
find_iter->second->AsGDataDirectory() : NULL; |
- DVLOG(1) << "Found parent for " << new_entry->file_name() |
- << " in map " << parent_id; |
- if (!dir) { |
+ if (dir) { |
+ DVLOG(1) << "Found parent for " << new_entry->file_name() |
+ << " in file_map " << parent_id; |
+ } else { |
DVLOG(1) << "Adding orphan " << new_entry->GetFilePath().value(); |
dir = orphaned_entries_dir; |
} |