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