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