Commit f162ebbf authored by Min Qin's avatar Min Qin Committed by Commit Bot

Early return if DownloadResponseHandler::OnComplete() has been called before

In redirection error cases, we call DownloadResponsehandler::OnComplete().
And when connection is closed, OnComplete() could get called again, causing
an NPE exception.
This CL fixes the issue by early return on the 2nd OnComplete() call.

BUG=890525

Change-Id: I2222a7980d7f53ff885b66b96ab2bdd1d963db75
Reviewed-on: https://chromium-review.googlesource.com/1255882Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595667}
parent a973d4b0
......@@ -74,6 +74,7 @@ DownloadResponseHandler::DownloadResponseHandler(
download_source_(download_source),
has_strong_validators_(false),
is_partial_request_(save_info_->offset > 0),
completed_(false),
abort_reason_(DOWNLOAD_INTERRUPT_REASON_NONE) {
if (!is_parallel_request) {
RecordDownloadCountWithSource(UNTHROTTLED_COUNT, download_source);
......@@ -201,6 +202,10 @@ void DownloadResponseHandler::OnStartLoadingResponseBody(
void DownloadResponseHandler::OnComplete(
const network::URLLoaderCompletionStatus& status) {
if (completed_)
return;
completed_ = true;
DownloadInterruptReason reason = HandleRequestCompletionStatus(
static_cast<net::Error>(status.error_code), has_strong_validators_,
cert_status_, abort_reason_);
......
......@@ -93,6 +93,7 @@ class COMPONENTS_DOWNLOAD_EXPORT DownloadResponseHandler
bool has_strong_validators_;
GURL origin_;
bool is_partial_request_;
bool completed_;
// The abort reason if this class decides to block the download.
DownloadInterruptReason abort_reason_;
......
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