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