Chromium Code Reviews| Index: content/app/content_main_runner.cc |
| diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc |
| index abe4f13051c45db0ac11f31e7ef09b59fe3f618b..227ebba66c5f1ce187d89e159995d6232e45d22e 100644 |
| --- a/content/app/content_main_runner.cc |
| +++ b/content/app/content_main_runner.cc |
| @@ -15,15 +15,18 @@ |
| #include "base/allocator/allocator_check.h" |
| #include "base/allocator/allocator_extension.h" |
| #include "base/at_exit.h" |
| +#include "base/base_switches.h" |
| #include "base/command_line.h" |
| #include "base/debug/debugger.h" |
| #include "base/debug/stack_trace.h" |
| +#include "base/feature_list.h" |
| #include "base/files/file_path.h" |
| #include "base/i18n/icu_util.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/macros.h" |
| #include "base/memory/scoped_vector.h" |
| +#include "base/metrics/field_trial.h" |
| #include "base/metrics/histogram_base.h" |
| #include "base/metrics/statistics_recorder.h" |
| #include "base/path_service.h" |
| @@ -125,6 +128,50 @@ extern int DownloadMain(const MainFunctionParams&); |
| namespace content { |
| +namespace { |
| + |
| +// This sets up two singletons responsible for managing field trials. The |
| +// |field_trial_list| singleton lives on the stack and must outlive the Run() |
| +// method of the process. |
| +void InitializeFieldTrialAndFeatureList( |
| + std::unique_ptr<base::FieldTrialList>* field_trial_list) { |
| + const base::CommandLine& command_line = |
| + *base::CommandLine::ForCurrentProcess(); |
| + std::string process_type = |
| + command_line.GetSwitchValueASCII(switches::kProcessType); |
| + |
| + // TODO(asvitkine): This logic should run for all child processes. |
|
jam
2016/05/03 19:45:08
why isn't this change doing it for all processes?
erikchen
2016/05/03 19:55:05
Moving this logic to contain_main_runner causes pr
jam
2016/05/03 20:07:38
In general when we plumb stuff like this to child
|
| + // https://crbug.com/563705. |
| + if (process_type == switches::kGpuProcess || |
| +#if defined(ENABLE_PLUGINS) |
| + process_type == switches::kPpapiPluginProcess || |
| +#endif // ENABLE_PLUGINS |
| + process_type == switches::kUtilityProcess) { |
| + // Initialize statistical testing infrastructure. We set the entropy |
| + // provider to nullptr to disallow non-browser processes from creating |
| + // their own one-time randomized trials; they should be created in the |
| + // browser process. |
| + field_trial_list->reset(new base::FieldTrialList(nullptr)); |
| + |
| + // Ensure any field trials in browser are reflected into the child |
| + // process. |
| + if (command_line.HasSwitch(switches::kForceFieldTrials)) { |
| + bool result = base::FieldTrialList::CreateTrialsFromString( |
| + command_line.GetSwitchValueASCII(switches::kForceFieldTrials), |
| + std::set<std::string>()); |
| + DCHECK(result); |
| + } |
| + |
| + std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| + feature_list->InitializeFromCommandLine( |
| + command_line.GetSwitchValueASCII(switches::kEnableFeatures), |
| + command_line.GetSwitchValueASCII(switches::kDisableFeatures)); |
| + base::FeatureList::SetInstance(std::move(feature_list)); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
| base::LazyInstance<ContentBrowserClient> |
| g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; |
| @@ -301,6 +348,9 @@ int RunZygote(const MainFunctionParams& main_function_params, |
| MainFunctionParams main_params(command_line); |
| main_params.zygote_child = true; |
| + std::unique_ptr<base::FieldTrialList> field_trial_list; |
| + InitializeFieldTrialAndFeatureList(&field_trial_list); |
| + |
| for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { |
| if (process_type == kMainFunctions[i].name) |
| return kMainFunctions[i].function(main_params); |
| @@ -729,6 +779,9 @@ class ContentMainRunnerImpl : public ContentMainRunner { |
| std::string process_type = |
| command_line.GetSwitchValueASCII(switches::kProcessType); |
| + std::unique_ptr<base::FieldTrialList> field_trial_list; |
| + InitializeFieldTrialAndFeatureList(&field_trial_list); |
| + |
| base::HistogramBase::EnableActivityReportHistogram(process_type); |
| MainFunctionParams main_params(command_line); |