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

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

Issue 10704026: Reland DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 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
diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
index 7570379eae814d624bfda65aab7759e8e965baef..472531f5276152bd083f7dbff6b5c65212e428b4 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -317,13 +317,9 @@ void DownloadManagerImpl::Shutdown() {
// 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_to_delete);
+ STLDeleteValues(&downloads_);
+ downloads_.clear();
// We'll have nothing more to report to the observers after this point.
observers_.Clear();
@@ -636,13 +632,6 @@ void DownloadManagerImpl::OnResponseCompleted(int32 download_id,
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();
@@ -801,20 +790,16 @@ int DownloadManagerImpl::RemoveDownloadItems(
// 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);
- downloads_.erase(download->GetId());
+ int32 download_id = download->GetId();
+ delete download;
+ downloads_.erase(download_id);
}
-
- // Tell observers to refresh their views.
NotifyModelChanged();
-
- // 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;
+ return static_cast<int>(pending_deletes.size());
}
void DownloadManagerImpl::DownloadRemoved(DownloadItemImpl* download) {
@@ -841,8 +826,6 @@ int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin,
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();
@@ -853,6 +836,7 @@ int DownloadManagerImpl::RemoveDownloadsBetween(base::Time remove_begin,
(remove_end.is_null() || download->GetStartTime() < remove_end) &&
(download->IsComplete() || download->IsCancelled())) {
AssertStateConsistent(download);
+ download->NotifyRemoved();
pending_deletes.push_back(download);
}
}

Powered by Google App Engine
This is Rietveld 408576698