Chromium Code Reviews| 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 | |
| 149 files_to_register->Share( | |
|
jam
2015/06/11 16:11:34
should be behind OS_ANDROID
btw it would be good
agrieve
2015/06/11 17:30:35
Done (and kicked off a try job, good advice!)
| |
| 150 kAndroidICUDataDescriptor, | |
| 151 base::i18n::GetIcuDataFileHandle(®ions[kAndroidICUDataDescriptor])); | |
| 152 | |
| 153 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
| 154 files_to_register->Share(kV8NativesDataDescriptor, | |
| 155 gin::V8Initializer::OpenNativesFileForChildProcesses( | |
| 156 ®ions[kV8NativesDataDescriptor])); | |
| 157 | |
| 158 base::MemoryMappedFile::Region snapshot_region; | |
| 159 base::PlatformFile snapshot_pf = | |
| 160 gin::V8Initializer::OpenSnapshotFileForChildProcesses(&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 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( | |
| 176 *cmd_line, child_process_id, files_to_register.get()); | |
| 177 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 178 | |
| 144 #if defined(OS_ANDROID) | 179 #if defined(OS_ANDROID) |
| 145 // Android WebView runs in single process, ensure that we never get here | 180 // Android WebView runs in single process, ensure that we never get here |
| 146 // when running in single process mode. | 181 // when running in single process mode. |
| 147 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | 182 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 | 183 |
| 154 StartChildProcess( | 184 StartChildProcess( |
| 155 cmd_line->argv(), child_process_id, files_to_register.Pass(), regions, | 185 cmd_line->argv(), child_process_id, files_to_register.Pass(), regions, |
| 156 base::Bind(&OnChildProcessStartedAndroid, callback, client_thread_id, | 186 base::Bind(&OnChildProcessStartedAndroid, callback, client_thread_id, |
| 157 begin_launch_time, base::Passed(&ipcfd))); | 187 begin_launch_time, base::Passed(&ipcfd))); |
| 158 | 188 |
| 159 #elif defined(OS_POSIX) | 189 #elif defined(OS_POSIX) |
| 160 // We need to close the client end of the IPC channel to reliably detect | 190 // We need to close the client end of the IPC channel to reliably detect |
| 161 // child termination. | 191 // child termination. |
| 162 | 192 |
| 163 #if !defined(OS_MACOSX) | 193 #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) { | 194 if (use_zygote) { |
| 170 base::ProcessHandle handle = ZygoteHostImpl::GetInstance()->ForkRequest( | 195 base::ProcessHandle handle = ZygoteHostImpl::GetInstance()->ForkRequest( |
| 171 cmd_line->argv(), files_to_register.Pass(), process_type); | 196 cmd_line->argv(), files_to_register.Pass(), process_type); |
| 172 process = base::Process(handle); | 197 process = base::Process(handle); |
| 173 } else | 198 } else |
| 174 // Fall through to the normal posix case below when we're not zygoting. | 199 // Fall through to the normal posix case below when we're not zygoting. |
| 175 #endif // !defined(OS_MACOSX) | 200 #endif // !defined(OS_MACOSX) |
| 176 { | 201 { |
| 177 // Convert FD mapping to FileHandleMappingVector | 202 // Convert FD mapping to FileHandleMappingVector |
| 178 base::FileHandleMappingVector fds_to_map = | 203 base::FileHandleMappingVector fds_to_map = |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 } | 535 } |
| 511 | 536 |
| 512 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 537 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 513 Client* client) { | 538 Client* client) { |
| 514 Client* ret = client_; | 539 Client* ret = client_; |
| 515 client_ = client; | 540 client_ = client; |
| 516 return ret; | 541 return ret; |
| 517 } | 542 } |
| 518 | 543 |
| 519 } // namespace content | 544 } // namespace content |
| OLD | NEW |