| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "base/path_service.h" |
| 5 #include "base/posix/global_descriptors.h" | 6 #include "base/posix/global_descriptors.h" |
| 6 #include "content/browser/child_process_launcher.h" | 7 #include "content/browser/child_process_launcher.h" |
| 7 #include "content/browser/child_process_launcher_helper.h" | 8 #include "content/browser/child_process_launcher_helper.h" |
| 8 #include "content/browser/child_process_launcher_helper_posix.h" | 9 #include "content/browser/child_process_launcher_helper_posix.h" |
| 9 #include "content/browser/renderer_host/render_sandbox_host_linux.h" | 10 #include "content/browser/renderer_host/render_sandbox_host_linux.h" |
| 10 #include "content/browser/zygote_host/zygote_communication_linux.h" | 11 #include "content/browser/zygote_host/zygote_communication_linux.h" |
| 11 #include "content/browser/zygote_host/zygote_host_impl_linux.h" | 12 #include "content/browser/zygote_host/zygote_host_impl_linux.h" |
| 12 #include "content/common/child_process_sandbox_support_impl_linux.h" | 13 #include "content/common/child_process_sandbox_support_impl_linux.h" |
| 13 #include "content/public/browser/content_browser_client.h" | 14 #include "content/public/browser/content_browser_client.h" |
| 14 #include "content/public/browser/zygote_handle_linux.h" | 15 #include "content/public/browser/zygote_handle_linux.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 27 return mojo::edk::ScopedPlatformHandle(); | 28 return mojo::edk::ScopedPlatformHandle(); |
| 28 } | 29 } |
| 29 | 30 |
| 30 void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() { | 31 void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() { |
| 31 DCHECK_CURRENTLY_ON(client_thread_id_); | 32 DCHECK_CURRENTLY_ON(client_thread_id_); |
| 32 } | 33 } |
| 33 | 34 |
| 34 std::unique_ptr<FileMappedForLaunch> | 35 std::unique_ptr<FileMappedForLaunch> |
| 35 ChildProcessLauncherHelper::GetFilesToMap() { | 36 ChildProcessLauncherHelper::GetFilesToMap() { |
| 36 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 37 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 37 | 38 return CreateDefaultPosixFilesToMap(*command_line(), child_process_id(), |
| 38 std::unique_ptr<FileDescriptorInfo> files_to_register = | 39 mojo_client_handle()); |
| 39 CreateDefaultPosixFilesToMap(*command_line(), child_process_id(), | |
| 40 mojo_client_handle()); | |
| 41 | |
| 42 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
| 43 bool snapshot_loaded = false; | |
| 44 base::MemoryMappedFile::Region unused_region; | |
| 45 base::PlatformFile natives_pf = | |
| 46 gin::V8Initializer::GetOpenNativesFileForChildProcesses(&unused_region); | |
| 47 DCHECK_GE(natives_pf, 0); | |
| 48 files_to_register->Share(kV8NativesDataDescriptor, natives_pf); | |
| 49 | |
| 50 base::MemoryMappedFile::Region snapshot_region; | |
| 51 base::PlatformFile snapshot_pf = | |
| 52 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses( | |
| 53 &snapshot_region); | |
| 54 // Failure to load the V8 snapshot is not necessarily an error. V8 can start | |
| 55 // up (slower) without the snapshot. | |
| 56 if (snapshot_pf != -1) { | |
| 57 snapshot_loaded = true; | |
| 58 files_to_register->Share(kV8SnapshotDataDescriptor, snapshot_pf); | |
| 59 } | |
| 60 if (GetProcessType() != switches::kZygoteProcess) { | |
| 61 command_line()->AppendSwitch(::switches::kV8NativesPassedByFD); | |
| 62 if (snapshot_loaded) { | |
| 63 command_line()->AppendSwitch(::switches::kV8SnapshotPassedByFD); | |
| 64 } | |
| 65 } | |
| 66 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
| 67 | |
| 68 return files_to_register; | |
| 69 } | 40 } |
| 70 | 41 |
| 71 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( | 42 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( |
| 72 const FileDescriptorInfo& files_to_register, | 43 const FileDescriptorInfo& files_to_register, |
| 73 base::LaunchOptions* options) { | 44 base::LaunchOptions* options) { |
| 74 // Convert FD mapping to FileHandleMappingVector | 45 // Convert FD mapping to FileHandleMappingVector |
| 75 std::unique_ptr<base::FileHandleMappingVector> fds_to_map = | 46 std::unique_ptr<base::FileHandleMappingVector> fds_to_map = |
| 76 files_to_register.GetMappingWithIDAdjustment( | 47 files_to_register.GetMappingWithIDAdjustment( |
| 77 base::GlobalDescriptors::kBaseDescriptor); | 48 base::GlobalDescriptors::kBaseDescriptor); |
| 78 | 49 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 136 } |
| 166 | 137 |
| 167 // static | 138 // static |
| 168 void ChildProcessLauncherHelper::SetProcessBackgroundedOnLauncherThread( | 139 void ChildProcessLauncherHelper::SetProcessBackgroundedOnLauncherThread( |
| 169 base::Process process, bool background) { | 140 base::Process process, bool background) { |
| 170 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 141 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 171 if (process.CanBackgroundProcesses()) | 142 if (process.CanBackgroundProcesses()) |
| 172 process.SetProcessBackgrounded(background); | 143 process.SetProcessBackgrounded(background); |
| 173 } | 144 } |
| 174 | 145 |
| 146 // static |
| 147 base::File ChildProcessLauncherHelper::OpenFile( |
| 148 const base::FilePath& path, |
| 149 base::MemoryMappedFile::Region* region) { |
| 150 base::FilePath exe_dir; |
| 151 bool result = base::PathService::Get(base::BasePathKey::DIR_EXE, &exe_dir); |
| 152 DCHECK(result); |
| 153 base::File file(exe_dir.Append(path), |
| 154 base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 155 *region = base::MemoryMappedFile::Region::kWholeFile; |
| 156 return file; |
| 157 } |
| 158 |
| 175 } // namespace internal | 159 } // namespace internal |
| 176 } // namespace content | 160 } // namespace content |
| OLD | NEW |