| 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/sandbox_linux/sandbox_linux.h" | 13 #include "content/common/sandbox_linux/sandbox_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(child_process_id(), mojo_client_handle(), |
| 38 std::unique_ptr<FileDescriptorInfo> files_to_register = | 39 true /* include_service_required_files */, |
| 39 CreateDefaultPosixFilesToMap(*command_line(), child_process_id(), | 40 GetProcessType(), command_line()); |
| 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 } | 41 } |
| 70 | 42 |
| 71 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( | 43 void ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread( |
| 72 const FileDescriptorInfo& files_to_register, | 44 const FileDescriptorInfo& files_to_register, |
| 73 base::LaunchOptions* options) { | 45 base::LaunchOptions* options) { |
| 74 // Convert FD mapping to FileHandleMappingVector | 46 // Convert FD mapping to FileHandleMappingVector |
| 75 std::unique_ptr<base::FileHandleMappingVector> fds_to_map = | 47 std::unique_ptr<base::FileHandleMappingVector> fds_to_map = |
| 76 files_to_register.GetMappingWithIDAdjustment( | 48 files_to_register.GetMappingWithIDAdjustment( |
| 77 base::GlobalDescriptors::kBaseDescriptor); | 49 base::GlobalDescriptors::kBaseDescriptor); |
| 78 | 50 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 137 } |
| 166 | 138 |
| 167 // static | 139 // static |
| 168 void ChildProcessLauncherHelper::SetProcessBackgroundedOnLauncherThread( | 140 void ChildProcessLauncherHelper::SetProcessBackgroundedOnLauncherThread( |
| 169 base::Process process, bool background) { | 141 base::Process process, bool background) { |
| 170 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | 142 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); |
| 171 if (process.CanBackgroundProcesses()) | 143 if (process.CanBackgroundProcesses()) |
| 172 process.SetProcessBackgrounded(background); | 144 process.SetProcessBackgrounded(background); |
| 173 } | 145 } |
| 174 | 146 |
| 147 // static |
| 148 void ChildProcessLauncherHelper::SetRegisteredFilesForService( |
| 149 const std::string& service_name, |
| 150 catalog::RequiredFileMap required_files) { |
| 151 SetFilesToShareForServicePosix(service_name, std::move(required_files)); |
| 152 } |
| 153 |
| 154 // static |
| 155 base::File OpenFileToShare(const base::FilePath& path, |
| 156 base::MemoryMappedFile::Region* region) { |
| 157 base::FilePath exe_dir; |
| 158 bool result = base::PathService::Get(base::BasePathKey::DIR_EXE, &exe_dir); |
| 159 DCHECK(result); |
| 160 base::File file(exe_dir.Append(path), |
| 161 base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 162 *region = base::MemoryMappedFile::Region::kWholeFile; |
| 163 return file; |
| 164 } |
| 165 |
| 175 } // namespace internal | 166 } // namespace internal |
| 176 } // namespace content | 167 } // namespace content |
| OLD | NEW |