chromium/components/omnibox/browser/omnibox_field_trial.cc

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

#include "components/omnibox/browser/omnibox_field_trial.h"

#include <algorithm>
#include <cmath>
#include <functional>
#include <string>

#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/no_destructor.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/system/sys_info.h"
#include "base/time/time.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "build/build_config.h"
#include "components/history/core/browser/url_database.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/page_classification_functions.h"
#include "components/omnibox/browser/url_index_private_data.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/optimization_guide/machine_learning_tflite_buildflags.h"
#include "components/search/search.h"
#include "components/variations/active_field_trials.h"
#include "components/variations/hashing.h"
#include "components/variations/variations_associated_data.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "ui/base/ui_base_features.h"

OmniboxEventProto;

namespace {

VariationParams;
ScoreBuckets;

void InitializeBucketsFromString(const std::string& bucket_string,
                                 ScoreBuckets* score_buckets) {}

void InitializeScoreBuckets(const VariationParams& params,
                            const char* relevance_cap_param,
                            const char* half_life_param,
                            const char* score_buckets_param,
                            const char* use_decay_factor_param,
                            ScoreBuckets* score_buckets) {}

// Background and implementation details:
//
// Each experiment group in any field trial can come with an optional set of
// parameters (key-value pairs).  In the bundled omnibox experiment
// (kBundledExperimentFieldTrialName), each experiment group comes with a
// list of parameters in the form:
//   key=<Rule>:
//       <OmniboxEventProto::PageClassification (as an int)>:
//       <whether Instant Extended is enabled (as a 1 or 0)>
//     (note that there are no linebreaks in keys; this format is for
//      presentation only>
//   value=<arbitrary string>
// Both the OmniboxEventProto::PageClassification and the Instant Extended
// entries can be "*", which means this rule applies for all values of the
// matching portion of the context.
// One example parameter is
//   key=SearchHistory:6:1
//   value=PreventInlining
// This means in page classification context 6 (a search result page doing
// search term replacement) with Instant Extended enabled, the SearchHistory
// experiment should PreventInlining.
//
// When an exact match to the rule in the current context is missing, we
// give preference to a wildcard rule that matches the instant extended
// context over a wildcard rule that matches the page classification
// context.  Hopefully, though, users will write their field trial configs
// so as not to rely on this fall back order.
//
// In short, this function tries to find the value associated with key
// |rule|:|page_classification|:|instant_extended|, failing that it looks up
// |rule|:*:|instant_extended|, failing that it looks up
// |rule|:|page_classification|:*, failing that it looks up |rule|:*:*,
// and failing that it returns the empty string.
std::string GetValueForRuleInContextFromVariationParams(
    const std::map<std::string, std::string>& params,
    const std::string& rule,
    OmniboxEventProto::PageClassification page_classification) {}

OmniboxFieldTrial::MLConfig& GetMLConfigInternal() {}

bool IsKoreanLocale(const std::string& locale) {}

}  // namespace

HUPScoringParams::ScoreBuckets::ScoreBuckets()
    :{}

HUPScoringParams::ScoreBuckets::ScoreBuckets(const ScoreBuckets& other) =
    default;

HUPScoringParams::ScoreBuckets::~ScoreBuckets() {}

size_t HUPScoringParams::ScoreBuckets::EstimateMemoryUsage() const {}

double HUPScoringParams::ScoreBuckets::HalfLifeTimeDecay(
    const base::TimeDelta& elapsed_time) const {}

size_t HUPScoringParams::EstimateMemoryUsage() const {}

int OmniboxFieldTrial::GetDisabledProviderTypes() {}

void OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes(
    std::vector<uint32_t>* field_trial_hashes) {}

void OmniboxFieldTrial::GetDemotionsByType(
    OmniboxEventProto::PageClassification current_page_classification,
    DemotionMultipliers* demotions_by_type) {}

size_t OmniboxFieldTrial::GetProviderMaxMatches(
    AutocompleteProvider::Type provider) {}

bool OmniboxFieldTrial::IsMaxURLMatchesFeatureEnabled() {}

size_t OmniboxFieldTrial::GetMaxURLMatches() {}

void OmniboxFieldTrial::GetDefaultHUPScoringParams(
    HUPScoringParams* scoring_params) {}

void OmniboxFieldTrial::GetExperimentalHUPScoringParams(
    HUPScoringParams* scoring_params) {}

float OmniboxFieldTrial::HQPBookmarkValue() {}

bool OmniboxFieldTrial::HQPAllowMatchInTLDValue() {}

bool OmniboxFieldTrial::HQPAllowMatchInSchemeValue() {}

void OmniboxFieldTrial::GetSuggestPollingStrategy(bool* from_last_keystroke,
                                                  int* polling_delay_ms) {}

std::string OmniboxFieldTrial::HQPExperimentalScoringBuckets() {}

float OmniboxFieldTrial::HQPExperimentalTopicalityThreshold() {}

int OmniboxFieldTrial::MaxNumHQPUrlsIndexedAtStartup() {}

size_t OmniboxFieldTrial::HQPMaxVisitsToScore() {}

float OmniboxFieldTrial::HQPTypedValue() {}

OmniboxFieldTrial::NumMatchesScores OmniboxFieldTrial::HQPNumMatchesScores() {}

size_t OmniboxFieldTrial::HQPNumTitleWordsToAllow() {}

bool OmniboxFieldTrial::HQPAlsoDoHUPLikeScoring() {}

bool OmniboxFieldTrial::HUPSearchDatabase() {}

bool OmniboxFieldTrial::IsOnDeviceHeadSuggestEnabledForIncognito() {}

bool OmniboxFieldTrial::IsOnDeviceHeadSuggestEnabledForNonIncognito() {}

bool OmniboxFieldTrial::IsOnDeviceHeadSuggestEnabledForAnyMode() {}

bool OmniboxFieldTrial::IsOnDeviceTailSuggestEnabled() {}

bool OmniboxFieldTrial::ShouldEncodeLeadingSpaceForOnDeviceTailSuggest() {}

bool OmniboxFieldTrial::ShouldApplyOnDeviceHeadModelSelectionFix() {}

bool OmniboxFieldTrial::IsOnDeviceHeadSuggestEnabledForLocale(
    const std::string& locale) {}

std::string OmniboxFieldTrial::OnDeviceHeadModelLocaleConstraint(
    bool is_incognito) {}

// Omnibox UI simplification - Uniform Suggestion Row Heights
const base::FeatureParam<bool> OmniboxFieldTrial::kSquareSuggestIconAnswers(
    &omnibox::kSquareSuggestIcons,
    "OmniboxSquareSuggestIconAnswers",
    true);
const base::FeatureParam<bool> OmniboxFieldTrial::kSquareSuggestIconIcons(
    &omnibox::kSquareSuggestIcons,
    "OmniboxSquareSuggestIconIcons",
    false);
const base::FeatureParam<bool> OmniboxFieldTrial::kSquareSuggestIconEntities(
    &omnibox::kSquareSuggestIcons,
    "OmniboxSquareSuggestIconEntities",
    false);
const base::FeatureParam<double>
    OmniboxFieldTrial::kSquareSuggestIconEntitiesScale(
        &omnibox::kSquareSuggestIcons,
        "OmniboxSquareSuggestIconEntitiesScale",
        0.8722);
const base::FeatureParam<bool> OmniboxFieldTrial::kSquareSuggestIconWeather(
    &omnibox::kSquareSuggestIcons,
    "OmniboxSquareSuggestIconWeather",
    true);

bool OmniboxFieldTrial::IsUniformRowHeightEnabled() {}

const base::FeatureParam<int> OmniboxFieldTrial::kRichSuggestionVerticalMargin(
    &omnibox::kUniformRowHeight,
    "OmniboxRichSuggestionVerticalMargin",
    6);

bool OmniboxFieldTrial::IsGM3TextStyleEnabled() {}

// In order to control the value of this "font size" param via Finch, the
// `kOmniboxSteadyStateTextStyle` feature flag must be enabled.
//
// Enabling `ChromeRefresh2023` Level 2 while leaving the
// `kOmniboxSteadyStateTextStyle` flag disabled, will result in the param being
// locked to its default value and ignoring any overrides provided via Finch.
//
// If neither `ChromeRefresh2023` Level 2 nor `kOmniboxSteadyStateTextStyle` are
// enabled, then this "font size" param will have zero effect on Chrome UI.
const base::FeatureParam<int> OmniboxFieldTrial::kFontSizeTouchUI(
    &omnibox::kOmniboxSteadyStateTextStyle,
    "OmniboxFontSizeTouchUI",
    15);

// In order to control the value of this "font size" param via Finch, the
// `kOmniboxSteadyStateTextStyle` feature flag must be enabled.
//
// Enabling `ChromeRefresh2023` Level 2 while leaving the
// `kOmniboxSteadyStateTextStyle` flag disabled, will result in the param being
// locked to its default value and ignoring any overrides provided via Finch.
//
// If neither `ChromeRefresh2023` Level 2 nor `kOmniboxSteadyStateTextStyle` are
// enabled, then this "font size" param will have zero effect on Chrome UI.
const base::FeatureParam<int> OmniboxFieldTrial::kFontSizeNonTouchUI(
    &omnibox::kOmniboxSteadyStateTextStyle,
    "OmniboxFontSizeNonTouchUI",
    13);

const char OmniboxFieldTrial::kBundledExperimentFieldTrialName[] =;
const char OmniboxFieldTrial::kDisableProvidersRule[] =;
const char OmniboxFieldTrial::kDemoteByTypeRule[] =;
const char OmniboxFieldTrial::kHQPBookmarkValueRule[] =;
const char OmniboxFieldTrial::kHQPTypedValueRule[] =;
const char OmniboxFieldTrial::kHQPAllowMatchInTLDRule[] =;
const char OmniboxFieldTrial::kHQPAllowMatchInSchemeRule[] =;
const char
    OmniboxFieldTrial::kMeasureSuggestPollingDelayFromLastKeystrokeRule[] =;
const char OmniboxFieldTrial::kSuggestPollingDelayMsRule[] =;
const char OmniboxFieldTrial::kHQPMaxVisitsToScoreRule[] =;
const char OmniboxFieldTrial::kHQPNumMatchesScoresRule[] =;
const char OmniboxFieldTrial::kHQPNumTitleWordsRule[] =;
const char OmniboxFieldTrial::kHQPAlsoDoHUPLikeScoringRule[] =;
const char OmniboxFieldTrial::kHUPSearchDatabaseRule[] =;
const char OmniboxFieldTrial::kHUPNewScoringTypedCountRelevanceCapParam[] =;
const char OmniboxFieldTrial::kHUPNewScoringTypedCountHalfLifeTimeParam[] =;
const char OmniboxFieldTrial::kHUPNewScoringTypedCountScoreBucketsParam[] =;
const char OmniboxFieldTrial::kHUPNewScoringTypedCountUseDecayFactorParam[] =;
const char OmniboxFieldTrial::kHUPNewScoringVisitedCountRelevanceCapParam[] =;
const char OmniboxFieldTrial::kHUPNewScoringVisitedCountHalfLifeTimeParam[] =;
const char OmniboxFieldTrial::kHUPNewScoringVisitedCountScoreBucketsParam[] =;
const char OmniboxFieldTrial::kHUPNewScoringVisitedCountUseDecayFactorParam[] =;

const char OmniboxFieldTrial::kHQPExperimentalScoringBucketsParam[] =;
const char
    OmniboxFieldTrial::kHQPExperimentalScoringTopicalityThresholdParam[] =;

const char
    OmniboxFieldTrial::kMaxNumHQPUrlsIndexedAtStartupOnLowEndDevicesParam[] =;
const char
    OmniboxFieldTrial::kMaxNumHQPUrlsIndexedAtStartupOnNonLowEndDevicesParam[] =;

const char OmniboxFieldTrial::kMaxZeroSuggestMatchesParam[] =;
const char OmniboxFieldTrial::kOmniboxMaxURLMatchesParam[] =;
const char OmniboxFieldTrial::kUIMaxAutocompleteMatchesByProviderParam[] =;
const char OmniboxFieldTrial::kUIMaxAutocompleteMatchesParam[] =;
const char OmniboxFieldTrial::kDynamicMaxAutocompleteUrlCutoffParam[] =;
const char OmniboxFieldTrial::kDynamicMaxAutocompleteIncreasedLimitParam[] =;

const char OmniboxFieldTrial::kOnDeviceHeadModelLocaleConstraint[] =;
const char OmniboxFieldTrial::kOnDeviceHeadModelSelectionFix[] =;

int OmniboxFieldTrial::kDefaultMinimumTimeBetweenSuggestQueriesMs =;

namespace OmniboxFieldTrial {

// Local history zero-prefix (aka zero-suggest) and prefix suggestions:

// The debouncing delay (in milliseconds) to use when throttling ZPS prefetch
// requests.
const base::FeatureParam<int> kZeroSuggestPrefetchDebounceDelay(
    &omnibox::kZeroSuggestPrefetchDebouncing,
    "ZeroSuggestPrefetchDebounceDelay",
    300);

// Whether to calculate debouncing delay relative to the latest successful run
// (instead of the latest run request).
const base::FeatureParam<bool> kZeroSuggestPrefetchDebounceFromLastRun(
    &omnibox::kZeroSuggestPrefetchDebouncing,
    "ZeroSuggestPrefetchDebounceFromLastRun",
    true);

// The maximum number of entries stored by the in-memory zero-suggest cache at
// at any given time (LRU eviction policy is used to enforce this limit).
const base::FeatureParam<int> kZeroSuggestCacheMaxSize(
    &omnibox::kZeroSuggestInMemoryCaching,
    "ZeroSuggestCacheMaxSize",
    5);

// The relevance score for remote zero-suggest ranges from 550-1400. A default
// value of 500 places local history zero-suggest below the remote zero-suggest.
const base::FeatureParam<int> kLocalHistoryZeroSuggestRelevanceScore(
    &omnibox::kAdjustLocalHistoryZeroSuggestRelevanceScore,
    "LocalHistoryZeroSuggestRelevanceScore",
    500);

bool IsZeroSuggestPrefetchingEnabled() {}

bool IsZeroSuggestPrefetchingEnabledInContext(
    metrics::OmniboxEventProto::PageClassification page_classification) {}

// Rich autocompletion.

bool IsRichAutocompletionEnabled() {}

bool RichAutocompletionShowAdditionalText() {}

const base::FeatureParam<bool> kRichAutocompletionAutocompleteTitles(
    &omnibox::kRichAutocompletion,
    "RichAutocompletionAutocompleteTitles",
    false);

const base::FeatureParam<bool>
    kRichAutocompletionAutocompleteTitlesShortcutProvider(
        &omnibox::kRichAutocompletion,
        "RichAutocompletionAutocompleteTitlesShortcutProvider",
        true);

const base::FeatureParam<int> kRichAutocompletionAutocompleteTitlesMinChar(
    &omnibox::kRichAutocompletion,
    "RichAutocompletionAutocompleteTitlesMinChar",
    3);

const base::FeatureParam<bool> kRichAutocompletionAutocompleteNonPrefixAll(
    &omnibox::kRichAutocompletion,
    "RichAutocompletionAutocompleteNonPrefixAll",
    false);

const base::FeatureParam<bool>
    kRichAutocompletionAutocompleteNonPrefixShortcutProvider(
        &omnibox::kRichAutocompletion,
        "RichAutocompletionAutocompleteNonPrefixShortcutProvider",
        false);

const base::FeatureParam<int> kRichAutocompletionAutocompleteNonPrefixMinChar(
    &omnibox::kRichAutocompletion,
    "RichAutocompletionAutocompleteNonPrefixMinChar",
    0);

const base::FeatureParam<bool> kRichAutocompletionShowAdditionalText(
    &omnibox::kRichAutocompletion,
    "RichAutocompletionAutocompleteShowAdditionalText",
    true);

const base::FeatureParam<bool> kRichAutocompletionAdditionalTextWithParenthesis(
    &omnibox::kRichAutocompletion,
    "RichAutocompletionAdditionalTextWithParenthesis",
    false);

const base::FeatureParam<bool> kRichAutocompletionAutocompleteShortcutText(
    &omnibox::kRichAutocompletion,
    "RichAutocompletionAutocompleteShortcutText",
    true);

const base::FeatureParam<int>
    kRichAutocompletionAutocompleteShortcutTextMinChar(
        &omnibox::kRichAutocompletion,
        "RichAutocompletionAutocompleteShortcutTextMinChar",
        3);

const base::FeatureParam<bool> kRichAutocompletionCounterfactual(
    &omnibox::kRichAutocompletion,
    "RichAutocompletionCounterfactual",
    false);

const base::FeatureParam<bool>
    kRichAutocompletionAutocompletePreferUrlsOverPrefixes(
        &omnibox::kRichAutocompletion,
        "RichAutocompletionAutocompletePreferUrlsOverPrefixes",
        false);

const base::FeatureParam<bool> kDomainSuggestionsCounterfactual(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsCounterfactual",
    false);

const base::FeatureParam<int> kDomainSuggestionsTypedUrlsThreshold(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsTypedUrlsThreshold",
    7);

const base::FeatureParam<int> kDomainSuggestionsTypedUrlsOffset(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsTypedUrlsOffset",
    1);

const base::FeatureParam<int> kDomainSuggestionsTypedVisitThreshold(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsTypedVisitThreshold",
    4);

const base::FeatureParam<int> kDomainSuggestionsTypedVisitOffset(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsTypedVisitOffset",
    1);

const base::FeatureParam<int> kDomainSuggestionsTypedVisitCapPerVisit(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsTypedVisitCapPerVisit",
    2);

const base::FeatureParam<int> kDomainSuggestionsMinInputLength(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsMinInputLength",
    4);

const base::FeatureParam<int> kDomainSuggestionsMaxMatchesPerDomain(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsMaxMatchesPerDomain",
    2);

const base::FeatureParam<double> kDomainSuggestionsScoreFactor(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsScoreFactor",
    1);

const base::FeatureParam<bool> kDomainSuggestionsAlternativeScoring(
    &omnibox::kDomainSuggestions,
    "DomainSuggestionsAlternativeScoring",
    false);

// ---------------------------------------------------------
// ML Relevance Scoring ->

// If true, enables scoring signal annotators for logging Omnibox scoring
// signals to OmniboxEventProto.
const base::FeatureParam<bool> kEnableScoringSignalsAnnotatorsForLogging(
    &omnibox::kLogUrlScoringSignals,
    "enable_scoring_signals_annotators",
    false);

// If true, enables scoring signal annotators for ML scoring.
const base::FeatureParam<bool> kEnableScoringSignalsAnnotatorsForMlScoring(
    &omnibox::kMlUrlScoring,
    "enable_scoring_signals_annotators_for_ml_scoring",
    true);

// If true, runs the ML scoring model but does not assign new relevance scores
// to the URL suggestions and does not rerank them.
const base::FeatureParam<bool> kMlUrlScoringCounterfactual(
    &omnibox::kMlUrlScoring,
    "MlUrlScoringCounterfactual",
    false);

// If true, increases the number of candidates the URL autocomplete providers
// pass to the controller beyond `provider_max_matches`.
const base::FeatureParam<bool> kMlUrlScoringUnlimitedNumCandidates(
    &omnibox::kMlUrlScoring,
    "MlUrlScoringUnlimitedNumCandidates",
    false);

const base::FeatureParam<std::string> kMlUrlScoringMaxMatchesByProvider(
    &omnibox::kMlUrlScoring,
    "MlUrlScoringMaxMatchesByProvider",
    "");

MLConfig::MLConfig() {}

MLConfig::~MLConfig() = default;

MLConfig::MLConfig(const MLConfig&) = default;

MLConfig& MLConfig::operator=(const MLConfig& other) = default;

ScopedMLConfigForTesting::ScopedMLConfigForTesting()
    :{}

ScopedMLConfigForTesting::~ScopedMLConfigForTesting() {}

MLConfig& ScopedMLConfigForTesting::GetMLConfig() {}

const MLConfig& GetMLConfig() {}

bool IsReportingUrlScoringSignalsEnabled() {}

bool IsPopulatingUrlScoringSignalsEnabled() {}

bool AreScoringSignalsAnnotatorsEnabled() {}
bool IsMlUrlScoringEnabled() {}
bool IsMlUrlScoringCounterfactual() {}
bool IsMlUrlScoringUnlimitedNumCandidatesEnabled() {}
bool IsUrlScoringModelEnabled() {}
bool IsMlUrlScoreCachingEnabled() {}

std::vector<std::pair<double, int>> GetPiecewiseMappingBreakPoints(
    PiecewiseMappingVariant mapping_variant) {}

// <- ML Relevance Scoring
// ---------------------------------------------------------
// Touch Down Trigger For Prefetch ->
const base::FeatureParam<int>
    kTouchDownTriggerForPrefetchMaxPrefetchesPerOmniboxSession(
        &omnibox::kOmniboxTouchDownTriggerForPrefetch,
        "max_prefetches_per_omnibox_session",
        5);
// <- Touch Down Trigger For Prefetch
// ---------------------------------------------------------
// Site Search Starter Pack ->
const base::FeatureParam<std::string> kGeminiUrlOverride(
    &omnibox::kStarterPackExpansion,
    "StarterPackGeminiUrlOverride",
    "https://gemini.google.com/prompt");

bool IsStarterPackExpansionEnabled() {}

bool IsStarterPackIPHEnabled() {}
// <- Site Search Starter Pack
// ---------------------------------------------------------
// Featured Enterprise Site Search ->
bool IsFeaturedEnterpriseSearchIPHEnabled() {}

}  // namespace OmniboxFieldTrial

std::string OmniboxFieldTrial::internal::GetValueForRuleInContext(
    const std::string& rule,
    OmniboxEventProto::PageClassification page_classification) {}

std::string OmniboxFieldTrial::internal::GetValueForRuleInContextByFeature(
    const base::Feature& feature,
    const std::string& rule,
    metrics::OmniboxEventProto::PageClassification page_classification) {}