OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/browser/child_process_launcher.h" | 5 #include "content/browser/child_process_launcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/i18n/icu_util.h" | |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/process/process.h" | 14 #include "base/process/process.h" |
14 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
17 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
18 #include "content/public/common/content_descriptors.h" | 19 #include "content/public/common/content_descriptors.h" |
19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
36 #include "base/memory/shared_memory.h" | 37 #include "base/memory/shared_memory.h" |
37 #include "base/memory/singleton.h" | 38 #include "base/memory/singleton.h" |
38 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 39 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
39 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 40 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
40 #include "content/common/child_process_sandbox_support_impl_linux.h" | 41 #include "content/common/child_process_sandbox_support_impl_linux.h" |
41 #endif | 42 #endif |
42 | 43 |
43 #if defined(OS_POSIX) | 44 #if defined(OS_POSIX) |
44 #include "base/posix/global_descriptors.h" | 45 #include "base/posix/global_descriptors.h" |
45 #include "content/browser/file_descriptor_info_impl.h" | 46 #include "content/browser/file_descriptor_info_impl.h" |
47 #include "gin/v8_initializer.h" | |
46 #endif | 48 #endif |
47 | 49 |
48 namespace content { | 50 namespace content { |
49 | 51 |
50 namespace { | 52 namespace { |
51 | 53 |
52 typedef base::Callback<void(bool, | 54 typedef base::Callback<void(bool, |
53 #if defined(OS_ANDROID) | 55 #if defined(OS_ANDROID) |
54 base::ScopedFD, | 56 base::ScopedFD, |
55 #endif | 57 #endif |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 scoped_ptr<FileDescriptorInfo> files_to_register( | 136 scoped_ptr<FileDescriptorInfo> files_to_register( |
135 FileDescriptorInfoImpl::Create()); | 137 FileDescriptorInfoImpl::Create()); |
136 | 138 |
137 #if defined(OS_ANDROID) | 139 #if defined(OS_ANDROID) |
138 files_to_register->Share(kPrimaryIPCChannel, ipcfd.get()); | 140 files_to_register->Share(kPrimaryIPCChannel, ipcfd.get()); |
139 #else | 141 #else |
140 files_to_register->Transfer(kPrimaryIPCChannel, ipcfd.Pass()); | 142 files_to_register->Transfer(kPrimaryIPCChannel, ipcfd.Pass()); |
141 #endif | 143 #endif |
142 #endif | 144 #endif |
143 | 145 |
146 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
147 std::map<int, base::MemoryMappedFile::Region> regions; | |
148 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
149 files_to_register->Share(kV8NativesDataDescriptor, | |
150 gin::V8Initializer::OpenNativesFileForChildProcesses( | |
151 ®ions[kV8NativesDataDescriptor])); | |
rmcilroy
2015/06/12 22:09:25
Please add a DCHECK that the natives_of is valid (
| |
152 | |
153 base::MemoryMappedFile::Region snapshot_region; | |
154 base::PlatformFile snapshot_pf = | |
155 gin::V8Initializer::OpenSnapshotFileForChildProcesses(&snapshot_region); | |
156 // Failure to load the V8 snapshot is not necessarily an error. V8 can start | |
157 // up (slower) without the snapshot. | |
158 if (snapshot_pf != -1) { | |
159 files_to_register->Share(kV8SnapshotDataDescriptor, snapshot_pf); | |
160 regions.insert(std::make_pair(kV8SnapshotDataDescriptor, snapshot_region)); | |
161 } | |
162 | |
163 if (process_type != switches::kZygoteProcess) { | |
164 cmd_line->AppendSwitch(::switches::kV8NativesPassedByFD); | |
165 if (snapshot_pf != -1) { | |
166 cmd_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | |
167 } | |
168 } | |
169 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
170 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( | |
171 *cmd_line, child_process_id, files_to_register.get()); | |
rmcilroy
2015/06/12 22:09:25
Nit - I'd move this call above the #ifdef V8_... b
| |
172 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | |
173 | |
144 #if defined(OS_ANDROID) | 174 #if defined(OS_ANDROID) |
175 files_to_register->Share( | |
176 kAndroidICUDataDescriptor, | |
177 base::i18n::GetIcuDataFileHandle(®ions[kAndroidICUDataDescriptor])); | |
178 | |
145 // Android WebView runs in single process, ensure that we never get here | 179 // Android WebView runs in single process, ensure that we never get here |
146 // when running in single process mode. | 180 // when running in single process mode. |
147 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | 181 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); |
148 std::map<int, base::MemoryMappedFile::Region> regions; | |
149 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( | |
150 *cmd_line, child_process_id, files_to_register.get()); | |
151 | |
152 GetContentClient()->browser()->AppendMappedFileCommandLineSwitches(cmd_line); | |
153 | 182 |
154 StartChildProcess( | 183 StartChildProcess( |
155 cmd_line->argv(), child_process_id, files_to_register.Pass(), regions, | 184 cmd_line->argv(), child_process_id, files_to_register.Pass(), regions, |
156 base::Bind(&OnChildProcessStartedAndroid, callback, client_thread_id, | 185 base::Bind(&OnChildProcessStartedAndroid, callback, client_thread_id, |
157 begin_launch_time, base::Passed(&ipcfd))); | 186 begin_launch_time, base::Passed(&ipcfd))); |
158 | 187 |
159 #elif defined(OS_POSIX) | 188 #elif defined(OS_POSIX) |
160 // We need to close the client end of the IPC channel to reliably detect | 189 // We need to close the client end of the IPC channel to reliably detect |
161 // child termination. | 190 // child termination. |
162 | 191 |
163 #if !defined(OS_MACOSX) | 192 #if !defined(OS_MACOSX) |
164 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( | |
165 *cmd_line, child_process_id, files_to_register.get()); | |
166 | |
167 GetContentClient()->browser()->AppendMappedFileCommandLineSwitches(cmd_line); | |
168 | |
169 if (use_zygote) { | 193 if (use_zygote) { |
170 base::ProcessHandle handle = ZygoteHostImpl::GetInstance()->ForkRequest( | 194 base::ProcessHandle handle = ZygoteHostImpl::GetInstance()->ForkRequest( |
171 cmd_line->argv(), files_to_register.Pass(), process_type); | 195 cmd_line->argv(), files_to_register.Pass(), process_type); |
172 process = base::Process(handle); | 196 process = base::Process(handle); |
173 } else | 197 } else |
174 // Fall through to the normal posix case below when we're not zygoting. | 198 // Fall through to the normal posix case below when we're not zygoting. |
175 #endif // !defined(OS_MACOSX) | 199 #endif // !defined(OS_MACOSX) |
176 { | 200 { |
177 // Convert FD mapping to FileHandleMappingVector | 201 // Convert FD mapping to FileHandleMappingVector |
178 base::FileHandleMappingVector fds_to_map = | 202 base::FileHandleMappingVector fds_to_map = |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
510 } | 534 } |
511 | 535 |
512 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 536 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
513 Client* client) { | 537 Client* client) { |
514 Client* ret = client_; | 538 Client* ret = client_; |
515 client_ = client; | 539 client_ = client; |
516 return ret; | 540 return ret; |
517 } | 541 } |
518 | 542 |
519 } // namespace content | 543 } // namespace content |
OLD | NEW |