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

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

Issue 10263019: DownloadManagerDelegate::ShouldCompleteDownload(callback) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: " Created 8 years, 8 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 9bdb48aa7bfbe2382d1e3b34056dbf0f6c79d308..4ed59b845dc50b01d0205031ccd303676280fad0 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -639,7 +639,13 @@ void DownloadManagerImpl::MaybeCompleteDownload(DownloadItem* download) {
DCHECK_EQ(1u, history_downloads_.count(download->GetDbHandle()));
// Give the delegate a chance to override.
- if (!delegate_->ShouldCompleteDownload(download))
+ // It's ok to keep re-setting the delegate's |maybe_complete_download| cb as
+ // long as there isn't another call-point trying to set it to a different cb.
+ // TODO(benjhayden): Change the callback to point directly to the item instead
+ // of |this| when DownloadItem supports weak-ptrs.
+ if (!delegate_->ShouldCompleteDownload(download, base::Bind(
+ &DownloadManagerImpl::MaybeCompleteDownloadById,
Randy Smith (Not in Mondays) 2012/05/01 18:21:49 Hmmm. I see why you're doing this. Another alter
benjhayden 2012/05/01 19:00:30 The new routine with its lookup seems safer.
+ this, download->GetId())))
return;
VLOG(20) << __FUNCTION__ << "()" << " executing: download = "
@@ -654,6 +660,12 @@ void DownloadManagerImpl::MaybeCompleteDownload(DownloadItem* download) {
download->OnDownloadCompleting(file_manager_);
}
+void DownloadManagerImpl::MaybeCompleteDownloadById(int download_id) {
+ DownloadItem* download_item = GetActiveDownload(download_id);
+ if (download_item != NULL)
+ MaybeCompleteDownload(download_item);
+}
+
void DownloadManagerImpl::DownloadCompleted(DownloadItem* download) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(download);

Powered by Google App Engine
This is Rietveld 408576698