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

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: merge Created 8 years, 7 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 cf9ae3a8ccfa5cc6452b485e79c4b9235746eaaf..0303c3b4c257a71af0f9b8afc756c3f06caca6a1 100644
--- a/content/browser/download/download_manager_impl.cc
+++ b/content/browser/download/download_manager_impl.cc
@@ -542,8 +542,7 @@ void DownloadManagerImpl::OnResponseCompleted(int32 download_id,
DownloadItem* download = active_downloads_[download_id];
download->OnAllDataSaved(size, hash);
-
- download->MaybeCompleteDownload();
+ MaybeCompleteDownload(download);
}
void DownloadManagerImpl::AssertStateConsistent(DownloadItem* download) const {
@@ -634,8 +633,14 @@ void DownloadManagerImpl::MaybeCompleteDownload(DownloadItem* download) {
DCHECK(download->IsPersisted());
DCHECK_EQ(1u, history_downloads_.count(download->GetDbHandle()));
- // Give the delegate a chance to override.
- if (!delegate_->ShouldCompleteDownload(download))
+ // Give the delegate a chance to override. It's ok to keep re-setting the
+ // delegate's |complete_callback| 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,
+ this, download->GetId())))
return;
VLOG(20) << __FUNCTION__ << "()" << " executing: download = "
@@ -647,6 +652,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);
« no previous file with comments | « content/browser/download/download_manager_impl.h ('k') | content/browser/download/download_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698