blob: 52db33b0e9c780f786473ad01be3f92206ad5e58 [file] [log] [blame]
andresp@webrtc.orga36ad692014-05-14 12:24:04 +00001//
2// Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3//
4// Use of this source code is governed by a BSD-style license
5// that can be found in the LICENSE file in the root of the source
6// tree. An additional intellectual property rights grant can be found
7// in the file PATENTS. All contributing project authors may
8// be found in the AUTHORS file in the root of the source tree.
9//
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_
12#define SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000013
14#include <string>
15
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000016// Field trials allow webrtc clients (such as Chrome) to turn on feature code
17// in binaries out in the field and gather information with that.
18//
Konrad Hofbaueree1e0152019-12-05 16:25:40 +010019// By default WebRTC provides an implementation of field trials that can be
Mirko Bonadei92e00382018-09-15 10:37:11 +020020// found in system_wrappers/source/field_trial.cc. If clients want to provide
21// a custom version, they will have to:
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000022//
Mirko Bonadei92e00382018-09-15 10:37:11 +020023// 1. Compile WebRTC defining the preprocessor macro
24// WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT (if GN is used this can be achieved
25// by setting the GN arg rtc_exclude_field_trial_default to true).
26// 2. Provide an implementation of:
27// std::string webrtc::field_trial::FindFullName(const std::string& trial).
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000028//
29// They are designed to wire up directly to chrome field trials and to speed up
30// developers by reducing the need to wire APIs to control whether a feature is
31// on/off. E.g. to experiment with a new method that could lead to a different
32// trade-off between CPU/bandwidth:
33//
34// 1 - Develop the feature with default behaviour off:
35//
Jonas Olsson5b2eda42019-06-11 14:29:40 +020036// if (FieldTrial::FindFullName("WebRTCExperimentMethod2") == "Enabled")
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000037// method2();
38// else
39// method1();
40//
41// 2 - Once the changes are rolled to chrome, the new code path can be
42// controlled as normal chrome field trials.
43//
44// 3 - Evaluate the new feature and clean the code paths.
45//
46// Notes:
47// - NOT every feature is a candidate to be controlled by this mechanism as
Konrad Hofbaueree1e0152019-12-05 16:25:40 +010048// it may require negotiation between involved parties (e.g. SDP).
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000049//
50// TODO(andresp): since chrome --force-fieldtrials does not marks the trial
Konrad Hofbaueree1e0152019-12-05 16:25:40 +010051// as active it does not get propagated to the renderer process. For now one
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000052// needs to push a config with start_active:true or run a local finch
53// server.
54//
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000055// TODO(andresp): find out how to get bots to run tests with trials enabled.
56
57namespace webrtc {
58namespace field_trial {
59
60// Returns the group name chosen for the named trial, or the empty string
61// if the trial does not exists.
62//
63// Note: To keep things tidy append all the trial names with WebRTC.
Mirko Bonadei51868f52019-11-23 15:10:32 +000064std::string FindFullName(const std::string& name);
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000065
sprangc1b57a12017-02-28 08:50:47 -080066// Convenience method, returns true iff FindFullName(name) return a string that
67// starts with "Enabled".
tommi9751c452017-02-28 09:26:22 -080068// TODO(tommi): Make sure all implementations support this.
69inline bool IsEnabled(const char* name) {
70 return FindFullName(name).find("Enabled") == 0;
71}
sprangc1b57a12017-02-28 08:50:47 -080072
Ilya Nikolaevskiy8cf45e92018-01-15 10:16:54 +010073// Convenience method, returns true iff FindFullName(name) return a string that
74// starts with "Disabled".
75inline bool IsDisabled(const char* name) {
76 return FindFullName(name).find("Disabled") == 0;
77}
78
Mirko Bonadei92e00382018-09-15 10:37:11 +020079// Optionally initialize field trial from a string.
80// This method can be called at most once before any other call into webrtc.
81// E.g. before the peer connection factory is constructed.
82// Note: trials_string must never be destroyed.
Mirko Bonadei51868f52019-11-23 15:10:32 +000083void InitFieldTrialsFromString(const char* trials_string);
Mirko Bonadei92e00382018-09-15 10:37:11 +020084
85const char* GetFieldTrialString();
86
Konrad Hofbaueree1e0152019-12-05 16:25:40 +010087#ifndef WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT
88// Validates the given field trial string.
89bool FieldTrialsStringIsValid(const char* trials_string);
90
91// Merges two field trial strings.
92//
93// If a key (trial) exists twice with conflicting values (groups), the value
94// in 'second' takes precedence.
95// Shall only be called with valid FieldTrial strings.
96std::string MergeFieldTrialsStrings(const char* first, const char* second);
97#endif // WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT
98
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000099} // namespace field_trial
100} // namespace webrtc
101
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200102#endif // SYSTEM_WRAPPERS_INCLUDE_FIELD_TRIAL_H_