tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

field_trials_registry.h (1828B)


      1 /*
      2 *  Copyright 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 #ifndef API_FIELD_TRIALS_REGISTRY_H_
     11 #define API_FIELD_TRIALS_REGISTRY_H_
     12 
     13 #include <string>
     14 #include <utility>
     15 
     16 #include "absl/strings/string_view.h"
     17 #include "api/field_trials_view.h"
     18 #include "rtc_base/containers/flat_set.h"
     19 #include "rtc_base/system/rtc_export.h"
     20 
     21 namespace webrtc {
     22 
     23 // Abstract base class for a field trial registry that verifies that any looked
     24 // up key has been pre-registered in accordance with `g3doc/field-trials.md`.
     25 class RTC_EXPORT FieldTrialsRegistry : public FieldTrialsView {
     26 public:
     27  FieldTrialsRegistry() = default;
     28 
     29  FieldTrialsRegistry(const FieldTrialsRegistry&) = default;
     30  FieldTrialsRegistry& operator=(const FieldTrialsRegistry&) = default;
     31 
     32  ~FieldTrialsRegistry() override = default;
     33 
     34  // Verifies that `key` is a registered field trial and then returns the
     35  // configured value for `key` or an empty string if the field trial isn't
     36  // configured.
     37  std::string Lookup(absl::string_view key) const override;
     38 
     39  // Register additional `keys` for testing. This should only be used for
     40  // imaginary keys that are never used outside test code.
     41  void RegisterKeysForTesting(flat_set<std::string> keys) {
     42    test_keys_ = std::move(keys);
     43  }
     44 
     45 private:
     46  virtual std::string GetValue(absl::string_view key) const = 0;
     47 
     48  // Imaginary keys only used for testing.
     49  flat_set<std::string> test_keys_;
     50 };
     51 
     52 }  // namespace webrtc
     53 
     54 #endif  // API_FIELD_TRIALS_REGISTRY_H_