Commit c588ee90 authored by Min Qin's avatar Min Qin Committed by Chromium LUCI CQ

Post a task when invoking CheckDownloadCallback

Currently this could cause an reentrance issues. Destroying a download
will immediately invoke the callback, and the callback will immediately
getting the destroyed DownloadItem.
Posting a task should solve the issue.

BUG=1152451

Change-Id: I8e6f5d64edad2593fa340ab876ebfd858b2a4699
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2561341
Commit-Queue: Min Qin <qinmin@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833635}
parent d9b3351f
......@@ -224,7 +224,9 @@ void CheckClientDownloadRequestBase::FinishRequest(
if (settings.has_value()) {
UploadBinary(reason, std::move(settings.value()));
} else {
std::move(callback_).Run(result);
// Post a task to avoid reentrance issue. http://crbug.com//1152451.
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE, base::BindOnce(std::move(callback_), result));
}
UMA_HISTOGRAM_ENUMERATION("SBClientDownload.CheckDownloadStats", reason,
......
......@@ -2414,9 +2414,13 @@ TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) {
// notification.
}
// Result won't be immediately available as it is being posted.
EXPECT_FALSE(has_result_);
base::RunLoop().RunUntilIdle();
// When download is destroyed, no need to check for client download request
// result.
EXPECT_TRUE(has_result_);
EXPECT_TRUE(IsResult(DownloadCheckResult::UNKNOWN));
EXPECT_FALSE(HasClientDownloadRequest());
}
......@@ -3430,6 +3434,10 @@ TEST_F(DownloadProtectionServiceTest,
std::move(item),
base::BindOnce(&DownloadProtectionServiceTest::SyncCheckDoneCallback,
base::Unretained(this)));
// Result won't be immediately available, wait for the response to
// be posted.
EXPECT_FALSE(has_result_);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(IsResult(DownloadCheckResult::WHITELISTED_BY_POLICY));
}
......
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