| 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 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 extern int PpapiBrokerMain(const MainFunctionParams&); | 130 extern int PpapiBrokerMain(const MainFunctionParams&); |
| 131 #endif | 131 #endif |
| 132 extern int RendererMain(const content::MainFunctionParams&); | 132 extern int RendererMain(const content::MainFunctionParams&); |
| 133 extern int UtilityMain(const MainFunctionParams&); | 133 extern int UtilityMain(const MainFunctionParams&); |
| 134 } // namespace content | 134 } // namespace content |
| 135 | 135 |
| 136 namespace content { | 136 namespace content { |
| 137 | 137 |
| 138 namespace { | 138 namespace { |
| 139 | 139 |
| 140 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) |
| 141 #if defined __LP64__ |
| 142 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 |
| 143 #else |
| 144 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 |
| 145 #endif |
| 146 #endif |
| 147 |
| 140 // This sets up two singletons responsible for managing field trials. The | 148 // This sets up two singletons responsible for managing field trials. The |
| 141 // |field_trial_list| singleton lives on the stack and must outlive the Run() | 149 // |field_trial_list| singleton lives on the stack and must outlive the Run() |
| 142 // method of the process. | 150 // method of the process. |
| 143 void InitializeFieldTrialAndFeatureList( | 151 void InitializeFieldTrialAndFeatureList( |
| 144 std::unique_ptr<base::FieldTrialList>* field_trial_list) { | 152 std::unique_ptr<base::FieldTrialList>* field_trial_list) { |
| 145 const base::CommandLine& command_line = | 153 const base::CommandLine& command_line = |
| 146 *base::CommandLine::ForCurrentProcess(); | 154 *base::CommandLine::ForCurrentProcess(); |
| 147 | 155 |
| 148 // Initialize statistical testing infrastructure. We set the entropy | 156 // Initialize statistical testing infrastructure. We set the entropy |
| 149 // provider to nullptr to disallow non-browser processes from creating | 157 // provider to nullptr to disallow non-browser processes from creating |
| (...skipping 13 matching lines...) Expand all Loading... |
| 163 command_line, switches::kFieldTrialHandle, -1); | 171 command_line, switches::kFieldTrialHandle, -1); |
| 164 #endif | 172 #endif |
| 165 | 173 |
| 166 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 174 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 167 base::FieldTrialList::CreateFeaturesFromCommandLine( | 175 base::FieldTrialList::CreateFeaturesFromCommandLine( |
| 168 command_line, switches::kEnableFeatures, switches::kDisableFeatures, | 176 command_line, switches::kEnableFeatures, switches::kDisableFeatures, |
| 169 feature_list.get()); | 177 feature_list.get()); |
| 170 base::FeatureList::SetInstance(std::move(feature_list)); | 178 base::FeatureList::SetInstance(std::move(feature_list)); |
| 171 } | 179 } |
| 172 | 180 |
| 181 void InitializeV8IfNeeded( |
| 182 const base::CommandLine& command_line, |
| 183 const std::string& process_type) { |
| 184 if (process_type == switches::kGpuProcess) |
| 185 return; |
| 186 |
| 187 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 188 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 189 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); |
| 190 #if !defined(OS_ANDROID) |
| 191 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared |
| 192 // with child processes via file descriptors. On Android they are set in |
| 193 // ChildProcessService::InternalInitChildProcess, otherwise set them here. |
| 194 if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { |
| 195 g_fds->Set( |
| 196 kV8NativesDataDescriptor, |
| 197 kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); |
| 198 } |
| 199 if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) { |
| 200 g_fds->Set( |
| 201 kV8SnapshotDataDescriptor, |
| 202 kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); |
| 203 } |
| 204 #endif // !OS_ANDROID |
| 205 int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor); |
| 206 int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor); |
| 207 if (v8_snapshot_fd != -1) { |
| 208 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor); |
| 209 gin::V8Initializer::LoadV8SnapshotFromFD( |
| 210 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); |
| 211 } else { |
| 212 gin::V8Initializer::LoadV8Snapshot(); |
| 213 } |
| 214 if (v8_natives_fd != -1) { |
| 215 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); |
| 216 gin::V8Initializer::LoadV8NativesFromFD( |
| 217 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); |
| 218 } else { |
| 219 gin::V8Initializer::LoadV8Natives(); |
| 220 } |
| 221 #else |
| 222 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 223 gin::V8Initializer::LoadV8Snapshot(); |
| 224 gin::V8Initializer::LoadV8Natives(); |
| 225 #endif // !CHROME_MULTIPLE_DLL_BROWSER |
| 226 #endif // OS_POSIX && !OS_MACOSX |
| 227 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
| 228 } |
| 229 |
| 173 } // namespace | 230 } // namespace |
| 174 | 231 |
| 175 #if !defined(CHROME_MULTIPLE_DLL_CHILD) | 232 #if !defined(CHROME_MULTIPLE_DLL_CHILD) |
| 176 base::LazyInstance<ContentBrowserClient> | 233 base::LazyInstance<ContentBrowserClient> |
| 177 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; | 234 g_empty_content_browser_client = LAZY_INSTANCE_INITIALIZER; |
| 178 #endif // !CHROME_MULTIPLE_DLL_CHILD | 235 #endif // !CHROME_MULTIPLE_DLL_CHILD |
| 179 | 236 |
| 180 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 237 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 181 base::LazyInstance<ContentGpuClient> | 238 base::LazyInstance<ContentGpuClient> |
| 182 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; | 239 g_empty_content_gpu_client = LAZY_INSTANCE_INITIALIZER; |
| 183 base::LazyInstance<ContentRendererClient> | 240 base::LazyInstance<ContentRendererClient> |
| 184 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; | 241 g_empty_content_renderer_client = LAZY_INSTANCE_INITIALIZER; |
| 185 base::LazyInstance<ContentUtilityClient> | 242 base::LazyInstance<ContentUtilityClient> |
| 186 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; | 243 g_empty_content_utility_client = LAZY_INSTANCE_INITIALIZER; |
| 187 #endif // !CHROME_MULTIPLE_DLL_BROWSER | 244 #endif // !CHROME_MULTIPLE_DLL_BROWSER |
| 188 | 245 |
| 189 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) | |
| 190 #if defined __LP64__ | |
| 191 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 | |
| 192 #else | |
| 193 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 | |
| 194 #endif | |
| 195 #endif | |
| 196 | |
| 197 #if defined(OS_POSIX) | 246 #if defined(OS_POSIX) |
| 198 | 247 |
| 199 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. | 248 // Setup signal-handling state: resanitize most signals, ignore SIGPIPE. |
| 200 void SetupSignalHandlers() { | 249 void SetupSignalHandlers() { |
| 201 // Sanitise our signal handling state. Signals that were ignored by our | 250 // Sanitise our signal handling state. Signals that were ignored by our |
| 202 // parent will also be ignored by us. We also inherit our parent's sigmask. | 251 // parent will also be ignored by us. We also inherit our parent's sigmask. |
| 203 sigset_t empty_signal_set; | 252 sigset_t empty_signal_set; |
| 204 CHECK_EQ(0, sigemptyset(&empty_signal_set)); | 253 CHECK_EQ(0, sigemptyset(&empty_signal_set)); |
| 205 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); | 254 CHECK_EQ(0, sigprocmask(SIG_SETMASK, &empty_signal_set, NULL)); |
| 206 | 255 |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 icudata_region)); | 749 icudata_region)); |
| 701 } else { | 750 } else { |
| 702 CHECK(base::i18n::InitializeICU()); | 751 CHECK(base::i18n::InitializeICU()); |
| 703 } | 752 } |
| 704 #else | 753 #else |
| 705 CHECK(base::i18n::InitializeICU()); | 754 CHECK(base::i18n::InitializeICU()); |
| 706 #endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) | 755 #endif // OS_ANDROID && (ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE) |
| 707 | 756 |
| 708 base::StatisticsRecorder::Initialize(); | 757 base::StatisticsRecorder::Initialize(); |
| 709 | 758 |
| 710 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 759 InitializeV8IfNeeded(command_line, process_type); |
| 711 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 712 #if !defined(OS_ANDROID) | |
| 713 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared | |
| 714 // with child processes via file descriptors. On Android they are set in | |
| 715 // ChildProcessService::InternalInitChildProcess, otherwise set them here. | |
| 716 if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { | |
| 717 g_fds->Set( | |
| 718 kV8NativesDataDescriptor, | |
| 719 kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); | |
| 720 } | |
| 721 if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) { | |
| 722 g_fds->Set( | |
| 723 kV8SnapshotDataDescriptor, | |
| 724 kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); | |
| 725 } | |
| 726 #endif // !OS_ANDROID | |
| 727 int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor); | |
| 728 int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor); | |
| 729 if (v8_snapshot_fd != -1) { | |
| 730 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor); | |
| 731 gin::V8Initializer::LoadV8SnapshotFromFD( | |
| 732 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); | |
| 733 } else { | |
| 734 gin::V8Initializer::LoadV8Snapshot(); | |
| 735 } | |
| 736 if (v8_natives_fd != -1) { | |
| 737 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); | |
| 738 gin::V8Initializer::LoadV8NativesFromFD( | |
| 739 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); | |
| 740 } else { | |
| 741 gin::V8Initializer::LoadV8Natives(); | |
| 742 } | |
| 743 #else | |
| 744 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | |
| 745 gin::V8Initializer::LoadV8Snapshot(); | |
| 746 gin::V8Initializer::LoadV8Natives(); | |
| 747 #endif // !CHROME_MULTIPLE_DLL_BROWSER | |
| 748 #endif // OS_POSIX && !OS_MACOSX | |
| 749 #endif // V8_USE_EXTERNAL_STARTUP_DATA | |
| 750 | 760 |
| 751 #if !defined(OFFICIAL_BUILD) | 761 #if !defined(OFFICIAL_BUILD) |
| 752 #if defined(OS_WIN) | 762 #if defined(OS_WIN) |
| 753 bool should_enable_stack_dump = !process_type.empty(); | 763 bool should_enable_stack_dump = !process_type.empty(); |
| 754 #else | 764 #else |
| 755 bool should_enable_stack_dump = true; | 765 bool should_enable_stack_dump = true; |
| 756 #endif | 766 #endif |
| 757 // Print stack traces to stderr when crashes occur. This opens up security | 767 // Print stack traces to stderr when crashes occur. This opens up security |
| 758 // holes so it should never be enabled for official builds. This needs to | 768 // holes so it should never be enabled for official builds. This needs to |
| 759 // happen before crash reporting is initialized (which for chrome happens in | 769 // happen before crash reporting is initialized (which for chrome happens in |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 | 891 |
| 882 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 892 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
| 883 }; | 893 }; |
| 884 | 894 |
| 885 // static | 895 // static |
| 886 ContentMainRunner* ContentMainRunner::Create() { | 896 ContentMainRunner* ContentMainRunner::Create() { |
| 887 return new ContentMainRunnerImpl(); | 897 return new ContentMainRunnerImpl(); |
| 888 } | 898 } |
| 889 | 899 |
| 890 } // namespace content | 900 } // namespace content |
| OLD | NEW |