Browse Source

feat: initialize field trials from command line arguments (#28401)

Fixes: #27877

Co-authored-by: Saúl Ibarra Corretgé <[email protected]>
trop[bot] 4 years ago
parent
commit
2f25c10818

+ 6 - 0
docs/api/command-line-switches.md

@@ -79,6 +79,12 @@ This switch can not be used in `app.commandLine.appendSwitch` since it is parsed
 earlier than user's app is loaded, but you can set the `ELECTRON_ENABLE_LOGGING`
 environment variable to achieve the same effect.
 
+## --force-fieldtrials=`trials`
+
+Field trials to be forcefully enabled or disabled.
+
+For example: `WebRTC-Audio-Red-For-Opus/Enabled/`
+
 ### --host-rules=`rules`
 
 A comma-separated list of `rules` that control how hostnames are mapped.

+ 3 - 0
shell/browser/electron_browser_main_parts.cc

@@ -334,6 +334,9 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
   base::FeatureList::ClearInstanceForTesting();
   InitializeFeatureList();
 
+  // Initialize field trials.
+  InitializeFieldTrials();
+
   // Initialize after user script environment creation.
   fake_browser_process_->PostEarlyInitialization();
 }

+ 9 - 0
shell/browser/feature_list.cc

@@ -9,6 +9,7 @@
 #include "base/base_switches.h"
 #include "base/command_line.h"
 #include "base/feature_list.h"
+#include "base/metrics/field_trial.h"
 #include "content/public/common/content_features.h"
 #include "electron/buildflags/buildflags.h"
 #include "media/base/media_switches.h"
@@ -48,4 +49,12 @@ void InitializeFeatureList() {
   base::FeatureList::InitializeInstance(enable_features, disable_features);
 }
 
+void InitializeFieldTrials() {
+  auto* cmd_line = base::CommandLine::ForCurrentProcess();
+  auto force_fieldtrials =
+      cmd_line->GetSwitchValueASCII(::switches::kForceFieldTrials);
+
+  base::FieldTrialList::CreateTrialsFromString(force_fieldtrials);
+}
+
 }  // namespace electron

+ 2 - 1
shell/browser/feature_list.h

@@ -7,6 +7,7 @@
 
 namespace electron {
 void InitializeFeatureList();
-}
+void InitializeFieldTrials();
+}  // namespace electron
 
 #endif  // SHELL_BROWSER_FEATURE_LIST_H_