Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/public/app/content_main_runner.h" | 5 #include "content/public/app/content_main_runner.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/allocator/allocator_check.h" | 15 #include "base/allocator/allocator_check.h" |
| 16 #include "base/allocator/allocator_extension.h" | 16 #include "base/allocator/allocator_extension.h" |
| 17 #include "base/at_exit.h" | 17 #include "base/at_exit.h" |
| 18 #include "base/base_switches.h" | |
| 18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 19 #include "base/debug/debugger.h" | 20 #include "base/debug/debugger.h" |
| 20 #include "base/debug/stack_trace.h" | 21 #include "base/debug/stack_trace.h" |
| 22 #include "base/feature_list.h" | |
| 21 #include "base/files/file_path.h" | 23 #include "base/files/file_path.h" |
| 22 #include "base/i18n/icu_util.h" | 24 #include "base/i18n/icu_util.h" |
| 23 #include "base/lazy_instance.h" | 25 #include "base/lazy_instance.h" |
| 24 #include "base/logging.h" | 26 #include "base/logging.h" |
| 25 #include "base/macros.h" | 27 #include "base/macros.h" |
| 26 #include "base/memory/scoped_vector.h" | 28 #include "base/memory/scoped_vector.h" |
| 29 #include "base/metrics/field_trial.h" | |
| 27 #include "base/metrics/histogram_base.h" | 30 #include "base/metrics/histogram_base.h" |
| 28 #include "base/metrics/statistics_recorder.h" | 31 #include "base/metrics/statistics_recorder.h" |
| 29 #include "base/path_service.h" | 32 #include "base/path_service.h" |
| 30 #include "base/process/launch.h" | 33 #include "base/process/launch.h" |
| 31 #include "base/process/memory.h" | 34 #include "base/process/memory.h" |
| 32 #include "base/process/process_handle.h" | 35 #include "base/process/process_handle.h" |
| 33 #include "base/profiler/scoped_tracker.h" | 36 #include "base/profiler/scoped_tracker.h" |
| 34 #include "base/strings/string_number_conversions.h" | 37 #include "base/strings/string_number_conversions.h" |
| 35 #include "base/strings/string_util.h" | 38 #include "base/strings/string_util.h" |
| 36 #include "base/strings/stringprintf.h" | 39 #include "base/strings/stringprintf.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 #endif | 121 #endif |
| 119 extern int RendererMain(const content::MainFunctionParams&); | 122 extern int RendererMain(const content::MainFunctionParams&); |
| 120 extern int UtilityMain(const MainFunctionParams&); | 123 extern int UtilityMain(const MainFunctionParams&); |
| 121 #if defined(OS_ANDROID) | 124 #if defined(OS_ANDROID) |
| 122 extern int DownloadMain(const MainFunctionParams&); | 125 extern int DownloadMain(const MainFunctionParams&); |
| 123 #endif | 126 #endif |
| 124 } // namespace content | 127 } // namespace content |
| 125 | 128 |
| 126 namespace content { | 129 namespace content { |
| 127 | 130 |
| 131 namespace { | |
| 132 | |
| 133 // This sets up two singletons responsible for managing field trials. The | |
| 134 // |field_trial_list| singleton lives on the stack and must outlive the Run() | |
| 135 // method of the process. | |
| 136 void InitializeFieldTrialAndFeatureList( | |
| 137 std::unique_ptr<base::FieldTrialList>* field_trial_list) { | |
| 138 const base::CommandLine& command_line = | |
| 139 *base::CommandLine::ForCurrentProcess(); | |
| 140 std::string process_type = | |
| 141 command_line.GetSwitchValueASCII(switches::kProcessType); | |
| 142 | |
| 143 // 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
| |
| 144 // https://crbug.com/563705. | |
| 145 if (process_type == switches::kGpuProcess || | |
| 146 #if defined(ENABLE_PLUGINS) | |
| 147 process_type == switches::kPpapiPluginProcess || | |
| 148 #endif // ENABLE_PLUGINS | |
| 149 process_type == switches::kUtilityProcess) { | |
| 150 // Initialize statistical testing infrastructure. We set the entropy | |
| 151 // provider to nullptr to disallow non-browser processes from creating | |
| 152 // their own one-time randomized trials; they should be created in the | |
| 153 // browser process. | |
| 154 field_trial_list->reset(new base::FieldTrialList(nullptr)); | |
| 155 | |
| 156 // Ensure any field trials in browser are reflected into the child | |
| 157 // process. | |
| 158 if (command_line.HasSwitch(switches::kForceFieldTrials)) { | |
| 159 bool result = base::FieldTrialList::CreateTrialsFromString( | |
| 160 command_line.GetSwitchValueASCII(switches::kForceFieldTrials), | |
| 161 std::set<std::string>()); | |
| 162 DCHECK(result); | |
| 163 } | |
| 164 | |
| 165 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 166 feature_list->InitializeFromCommandLine( | |
| 167 command_line.GetSwitchValueASCII(switches::kEnableFeatures), | |
| 168 command_line.GetSwitchValueASCII(switches::kDisableFeatures)); | |
| 169 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 170 } | |
| 171 } | |
| 172 | |
| 173 } // namespace | |
| 174 | |
| 128 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | 175 #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
| 129 base::LazyInstance<ContentBrowserClient> | 176 base::LazyInstance<ContentBrowserClient> |
| 130 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; | 177 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; |
| 131 #endif // !CHROME_MULTIPLE_DLL_CHILD | 178 #endif // !CHROME_MULTIPLE_DLL_CHILD |
| 132 | 179 |
| 133 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 180 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 134 base::LazyInstance<ContentGpuClient> | 181 base::LazyInstance<ContentGpuClient> |
| 135 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; | 182 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; |
| 136 base::LazyInstance<ContentRendererClient> | 183 base::LazyInstance<ContentRendererClient> |
| 137 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 184 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 // line so update it here with the new version. | 341 // line so update it here with the new version. |
| 295 const base::CommandLine& command_line = | 342 const base::CommandLine& command_line = |
| 296 *base::CommandLine::ForCurrentProcess(); | 343 *base::CommandLine::ForCurrentProcess(); |
| 297 std::string process_type = | 344 std::string process_type = |
| 298 command_line.GetSwitchValueASCII(switches::kProcessType); | 345 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 299 ContentClientInitializer::Set(process_type, delegate); | 346 ContentClientInitializer::Set(process_type, delegate); |
| 300 | 347 |
| 301 MainFunctionParams main_params(command_line); | 348 MainFunctionParams main_params(command_line); |
| 302 main_params.zygote_child = true; | 349 main_params.zygote_child = true; |
| 303 | 350 |
| 351 std::unique_ptr<base::FieldTrialList> field_trial_list; | |
| 352 InitializeFieldTrialAndFeatureList(&field_trial_list); | |
| 353 | |
| 304 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { | 354 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { |
| 305 if (process_type == kMainFunctions[i].name) | 355 if (process_type == kMainFunctions[i].name) |
| 306 return kMainFunctions[i].function(main_params); | 356 return kMainFunctions[i].function(main_params); |
| 307 } | 357 } |
| 308 | 358 |
| 309 if (delegate) | 359 if (delegate) |
| 310 return delegate->RunProcess(process_type, main_params); | 360 return delegate->RunProcess(process_type, main_params); |
| 311 | 361 |
| 312 NOTREACHED() << "Unknown zygote process type: " << process_type; | 362 NOTREACHED() << "Unknown zygote process type: " << process_type; |
| 313 return 1; | 363 return 1; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 } | 772 } |
| 723 | 773 |
| 724 int Run() override { | 774 int Run() override { |
| 725 DCHECK(is_initialized_); | 775 DCHECK(is_initialized_); |
| 726 DCHECK(!is_shutdown_); | 776 DCHECK(!is_shutdown_); |
| 727 const base::CommandLine& command_line = | 777 const base::CommandLine& command_line = |
| 728 *base::CommandLine::ForCurrentProcess(); | 778 *base::CommandLine::ForCurrentProcess(); |
| 729 std::string process_type = | 779 std::string process_type = |
| 730 command_line.GetSwitchValueASCII(switches::kProcessType); | 780 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 731 | 781 |
| 782 std::unique_ptr<base::FieldTrialList> field_trial_list; | |
| 783 InitializeFieldTrialAndFeatureList(&field_trial_list); | |
| 784 | |
| 732 base::HistogramBase::EnableActivityReportHistogram(process_type); | 785 base::HistogramBase::EnableActivityReportHistogram(process_type); |
| 733 | 786 |
| 734 MainFunctionParams main_params(command_line); | 787 MainFunctionParams main_params(command_line); |
| 735 main_params.ui_task = ui_task_; | 788 main_params.ui_task = ui_task_; |
| 736 #if defined(OS_WIN) | 789 #if defined(OS_WIN) |
| 737 main_params.sandbox_info = &sandbox_info_; | 790 main_params.sandbox_info = &sandbox_info_; |
| 738 #elif defined(OS_MACOSX) | 791 #elif defined(OS_MACOSX) |
| 739 main_params.autorelease_pool = autorelease_pool_.get(); | 792 main_params.autorelease_pool = autorelease_pool_.get(); |
| 740 #endif | 793 #endif |
| 741 | 794 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 | 851 |
| 799 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 852 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 800 }; | 853 }; |
| 801 | 854 |
| 802 // static | 855 // static |
| 803 ContentMainRunner* ContentMainRunner::Create() { | 856 ContentMainRunner* ContentMainRunner::Create() { |
| 804 return new ContentMainRunnerImpl(); | 857 return new ContentMainRunnerImpl(); |
| 805 } | 858 } |
| 806 | 859 |
| 807 } // namespace content | 860 } // namespace content |
| OLD | NEW |