| Index: webrtc/test/field_trial.cc
|
| diff --git a/webrtc/test/field_trial.cc b/webrtc/test/field_trial.cc
|
| index 613fb67679a583c797d2ff57c8f4dbec922bc401..c40d0783d8d60d914ced95b530701b6b9e38117c 100644
|
| --- a/webrtc/test/field_trial.cc
|
| +++ b/webrtc/test/field_trial.cc
|
| @@ -18,27 +18,13 @@
|
| #include <string>
|
|
|
| #include "webrtc/system_wrappers/include/field_trial.h"
|
| +#include "webrtc/system_wrappers/include/field_trial_default.h"
|
|
|
| namespace webrtc {
|
| namespace {
|
| -// Clients of this library have show a clear intent to setup field trials by
|
| -// linking with it. As so try to crash if they forget to call
|
| -// InitFieldTrialsFromString before webrtc tries to access a field trial.
|
| bool field_trials_initiated_ = false;
|
| -std::map<std::string, std::string> field_trials_;
|
| } // namespace
|
|
|
| -namespace field_trial {
|
| -std::string FindFullName(const std::string& trial_name) {
|
| - assert(field_trials_initiated_);
|
| - std::map<std::string, std::string>::const_iterator it =
|
| - field_trials_.find(trial_name);
|
| - if (it == field_trials_.end())
|
| - return std::string();
|
| - return it->second;
|
| -}
|
| -} // namespace field_trial
|
| -
|
| namespace test {
|
| // Note: this code is copied from src/base/metrics/field_trial.cc since the aim
|
| // is to mimic chromium --force-fieldtrials.
|
| @@ -53,6 +39,7 @@ void InitFieldTrialsFromString(const std::string& trials_string) {
|
| return;
|
|
|
| size_t next_item = 0;
|
| + std::map<std::string, std::string> field_trials;
|
| while (next_item < trials_string.length()) {
|
| size_t name_end = trials_string.find(kPersistentStringSeparator, next_item);
|
| if (name_end == trials_string.npos || next_item == name_end)
|
| @@ -67,15 +54,18 @@ void InitFieldTrialsFromString(const std::string& trials_string) {
|
| next_item = group_name_end + 1;
|
|
|
| // Fail if duplicate with different group name.
|
| - if (field_trials_.find(name) != field_trials_.end() &&
|
| - field_trials_.find(name)->second != group_name)
|
| + if (field_trials.find(name) != field_trials.end() &&
|
| + field_trials.find(name)->second != group_name) {
|
| break;
|
| + }
|
|
|
| - field_trials_[name] = group_name;
|
| + field_trials[name] = group_name;
|
|
|
| // Successfully parsed all field trials from the string.
|
| - if (next_item == trials_string.length())
|
| + if (next_item == trials_string.length()) {
|
| + webrtc::field_trial::InitFieldTrialsFromString(trials_string.c_str());
|
| return;
|
| + }
|
| }
|
| // Using fprintf as LOG does not print when this is called early in main.
|
| fprintf(stderr, "Invalid field trials string.\n");
|
| @@ -85,18 +75,18 @@ void InitFieldTrialsFromString(const std::string& trials_string) {
|
| }
|
|
|
| ScopedFieldTrials::ScopedFieldTrials(const std::string& config)
|
| - : previous_field_trials_(field_trials_) {
|
| + : previous_field_trials_(webrtc::field_trial::GetFieldTrialString()) {
|
| assert(field_trials_initiated_);
|
| field_trials_initiated_ = false;
|
| - field_trials_.clear();
|
| - InitFieldTrialsFromString(config);
|
| + current_field_trials_ = config;
|
| + InitFieldTrialsFromString(current_field_trials_);
|
| }
|
|
|
| ScopedFieldTrials::~ScopedFieldTrials() {
|
| // Should still be initialized, since InitFieldTrials is called from ctor.
|
| // That's why we don't restore the flag.
|
| assert(field_trials_initiated_);
|
| - field_trials_ = previous_field_trials_;
|
| + webrtc::field_trial::InitFieldTrialsFromString(previous_field_trials_);
|
| }
|
|
|
| } // namespace test
|
|
|