chromium/components/optimization_guide/core/optimization_guide_features.cc

// Copyright 2019 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/optimization_guide/core/optimization_guide_features.h"

#include <cstring>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/enum_set.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/rand_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/to_string.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "components/optimization_guide/core/feature_registry/mqls_feature_registry.h"
#include "components/optimization_guide/core/insertion_ordered_set.h"
#include "components/optimization_guide/core/model_execution/feature_keys.h"
#include "components/optimization_guide/core/optimization_guide_constants.h"
#include "components/optimization_guide/core/optimization_guide_enums.h"
#include "components/optimization_guide/core/optimization_guide_switches.h"
#include "components/optimization_guide/machine_learning_tflite_buildflags.h"
#include "components/optimization_guide/proto/common_types.pb.h"
#include "components/variations/hashing.h"
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/google_api_keys.h"
#include "net/base/url_util.h"
#include "ui/base/l10n/l10n_util.h"

namespace optimization_guide {
namespace features {

namespace {

constexpr auto enabled_by_default_mobile_only =base::FEATURE_ENABLED_BY_DEFAULT;
#else
    base::FEATURE_DISABLED_BY_DEFAULT;
#endif

}  // namespace

// Enables the syncing of the Optimization Hints component, which provides
// hints for what optimizations can be applied on a page load.
BASE_FEATURE();

// Enables fetching from a remote Optimization Guide Service.
BASE_FEATURE();

BASE_FEATURE();

// Enables performance info in the context menu and fetching from a remote
// Optimization Guide Service.
BASE_FEATURE();

// Enables the prediction of optimization targets.
BASE_FEATURE();

// Enables the downloading of models.
BASE_FEATURE();

// Enables push notification of hints.
BASE_FEATURE();

// This feature flag does not turn off any behavior, it is only used for
// experiment parameters.
BASE_FEATURE();

// Enables the validation of optimization guide metadata.
BASE_FEATURE();

BASE_FEATURE();

BASE_FEATURE();

BASE_FEATURE();

BASE_FEATURE();

// Killswitch for fetching on search results from a remote Optimization Guide
// Service.
BASE_FEATURE();

// Kill switch for disabling model quality logging.
BASE_FEATURE();

// Enables fetching personalized metadata from Optimization Guide Service.
BASE_FEATURE();

// An emergency kill switch feature to stop serving certain model versions per
// optimization target. This is useful in exceptional situations when a bad
// model version got served that lead to crashes or critical failures, and an
// immediate remedy is needed to stop serving those versions.
BASE_FEATURE();

// Whether to enable model execution.
BASE_FEATURE();

// Whether to use the on device model service in optimization guide.
BASE_FEATURE();

// Whether to allow on device model evaluation for Compose. This has no effect
// if OptimizationGuideOnDeviceModel is off.
BASE_FEATURE();

// Whether the on device service is launched after a delay on startup to log
// metrics.
BASE_FEATURE();

// Whether to download the text safety classifier model.
BASE_FEATURE();

// Whether the text safety remote fallback should be used.
BASE_FEATURE();

// Whether the on-device model validation checks are enabled.
BASE_FEATURE();

// Whether the on-device model enables support_multiple_sessions
BASE_FEATURE();

// The default value here is a bit of a guess.
// TODO(crbug.com/40163041): This should be tuned once metrics are available.
base::TimeDelta PageTextExtractionOutstandingRequestsGracePeriod() {}

bool ShouldBatchUpdateHintsForActiveTabsAndTopHosts() {}

size_t MaxResultsForSRPFetch() {}

size_t MaxHostsForOptimizationGuideServiceHintsFetch() {}

size_t MaxUrlsForOptimizationGuideServiceHintsFetch() {}

size_t MaxHostsForRecordingSuccessfullyCovered() {}

base::TimeDelta StoredFetchedHintsFreshnessDuration() {}

std::string GetOptimizationGuideServiceAPIKey() {}

GURL GetOptimizationGuideServiceGetHintsURL() {}

GURL GetOptimizationGuideServiceGetModelsURL() {}

bool IsOptimizationTargetPredictionEnabled() {}

bool IsOptimizationHintsEnabled() {}

bool IsModelQualityLoggingEnabled() {}

bool IsModelQualityLoggingEnabledForFeature(
    const MqlsFeatureMetadata* metadata) {}

bool IsRemoteFetchingEnabled() {}

bool IsSRPFetchingEnabled() {}

bool IsPushNotificationsEnabled() {}

bool IsRemoteFetchingForAnonymousDataConsentEnabled() {}

bool IsRemoteFetchingExplicitlyAllowedForPerformanceInfo() {}

int MaxServerBloomFilterByteSize() {}

base::TimeDelta GetHostHintsFetchRefreshDuration() {}

base::TimeDelta GetActiveTabsFetchRefreshDuration() {}

base::TimeDelta GetActiveTabsStalenessTolerance() {}

size_t MaxConcurrentBatchUpdateFetches() {}

size_t MaxConcurrentPageNavigationFetches() {}

base::TimeDelta ActiveTabsHintsFetchRandomMinDelay() {}

base::TimeDelta ActiveTabsHintsFetchRandomMaxDelay() {}

base::TimeDelta StoredHostModelFeaturesFreshnessDuration() {}

base::TimeDelta StoredModelsValidDuration() {}

base::TimeDelta URLKeyedHintValidCacheDuration() {}

size_t MaxHostsForOptimizationGuideServiceModelsFetch() {}

size_t MaxHostModelFeaturesCacheSize() {}

size_t MaxHostKeyedHintCacheSize() {}

size_t MaxURLKeyedHintCacheSize() {}

bool ShouldPersistHintsToDisk() {}

RequestContextSet GetAllowedContextsForPersonalizedMetadata() {}

bool ShouldOverrideOptimizationTargetDecisionForMetricsPurposes(
    proto::OptimizationTarget optimization_target) {}

base::TimeDelta PredictionModelFetchRandomMinDelay() {}

base::TimeDelta PredictionModelFetchRandomMaxDelay() {}

base::TimeDelta PredictionModelFetchRetryDelay() {}

base::TimeDelta PredictionModelFetchStartupDelay() {}

base::TimeDelta PredictionModelFetchInterval() {}

base::TimeDelta PredictionModelNewRegistrationFetchRandomDelay() {}

bool IsModelExecutionWatchdogEnabled() {}

base::TimeDelta ModelExecutionWatchdogDefaultTimeout() {}

bool IsModelDownloadingEnabled() {}

bool IsUnrestrictedModelDownloadingEnabled() {}

base::TimeDelta GetOnloadDelayForHintsFetching() {}

bool ShouldMetadataValidationFetchHostKeyed() {}

bool ShouldDeferStartupActiveTabsHintsFetch() {}

std::optional<int> OverrideNumThreadsForOptTarget(
    proto::OptimizationTarget opt_target) {}

bool TFLiteXNNPACKDelegateEnabled() {}

bool ShouldCheckFailedComponentVersionPref() {}

std::map<proto::OptimizationTarget, std::set<int64_t>>
GetPredictionModelVersionsInKillSwitch() {}

bool ShouldLoadOnDeviceModelExecutionConfigWithHigherPriority() {}

base::TimeDelta GetOnDeviceModelIdleTimeout() {}

bool GetOnDeviceModelSupportMultipleSessions() {}

base::TimeDelta GetOnDeviceModelExecutionValidationStartupDelay() {}

int GetOnDeviceModelMinTokensForContext() {}

int GetOnDeviceModelMaxTokensForContext() {}

int GetOnDeviceModelContextTokenChunkSize() {}

int GetOnDeviceModelMaxTokensForExecute() {}

int GetOnDeviceModelMaxTokensForOutput() {}

int GetOnDeviceModelCrashCountBeforeDisable() {}

int GetOnDeviceModelTimeoutCountBeforeDisable() {}

base::TimeDelta GetOnDeviceStartupMetricDelay() {}

base::TimeDelta GetOnDeviceModelTimeForInitialResponse() {}

bool GetOnDeviceFallbackToServerOnDisconnect() {}

bool IsPerformanceClassCompatibleWithOnDeviceModel(
    OnDeviceModelPerformanceClass performance_class) {}

bool CanLaunchOnDeviceModelService() {}

bool IsOnDeviceExecutionEnabled() {}

base::TimeDelta GetOnDeviceEligibleModelFeatureRecentUsePeriod() {}

base::TimeDelta GetOnDeviceModelRetentionTime() {}

bool IsFreeDiskSpaceSufficientForOnDeviceModelInstall(
    int64_t free_disk_space_bytes) {}

bool IsFreeDiskSpaceTooLowForOnDeviceModelInstall(
    int64_t free_disk_space_bytes) {}

bool GetOnDeviceModelRetractUnsafeContent() {}

bool ShouldUseTextSafetyClassifierModel() {}

uint32_t GetOnDeviceModelTextSafetyTokenInterval() {}

double GetOnDeviceModelLanguageDetectionMinimumReliability() {}

bool ShouldUseTextSafetyRemoteFallbackForEligibleFeatures() {}

int GetOnDeviceModelNumRepeats() {}

int GetOnDeviceModelMinRepeatChars() {}

bool GetOnDeviceModelRetractRepeats() {}

int GetOnDeviceModelDefaultTopK() {}

int GetOnDeviceModelMaxTopK() {}

double GetOnDeviceModelDefaultTemperature() {}

std::vector<uint32_t> GetOnDeviceModelAllowedAdaptationRanks() {}

bool IsOnDeviceModelValidationEnabled() {}

bool ShouldOnDeviceModelBlockOnValidationFailure() {}

bool ShouldOnDeviceModelClearValidationOnVersionChange() {}

base::TimeDelta GetOnDeviceModelValidationDelay() {}

int GetOnDeviceModelValidationAttemptCount() {}

}  // namespace features
}  // namespace optimization_guide