tor-browser

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

deprecated_global_field_trials.cc (1903B)


      1 /*
      2 *  Copyright 2019 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 #include "api/environment/deprecated_global_field_trials.h"
     11 
     12 #include <cstddef>
     13 #include <string>
     14 
     15 #include "absl/strings/string_view.h"
     16 
     17 namespace webrtc {
     18 namespace {
     19 
     20 constinit const char* global_field_trial_string = nullptr;
     21 
     22 }  // namespace
     23 
     24 void DeprecatedGlobalFieldTrials::Set(const char* field_trials) {
     25  global_field_trial_string = field_trials;
     26 }
     27 
     28 std::string DeprecatedGlobalFieldTrials::GetValue(absl::string_view key) const {
     29  if (global_field_trial_string == nullptr)
     30    return std::string();
     31 
     32  absl::string_view trials_string(global_field_trial_string);
     33  if (trials_string.empty())
     34    return std::string();
     35 
     36  size_t next_item = 0;
     37  while (next_item < trials_string.length()) {
     38    // Find next name/value pair in field trial configuration string.
     39    size_t field_name_end = trials_string.find('/', next_item);
     40    if (field_name_end == trials_string.npos || field_name_end == next_item)
     41      break;
     42    size_t field_value_end = trials_string.find('/', field_name_end + 1);
     43    if (field_value_end == trials_string.npos ||
     44        field_value_end == field_name_end + 1)
     45      break;
     46    absl::string_view field_name =
     47        trials_string.substr(next_item, field_name_end - next_item);
     48    absl::string_view field_value = trials_string.substr(
     49        field_name_end + 1, field_value_end - field_name_end - 1);
     50    next_item = field_value_end + 1;
     51 
     52    if (key == field_name)
     53      return std::string(field_value);
     54  }
     55  return std::string();
     56 }
     57 }  // namespace webrtc