#include "chrome/browser/navigation_predictor/navigation_predictor.h"
#include <algorithm>
#include <memory>
#include <optional>
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/hash/hash.h"
#include "base/metrics/field_trial_params.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/system/sys_info.h"
#include "base/time/default_tick_clock.h"
#include "chrome/browser/navigation_predictor/navigation_predictor_keyed_service.h"
#include "chrome/browser/navigation_predictor/navigation_predictor_keyed_service_factory.h"
#include "chrome/browser/navigation_predictor/preloading_model_keyed_service.h"
#include "chrome/browser/navigation_predictor/preloading_model_keyed_service_factory.h"
#include "chrome/browser/preloading/preloading_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
#include "components/variations/variations_switches.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/preloading_data.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/message.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"
#include "url/url_canon.h"
namespace {
constexpr size_t kMaxClicksTracked = …;
bool IsPrerendering(content::RenderFrameHost& render_frame_host) { … }
NavigationPredictor::FontSizeBucket GetFontSizeFromPx(uint32_t font_size_px) { … }
bool IsBoldFont(uint32_t font_weight) { … }
struct PathLengthDepthAndHash { … };
PathLengthDepthAndHash GetUrlPathLengthDepthAndHash(const GURL& target_url) { … }
int GetLinearBucketForLinkLocation(int value) { … }
int GetLinearBucketForRatioArea(int value) { … }
base::TimeDelta MLModelExecutionTimerStartDelay() { … }
base::TimeDelta MLModelExecutionTimerInterval() { … }
bool MLModelOneExecutionPerHover() { … }
base::TimeDelta MLModelMaxHoverTime() { … }
void RecordMetricsForModelTraining(
const PreloadingModelKeyedService::Inputs& inputs,
ukm::SourceId ukm_source,
std::optional<double> sampling_likelihood,
bool is_accurate) { … }
bool MaySendTraffic() { … }
}
NavigationPredictor::AnchorElementData::AnchorElementData(
blink::mojom::AnchorElementMetricsPtr metrics,
base::TimeTicks first_report_timestamp)
: … { … }
NavigationPredictor::AnchorElementData::~AnchorElementData() = default;
NavigationPredictor::NavigationPredictor(
content::RenderFrameHost& render_frame_host,
mojo::PendingReceiver<AnchorElementMetricsHost> receiver)
: … { … }
NavigationPredictor::~NavigationPredictor() { … }
void NavigationPredictor::Create(
content::RenderFrameHost* render_frame_host,
mojo::PendingReceiver<blink::mojom::AnchorElementMetricsHost> receiver) { … }
NavigationPredictorMetricsDocumentData&
NavigationPredictor::GetNavigationPredictorMetricsDocumentData() const { … }
void NavigationPredictor::ReportNewAnchorElements(
std::vector<blink::mojom::AnchorElementMetricsPtr> elements,
const std::vector<uint32_t>& removed_elements) { … }
void NavigationPredictor::OnPreloadingHeuristicsModelDone(
GURL url,
PreloadingModelKeyedService::Result result) { … }
void NavigationPredictor::ProcessPointerEventUsingMLModel(
blink::mojom::AnchorElementPointerEventForMLModelPtr pointer_event) { … }
void NavigationPredictor::OnMLModelExecutionTimerFired() { … }
void NavigationPredictor::SetModelScoreCallbackForTesting(
ModelScoreCallbackForTesting callback) { … }
void NavigationPredictor::SetTaskRunnerForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const base::TickClock* clock) { … }
bool NavigationPredictor::disable_renderer_metric_sending_delay_for_testing_ = …;
void NavigationPredictor::DisableRendererMetricSendingDelayForTesting() { … }
void NavigationPredictor::ShouldSkipUpdateDelays(
ShouldSkipUpdateDelaysCallback callback) { … }
void NavigationPredictor::ReportAnchorElementClick(
blink::mojom::AnchorElementClickPtr click) { … }
void NavigationPredictor::ReportAnchorElementsLeftViewport(
std::vector<blink::mojom::AnchorElementLeftViewportPtr> elements) { … }
void NavigationPredictor::ReportAnchorElementsPositionUpdate(
std::vector<blink::mojom::AnchorElementPositionUpdatePtr> elements) { … }
void NavigationPredictor::ReportAnchorElementPointerDataOnHoverTimerFired(
blink::mojom::AnchorElementPointerDataOnHoverTimerFiredPtr msg) { … }
void NavigationPredictor::ReportAnchorElementPointerOver(
blink::mojom::AnchorElementPointerOverPtr pointer_over_event) { … }
void NavigationPredictor::ReportAnchorElementPointerOut(
blink::mojom::AnchorElementPointerOutPtr hover_event) { … }
void NavigationPredictor::ReportAnchorElementPointerDown(
blink::mojom::AnchorElementPointerDownPtr pointer_down_event) { … }
void NavigationPredictor::ReportAnchorElementsEnteredViewport(
std::vector<blink::mojom::AnchorElementEnteredViewportPtr> elements) { … }
bool NavigationPredictor::IsTargetURLTheSameAsDocument(
const AnchorElementData& anchor) { … }