Don't require call to ValidateFieldTrialsStringOrDie for ScopedFieldTrials.

Bug: webrtc:9883
Change-Id: Iae7b2d22666ad57176237241a7f895cbd47cd26d
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/134311
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27846}
diff --git a/test/field_trial.cc b/test/field_trial.cc
index 2fb5da4..48d0bd3 100644
--- a/test/field_trial.cc
+++ b/test/field_trial.cc
@@ -20,19 +20,12 @@
 #include "system_wrappers/include/field_trial.h"
 
 namespace webrtc {
-namespace {
-bool field_trials_initiated_ = false;
-}  // namespace
-
 namespace test {
+namespace {
 
-void ValidateFieldTrialsStringOrDie(const std::string& trials_string) {
+void InnerValidateFieldTrialsStringOrDie(const std::string& trials_string) {
   static const char kPersistentStringSeparator = '/';
 
-  // Catch an error if this is called more than once.
-  assert(!field_trials_initiated_);
-  field_trials_initiated_ = true;
-
   if (trials_string.empty())
     return;
 
@@ -61,7 +54,6 @@
 
     // Successfully parsed all field trials from the string.
     if (next_item == trials_string.length()) {
-      // webrtc::field_trial::InitFieldTrialsFromString(trials_string.c_str());
       return;
     }
   }
@@ -71,20 +63,24 @@
   // Using abort so it crashes in both debug and release mode.
   abort();
 }
+}  // namespace
+
+void ValidateFieldTrialsStringOrDie(const std::string& trials_string) {
+  static bool field_trials_initiated_ = false;
+  // Catch an error if this is called more than once.
+  assert(!field_trials_initiated_);
+  field_trials_initiated_ = true;
+  InnerValidateFieldTrialsStringOrDie(trials_string);
+}
 
 ScopedFieldTrials::ScopedFieldTrials(const std::string& config)
     : previous_field_trials_(webrtc::field_trial::GetFieldTrialString()) {
-  assert(field_trials_initiated_);
-  field_trials_initiated_ = false;
   current_field_trials_ = config;
-  ValidateFieldTrialsStringOrDie(current_field_trials_);
+  InnerValidateFieldTrialsStringOrDie(current_field_trials_);
   webrtc::field_trial::InitFieldTrialsFromString(current_field_trials_.c_str());
 }
 
 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_);
   webrtc::field_trial::InitFieldTrialsFromString(previous_field_trials_);
 }