forked from mirrors/gecko-dev
Bug 1918028 - avoid potential future hang when cancelling Content Analysis WARN response a=diannaS
Don't cache canceled CA results, as this can cause particular problem with WARN responses, which shouldn't be in the cache. Original Revision: https://phabricator.services.mozilla.com/D221880 Differential Revision: https://phabricator.services.mozilla.com/D222620
This commit is contained in:
parent
2577d7d689
commit
040ea06307
1 changed files with 37 additions and 4 deletions
|
|
@ -1089,9 +1089,15 @@ ContentAnalysis::TestOnlySetCACmdLineArg(bool aVal) {
|
|||
|
||||
nsresult ContentAnalysis::CancelWithError(nsCString aRequestToken,
|
||||
nsresult aResult) {
|
||||
LOGD(
|
||||
"ContentAnalysis::CancelWithError dispatching to main thread for "
|
||||
"request %s",
|
||||
aRequestToken.get());
|
||||
return NS_DispatchToMainThread(NS_NewCancelableRunnableFunction(
|
||||
"ContentAnalysis::CancelWithError",
|
||||
[aResult, aRequestToken = std::move(aRequestToken)]() mutable {
|
||||
LOGD("ContentAnalysis::CancelWithError on main thread for request %s",
|
||||
aRequestToken.get());
|
||||
RefPtr<ContentAnalysis> owner = GetContentAnalysisFromService();
|
||||
if (!owner) {
|
||||
// May be shutting down
|
||||
|
|
@ -1371,6 +1377,7 @@ void ContentAnalysis::DoAnalyzeRequest(
|
|||
"ContentAnalysis::RunAnalyzeRequestTask::HandleResponse",
|
||||
[pbResponse = std::move(pbResponse),
|
||||
aRequestToCache = std::move(aRequestToCache)]() mutable {
|
||||
LOGD("RunAnalyzeRequestTask on main thread about to send response");
|
||||
RefPtr<ContentAnalysis> owner = GetContentAnalysisFromService();
|
||||
if (!owner) {
|
||||
// May be shutting down
|
||||
|
|
@ -1384,11 +1391,33 @@ void ContentAnalysis::DoAnalyzeRequest(
|
|||
return;
|
||||
}
|
||||
if (aRequestToCache) {
|
||||
[&]() {
|
||||
nsIContentAnalysisResponse::Action action;
|
||||
if (NS_SUCCEEDED(response->GetAction(&action))) {
|
||||
if (NS_FAILED(response->GetAction(&action))) {
|
||||
LOGE("Content analysis couldn't get action from response!");
|
||||
return;
|
||||
}
|
||||
nsCString responseRequestToken;
|
||||
nsresult requestRv =
|
||||
response->GetRequestToken(responseRequestToken);
|
||||
if (NS_FAILED(requestRv)) {
|
||||
LOGE(
|
||||
"Content analysis couldn't get request token from response!");
|
||||
return;
|
||||
}
|
||||
{
|
||||
auto callbackMap = owner->mCallbackMap.Lock();
|
||||
auto maybeCallbackData =
|
||||
callbackMap->MaybeGet(responseRequestToken);
|
||||
// This prevents caching cancelled results to avoid issues like
|
||||
// bug 1918028.
|
||||
if (maybeCallbackData.isSome() &&
|
||||
!maybeCallbackData->Canceled()) {
|
||||
owner->mCachedData.SetData(std::move(aRequestToCache), action);
|
||||
}
|
||||
}
|
||||
}();
|
||||
}
|
||||
owner->IssueResponse(response);
|
||||
}));
|
||||
}
|
||||
|
|
@ -1611,6 +1640,10 @@ NS_IMETHODIMP
|
|||
ContentAnalysis::RespondToWarnDialog(const nsACString& aRequestToken,
|
||||
bool aAllowContent) {
|
||||
nsCString requestToken(aRequestToken);
|
||||
LOGD(
|
||||
"ContentAnalysis::RespondToWarnDialog dispatching to main thread for "
|
||||
"request %s",
|
||||
requestToken.get());
|
||||
NS_DispatchToMainThread(NS_NewCancelableRunnableFunction(
|
||||
"RespondToWarnDialog",
|
||||
[aAllowContent, requestToken = std::move(requestToken)]() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue