Jonas Oreland | 128c4dc | 2022-03-30 05:57:48 | [diff] [blame] | 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 | |
Jonas Oreland | f096e74 | 2022-05-31 09:15:19 | [diff] [blame] | 14 | #include <memory> |
Jonas Oreland | 128c4dc | 2022-03-30 05:57:48 | [diff] [blame] | 15 | #include <string> |
| 16 | |
| 17 | #include "absl/strings/string_view.h" |
Emil Lundmark | 1c8103d | 2022-09-21 13:20:22 | [diff] [blame^] | 18 | #include "api/field_trials_registry.h" |
Jonas Oreland | 128c4dc | 2022-03-30 05:57:48 | [diff] [blame] | 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)) |
Jonas Oreland | f096e74 | 2022-05-31 09:15:19 | [diff] [blame] | 36 | // (unless using CreateNoGlobal): |
Emil Lundmark | 1c8103d | 2022-09-21 13:20:22 | [diff] [blame^] | 37 | class FieldTrials : public FieldTrialsRegistry { |
Jonas Oreland | 128c4dc | 2022-03-30 05:57:48 | [diff] [blame] | 38 | public: |
| 39 | explicit FieldTrials(const std::string& s); |
| 40 | ~FieldTrials(); |
| 41 | |
Jonas Oreland | f096e74 | 2022-05-31 09:15:19 | [diff] [blame] | 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 | |
Jonas Oreland | 128c4dc | 2022-03-30 05:57:48 | [diff] [blame] | 46 | private: |
Jonas Oreland | f096e74 | 2022-05-31 09:15:19 | [diff] [blame] | 47 | explicit FieldTrials(const std::string& s, bool); |
Emil Lundmark | 1c8103d | 2022-09-21 13:20:22 | [diff] [blame^] | 48 | |
| 49 | std::string GetValue(absl::string_view key) const override; |
| 50 | |
Jonas Oreland | f096e74 | 2022-05-31 09:15:19 | [diff] [blame] | 51 | const bool uses_global_; |
Jonas Oreland | 128c4dc | 2022-03-30 05:57:48 | [diff] [blame] | 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_ |