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