| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 if (field_trial_handle != base::kInvalidPlatformFile) | 167 if (field_trial_handle != base::kInvalidPlatformFile) |
| 168 files_to_register->Share(kFieldTrialDescriptor, field_trial_handle); | 168 files_to_register->Share(kFieldTrialDescriptor, field_trial_handle); |
| 169 #if defined(OS_ANDROID) | 169 #if defined(OS_ANDROID) |
| 170 files_to_register->Share(kMojoIPCChannel, mojo_fd.get()); | 170 files_to_register->Share(kMojoIPCChannel, mojo_fd.get()); |
| 171 #else | 171 #else |
| 172 files_to_register->Transfer(kMojoIPCChannel, std::move(mojo_fd)); | 172 files_to_register->Transfer(kMojoIPCChannel, std::move(mojo_fd)); |
| 173 #endif | 173 #endif |
| 174 #endif | 174 #endif |
| 175 | 175 |
| 176 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 176 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 177 std::map<int, base::MemoryMappedFile::Region> regions; | |
| 178 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( | 177 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( |
| 179 *cmd_line, child_process_id, files_to_register.get() | 178 *cmd_line, child_process_id, files_to_register.get()); |
| 180 #if defined(OS_ANDROID) | |
| 181 , ®ions | |
| 182 #endif | |
| 183 ); | |
| 184 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 179 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 185 bool snapshot_loaded = false; | 180 bool snapshot_loaded = false; |
| 181 base::MemoryMappedFile::Region region; |
| 186 #if defined(OS_ANDROID) | 182 #if defined(OS_ANDROID) |
| 187 base::MemoryMappedFile::Region region; | 183 auto maybe_register = [®ion, &files_to_register](int key, int fd) { |
| 188 auto maybe_register = [®ion, ®ions, &files_to_register](int key, | 184 if (fd != -1) |
| 189 int fd) { | 185 files_to_register->ShareWithRegion(key, fd, region); |
| 190 if (fd != -1) { | |
| 191 files_to_register->Share(key, fd); | |
| 192 regions.insert(std::make_pair(key, region)); | |
| 193 } | |
| 194 }; | 186 }; |
| 195 maybe_register( | 187 maybe_register( |
| 196 kV8NativesDataDescriptor, | 188 kV8NativesDataDescriptor, |
| 197 gin::V8Initializer::GetOpenNativesFileForChildProcesses(®ion)); | 189 gin::V8Initializer::GetOpenNativesFileForChildProcesses(®ion)); |
| 198 maybe_register( | 190 maybe_register( |
| 199 kV8SnapshotDataDescriptor32, | 191 kV8SnapshotDataDescriptor32, |
| 200 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, true)); | 192 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, true)); |
| 201 maybe_register( | 193 maybe_register( |
| 202 kV8SnapshotDataDescriptor64, | 194 kV8SnapshotDataDescriptor64, |
| 203 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, false)); | 195 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, false)); |
| 204 | 196 |
| 205 snapshot_loaded = true; | 197 snapshot_loaded = true; |
| 206 #else | 198 #else |
| 207 base::PlatformFile natives_pf = | 199 base::PlatformFile natives_pf = |
| 208 gin::V8Initializer::GetOpenNativesFileForChildProcesses( | 200 gin::V8Initializer::GetOpenNativesFileForChildProcesses(®ion); |
| 209 ®ions[kV8NativesDataDescriptor]); | |
| 210 DCHECK_GE(natives_pf, 0); | 201 DCHECK_GE(natives_pf, 0); |
| 211 files_to_register->Share(kV8NativesDataDescriptor, natives_pf); | 202 files_to_register->ShareWithRegion( |
| 203 kV8NativesDataDescriptor, natives_pf, region); |
| 212 | 204 |
| 213 base::MemoryMappedFile::Region snapshot_region; | |
| 214 base::PlatformFile snapshot_pf = | 205 base::PlatformFile snapshot_pf = |
| 215 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses( | 206 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion); |
| 216 &snapshot_region); | |
| 217 // Failure to load the V8 snapshot is not necessarily an error. V8 can start | 207 // Failure to load the V8 snapshot is not necessarily an error. V8 can start |
| 218 // up (slower) without the snapshot. | 208 // up (slower) without the snapshot. |
| 219 if (snapshot_pf != -1) { | 209 if (snapshot_pf != -1) { |
| 220 snapshot_loaded = true; | 210 snapshot_loaded = true; |
| 221 files_to_register->Share(kV8SnapshotDataDescriptor, snapshot_pf); | 211 files_to_register->ShareWithRegion( |
| 222 regions.insert(std::make_pair(kV8SnapshotDataDescriptor, snapshot_region)); | 212 kV8SnapshotDataDescriptor, snapshot_pf, region); |
| 223 } | 213 } |
| 224 #endif | 214 #endif |
| 225 | 215 |
| 226 if (process_type != switches::kZygoteProcess) { | 216 if (process_type != switches::kZygoteProcess) { |
| 227 cmd_line->AppendSwitch(::switches::kV8NativesPassedByFD); | 217 cmd_line->AppendSwitch(::switches::kV8NativesPassedByFD); |
| 228 if (snapshot_loaded) { | 218 if (snapshot_loaded) { |
| 229 cmd_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | 219 cmd_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); |
| 230 } | 220 } |
| 231 } | 221 } |
| 232 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) | 222 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) |
| 233 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 223 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
| 234 | 224 |
| 235 #if defined(OS_ANDROID) | 225 #if defined(OS_ANDROID) |
| 236 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | 226 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE |
| 237 files_to_register->Share( | 227 base::MemoryMappedFile::Region icu_region; |
| 238 kAndroidICUDataDescriptor, | 228 base::PlatformFile icu_pf = base::i18n::GetIcuDataFileHandle(&icu_region); |
| 239 base::i18n::GetIcuDataFileHandle(®ions[kAndroidICUDataDescriptor])); | 229 files_to_register->ShareWithRegion( |
| 230 kAndroidICUDataDescriptor, icu_pf, icu_region); |
| 240 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | 231 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE |
| 241 | 232 |
| 242 // Android WebView runs in single process, ensure that we never get here | 233 // Android WebView runs in single process, ensure that we never get here |
| 243 // when running in single process mode. | 234 // when running in single process mode. |
| 244 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | 235 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); |
| 245 | 236 |
| 246 StartChildProcess( | 237 StartChildProcess( |
| 247 cmd_line->argv(), child_process_id, std::move(files_to_register), regions, | 238 cmd_line->argv(), child_process_id, std::move(files_to_register), |
| 248 base::Bind(&OnChildProcessStartedAndroid, callback, client_thread_id, | 239 base::Bind(&OnChildProcessStartedAndroid, callback, client_thread_id, |
| 249 begin_launch_time, base::Passed(&mojo_fd))); | 240 begin_launch_time, base::Passed(&mojo_fd))); |
| 250 | 241 |
| 251 #elif defined(OS_POSIX) | 242 #elif defined(OS_POSIX) |
| 252 // We need to close the client end of the IPC channel to reliably detect | 243 // We need to close the client end of the IPC channel to reliably detect |
| 253 // child termination. | 244 // child termination. |
| 254 | 245 |
| 255 #if !defined(OS_MACOSX) | 246 #if !defined(OS_MACOSX) |
| 256 ZygoteHandle* zygote_handle = | 247 ZygoteHandle* zygote_handle = |
| 257 !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoZygote) | 248 !base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoZygote) |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 } | 596 } |
| 606 | 597 |
| 607 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 598 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
| 608 Client* client) { | 599 Client* client) { |
| 609 Client* ret = client_; | 600 Client* ret = client_; |
| 610 client_ = client; | 601 client_ = client; |
| 611 return ret; | 602 return ret; |
| 612 } | 603 } |
| 613 | 604 |
| 614 } // namespace content | 605 } // namespace content |
| OLD | NEW |