blob: 60158f48865bc51aafd7a371323524ab5c2feab3 [file] [log] [blame]
andresp@webrtc.orga36ad692014-05-14 12:24:04 +00001// Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
2//
3// Use of this source code is governed by a BSD-style license
4// that can be found in the LICENSE file in the root of the source
5// tree. An additional intellectual property rights grant can be found
6// in the file PATENTS. All contributing project authors may
7// be found in the AUTHORS file in the root of the source tree.
8//
9
Karl Wiberg79eb1d92017-11-08 12:26:07 +010010#include "system_wrappers/include/field_trial.h"
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000011
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000012#include <string>
13
14// Simple field trial implementation, which allows client to
15// specify desired flags in InitFieldTrialsFromString.
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000016namespace webrtc {
17namespace field_trial {
18
Karl Wiberg79eb1d92017-11-08 12:26:07 +010019static const char* trials_init_string = NULL;
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000020
Mirko Bonadei92e00382018-09-15 10:37:11 +020021#ifndef WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000022std::string FindFullName(const std::string& name) {
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000023 if (trials_init_string == NULL)
24 return std::string();
25
26 std::string trials_string(trials_init_string);
27 if (trials_string.empty())
28 return std::string();
29
30 static const char kPersistentStringSeparator = '/';
31 size_t next_item = 0;
32 while (next_item < trials_string.length()) {
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000033 // Find next name/value pair in field trial configuration string.
Karl Wiberg79eb1d92017-11-08 12:26:07 +010034 size_t field_name_end =
35 trials_string.find(kPersistentStringSeparator, next_item);
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000036 if (field_name_end == trials_string.npos || field_name_end == next_item)
37 break;
Karl Wiberg79eb1d92017-11-08 12:26:07 +010038 size_t field_value_end =
39 trials_string.find(kPersistentStringSeparator, field_name_end + 1);
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000040 if (field_value_end == trials_string.npos ||
41 field_value_end == field_name_end + 1)
42 break;
43 std::string field_name(trials_string, next_item,
Karl Wiberg79eb1d92017-11-08 12:26:07 +010044 field_name_end - next_item);
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000045 std::string field_value(trials_string, field_name_end + 1,
Karl Wiberg79eb1d92017-11-08 12:26:07 +010046 field_value_end - field_name_end - 1);
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000047 next_item = field_value_end + 1;
48
49 if (name == field_name)
50 return field_value;
51 }
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000052 return std::string();
53}
Mirko Bonadei92e00382018-09-15 10:37:11 +020054#endif // WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000055
glaznev@webrtc.org669bc7e2015-02-09 18:17:46 +000056// Optionally initialize field trial from a string.
57void InitFieldTrialsFromString(const char* trials_string) {
58 trials_init_string = trials_string;
59}
60
phoglund37ebcf02016-01-08 05:04:57 -080061const char* GetFieldTrialString() {
62 return trials_init_string;
63}
64
andresp@webrtc.orga36ad692014-05-14 12:24:04 +000065} // namespace field_trial
66} // namespace webrtc