Commit 912b6e6e authored by Yuzu Saijo's avatar Yuzu Saijo Committed by Commit Bot

[bfcache] Add is_in_back_forward_cache_ bit in SWPH

This CL adds is_in_back_forward_cache_ bit in ServiceWorkerProviderHost
instead of each time referring to RenderFrameHost's
is_in_back_forward_cache(). Currently, SWPH and RFH have different
lifetime and that is why this bit should be kept in SWPH.
Once SWPH and RFH have the same lifetime, this bit will not be needed
any more.

Change-Id: Ie6dfb3608577f663cb37770e4b77166c8fca7e58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1909059Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Commit-Queue: Yuzu Saijo <yuzus@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715205}
parent 81f442ea
...@@ -318,7 +318,8 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost( ...@@ -318,7 +318,8 @@ ServiceWorkerProviderHost::ServiceWorkerProviderHost(
: base::BindRepeating(&WebContents::FromFrameTreeNodeId, : base::BindRepeating(&WebContents::FromFrameTreeNodeId,
frame_tree_node_id_)), frame_tree_node_id_)),
context_(context), context_(context),
interface_provider_binding_(this) { interface_provider_binding_(this),
is_in_back_forward_cache_(false) {
DCHECK_NE(blink::mojom::ServiceWorkerProviderType::kUnknown, type_); DCHECK_NE(blink::mojom::ServiceWorkerProviderType::kUnknown, type_);
if (type_ == blink::mojom::ServiceWorkerProviderType::kForServiceWorker) { if (type_ == blink::mojom::ServiceWorkerProviderType::kForServiceWorker) {
...@@ -446,7 +447,7 @@ void ServiceWorkerProviderHost::OnSkippedWaiting( ...@@ -446,7 +447,7 @@ void ServiceWorkerProviderHost::OnSkippedWaiting(
return; return;
if (ServiceWorkerContext::IsServiceWorkerOnUIEnabled() && if (ServiceWorkerContext::IsServiceWorkerOnUIEnabled() &&
IsInBackForwardCache()) { IsBackForwardCacheEnabled() && IsInBackForwardCache()) {
// This ServiceWorkerProviderHost is evicted from BackForwardCache in // This ServiceWorkerProviderHost is evicted from BackForwardCache in
// |ActivateWaitingVersion|, but not deleted yet. This can happen because // |ActivateWaitingVersion|, but not deleted yet. This can happen because
// asynchronous eviction and |OnSkippedWaiting| are in the same task. // asynchronous eviction and |OnSkippedWaiting| are in the same task.
...@@ -1604,22 +1605,14 @@ void ServiceWorkerProviderHost::CreateQuicTransportConnector( ...@@ -1604,22 +1605,14 @@ void ServiceWorkerProviderHost::CreateQuicTransportConnector(
bool ServiceWorkerProviderHost::IsInBackForwardCache() const { bool ServiceWorkerProviderHost::IsInBackForwardCache() const {
DCHECK(ServiceWorkerContext::IsServiceWorkerOnUIEnabled()); DCHECK(ServiceWorkerContext::IsServiceWorkerOnUIEnabled());
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!IsBackForwardCacheEnabled()) { return is_in_back_forward_cache_;
// BackForwardCache is not enabled or only enabled for non-ServiceWorker
// controlled pages.
return false;
}
DCHECK_EQ(type_, blink::mojom::ServiceWorkerProviderType::kForWindow);
auto* rfh = RenderFrameHostImpl::FromID(render_process_id_, frame_id_);
if (!rfh)
return false;
return rfh->is_in_back_forward_cache();
} }
void ServiceWorkerProviderHost::EvictFromBackForwardCache() { void ServiceWorkerProviderHost::EvictFromBackForwardCache() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(IsBackForwardCacheEnabled()); DCHECK(IsBackForwardCacheEnabled());
DCHECK_EQ(type_, blink::mojom::ServiceWorkerProviderType::kForWindow); DCHECK_EQ(type_, blink::mojom::ServiceWorkerProviderType::kForWindow);
is_in_back_forward_cache_ = false;
auto* rfh = RenderFrameHostImpl::FromID(render_process_id_, frame_id_); auto* rfh = RenderFrameHostImpl::FromID(render_process_id_, frame_id_);
// |rfh| could be evicted before this function is called. // |rfh| could be evicted before this function is called.
if (!rfh || !rfh->is_in_back_forward_cache()) if (!rfh || !rfh->is_in_back_forward_cache())
...@@ -1635,6 +1628,7 @@ void ServiceWorkerProviderHost::OnEnterBackForwardCache() { ...@@ -1635,6 +1628,7 @@ void ServiceWorkerProviderHost::OnEnterBackForwardCache() {
DCHECK_EQ(type_, blink::mojom::ServiceWorkerProviderType::kForWindow); DCHECK_EQ(type_, blink::mojom::ServiceWorkerProviderType::kForWindow);
if (controller_) if (controller_)
controller_->MoveControlleeToBackForwardCacheMap(client_uuid_); controller_->MoveControlleeToBackForwardCacheMap(client_uuid_);
is_in_back_forward_cache_ = true;
} }
void ServiceWorkerProviderHost::OnRestoreFromBackForwardCache() { void ServiceWorkerProviderHost::OnRestoreFromBackForwardCache() {
...@@ -1643,6 +1637,7 @@ void ServiceWorkerProviderHost::OnRestoreFromBackForwardCache() { ...@@ -1643,6 +1637,7 @@ void ServiceWorkerProviderHost::OnRestoreFromBackForwardCache() {
DCHECK_EQ(type_, blink::mojom::ServiceWorkerProviderType::kForWindow); DCHECK_EQ(type_, blink::mojom::ServiceWorkerProviderType::kForWindow);
if (controller_) if (controller_)
controller_->RestoreControlleeFromBackForwardCacheMap(client_uuid_); controller_->RestoreControlleeFromBackForwardCacheMap(client_uuid_);
is_in_back_forward_cache_ = false;
} }
void ServiceWorkerProviderHost::SetExecutionReady() { void ServiceWorkerProviderHost::SetExecutionReady() {
......
...@@ -788,6 +788,10 @@ class CONTENT_EXPORT ServiceWorkerProviderHost ...@@ -788,6 +788,10 @@ class CONTENT_EXPORT ServiceWorkerProviderHost
base::Optional<network::mojom::CrossOriginEmbedderPolicy> base::Optional<network::mojom::CrossOriginEmbedderPolicy>
cross_origin_embedder_policy_; cross_origin_embedder_policy_;
// TODO(yuzus): This bit will be unnecessary once ServiceWorkerProviderHost
// and RenderFrameHost have the same lifetime.
bool is_in_back_forward_cache_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost);
}; };
......
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