Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1058)

Unified Diff: content/browser/download/download_manager_impl.cc

Issue 10837125: Revert 149794 - DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1228/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_manager_impl.cc
===================================================================
--- content/browser/download/download_manager_impl.cc (revision 150095)
+++ content/browser/download/download_manager_impl.cc (working copy)
@@ -321,9 +321,13 @@
// and all in progress downloads have been cancelled. We can now delete
// anything left.
+ // Copy downloads_ to separate container so as not to set off checks
+ // in DownloadItem destruction.
+ DownloadMap downloads_to_delete;
+ downloads_to_delete.swap(downloads_);
+
active_downloads_.clear();
- STLDeleteValues(&downloads_);
- downloads_.clear();
+ STLDeleteValues(&downloads_to_delete);
// We'll have nothing more to report to the observers after this point.
observers_.Clear();
@@ -613,6 +617,13 @@
void DownloadManagerImpl::AssertStateConsistent(
DownloadItemImpl* download) const {
+ if (download->GetState() == DownloadItem::REMOVING) {
+ DCHECK(!ContainsKey(downloads_, download->GetId()));
+ DCHECK(!ContainsKey(active_downloads_, download->GetId()));
+ return;
+ }
+
+ // Should be in downloads_ if we're not REMOVING.
CHECK(ContainsKey(downloads_, download->GetId()));
int64 state = download->GetState();
@@ -771,16 +782,20 @@
// Delete from internal maps.
for (DownloadItemImplVector::const_iterator it = pending_deletes.begin();
- it != pending_deletes.end();
- ++it) {
+ it != pending_deletes.end();
+ ++it) {
DownloadItemImpl* download = *it;
DCHECK(download);
- int32 download_id = download->GetId();
- delete download;
- downloads_.erase(download_id);
+ downloads_.erase(download->GetId());
}
+
+ // Tell observers to refresh their views.
NotifyModelChanged();
- return static_cast<int>(pending_deletes.size());
+
+ // Delete the download items themselves.
+ const int num_deleted = static_cast<int>(pending_deletes.size());
+ STLDeleteContainerPointers(pending_deletes.begin(), pending_deletes.end());
+ return num_deleted;
}
void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
@@ -807,6 +822,8 @@
if (delegate_)
delegate_->RemoveItemsFromPersistentStoreBetween(remove_begin, remove_end);
+ // All downloads visible to the user will be in the history,
+ // so scan that map.
DownloadItemImplVector pending_deletes;
for (DownloadMap::const_iterator it = downloads_.begin();
it != downloads_.end();
@@ -817,7 +834,6 @@
(remove_end.is_null() || download->GetStartTime() < remove_end) &&
(download->IsComplete() || download->IsCancelled())) {
AssertStateConsistent(download);
- download->NotifyRemoved();
pending_deletes.push_back(download);
}
}
« no previous file with comments | « content/browser/download/download_item_impl_unittest.cc ('k') | content/browser/download/drag_download_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698