From 669bc7ee437ae72aa90eb96e33699bfe5c666d8e Mon Sep 17 00:00:00 2001 From: "glaznev@webrtc.org" Date: Mon, 9 Feb 2015 18:17:46 +0000 Subject: [PATCH] Modify default field trial implementation to allow WebRTC client to turn on feature code. R=andresp@webrtc.org, henrika@webrtc.org, mflodman@webrtc.org Review URL: https://webrtc-codereview.appspot.com/39729004 Cr-Commit-Position: refs/heads/master@{#8301} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8301 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/system_wrappers/BUILD.gn | 1 + .../interface/field_trial_default.h | 26 +++++++++++ .../source/field_trial_default.cc | 44 ++++++++++++++++++- webrtc/system_wrappers/system_wrappers.gyp | 1 + 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 webrtc/system_wrappers/interface/field_trial_default.h diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn index c4f1da5ef1..23063f33de 100644 --- a/webrtc/system_wrappers/BUILD.gn +++ b/webrtc/system_wrappers/BUILD.gn @@ -188,6 +188,7 @@ static_library("system_wrappers") { source_set("field_trial_default") { sources = [ + "interface/field_trial_default.h", "source/field_trial_default.cc", ] diff --git a/webrtc/system_wrappers/interface/field_trial_default.h b/webrtc/system_wrappers/interface/field_trial_default.h new file mode 100644 index 0000000000..fafe550dcc --- /dev/null +++ b/webrtc/system_wrappers/interface/field_trial_default.h @@ -0,0 +1,26 @@ +// +// Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// + +#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_DEFAULT_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_DEFAULT_H_ + +namespace webrtc { +namespace field_trial { + +// Optionally initialize field trial from a string. +// This method can be called at most once before any other call into webrtc. +// E.g. before the peer connection factory is constructed. +// Note: trials_string must never be destroyed. +void InitFieldTrialsFromString(const char* trials_string); + +} // namespace field_trial +} // namespace webrtc + +#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_FIELD_TRIAL_DEFAULT_H_ diff --git a/webrtc/system_wrappers/source/field_trial_default.cc b/webrtc/system_wrappers/source/field_trial_default.cc index 892623cef5..97b703f6b1 100644 --- a/webrtc/system_wrappers/source/field_trial_default.cc +++ b/webrtc/system_wrappers/source/field_trial_default.cc @@ -8,15 +8,55 @@ // #include "webrtc/system_wrappers/interface/field_trial.h" +#include "webrtc/system_wrappers/interface/field_trial_default.h" -// Clients of webrtc that do not want to configure field trials can link with -// this instead of providing their own implementation. +#include + +// Simple field trial implementation, which allows client to +// specify desired flags in InitFieldTrialsFromString. namespace webrtc { namespace field_trial { +static const char *trials_init_string = NULL; + std::string FindFullName(const std::string& name) { + if (trials_init_string == NULL) + return std::string(); + + std::string trials_string(trials_init_string); + if (trials_string.empty()) + return std::string(); + + static const char kPersistentStringSeparator = '/'; + size_t next_item = 0; + while (next_item < trials_string.length()) { + + // Find next name/value pair in field trial configuration string. + size_t field_name_end = trials_string.find( + kPersistentStringSeparator, next_item); + if (field_name_end == trials_string.npos || field_name_end == next_item) + break; + size_t field_value_end = trials_string.find( + kPersistentStringSeparator, field_name_end + 1); + if (field_value_end == trials_string.npos || + field_value_end == field_name_end + 1) + break; + std::string field_name(trials_string, next_item, + field_name_end - next_item); + std::string field_value(trials_string, field_name_end + 1, + field_value_end - field_name_end - 1); + next_item = field_value_end + 1; + + if (name == field_name) + return field_value; + } return std::string(); } +// Optionally initialize field trial from a string. +void InitFieldTrialsFromString(const char* trials_string) { + trials_init_string = trials_string; +} + } // namespace field_trial } // namespace webrtc diff --git a/webrtc/system_wrappers/system_wrappers.gyp b/webrtc/system_wrappers/system_wrappers.gyp index 50801de1e1..683840f4b9 100644 --- a/webrtc/system_wrappers/system_wrappers.gyp +++ b/webrtc/system_wrappers/system_wrappers.gyp @@ -205,6 +205,7 @@ 'target_name': 'field_trial_default', 'type': 'static_library', 'sources': [ + 'interface/field_trial_default.h', 'source/field_trial_default.cc', ], 'dependencies': [