From 76ed738ec278b7e67216c41805a79333facdb3b6 Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Mon, 4 Aug 2025 10:47:33 +0200 Subject: [PATCH] Delete field_trial::FindFullName Thus remove support for providing field trials implementation link-time. Bug: webrtc:42220378 Change-Id: Ifd1240d81485820831195ebb915a3037d7dd8986 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/396880 Reviewed-by: Harald Alvestrand Commit-Queue: Danil Chapovalov Cr-Commit-Position: refs/heads/main@{#45273} --- api/transport/field_trial_based_config.cc | 31 ++++++++++++++- native-api.md | 12 ------ system_wrappers/BUILD.gn | 6 --- system_wrappers/include/field_trial.h | 8 ---- system_wrappers/source/field_trial.cc | 46 ----------------------- test/fuzzers/BUILD.gn | 3 +- webrtc.gni | 15 ++------ 7 files changed, 34 insertions(+), 87 deletions(-) diff --git a/api/transport/field_trial_based_config.cc b/api/transport/field_trial_based_config.cc index bd9313a59f..bd9adaa1fc 100644 --- a/api/transport/field_trial_based_config.cc +++ b/api/transport/field_trial_based_config.cc @@ -9,6 +9,7 @@ */ #include "api/transport/field_trial_based_config.h" +#include #include #include "absl/strings/string_view.h" @@ -18,7 +19,35 @@ namespace webrtc { std::string FieldTrialBasedConfig::GetValue(absl::string_view key) const { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - return field_trial::FindFullName(std::string(key)); + const char* global_field_trial_string = field_trial::GetFieldTrialString(); #pragma clang diagnostic pop + + if (global_field_trial_string == nullptr) + return std::string(); + + absl::string_view trials_string(global_field_trial_string); + if (trials_string.empty()) + return std::string(); + + size_t next_item = 0; + while (next_item < trials_string.length()) { + // Find next name/value pair in field trial configuration string. + size_t field_name_end = trials_string.find('/', next_item); + if (field_name_end == trials_string.npos || field_name_end == next_item) + break; + size_t field_value_end = trials_string.find('/', field_name_end + 1); + if (field_value_end == trials_string.npos || + field_value_end == field_name_end + 1) + break; + absl::string_view field_name = + trials_string.substr(next_item, field_name_end - next_item); + absl::string_view field_value = trials_string.substr( + field_name_end + 1, field_value_end - field_name_end - 1); + next_item = field_value_end + 1; + + if (key == field_name) + return std::string(field_value); + } + return std::string(); } } // namespace webrtc diff --git a/native-api.md b/native-api.md index 66445203cb..ec100a3320 100644 --- a/native-api.md +++ b/native-api.md @@ -84,18 +84,6 @@ You can achieve this by defining the preprocessor macro argument `rtc_builtin_ssl_root_certificates` to false and GN will define the macro for you. -## `WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT` -If you want to provide your own implementation of `webrtc::field_trial` functions -(more info [here][field_trial_h]) you will have to exclude WebRTC's default -implementation. - -You can achieve this by defining the preprocessor macro -`WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT`. If you use GN, you can just set the GN -argument `rtc_exclude_field_trial_default` to true and GN will define the -macro for you. - -[field_trial_h]: https://webrtc.googlesource.com/src/+/main/system_wrappers/include/field_trial.h - ## `WEBRTC_EXCLUDE_METRICS_DEFAULT` If you want to provide your own implementation of `webrtc::metrics` functions (more info [here][metrics_h]) you will have to exclude WebRTC's default diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn index 52efbf7c09..822b565610 100644 --- a/system_wrappers/BUILD.gn +++ b/system_wrappers/BUILD.gn @@ -51,16 +51,10 @@ rtc_library("field_trial") { "include/field_trial.h", "source/field_trial.cc", ] - if (rtc_exclude_field_trial_default) { - defines = [ "WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT" ] - } deps = [ - "../experiments:registered_field_trials", "../rtc_base:checks", "../rtc_base:logging", "../rtc_base:stringutils", - "../rtc_base/containers:flat_set", - "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/strings:string_view", ] } diff --git a/system_wrappers/include/field_trial.h b/system_wrappers/include/field_trial.h index 3647c358fb..ee70cbb629 100644 --- a/system_wrappers/include/field_trial.h +++ b/system_wrappers/include/field_trial.h @@ -25,14 +25,6 @@ namespace webrtc { namespace field_trial { -// Returns the group name chosen for the named trial, or the empty string -// if the trial does not exists. -// -// Note: To keep things tidy append all the trial names with WebRTC. -// TODO: bugs.webrtc.org/42220378 - Remove from api after August 1, 2025. -[[deprecated]] -std::string FindFullName(absl::string_view name); - // Optionally initialize field trial from a string. // This method can be called at most once before any other call into webrtc. // E.g. before the peer connection factory is constructed. diff --git a/system_wrappers/source/field_trial.cc b/system_wrappers/source/field_trial.cc index 569e6cb5eb..b426f42050 100644 --- a/system_wrappers/source/field_trial.cc +++ b/system_wrappers/source/field_trial.cc @@ -15,15 +15,11 @@ #include #include -#include "absl/algorithm/container.h" // IWYU pragma: keep #include "absl/strings/string_view.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" #include "rtc_base/string_encode.h" -// Generated file. -#include "experiments/registered_field_trials.h" // IWYU pragma: keep - // Simple field trial implementation, which allows client to // specify desired flags in InitFieldTrialsFromString. namespace webrtc { @@ -110,48 +106,6 @@ std::string MergeFieldTrialsStrings(absl::string_view first, return merged; } -#ifndef WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT -std::string FindFullName(absl::string_view name) { -#if WEBRTC_STRICT_FIELD_TRIALS == 1 - RTC_DCHECK(absl::c_linear_search(kRegisteredFieldTrials, name)) - << name << " is not registered, see g3doc/field-trials.md."; -#elif WEBRTC_STRICT_FIELD_TRIALS == 2 - RTC_LOG_IF(LS_WARNING, !absl::c_linear_search(kRegisteredFieldTrials, name)) - << name << " is not registered, see g3doc/field-trials.md."; -#endif - - if (trials_init_string == nullptr) - return std::string(); - - absl::string_view trials_string(trials_init_string); - if (trials_string.empty()) - return std::string(); - - size_t next_item = 0; - while (next_item < trials_string.length()) { - // Find next name/value pair in field trial configuration string. - size_t field_name_end = - trials_string.find(kPersistentStringSeparator, next_item); - if (field_name_end == trials_string.npos || field_name_end == next_item) - break; - size_t field_value_end = - trials_string.find(kPersistentStringSeparator, field_name_end + 1); - if (field_value_end == trials_string.npos || - field_value_end == field_name_end + 1) - break; - absl::string_view field_name = - trials_string.substr(next_item, field_name_end - next_item); - absl::string_view field_value = trials_string.substr( - field_name_end + 1, field_value_end - field_name_end - 1); - next_item = field_value_end + 1; - - if (name == field_name) - return std::string(field_value); - } - return std::string(); -} -#endif // WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT - // Optionally initialize field trial from a string. void InitFieldTrialsFromString(const char* trials_string) { RTC_LOG(LS_INFO) << "Setting field trial string:" << trials_string; diff --git a/test/fuzzers/BUILD.gn b/test/fuzzers/BUILD.gn index 6bdaf144fb..9d61ce653a 100644 --- a/test/fuzzers/BUILD.gn +++ b/test/fuzzers/BUILD.gn @@ -19,10 +19,9 @@ rtc_library("webrtc_fuzzer_main") { ] # When WebRTC fuzzer tests are built on Chromium bots they need to link - # with Chromium's implementation of metrics, field trial, and system time. + # with Chromium's implementation of metrics and system time. if (build_with_chromium) { deps += [ - "../../../webrtc_overrides:field_trial", "../../../webrtc_overrides:metrics", "../../../webrtc_overrides:system_time", ] diff --git a/webrtc.gni b/webrtc.gni index 112233b7d3..481a65231b 100644 --- a/webrtc.gni +++ b/webrtc.gni @@ -69,18 +69,9 @@ declare_args() { # annotated symbols. rtc_enable_objc_symbol_export = rtc_enable_symbol_export - # Setting this to true will define WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT which - # will tell the pre-processor to remove the default definition of symbols - # needed to use field_trial. In that case a new implementation needs to be - # provided. - if (build_with_chromium) { - # When WebRTC is built as part of Chromium it should exclude the default - # implementation of field_trial unless it is building for NACL or - # Chromecast. - rtc_exclude_field_trial_default = !is_nacl && !is_castos && !is_cast_android - } else { - rtc_exclude_field_trial_default = false - } + # Deprecated, this flag has no effect. + # TODO: bugs.webrtc.org/42220378 - Delete after August 15, 2025. + rtc_exclude_field_trial_default = false # Setting this to true will define WEBRTC_EXCLUDE_METRICS_DEFAULT which # will tell the pre-processor to remove the default definition of symbols