andresp@webrtc.org | a36ad69 | 2014-05-14 12:24:04 +0000 | [diff] [blame] | 1 | // 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 Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 10 | #include "system_wrappers/include/field_trial.h" |
andresp@webrtc.org | a36ad69 | 2014-05-14 12:24:04 +0000 | [diff] [blame] | 11 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame^] | 12 | #include <stddef.h> |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 13 | #include <string> |
| 14 | |
| 15 | // Simple field trial implementation, which allows client to |
| 16 | // specify desired flags in InitFieldTrialsFromString. |
andresp@webrtc.org | a36ad69 | 2014-05-14 12:24:04 +0000 | [diff] [blame] | 17 | namespace webrtc { |
| 18 | namespace field_trial { |
| 19 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 20 | static const char* trials_init_string = NULL; |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 21 | |
Mirko Bonadei | 92e0038 | 2018-09-15 10:37:11 +0200 | [diff] [blame] | 22 | #ifndef WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT |
andresp@webrtc.org | a36ad69 | 2014-05-14 12:24:04 +0000 | [diff] [blame] | 23 | std::string FindFullName(const std::string& name) { |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 24 | if (trials_init_string == NULL) |
| 25 | return std::string(); |
| 26 | |
| 27 | std::string trials_string(trials_init_string); |
| 28 | if (trials_string.empty()) |
| 29 | return std::string(); |
| 30 | |
| 31 | static const char kPersistentStringSeparator = '/'; |
| 32 | size_t next_item = 0; |
| 33 | while (next_item < trials_string.length()) { |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 34 | // Find next name/value pair in field trial configuration string. |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 35 | size_t field_name_end = |
| 36 | trials_string.find(kPersistentStringSeparator, next_item); |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 37 | if (field_name_end == trials_string.npos || field_name_end == next_item) |
| 38 | break; |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 39 | size_t field_value_end = |
| 40 | trials_string.find(kPersistentStringSeparator, field_name_end + 1); |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 41 | if (field_value_end == trials_string.npos || |
| 42 | field_value_end == field_name_end + 1) |
| 43 | break; |
| 44 | std::string field_name(trials_string, next_item, |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 45 | field_name_end - next_item); |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 46 | std::string field_value(trials_string, field_name_end + 1, |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 47 | field_value_end - field_name_end - 1); |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 48 | next_item = field_value_end + 1; |
| 49 | |
| 50 | if (name == field_name) |
| 51 | return field_value; |
| 52 | } |
andresp@webrtc.org | a36ad69 | 2014-05-14 12:24:04 +0000 | [diff] [blame] | 53 | return std::string(); |
| 54 | } |
Mirko Bonadei | 92e0038 | 2018-09-15 10:37:11 +0200 | [diff] [blame] | 55 | #endif // WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT |
andresp@webrtc.org | a36ad69 | 2014-05-14 12:24:04 +0000 | [diff] [blame] | 56 | |
glaznev@webrtc.org | 669bc7e | 2015-02-09 18:17:46 +0000 | [diff] [blame] | 57 | // Optionally initialize field trial from a string. |
| 58 | void InitFieldTrialsFromString(const char* trials_string) { |
| 59 | trials_init_string = trials_string; |
| 60 | } |
| 61 | |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 62 | const char* GetFieldTrialString() { |
| 63 | return trials_init_string; |
| 64 | } |
| 65 | |
andresp@webrtc.org | a36ad69 | 2014-05-14 12:24:04 +0000 | [diff] [blame] | 66 | } // namespace field_trial |
| 67 | } // namespace webrtc |