Commit 7313243e authored by Min Qin's avatar Min Qin Committed by Commit Bot

Remove CheckClientDownloadRequest from DownloadItem observer list on destruction

DownloadProtectionService::SetEnabled(false) could destroy all
CheckClientDownloadRequests before they are finished. If that happens,
we need to remove the latter from all the DownloadItems' observer list
they are observing. Otherwise, DownloadItemImpl dtor could hit NPE due
to these deleted observers.

BUG=906004

Change-Id: Ic4971c0e95087315433ca30ad5a56684abc112e3
Reviewed-on: https://chromium-review.googlesource.com/c/1359470Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613754}
parent becd2587
......@@ -369,6 +369,8 @@ bool CheckClientDownloadRequest::IsSupportedDownload(
CheckClientDownloadRequest::~CheckClientDownloadRequest() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (item_)
item_->RemoveObserver(this);
weakptr_factory_.InvalidateWeakPtrs();
}
......@@ -806,6 +808,7 @@ void CheckClientDownloadRequest::FinishRequest(
if (reason != REASON_DOWNLOAD_DESTROYED)
callback_.Run(result);
item_->RemoveObserver(this);
item_ = nullptr;
service_->RequestFinished(this);
// DownloadProtectionService::RequestFinished may delete us.
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment