#include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_service.h"
#include <iterator>
#include <memory>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/json/values_util.h"
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/prefetch/pref_names.h"
#include "chrome/browser/preloading/chrome_preloading.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/cache_alias_search_prefetch_url_loader.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/field_trial_settings.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_request.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/search_prefetch_url_loader.h"
#include "chrome/browser/preloading/prefetch/search_prefetch/streaming_search_prefetch_url_loader.h"
#include "chrome/browser/preloading/preloading_prefs.h"
#include "chrome/browser/preloading/prerender/prerender_manager.h"
#include "chrome/browser/preloading/prerender/prerender_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "chrome/common/pref_names.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_match_type.h"
#include "components/omnibox/browser/autocomplete_result.h"
#include "components/omnibox/browser/base_search_provider.h"
#include "components/omnibox/browser/omnibox_log.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/preloading_data.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "net/base/load_flags.h"
#include "net/base/url_util.h"
#include "services/network/public/cpp/network_quality_tracker.h"
#include "services/network/public/cpp/resource_request.h"
#include "ui/base/page_transition_types.h"
#include "url/origin.h"
NavigationPredictor;
namespace {
void SetIsNavigationInDomainCallback(content::PreloadingData* preloading_data) { … }
GURL GetPreloadURLFromMatch(
const TemplateURLRef::SearchTermsArgs& search_terms_args_from_match,
TemplateURLService* template_url_service,
std::string prefetch_param) { … }
struct SearchPrefetchEligibilityReasonRecorder { … };
void RecordFinalStatus(SearchPrefetchStatus status, bool navigation_prefetch) { … }
bool ShouldPrefetch(const AutocompleteMatch& match) { … }
void SetEligibility(content::PreloadingAttempt* preloading_attempt,
content::PreloadingEligibility eligibility) { … }
bool CheckAndSetPrefetchHoldbackStatus(
content::PreloadingAttempt* preloading_attempt) { … }
void SetTriggeringOutcome(content::PreloadingAttempt* preloading_attempt,
content::PreloadingTriggeringOutcome outcome) { … }
content::PreloadingFailureReason ToPreloadingFailureReason(
SearchPrefetchServingReason reason) { … }
bool IsSlowNetwork() { … }
}
struct SearchPrefetchService::SearchPrefetchServingReasonRecorder { … };
void SearchPrefetchService::RegisterProfilePrefs(PrefRegistrySimple* registry) { … }
SearchPrefetchService::SearchPrefetchService(Profile* profile)
: … { … }
SearchPrefetchService::~SearchPrefetchService() = default;
void SearchPrefetchService::Shutdown() { … }
bool SearchPrefetchService::MaybePrefetchURL(
const GURL& url,
content::WebContents* web_contents) { … }
bool SearchPrefetchService::MaybePrefetchURL(
const GURL& url,
bool navigation_prefetch,
content::WebContents* web_contents,
content::PreloadingPredictor predictor) { … }
void SearchPrefetchService::OnURLOpenedFromOmnibox(OmniboxLog* log) { … }
void SearchPrefetchService::OnPrerenderedRequestUsed(
const GURL& canonical_search_url,
const GURL& navigation_url) { … }
SearchPrefetchURLLoader::RequestHandler
SearchPrefetchService::MaybeCreateResponseReader(
const network::ResourceRequest& tentative_resource_request) { … }
std::optional<SearchPrefetchStatus>
SearchPrefetchService::GetSearchPrefetchStatusForTesting(
const GURL& canonical_search_url) { … }
GURL SearchPrefetchService::GetRealPrefetchUrlForTesting(
const GURL& canonical_search_url) { … }
SearchPrefetchURLLoader::RequestHandler
SearchPrefetchService::TakePrefetchResponseFromMemoryCache(
const network::ResourceRequest& tentative_resource_request) { … }
SearchPrefetchURLLoader::RequestHandler
SearchPrefetchService::TakePrefetchResponseFromDiskCache(
const GURL& navigation_url) { … }
void SearchPrefetchService::ClearPrefetches() { … }
void SearchPrefetchService::DeletePrefetch(GURL canonical_search_url) { … }
void SearchPrefetchService::ReportFetchResult(bool error) { … }
void SearchPrefetchService::OnResultChanged(content::WebContents* web_contents,
const AutocompleteResult& result) { … }
bool SearchPrefetchService::OnNavigationLikely(
size_t index,
const AutocompleteMatch& match,
NavigationPredictor navigation_predictor,
content::WebContents* web_contents) { … }
void SearchPrefetchService::OnTemplateURLServiceChanged() { … }
void SearchPrefetchService::ClearCacheEntry(const GURL& navigation_url) { … }
void SearchPrefetchService::UpdateServeTime(const GURL& navigation_url) { … }
void SearchPrefetchService::AddCacheEntry(const GURL& navigation_url,
const GURL& prefetch_url) { … }
bool SearchPrefetchService::LoadFromPrefs() { … }
void SearchPrefetchService::SaveToPrefs() const { … }
bool SearchPrefetchService::LoadFromPrefsForTesting() { … }
void SearchPrefetchService::ObserveTemplateURLService(
TemplateURLService* template_url_service) { … }
void SearchPrefetchService::CoordinatePrefetchWithPrerender(
const AutocompleteMatch& match,
content::WebContents* web_contents,
TemplateURLService* template_url_service,
const GURL& canonical_search_url) { … }
std::map<GURL, std::unique_ptr<SearchPrefetchRequest>>::iterator
SearchPrefetchService::RetrieveSearchTermsInMemoryCache(
const network::ResourceRequest& tentative_resource_request,
SearchPrefetchServingReasonRecorder& recorder) { … }
void SearchPrefetchService::FireAllExpiryTimerForTesting() { … }
void SearchPrefetchService::SetLoaderDestructionCallbackForTesting(
const GURL& canonical_search_url,
base::OnceClosure streaming_url_loader_destruction_callback) { … }
void SearchPrefetchService::MaybePreloadDictionary(
const AutocompleteResult& result) { … }
void SearchPrefetchService::DeletePreloadedDictionaries() { … }