Commit 6f157120 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Cancel keepalive request which has received response when detached

A request with keepalive set should continue working after the
associated FetchContext is detached, but no one cares its status after
it gets response. With this change such requests will be cancelled.

Bug: 764589
Change-Id: I9a5b9de6d658311bab27ab85fee3dea406457488
Reviewed-on: https://chromium-review.googlesource.com/885702Reviewed-by: default avatarTakeshi Yoshino <tyoshino@chromium.org>
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532365}
parent ada8b3f1
...@@ -1778,13 +1778,13 @@ void ResourceFetcher::StopFetchingInternal(StopFetchingTarget target) { ...@@ -1778,13 +1778,13 @@ void ResourceFetcher::StopFetchingInternal(StopFetchingTarget target) {
HeapVector<Member<ResourceLoader>> loaders_to_cancel; HeapVector<Member<ResourceLoader>> loaders_to_cancel;
for (const auto& loader : non_blocking_loaders_) { for (const auto& loader : non_blocking_loaders_) {
if (target == StopFetchingTarget::kIncludingKeepaliveLoaders || if (target == StopFetchingTarget::kIncludingKeepaliveLoaders ||
!loader->GetKeepalive()) { !loader->ShouldBeKeptAliveWhenDetached()) {
loaders_to_cancel.push_back(loader); loaders_to_cancel.push_back(loader);
} }
} }
for (const auto& loader : loaders_) { for (const auto& loader : loaders_) {
if (target == StopFetchingTarget::kIncludingKeepaliveLoaders || if (target == StopFetchingTarget::kIncludingKeepaliveLoaders ||
!loader->GetKeepalive()) { !loader->ShouldBeKeptAliveWhenDetached()) {
loaders_to_cancel.push_back(loader); loaders_to_cancel.push_back(loader);
} }
} }
......
...@@ -483,6 +483,13 @@ void ResourceLoader::DidReceiveResponse( ...@@ -483,6 +483,13 @@ void ResourceLoader::DidReceiveResponse(
std::unique_ptr<WebDataConsumerHandle> handle) { std::unique_ptr<WebDataConsumerHandle> handle) {
DCHECK(!web_url_response.IsNull()); DCHECK(!web_url_response.IsNull());
if (Context().IsDetached()) {
// If the fetch context is already detached, we don't need further signals,
// so let's cancel the request.
HandleError(ResourceError::CancelledError(web_url_response.Url()));
return;
}
Resource::Type resource_type = resource_->GetType(); Resource::Type resource_type = resource_->GetType();
const ResourceRequest& initial_request = resource_->GetResourceRequest(); const ResourceRequest& initial_request = resource_->GetResourceRequest();
...@@ -763,8 +770,9 @@ void ResourceLoader::ActivateCacheAwareLoadingIfNeeded( ...@@ -763,8 +770,9 @@ void ResourceLoader::ActivateCacheAwareLoadingIfNeeded(
is_cache_aware_loading_activated_ = true; is_cache_aware_loading_activated_ = true;
} }
bool ResourceLoader::GetKeepalive() const { bool ResourceLoader::ShouldBeKeptAliveWhenDetached() const {
return resource_->GetResourceRequest().GetKeepalive(); return resource_->GetResourceRequest().GetKeepalive() &&
resource_->GetResponse().IsNull();
} }
} // namespace blink } // namespace blink
...@@ -84,7 +84,7 @@ class PLATFORM_EXPORT ResourceLoader final ...@@ -84,7 +84,7 @@ class PLATFORM_EXPORT ResourceLoader final
} }
ResourceFetcher* Fetcher() { return fetcher_; } ResourceFetcher* Fetcher() { return fetcher_; }
bool GetKeepalive() const; bool ShouldBeKeptAliveWhenDetached() const;
// WebURLLoaderClient // WebURLLoaderClient
// //
......
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