Commit 90b35e9d authored by Hajime Hoshi's avatar Hajime Hoshi Committed by Commit Bot

BackForwardCache: Move CanStoreDocumentResult::Reason to BackForwardCacheMetrics file

This is a preparation to take the reason why the document is not cached
and record it.

Bug: 1004676
Change-Id: Ib87b4115566e227441b5b9d546722ef204f5c4b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1820404
Commit-Queue: Hajime Hoshi <hajimehoshi@chromium.org>
Reviewed-by: default avatarArthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699727}
parent 081ba9c9
......@@ -119,19 +119,9 @@ std::string DescribeFeatures(uint64_t blocklisted_features) {
} // namespace
enum class BackForwardCacheImpl::CanStoreDocumentResult::Reason : uint8_t {
kNotMainFrame,
kBackForwardCacheDisabled,
kRelatedActiveContentsExist,
kHTTPStatusNotOK,
kSchemeNotHTTPOrHTTPS,
kLoading,
kWasGrantedMediaAccess,
kBlocklistedFeatures,
kDisableForRenderFrameHostCalled
};
std::string BackForwardCacheImpl::CanStoreDocumentResult::ToString() {
using Reason = BackForwardCacheMetrics::CanNotStoreDocumentReason;
if (can_store)
return "Yes";
......@@ -169,20 +159,23 @@ BackForwardCacheImpl::CanStoreDocumentResult::Yes() {
}
BackForwardCacheImpl::CanStoreDocumentResult
BackForwardCacheImpl::CanStoreDocumentResult::No(Reason reason) {
BackForwardCacheImpl::CanStoreDocumentResult::No(
BackForwardCacheMetrics::CanNotStoreDocumentReason reason) {
return CanStoreDocumentResult(false, reason, 0);
}
BackForwardCacheImpl::CanStoreDocumentResult
BackForwardCacheImpl::CanStoreDocumentResult::NoDueToFeatures(
uint64_t blocklisted_features) {
return CanStoreDocumentResult(false, Reason::kBlocklistedFeatures,
return CanStoreDocumentResult(
false,
BackForwardCacheMetrics::CanNotStoreDocumentReason::kBlocklistedFeatures,
blocklisted_features);
}
BackForwardCacheImpl::CanStoreDocumentResult::CanStoreDocumentResult(
bool can_store,
base::Optional<Reason> reason,
base::Optional<BackForwardCacheMetrics::CanNotStoreDocumentReason> reason,
uint64_t blocklisted_features)
: can_store(can_store),
reason(reason),
......@@ -202,17 +195,19 @@ BackForwardCacheImpl::CanStoreDocument(RenderFrameHostImpl* rfh) {
// Use the BackForwardCache only for the main frame.
if (rfh->GetParent()) {
return CanStoreDocumentResult::No(
CanStoreDocumentResult::Reason::kNotMainFrame);
BackForwardCacheMetrics::CanNotStoreDocumentReason::kNotMainFrame);
}
if (!IsBackForwardCacheEnabled() || is_disabled_for_testing_) {
return CanStoreDocumentResult::No(
CanStoreDocumentResult::Reason::kBackForwardCacheDisabled);
BackForwardCacheMetrics::CanNotStoreDocumentReason::
kBackForwardCacheDisabled);
}
if (rfh->is_back_forward_cache_disallowed()) {
return CanStoreDocumentResult::No(
CanStoreDocumentResult::Reason::kDisableForRenderFrameHostCalled);
BackForwardCacheMetrics::CanNotStoreDocumentReason::
kDisableForRenderFrameHostCalled);
}
// Two pages in the same BrowsingInstance can script each other. When a page
......@@ -226,21 +221,23 @@ BackForwardCacheImpl::CanStoreDocument(RenderFrameHostImpl* rfh) {
// BrowsingInstance.
if (rfh->GetSiteInstance()->GetRelatedActiveContentsCount() != 0) {
return CanStoreDocumentResult::No(
CanStoreDocumentResult::Reason::kRelatedActiveContentsExist);
BackForwardCacheMetrics::CanNotStoreDocumentReason::
kRelatedActiveContentsExist);
}
// Only store documents that have successful http status code.
// Note that for error pages, |last_http_status_code| is equal to 0.
if (rfh->last_http_status_code() != net::HTTP_OK) {
return CanStoreDocumentResult::No(
CanStoreDocumentResult::Reason::kHTTPStatusNotOK);
BackForwardCacheMetrics::CanNotStoreDocumentReason::kHTTPStatusNotOK);
}
// Do store main document with non HTTP/HTTPS URL scheme. In particular, this
// excludes the new tab page.
if (!rfh->GetLastCommittedURL().SchemeIsHTTPOrHTTPS()) {
return CanStoreDocumentResult::No(
CanStoreDocumentResult::Reason::kSchemeNotHTTPOrHTTPS);
BackForwardCacheMetrics::CanNotStoreDocumentReason::
kSchemeNotHTTPOrHTTPS);
}
return CanStoreRenderFrameHost(rfh, GetDisallowedFeatures());
......@@ -257,15 +254,18 @@ BackForwardCacheImpl::CanStoreRenderFrameHost(RenderFrameHostImpl* rfh,
bool is_loading = rfh->frame_tree_node()->IsMainFrame()
? rfh->is_loading()
: rfh->frame_tree_node()->IsLoading();
if (is_loading)
return CanStoreDocumentResult::No(CanStoreDocumentResult::Reason::kLoading);
if (is_loading) {
return CanStoreDocumentResult::No(
BackForwardCacheMetrics::CanNotStoreDocumentReason::kLoading);
}
// If the rfh has ever granted media access, prevent it from entering cache.
// TODO(crbug.com/989379): Consider only blocking when there's an active
// media stream.
if (rfh->was_granted_media_access()) {
return CanStoreDocumentResult::No(
CanStoreDocumentResult::Reason::kWasGrantedMediaAccess);
BackForwardCacheMetrics::CanNotStoreDocumentReason::
kWasGrantedMediaAccess);
}
// Don't cache the page if it uses any disallowed features.
......
......@@ -15,6 +15,7 @@
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "content/browser/frame_host/back_forward_cache_metrics.h"
#include "content/common/content_export.h"
#include "content/public/browser/back_forward_cache.h"
#include "content/public/browser/global_routing_id.h"
......@@ -35,17 +36,16 @@ class CONTENT_EXPORT BackForwardCacheImpl : public BackForwardCache {
~BackForwardCacheImpl();
struct CanStoreDocumentResult {
enum class Reason : uint8_t;
CanStoreDocumentResult(const CanStoreDocumentResult&);
~CanStoreDocumentResult();
bool can_store;
base::Optional<Reason> reason;
base::Optional<BackForwardCacheMetrics::CanNotStoreDocumentReason> reason;
uint64_t blocklisted_features;
static CanStoreDocumentResult Yes();
static CanStoreDocumentResult No(Reason reason);
static CanStoreDocumentResult No(
BackForwardCacheMetrics::CanNotStoreDocumentReason reason);
static CanStoreDocumentResult NoDueToFeatures(uint64_t features);
std::string ToString();
......@@ -53,8 +53,10 @@ class CONTENT_EXPORT BackForwardCacheImpl : public BackForwardCache {
operator bool() const { return can_store; }
private:
CanStoreDocumentResult(bool can_store,
base::Optional<Reason> reason,
CanStoreDocumentResult(
bool can_store,
base::Optional<BackForwardCacheMetrics::CanNotStoreDocumentReason>
reason,
uint64_t blocklisted_features);
};
......
......@@ -30,6 +30,18 @@ class RenderFrameHostImpl;
class BackForwardCacheMetrics
: public base::RefCounted<BackForwardCacheMetrics> {
public:
enum class CanNotStoreDocumentReason : uint8_t {
kNotMainFrame,
kBackForwardCacheDisabled,
kRelatedActiveContentsExist,
kHTTPStatusNotOK,
kSchemeNotHTTPOrHTTPS,
kLoading,
kWasGrantedMediaAccess,
kBlocklistedFeatures,
kDisableForRenderFrameHostCalled
};
// Creates a potential new metrics object for the navigation.
// Note that this object will not be used if the entry we are navigating to
// already has the BackForwardCacheMetrics object (which happens for history
......
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