xref: /aosp_15_r20/external/webrtc/api/field_trials.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef API_FIELD_TRIALS_H_
12*d9f75844SAndroid Build Coastguard Worker #define API_FIELD_TRIALS_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <memory>
15*d9f75844SAndroid Build Coastguard Worker #include <string>
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/string_view.h"
18*d9f75844SAndroid Build Coastguard Worker #include "api/field_trials_registry.h"
19*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/containers/flat_map.h"
20*d9f75844SAndroid Build Coastguard Worker 
21*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
22*d9f75844SAndroid Build Coastguard Worker 
23*d9f75844SAndroid Build Coastguard Worker // The FieldTrials class is used to inject field trials into webrtc.
24*d9f75844SAndroid Build Coastguard Worker //
25*d9f75844SAndroid Build Coastguard Worker // Field trials allow webrtc clients (such as Chromium) to turn on feature code
26*d9f75844SAndroid Build Coastguard Worker // in binaries out in the field and gather information with that.
27*d9f75844SAndroid Build Coastguard Worker //
28*d9f75844SAndroid Build Coastguard Worker // They are designed to be easy to use with Chromium field trials and to speed
29*d9f75844SAndroid Build Coastguard Worker // up developers by reducing the need to wire up APIs to control whether a
30*d9f75844SAndroid Build Coastguard Worker // feature is on/off.
31*d9f75844SAndroid Build Coastguard Worker //
32*d9f75844SAndroid Build Coastguard Worker // The field trials are injected into objects that use them at creation time.
33*d9f75844SAndroid Build Coastguard Worker //
34*d9f75844SAndroid Build Coastguard Worker // NOTE: Creating multiple FieldTrials-object is currently prohibited
35*d9f75844SAndroid Build Coastguard Worker // until we remove the global string (TODO(bugs.webrtc.org/10335))
36*d9f75844SAndroid Build Coastguard Worker // (unless using CreateNoGlobal):
37*d9f75844SAndroid Build Coastguard Worker class FieldTrials : public FieldTrialsRegistry {
38*d9f75844SAndroid Build Coastguard Worker  public:
39*d9f75844SAndroid Build Coastguard Worker   explicit FieldTrials(const std::string& s);
40*d9f75844SAndroid Build Coastguard Worker   ~FieldTrials();
41*d9f75844SAndroid Build Coastguard Worker 
42*d9f75844SAndroid Build Coastguard Worker   // Create a FieldTrials object that is not reading/writing from
43*d9f75844SAndroid Build Coastguard Worker   // global variable (i.e can not be used for all parts of webrtc).
44*d9f75844SAndroid Build Coastguard Worker   static std::unique_ptr<FieldTrials> CreateNoGlobal(const std::string& s);
45*d9f75844SAndroid Build Coastguard Worker 
46*d9f75844SAndroid Build Coastguard Worker  private:
47*d9f75844SAndroid Build Coastguard Worker   explicit FieldTrials(const std::string& s, bool);
48*d9f75844SAndroid Build Coastguard Worker 
49*d9f75844SAndroid Build Coastguard Worker   std::string GetValue(absl::string_view key) const override;
50*d9f75844SAndroid Build Coastguard Worker 
51*d9f75844SAndroid Build Coastguard Worker   const bool uses_global_;
52*d9f75844SAndroid Build Coastguard Worker   const std::string field_trial_string_;
53*d9f75844SAndroid Build Coastguard Worker   const char* const previous_field_trial_string_;
54*d9f75844SAndroid Build Coastguard Worker   const flat_map<std::string, std::string> key_value_map_;
55*d9f75844SAndroid Build Coastguard Worker };
56*d9f75844SAndroid Build Coastguard Worker 
57*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
58*d9f75844SAndroid Build Coastguard Worker 
59*d9f75844SAndroid Build Coastguard Worker #endif  // API_FIELD_TRIALS_H_
60