Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initialize field trials from command line arguments #28401

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api/command-line-switches.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions shell/browser/electron_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 9 additions & 0 deletions shell/browser/feature_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion shell/browser/feature_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace electron {
void InitializeFeatureList();
}
void InitializeFieldTrials();
} // namespace electron

#endif // SHELL_BROWSER_FEATURE_LIST_H_