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); | |
Alexei Svitkine (slow)
2016/05/04 15:08:08
Nit: This line is no longer needed, right?
erikchen
2016/05/04 16:10:10
https://codereview.chromium.org/1948663003/
| |
142 | |
143 // Initialize statistical testing infrastructure. We set the entropy | |
144 // provider to nullptr to disallow non-browser processes from creating | |
145 // their own one-time randomized trials; they should be created in the | |
146 // browser process. | |
147 field_trial_list->reset(new base::FieldTrialList(nullptr)); | |
148 | |
149 // Ensure any field trials in browser are reflected into the child | |
150 // process. | |
151 if (command_line.HasSwitch(switches::kForceFieldTrials)) { | |
152 bool result = base::FieldTrialList::CreateTrialsFromString( | |
153 command_line.GetSwitchValueASCII(switches::kForceFieldTrials), | |
154 std::set<std::string>()); | |
155 DCHECK(result); | |
156 } | |
157 | |
158 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
159 feature_list->InitializeFromCommandLine( | |
160 command_line.GetSwitchValueASCII(switches::kEnableFeatures), | |
161 command_line.GetSwitchValueASCII(switches::kDisableFeatures)); | |
162 base::FeatureList::SetInstance(std::move(feature_list)); | |
163 } | |
164 | |
165 } // namespace | |
166 | |
128 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | 167 #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
129 base::LazyInstance<ContentBrowserClient> | 168 base::LazyInstance<ContentBrowserClient> |
130 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; | 169 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; |
131 #endif // !CHROME_MULTIPLE_DLL_CHILD | 170 #endif // !CHROME_MULTIPLE_DLL_CHILD |
132 | 171 |
133 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 172 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
134 base::LazyInstance<ContentGpuClient> | 173 base::LazyInstance<ContentGpuClient> |
135 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; | 174 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; |
136 base::LazyInstance<ContentRendererClient> | 175 base::LazyInstance<ContentRendererClient> |
137 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 176 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. | 333 // line so update it here with the new version. |
295 const base::CommandLine& command_line = | 334 const base::CommandLine& command_line = |
296 *base::CommandLine::ForCurrentProcess(); | 335 *base::CommandLine::ForCurrentProcess(); |
297 std::string process_type = | 336 std::string process_type = |
298 command_line.GetSwitchValueASCII(switches::kProcessType); | 337 command_line.GetSwitchValueASCII(switches::kProcessType); |
299 ContentClientInitializer::Set(process_type, delegate); | 338 ContentClientInitializer::Set(process_type, delegate); |
300 | 339 |
301 MainFunctionParams main_params(command_line); | 340 MainFunctionParams main_params(command_line); |
302 main_params.zygote_child = true; | 341 main_params.zygote_child = true; |
303 | 342 |
343 std::unique_ptr<base::FieldTrialList> field_trial_list; | |
344 InitializeFieldTrialAndFeatureList(&field_trial_list); | |
345 | |
304 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { | 346 for (size_t i = 0; i < arraysize(kMainFunctions); ++i) { |
305 if (process_type == kMainFunctions[i].name) | 347 if (process_type == kMainFunctions[i].name) |
306 return kMainFunctions[i].function(main_params); | 348 return kMainFunctions[i].function(main_params); |
307 } | 349 } |
308 | 350 |
309 if (delegate) | 351 if (delegate) |
310 return delegate->RunProcess(process_type, main_params); | 352 return delegate->RunProcess(process_type, main_params); |
311 | 353 |
312 NOTREACHED() << "Unknown zygote process type: " << process_type; | 354 NOTREACHED() << "Unknown zygote process type: " << process_type; |
313 return 1; | 355 return 1; |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 } | 764 } |
723 | 765 |
724 int Run() override { | 766 int Run() override { |
725 DCHECK(is_initialized_); | 767 DCHECK(is_initialized_); |
726 DCHECK(!is_shutdown_); | 768 DCHECK(!is_shutdown_); |
727 const base::CommandLine& command_line = | 769 const base::CommandLine& command_line = |
728 *base::CommandLine::ForCurrentProcess(); | 770 *base::CommandLine::ForCurrentProcess(); |
729 std::string process_type = | 771 std::string process_type = |
730 command_line.GetSwitchValueASCII(switches::kProcessType); | 772 command_line.GetSwitchValueASCII(switches::kProcessType); |
731 | 773 |
774 // Run this logic on all child processes. Zygotes will run this at a later | |
775 // point in time when the command line has been updated. | |
776 std::unique_ptr<base::FieldTrialList> field_trial_list; | |
777 if (!process_type.empty() && process_type != switches::kZygoteProcess) | |
778 InitializeFieldTrialAndFeatureList(&field_trial_list); | |
779 | |
732 base::HistogramBase::EnableActivityReportHistogram(process_type); | 780 base::HistogramBase::EnableActivityReportHistogram(process_type); |
733 | 781 |
734 MainFunctionParams main_params(command_line); | 782 MainFunctionParams main_params(command_line); |
735 main_params.ui_task = ui_task_; | 783 main_params.ui_task = ui_task_; |
736 #if defined(OS_WIN) | 784 #if defined(OS_WIN) |
737 main_params.sandbox_info = &sandbox_info_; | 785 main_params.sandbox_info = &sandbox_info_; |
738 #elif defined(OS_MACOSX) | 786 #elif defined(OS_MACOSX) |
739 main_params.autorelease_pool = autorelease_pool_.get(); | 787 main_params.autorelease_pool = autorelease_pool_.get(); |
740 #endif | 788 #endif |
741 | 789 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
798 | 846 |
799 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 847 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
800 }; | 848 }; |
801 | 849 |
802 // static | 850 // static |
803 ContentMainRunner* ContentMainRunner::Create() { | 851 ContentMainRunner* ContentMainRunner::Create() { |
804 return new ContentMainRunnerImpl(); | 852 return new ContentMainRunnerImpl(); |
805 } | 853 } |
806 | 854 |
807 } // namespace content | 855 } // namespace content |
OLD | NEW |