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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "components/tracing/browser/trace_config_file.h" | 45 #include "components/tracing/browser/trace_config_file.h" |
46 #include "components/tracing/common/trace_to_console.h" | 46 #include "components/tracing/common/trace_to_console.h" |
47 #include "components/tracing/common/tracing_switches.h" | 47 #include "components/tracing/common/tracing_switches.h" |
48 #include "content/app/mojo/mojo_init.h" | 48 #include "content/app/mojo/mojo_init.h" |
49 #include "content/common/set_process_title.h" | 49 #include "content/common/set_process_title.h" |
50 #include "content/common/url_schemes.h" | 50 #include "content/common/url_schemes.h" |
51 #include "content/public/app/content_main.h" | 51 #include "content/public/app/content_main.h" |
52 #include "content/public/app/content_main_delegate.h" | 52 #include "content/public/app/content_main_delegate.h" |
53 #include "content/public/common/content_client.h" | 53 #include "content/public/common/content_client.h" |
54 #include "content/public/common/content_constants.h" | 54 #include "content/public/common/content_constants.h" |
| 55 #include "content/public/common/content_descriptor_keys.h" |
55 #include "content/public/common/content_paths.h" | 56 #include "content/public/common/content_paths.h" |
56 #include "content/public/common/content_switches.h" | 57 #include "content/public/common/content_switches.h" |
57 #include "content/public/common/main_function_params.h" | 58 #include "content/public/common/main_function_params.h" |
58 #include "content/public/common/sandbox_init.h" | 59 #include "content/public/common/sandbox_init.h" |
59 #include "ipc/ipc_descriptors.h" | 60 #include "ipc/ipc_descriptors.h" |
60 #include "media/base/media.h" | 61 #include "media/base/media.h" |
61 #include "ppapi/features/features.h" | 62 #include "ppapi/features/features.h" |
| 63 #include "services/service_manager/public/cpp/shared_file_util.h" |
62 #include "ui/base/ui_base_paths.h" | 64 #include "ui/base/ui_base_paths.h" |
63 #include "ui/base/ui_base_switches.h" | 65 #include "ui/base/ui_base_switches.h" |
64 | 66 |
65 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ | 67 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && \ |
66 !defined(CHROME_MULTIPLE_DLL_BROWSER) | 68 !defined(CHROME_MULTIPLE_DLL_BROWSER) |
67 #include "gin/v8_initializer.h" | 69 #include "gin/v8_initializer.h" |
68 #endif | 70 #endif |
69 | 71 |
70 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
71 #include <malloc.h> | 73 #include <malloc.h> |
72 #include <cstring> | 74 #include <cstring> |
73 | 75 |
74 #include "base/trace_event/trace_event_etw_export_win.h" | 76 #include "base/trace_event/trace_event_etw_export_win.h" |
75 #include "base/win/process_startup_helper.h" | 77 #include "base/win/process_startup_helper.h" |
76 #include "sandbox/win/src/sandbox_types.h" | 78 #include "sandbox/win/src/sandbox_types.h" |
77 #include "ui/base/win/atl_module.h" | 79 #include "ui/base/win/atl_module.h" |
78 #include "ui/display/win/dpi.h" | 80 #include "ui/display/win/dpi.h" |
79 #elif defined(OS_MACOSX) | 81 #elif defined(OS_MACOSX) |
80 #include "base/allocator/allocator_shim.h" | 82 #include "base/allocator/allocator_shim.h" |
81 #include "base/mac/scoped_nsautorelease_pool.h" | 83 #include "base/mac/scoped_nsautorelease_pool.h" |
82 #include "base/power_monitor/power_monitor_device_source.h" | 84 #include "base/power_monitor/power_monitor_device_source.h" |
83 #include "content/app/mac/mac_init.h" | 85 #include "content/app/mac/mac_init.h" |
84 #include "content/browser/mach_broker_mac.h" | 86 #include "content/browser/mach_broker_mac.h" |
85 #include "content/common/sandbox_init_mac.h" | 87 #include "content/common/sandbox_init_mac.h" |
86 #endif // OS_WIN | 88 #endif // OS_WIN |
87 | 89 |
88 #if defined(OS_POSIX) | 90 #if defined(OS_POSIX) |
89 #include <signal.h> | 91 #include <signal.h> |
90 | 92 |
| 93 #include "base/file_descriptor_store.h" |
91 #include "base/posix/global_descriptors.h" | 94 #include "base/posix/global_descriptors.h" |
92 #include "content/public/common/content_descriptors.h" | 95 #include "content/public/common/content_descriptors.h" |
93 | 96 |
94 #if !defined(OS_MACOSX) | 97 #if !defined(OS_MACOSX) |
95 #include "content/public/common/zygote_fork_delegate_linux.h" | 98 #include "content/public/common/zygote_fork_delegate_linux.h" |
96 #endif | 99 #endif |
97 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 100 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
98 #include "content/zygote/zygote_main.h" | 101 #include "content/zygote/zygote_main.h" |
99 #endif | 102 #endif |
100 | 103 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 extern int RendererMain(const content::MainFunctionParams&); | 143 extern int RendererMain(const content::MainFunctionParams&); |
141 extern int UtilityMain(const MainFunctionParams&); | 144 extern int UtilityMain(const MainFunctionParams&); |
142 } // namespace content | 145 } // namespace content |
143 | 146 |
144 namespace content { | 147 namespace content { |
145 | 148 |
146 namespace { | 149 namespace { |
147 | 150 |
148 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) | 151 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) && defined(OS_ANDROID) |
149 #if defined __LP64__ | 152 #if defined __LP64__ |
150 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor64 | 153 #define kV8SnapshotDataDescriptor kV8Snapshot64DataDescriptor |
151 #else | 154 #else |
152 #define kV8SnapshotDataDescriptor kV8SnapshotDataDescriptor32 | 155 #define kV8SnapshotDataDescriptor kV8Snapshot32DataDescriptor |
153 #endif | 156 #endif |
154 #endif | 157 #endif |
155 | 158 |
156 // This sets up two singletons responsible for managing field trials. The | 159 // This sets up two singletons responsible for managing field trials. The |
157 // |field_trial_list| singleton lives on the stack and must outlive the Run() | 160 // |field_trial_list| singleton lives on the stack and must outlive the Run() |
158 // method of the process. | 161 // method of the process. |
159 void InitializeFieldTrialAndFeatureList( | 162 void InitializeFieldTrialAndFeatureList( |
160 std::unique_ptr<base::FieldTrialList>* field_trial_list) { | 163 std::unique_ptr<base::FieldTrialList>* field_trial_list) { |
161 const base::CommandLine& command_line = | 164 const base::CommandLine& command_line = |
162 *base::CommandLine::ForCurrentProcess(); | 165 *base::CommandLine::ForCurrentProcess(); |
(...skipping 24 matching lines...) Expand all Loading... |
187 } | 190 } |
188 | 191 |
189 void InitializeV8IfNeeded( | 192 void InitializeV8IfNeeded( |
190 const base::CommandLine& command_line, | 193 const base::CommandLine& command_line, |
191 const std::string& process_type) { | 194 const std::string& process_type) { |
192 if (process_type == switches::kGpuProcess) | 195 if (process_type == switches::kGpuProcess) |
193 return; | 196 return; |
194 | 197 |
195 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 198 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
196 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 199 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
197 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance(); | 200 base::FileDescriptorStore& file_descriptor_store = |
198 #if !defined(OS_ANDROID) | 201 base::FileDescriptorStore::GetInstance(); |
199 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor could be shared | 202 base::MemoryMappedFile::Region region; |
200 // with child processes via file descriptors. On Android they are set in | 203 base::ScopedFD v8_snapshot_fd = |
201 // ChildProcessService::InternalInitChildProcess, otherwise set them here. | 204 file_descriptor_store.MaybeTakeFD(kV8SnapshotDataDescriptor, ®ion); |
202 if (command_line.HasSwitch(switches::kV8NativesPassedByFD)) { | 205 if (v8_snapshot_fd.is_valid()) { |
203 g_fds->Set( | 206 gin::V8Initializer::LoadV8SnapshotFromFD(v8_snapshot_fd.get(), |
204 kV8NativesDataDescriptor, | 207 region.offset, region.size); |
205 kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); | |
206 } | |
207 if (command_line.HasSwitch(switches::kV8SnapshotPassedByFD)) { | |
208 g_fds->Set( | |
209 kV8SnapshotDataDescriptor, | |
210 kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor); | |
211 } | |
212 #endif // !OS_ANDROID | |
213 int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor); | |
214 int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor); | |
215 if (v8_snapshot_fd != -1) { | |
216 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor); | |
217 gin::V8Initializer::LoadV8SnapshotFromFD( | |
218 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size); | |
219 } else { | 208 } else { |
220 gin::V8Initializer::LoadV8Snapshot(); | 209 gin::V8Initializer::LoadV8Snapshot(); |
221 } | 210 } |
222 if (v8_natives_fd != -1) { | 211 base::ScopedFD v8_natives_fd = |
223 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor); | 212 file_descriptor_store.MaybeTakeFD(kV8NativesDataDescriptor, ®ion); |
224 gin::V8Initializer::LoadV8NativesFromFD( | 213 if (v8_natives_fd.is_valid()) { |
225 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size); | 214 gin::V8Initializer::LoadV8NativesFromFD(v8_natives_fd.get(), |
| 215 region.offset, region.size); |
226 } else { | 216 } else { |
227 gin::V8Initializer::LoadV8Natives(); | 217 gin::V8Initializer::LoadV8Natives(); |
228 } | 218 } |
229 #else | 219 #else |
230 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) | 220 #if !defined(CHROME_MULTIPLE_DLL_BROWSER) |
231 gin::V8Initializer::LoadV8Snapshot(); | 221 gin::V8Initializer::LoadV8Snapshot(); |
232 gin::V8Initializer::LoadV8Natives(); | 222 gin::V8Initializer::LoadV8Natives(); |
233 #endif // !CHROME_MULTIPLE_DLL_BROWSER | 223 #endif // !CHROME_MULTIPLE_DLL_BROWSER |
234 #endif // OS_POSIX && !OS_MACOSX | 224 #endif // OS_POSIX && !OS_MACOSX |
235 #endif // V8_USE_EXTERNAL_STARTUP_DATA | 225 #endif // V8_USE_EXTERNAL_STARTUP_DATA |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, | 258 {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, |
269 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below. | 259 SIGALRM, SIGTERM, SIGCHLD, SIGBUS, SIGTRAP}; // SIGPIPE is set below. |
270 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) { | 260 for (unsigned i = 0; i < arraysize(signals_to_reset); i++) { |
271 CHECK_EQ(0, sigaction(signals_to_reset[i], &sigact, NULL)); | 261 CHECK_EQ(0, sigaction(signals_to_reset[i], &sigact, NULL)); |
272 } | 262 } |
273 | 263 |
274 // Always ignore SIGPIPE. We check the return value of write(). | 264 // Always ignore SIGPIPE. We check the return value of write(). |
275 CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN)); | 265 CHECK_NE(SIG_ERR, signal(SIGPIPE, SIG_IGN)); |
276 } | 266 } |
277 | 267 |
| 268 void PopulateFDsFromCommandLine() { |
| 269 const std::string& shared_file_param = |
| 270 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 271 switches::kSharedFiles); |
| 272 if (shared_file_param.empty()) |
| 273 return; |
| 274 |
| 275 base::Optional<std::map<int, std::string>> shared_file_descriptors = |
| 276 service_manager::ParseSharedFileSwitchValue(shared_file_param); |
| 277 if (!shared_file_descriptors) |
| 278 return; |
| 279 |
| 280 for (const auto& descriptor : *shared_file_descriptors) { |
| 281 base::MemoryMappedFile::Region region; |
| 282 const std::string& key = descriptor.second; |
| 283 base::ScopedFD fd = base::GlobalDescriptors::GetInstance()->TakeFD( |
| 284 descriptor.first, ®ion); |
| 285 base::FileDescriptorStore::GetInstance().Set(key, std::move(fd), region); |
| 286 } |
| 287 } |
| 288 |
278 #endif // OS_POSIX | 289 #endif // OS_POSIX |
279 | 290 |
280 void CommonSubprocessInit() { | 291 void CommonSubprocessInit() { |
281 #if defined(OS_WIN) | 292 #if defined(OS_WIN) |
282 // HACK: Let Windows know that we have started. This is needed to suppress | 293 // HACK: Let Windows know that we have started. This is needed to suppress |
283 // the IDC_APPSTARTING cursor from being displayed for a prolonged period | 294 // the IDC_APPSTARTING cursor from being displayed for a prolonged period |
284 // while a subprocess is starting. | 295 // while a subprocess is starting. |
285 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); | 296 PostThreadMessage(GetCurrentThreadId(), WM_NULL, 0, 0); |
286 MSG msg; | 297 MSG msg; |
287 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); | 298 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 601 |
591 #if defined(OS_MACOSX) | 602 #if defined(OS_MACOSX) |
592 // We need this pool for all the objects created before we get to the | 603 // We need this pool for all the objects created before we get to the |
593 // event loop, but we don't want to leave them hanging around until the | 604 // event loop, but we don't want to leave them hanging around until the |
594 // app quits. Each "main" needs to flush this pool right before it goes into | 605 // app quits. Each "main" needs to flush this pool right before it goes into |
595 // its main event loop to get rid of the cruft. | 606 // its main event loop to get rid of the cruft. |
596 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); | 607 autorelease_pool_.reset(new base::mac::ScopedNSAutoreleasePool()); |
597 InitializeMac(); | 608 InitializeMac(); |
598 #endif | 609 #endif |
599 | 610 |
600 // On Android, the command line is initialized when library is loaded and | 611 // On Android, the command line is initialized and the FDs set when the |
601 // we have already started our TRACE_EVENT0. | 612 // library is loaded and we have already started our TRACE_EVENT0. |
602 #if !defined(OS_ANDROID) | 613 #if !defined(OS_ANDROID) |
603 // argc/argv are ignored on Windows and Android; see command_line.h for | 614 // argc/argv are ignored on Windows and Android; see command_line.h for |
604 // details. | 615 // details. |
605 int argc = 0; | 616 int argc = 0; |
606 const char** argv = NULL; | 617 const char** argv = NULL; |
607 | 618 |
608 #if !defined(OS_WIN) | 619 #if !defined(OS_WIN) |
609 argc = params.argc; | 620 argc = params.argc; |
610 argv = params.argv; | 621 argv = params.argv; |
611 #endif | 622 #endif |
612 | 623 |
613 base::CommandLine::Init(argc, argv); | 624 base::CommandLine::Init(argc, argv); |
614 | 625 |
| 626 #if defined(OS_POSIX) |
| 627 PopulateFDsFromCommandLine(); |
| 628 #endif |
| 629 |
615 base::EnableTerminationOnHeapCorruption(); | 630 base::EnableTerminationOnHeapCorruption(); |
616 | 631 |
617 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. | 632 // TODO(yiyaoliu, vadimt): Remove this once crbug.com/453640 is fixed. |
618 // Enable profiler recording right after command line is initialized so that | 633 // Enable profiler recording right after command line is initialized so that |
619 // browser startup can be instrumented. | 634 // browser startup can be instrumented. |
620 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) | 635 if (delegate_ && delegate_->ShouldEnableProfilerRecording()) |
621 tracked_objects::ScopedTracker::Enable(); | 636 tracked_objects::ScopedTracker::Enable(); |
622 | 637 |
623 SetProcessTitleFromCommandLine(argv); | 638 SetProcessTitleFromCommandLine(argv); |
624 #endif // !OS_ANDROID | 639 #endif // !OS_ANDROID |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 | 917 |
903 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); | 918 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); |
904 }; | 919 }; |
905 | 920 |
906 // static | 921 // static |
907 ContentMainRunner* ContentMainRunner::Create() { | 922 ContentMainRunner* ContentMainRunner::Create() { |
908 return new ContentMainRunnerImpl(); | 923 return new ContentMainRunnerImpl(); |
909 } | 924 } |
910 | 925 |
911 } // namespace content | 926 } // namespace content |
OLD | NEW |