chromium/chrome/browser/ui/webui/top_chrome/webui_contents_preload_manager.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/webui/top_chrome/webui_contents_preload_manager.h"

#include <memory>
#include <optional>
#include <string>

#include "base/auto_reset.h"
#include "base/containers/contains.h"
#include "base/feature_list.h"
#include "base/memory/memory_pressure_monitor.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/scoped_observation.h"
#include "base/strings/strcat.h"
#include "base/timer/timer.h"
#include "chrome/browser/page_load_metrics/page_load_metrics_initialize.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/task_manager/web_contents_tags.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/webui/top_chrome/per_profile_webui_tracker.h"
#include "chrome/browser/ui/webui/top_chrome/preload_context.h"
#include "chrome/browser/ui/webui/top_chrome/profile_preload_candidate_selector.h"
#include "chrome/browser/ui/webui/top_chrome/top_chrome_web_ui_controller.h"
#include "chrome/browser/ui/webui/top_chrome/top_chrome_webui_config.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ui/base/models/menu_model.h"
#include "url/url_constants.h"

namespace {

// Enum class representing the results of attempting to use a preloaded WebUI
// when WebUIContentsPreloadedManager::Request() is called.
// The description of each value is also in tools/metrics/histograms/enums.xml.
enum class WebUIPreloadResult {};

// A candidate selector that always preloads a fixed WebUI.
class FixedCandidateSelector : public webui::PreloadCandidateSelector {};

bool IsFeatureEnabled() {}

bool IsSmartPreloadEnabled() {}

bool IsDelayPreloadEnabled() {}

content::WebContents::CreateParams GetWebContentsCreateParams(
    const GURL& webui_url,
    content::BrowserContext* browser_context) {}

content::WebUIController* GetWebUIController(
    content::WebContents* web_contents) {}

}  // namespace

// A stub WebUI page embdeder that captures the ready-to-show signal.
class WebUIContentsPreloadManager::WebUIControllerEmbedderStub final
    : public TopChromeWebUIController::Embedder {};

class WebUIContentsPreloadManager::PendingPreload
    : public content::WebContentsObserver,
      public ProfileObserver {};

RequestResult;

RequestResult::RequestResult() = default;
RequestResult::~RequestResult() = default;
RequestResult::RequestResult(RequestResult&&) = default;
RequestResult& RequestResult::operator=(RequestResult&&) = default;

WebUIContentsPreloadManager::WebUIContentsPreloadManager() {}

WebUIContentsPreloadManager::~WebUIContentsPreloadManager() = default;

// static
WebUIContentsPreloadManager* WebUIContentsPreloadManager::GetInstance() {}

void WebUIContentsPreloadManager::WarmupForBrowser(Browser* browser) {}

std::optional<GURL> WebUIContentsPreloadManager::GetNextWebUIURLToPreload(
    content::BrowserContext* browser_context) const {}

std::vector<GURL> WebUIContentsPreloadManager::GetAllPreloadableWebUIURLs() {}

void WebUIContentsPreloadManager::SetPreloadCandidateSelector(
    std::unique_ptr<webui::PreloadCandidateSelector>
        preload_candidate_selector) {}

void WebUIContentsPreloadManager::MaybePreloadForBrowserContext(
    content::BrowserContext* browser_context) {}

void WebUIContentsPreloadManager::MaybePreloadForBrowserContextLater(
    content::BrowserContext* browser_context,
    content::WebContents* busy_web_contents_to_watch,
    base::TimeDelta deadline) {}

void WebUIContentsPreloadManager::SetPreloadedContents(
    std::unique_ptr<content::WebContents> web_contents) {}

RequestResult WebUIContentsPreloadManager::Request(
    const GURL& webui_url,
    content::BrowserContext* browser_context) {}

std::optional<base::TimeTicks> WebUIContentsPreloadManager::GetRequestTime(
    content::WebContents* web_contents) {}

void WebUIContentsPreloadManager::DisableNavigationForTesting() {}

std::unique_ptr<content::WebContents>
WebUIContentsPreloadManager::CreateNewContents(
    content::BrowserContext* browser_context,
    GURL url) {}

void WebUIContentsPreloadManager::LoadURLForContents(
    content::WebContents* web_contents,
    GURL url) {}

bool WebUIContentsPreloadManager::ShouldPreloadForBrowserContext(
    content::BrowserContext* browser_context) const {}

void WebUIContentsPreloadManager::OnProfileWillBeDestroyed(Profile* profile) {}

void WebUIContentsPreloadManager::OnWebContentsDestroyed(
    content::WebContents* web_contents) {}

void WebUIContentsPreloadManager::OnWebContentsPrimaryPageChanged(
    content::WebContents* web_contents) {}