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 <hta@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45273}
This commit is contained in:
Danil Chapovalov 2025-08-04 10:47:33 +02:00 committed by WebRTC LUCI CQ
parent 3fe6c9abaf
commit 76ed738ec2
7 changed files with 34 additions and 87 deletions

View File

@ -9,6 +9,7 @@
*/
#include "api/transport/field_trial_based_config.h"
#include <cstddef>
#include <string>
#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

View File

@ -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

View File

@ -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",
]
}

View File

@ -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.

View File

@ -15,15 +15,11 @@
#include <utility>
#include <vector>
#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;

View File

@ -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",
]

View File

@ -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