Commit db8581db authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Chromium LUCI CQ

Add timeout eviction for bfcache in ResponseBodyLoader, URLLoaderClientImpl

Ensures we won't keep a connection too long when deferred for bfcache.
The timeout is determined by the "max_time_to_live" param of
kLoadingTasksUnfreezable, defaulting to 15 seconds.

Bug: 1137682
Change-Id: I66cb229285f40ef12a69734975ac77c820a02082
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569020
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833609}
parent 4b6ec022
......@@ -92,6 +92,7 @@
namespace blink {
constexpr uint32_t ResourceFetcher::kKeepaliveInflightBytesQuota;
constexpr int kDefaultTimeToLiveWhileInBackForwardCacheInSeconds = 15;
namespace {
......@@ -618,6 +619,11 @@ ResourceFetcher::ResourceFetcher(const ResourceFetcherInit& init)
InstanceCounters::IncrementCounter(InstanceCounters::kResourceFetcherCounter);
if (IsMainThread())
MainThreadFetchersSet().insert(this);
back_forward_cache_timeout_ =
base::TimeDelta::FromSeconds(base::GetFieldTrialParamByFeatureAsInt(
blink::features::kLoadingTasksUnfreezable, "max_time_to_live",
kDefaultTimeToLiveWhileInBackForwardCacheInSeconds));
}
ResourceFetcher::~ResourceFetcher() {
......@@ -2094,6 +2100,36 @@ void ResourceFetcher::SetDefersLoading(WebURLLoader::DeferType defers) {
loader->SetDefersLoading(defers);
for (const auto& loader : loaders_)
loader->SetDefersLoading(defers);
if (defers == WebURLLoader::DeferType::kDeferredWithBackForwardCache &&
!back_forward_cache_eviction_timer_.IsRunning()) {
back_forward_cache_eviction_timer_.SetTaskRunner(unfreezable_task_runner_);
back_forward_cache_eviction_timer_.Start(
FROM_HERE, back_forward_cache_timeout_,
base::BindOnce(&ResourceFetcher::OnBackForwardCacheEvictionTimerFired,
weak_ptr_factory_.GetWeakPtr()));
} else if (defers != WebURLLoader::DeferType::kDeferredWithBackForwardCache) {
// The page associated with this ResourceFetcher is no longer in the
// back-forward cache, so stop the back-forward cache eviction timer if it's
// currently running.
if (back_forward_cache_eviction_timer_.IsRunning())
back_forward_cache_eviction_timer_.Stop();
}
}
void ResourceFetcher::OnBackForwardCacheEvictionTimerFired() {
// If all the loaders are keepalive, we don't need to evict.
bool all_loaders_are_keepalive = true;
for (const auto& loader : loaders_) {
all_loaders_are_keepalive &= loader->ShouldBeKeptAliveWhenDetached();
}
for (const auto& loader : non_blocking_loaders_) {
all_loaders_are_keepalive &= loader->ShouldBeKeptAliveWhenDetached();
}
if (all_loaders_are_keepalive)
return;
StopFetching();
EvictFromBackForwardCache();
}
void ResourceFetcher::UpdateAllImageResourcePriorities() {
......
......@@ -415,6 +415,8 @@ class PLATFORM_EXPORT ResourceFetcher
void WarnUnusedPreloads();
void OnBackForwardCacheEvictionTimerFired();
Member<DetachableResourceFetcherProperties> properties_;
Member<ResourceLoadObserver> resource_load_observer_;
Member<FetchContext> context_;
......@@ -468,6 +470,9 @@ class PLATFORM_EXPORT ResourceFetcher
HeapHashSet<Member<SubresourceWebBundle>> subresource_web_bundles_;
base::OneShotTimer back_forward_cache_eviction_timer_;
base::TimeDelta back_forward_cache_timeout_;
// This is not in the bit field below because we want to use AutoReset.
bool is_in_request_resource_ = false;
......@@ -482,6 +487,9 @@ class PLATFORM_EXPORT ResourceFetcher
static constexpr uint32_t kKeepaliveInflightBytesQuota = 64 * 1024;
// NOTE: This must be the last member.
base::WeakPtrFactory<ResourceFetcher> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ResourceFetcher);
};
......
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