#include "content/browser/preloading/prerender/prerender_host_registry.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/memory_pressure_monitor.h"
#include "base/metrics/field_trial_params.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/system/sys_info.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "content/browser/devtools/devtools_instrumentation.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h"
#include "content/browser/preloading/preloading_data_impl.h"
#include "content/browser/preloading/preloading_trigger_type_impl.h"
#include "content/browser/preloading/prerender/devtools_prerender_attempt.h"
#include "content/browser/preloading/prerender/prerender_features.h"
#include "content/browser/preloading/prerender/prerender_final_status.h"
#include "content/browser/preloading/prerender/prerender_metrics.h"
#include "content/browser/preloading/prerender/prerender_navigation_utils.h"
#include "content/browser/preloading/prerender/prerender_new_tab_handle.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/browser/renderer_host/navigation_request.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/frame.mojom.h"
#include "content/public/browser/client_hints_controller_delegate.h"
#include "content/public/browser/preloading.h"
#include "content/public/browser/preloading_data.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/visibility.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "net/base/load_flags.h"
#include "services/network/public/cpp/network_quality_tracker.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"
namespace content {
namespace {
bool IsBackground(Visibility visibility) { … }
bool IsAllowedToActivateInBackgroundForTesting() { … }
bool DeviceHasEnoughMemoryForPrerender() { … }
base::MemoryPressureListener::MemoryPressureLevel
GetCurrentMemoryPressureLevel() { … }
std::unique_ptr<network::SimpleURLLoader> CreateHttpCacheQueryingResourceLoad(
const GURL& back_url) { … }
bool IsNavigationInSessionHistoryPredictorDomain(NavigationHandle* handle) { … }
PreloadingEligibility ToEligibility(PrerenderFinalStatus status) { … }
class PrerenderHostBuilder { … };
PrerenderHostBuilder::PrerenderHostBuilder(PreloadingAttempt* attempt)
: … { … }
PrerenderHostBuilder::~PrerenderHostBuilder() { … }
void PrerenderHostBuilder::Drop() { … }
bool PrerenderHostBuilder::IsDropped() const { … }
std::unique_ptr<PrerenderHost> PrerenderHostBuilder::Build(
const PrerenderAttributes& attributes,
WebContentsImpl& prerender_web_contents) { … }
void PrerenderHostBuilder::RejectAsNotEligible(
const PrerenderAttributes& attributes,
PrerenderFinalStatus status) { … }
bool PrerenderHostBuilder::CheckIfShouldHoldback() { … }
void PrerenderHostBuilder::RejectDueToHoldback() { … }
void PrerenderHostBuilder::RejectAsDuplicate() { … }
void PrerenderHostBuilder::SetHoldbackOverride(
PreloadingHoldbackStatus status) { … }
void PrerenderHostBuilder::RejectAsFailure(
const PrerenderAttributes& attributes,
PrerenderFinalStatus status) { … }
bool IsSlowNetwork(WebContents* web_contents) { … }
}
const char kMaxNumOfRunningSpeculationRulesEagerPrerenders[] = …;
const char kMaxNumOfRunningSpeculationRulesNonEagerPrerenders[] = …;
const char kMaxNumOfRunningEmbedderPrerenders[] = …;
PrerenderHostRegistry::PrerenderHostRegistry(WebContents& web_contents)
: … { … }
PrerenderHostRegistry::~PrerenderHostRegistry() { … }
void PrerenderHostRegistry::AddObserver(Observer* observer) { … }
void PrerenderHostRegistry::RemoveObserver(Observer* observer) { … }
int PrerenderHostRegistry::CreateAndStartHost(
const PrerenderAttributes& attributes,
PreloadingAttempt* attempt) { … }
int PrerenderHostRegistry::CreateAndStartHostForNewTab(
const PrerenderAttributes& attributes,
const PreloadingPredictor& creating_predictor,
const PreloadingPredictor& enacting_predictor,
PreloadingConfidence confidence) { … }
int PrerenderHostRegistry::StartPrerendering(int frame_tree_node_id) { … }
std::set<int> PrerenderHostRegistry::CancelHosts(
const std::vector<int>& frame_tree_node_ids,
const PrerenderCancellationReason& reason) { … }
bool PrerenderHostRegistry::CancelHost(int frame_tree_node_id,
PrerenderFinalStatus final_status) { … }
bool PrerenderHostRegistry::CancelHost(
int frame_tree_node_id,
const PrerenderCancellationReason& reason) { … }
void PrerenderHostRegistry::CancelHostsForTriggers(
std::vector<PreloadingTriggerType> trigger_types,
const PrerenderCancellationReason& reason) { … }
void PrerenderHostRegistry::CancelAllHosts(PrerenderFinalStatus final_status) { … }
bool PrerenderHostRegistry::CancelHostInternal(
int frame_tree_node_id,
const PrerenderCancellationReason& reason) { … }
bool PrerenderHostRegistry::CancelNewTabHostInternal(
int frame_tree_node_id,
const PrerenderCancellationReason& reason) { … }
int PrerenderHostRegistry::FindPotentialHostToActivate(
NavigationRequest& navigation_request) { … }
int PrerenderHostRegistry::ReserveHostToActivate(
NavigationRequest& navigation_request,
int expected_host_id) { … }
RenderFrameHostImpl* PrerenderHostRegistry::GetRenderFrameHostForReservedHost(
int frame_tree_node_id) { … }
std::unique_ptr<StoredPage> PrerenderHostRegistry::ActivateReservedHost(
int frame_tree_node_id,
NavigationRequest& navigation_request) { … }
void PrerenderHostRegistry::OnActivationFinished(int frame_tree_node_id) { … }
PrerenderHost* PrerenderHostRegistry::FindNonReservedHostById(
int frame_tree_node_id) { … }
bool PrerenderHostRegistry::HasReservedHost() const { … }
std::unique_ptr<WebContentsImpl>
PrerenderHostRegistry::TakePreCreatedWebContentsForNewTabIfExists(
const mojom::CreateNewWindowParams& create_new_window_params,
const WebContents::CreateParams& web_contents_create_params) { … }
std::vector<FrameTree*> PrerenderHostRegistry::GetPrerenderFrameTrees() { … }
PrerenderHost* PrerenderHostRegistry::FindHostByUrlForTesting(
const GURL& prerendering_url) { … }
bool PrerenderHostRegistry::HasNewTabHandleByIdForTesting(
int frame_tree_node_id) { … }
void PrerenderHostRegistry::CancelAllHostsForTesting() { … }
void PrerenderHostRegistry::BackNavigationLikely(
PreloadingPredictor predictor) { … }
void PrerenderHostRegistry::OnBackResourceCacheResult(
PreloadingPredictor predictor,
base::WeakPtr<PreloadingAttempt> attempt,
GURL back_url,
scoped_refptr<net::HttpResponseHeaders> headers) { … }
base::WeakPtr<PrerenderHostRegistry> PrerenderHostRegistry::GetWeakPtr() { … }
void PrerenderHostRegistry::DidStartNavigation(
NavigationHandle* navigation_handle) { … }
void PrerenderHostRegistry::ReadyToCommitNavigation(
NavigationHandle* navigation_handle) { … }
void PrerenderHostRegistry::DidFinishNavigation(
NavigationHandle* navigation_handle) { … }
void PrerenderHostRegistry::OnVisibilityChanged(Visibility visibility) { … }
void PrerenderHostRegistry::PrimaryMainFrameRenderProcessGone(
base::TerminationStatus status) { … }
bool PrerenderHostRegistry::CanNavigationActivateHost(
NavigationRequest& navigation_request,
PrerenderHost& host) { … }
void PrerenderHostRegistry::ScheduleToDeleteAbandonedHost(
std::unique_ptr<PrerenderHost> prerender_host,
const PrerenderCancellationReason& cancellation_reason) { … }
void PrerenderHostRegistry::DeleteAbandonedHosts() { … }
void PrerenderHostRegistry::NotifyTrigger(const GURL& url) { … }
void PrerenderHostRegistry::NotifyCancel(
int host_frame_tree_node_id,
const PrerenderCancellationReason& reason) { … }
PreloadingTriggerType PrerenderHostRegistry::GetPrerenderTriggerType(
int frame_tree_node_id) { … }
const std::string& PrerenderHostRegistry::GetPrerenderEmbedderHistogramSuffix(
int frame_tree_node_id) { … }
PrerenderHostRegistry::PrerenderLimitGroup
PrerenderHostRegistry::GetPrerenderLimitGroup(
PreloadingTriggerType trigger_type,
std::optional<blink::mojom::SpeculationEagerness> eagerness) { … }
int PrerenderHostRegistry::GetHostCountByLimitGroup(
PrerenderLimitGroup limit_group) { … }
bool PrerenderHostRegistry::IsAllowedToStartPrerenderingForTrigger(
PreloadingTriggerType trigger_type,
std::optional<blink::mojom::SpeculationEagerness> eagerness) { … }
void PrerenderHostRegistry::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { … }
scoped_refptr<base::SingleThreadTaskRunner>
PrerenderHostRegistry::GetTimerTaskRunner() { … }
void PrerenderHostRegistry::SetTaskRunnerForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
bool PrerenderHostRegistry::PrerenderCanBeStartedWhenInitiatorIsInBackground() { … }
}