blob: bf7a7cc62547a27b2a556eac84760adb5aefaa90 [file] [log] [blame]
Jonas Oreland128c4dc2022-03-30 05:57:481/*
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 Orelandf096e742022-05-31 09:15:1914#include <memory>
Jonas Oreland128c4dc2022-03-30 05:57:4815#include <string>
16
17#include "absl/strings/string_view.h"
Emil Lundmark1c8103d2022-09-21 13:20:2218#include "api/field_trials_registry.h"
Jonas Oreland128c4dc2022-03-30 05:57:4819#include "rtc_base/containers/flat_map.h"
20
21namespace 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 Orelandf096e742022-05-31 09:15:1936// (unless using CreateNoGlobal):
Emil Lundmark1c8103d2022-09-21 13:20:2237class FieldTrials : public FieldTrialsRegistry {
Jonas Oreland128c4dc2022-03-30 05:57:4838 public:
39 explicit FieldTrials(const std::string& s);
40 ~FieldTrials();
41
Jonas Orelandf096e742022-05-31 09:15:1942 // 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 Oreland128c4dc2022-03-30 05:57:4846 private:
Jonas Orelandf096e742022-05-31 09:15:1947 explicit FieldTrials(const std::string& s, bool);
Emil Lundmark1c8103d2022-09-21 13:20:2248
49 std::string GetValue(absl::string_view key) const override;
50
Jonas Orelandf096e742022-05-31 09:15:1951 const bool uses_global_;
Jonas Oreland128c4dc2022-03-30 05:57:4852 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_