Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
boliu
2017/01/12 02:00:07
2017 for new files
Jay Civelli
2017/01/12 23:05:41
Done.
This was written in 2016 though :-)
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/child_process_launcher.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/i18n/icu_util.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/metrics/field_trial.h" | |
| 12 #include "content/browser/android/child_process_launcher_android_jni.h" | |
| 13 #include "content/browser/child_process_launcher_posix.h" | |
| 14 #include "content/browser/file_descriptor_info_impl.h" | |
| 15 #include "content/browser/web_contents/web_contents_impl.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "content/public/browser/render_process_host.h" | |
| 18 #include "content/public/common/content_descriptors.h" | |
| 19 #include "content/public/common/content_switches.h" | |
| 20 #include "gin/v8_initializer.h" | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 namespace { | |
| 25 | |
| 26 struct ChildProcessHelperHolder { | |
| 27 public: | |
| 28 explicit ChildProcessHelperHolder(ChildProcessLauncher::Helper* helper) | |
| 29 : helper(helper) { | |
| 30 } | |
| 31 | |
| 32 scoped_refptr<ChildProcessLauncher::Helper> helper; | |
| 33 }; | |
| 34 | |
| 35 // Callback invoked from Java once the process has been started. | |
| 36 void ChildProcessStartedCallback( | |
| 37 ChildProcessHelperHolder* helper_holder, | |
| 38 base::ProcessHandle handle, | |
| 39 int launch_result) { | |
| 40 // TODO(jcivelli): Remove this by defining better what happens on what thread | |
| 41 // in the corresponding Java code. | |
| 42 if (BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)) { | |
| 43 helper_holder->helper->PostLaunchOnLauncherThread( | |
| 44 base::Process(handle), nullptr, launch_result); | |
| 45 } else { | |
| 46 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | |
| 47 base::Bind(&ChildProcessLauncher::Helper::PostLaunchOnLauncherThread, | |
|
boliu
2017/01/12 02:00:07
this is an extra thread hop compared to previous c
Jay Civelli
2017/01/12 23:05:41
True, this seems to be called mostly on the UI thr
| |
| 48 helper_holder->helper, | |
| 49 base::Passed(base::Process(handle)), | |
| 50 nullptr, | |
| 51 launch_result)); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 void ChildProcessLauncher::Helper::BeforeLaunchOnClientThread() { | |
| 58 // Android only supports renderer, sandboxed utility and gpu. | |
| 59 std::string process_type = | |
| 60 command_line()->GetSwitchValueASCII(switches::kProcessType); | |
| 61 CHECK(process_type == switches::kGpuProcess || | |
| 62 process_type == switches::kRendererProcess || | |
| 63 #if BUILDFLAG(ENABLE_PLUGINS) | |
| 64 process_type == switches::kPpapiPluginProcess || | |
| 65 #endif | |
| 66 process_type == switches::kUtilityProcess) | |
| 67 << "Unsupported process type: " << process_type; | |
| 68 | |
| 69 // Non-sandboxed utility or renderer process are currently not supported. | |
| 70 DCHECK(process_type == switches::kGpuProcess || | |
| 71 !command_line()->HasSwitch(switches::kNoSandbox)); | |
| 72 } | |
| 73 | |
| 74 mojo::edk::ScopedPlatformHandle | |
| 75 ChildProcessLauncher::Helper::PrepareMojoPipeHandlesOnClientThread() { | |
| 76 return mojo::edk::ScopedPlatformHandle(); | |
| 77 } | |
| 78 | |
| 79 std::unique_ptr<FileDescriptorInfo> | |
| 80 ChildProcessLauncher::Helper::GetFilesToMap() { | |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | |
| 82 | |
| 83 // Android WebView runs in single process, ensure that we never get here when | |
| 84 // running in single process mode. | |
| 85 CHECK(!command_line()->HasSwitch(switches::kSingleProcess)); | |
| 86 | |
| 87 std::unique_ptr<FileDescriptorInfo> files_to_register = | |
| 88 CreateDefaultPosixFilesToMap(*command_line(), child_process_id(), | |
| 89 mojo_client_handle()); | |
| 90 | |
| 91 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
| 92 base::MemoryMappedFile::Region region; | |
| 93 auto maybe_register = [®ion, &files_to_register](int key, int fd) { | |
| 94 if (fd != -1) | |
| 95 files_to_register->ShareWithRegion(key, fd, region); | |
| 96 }; | |
| 97 maybe_register( | |
| 98 kV8NativesDataDescriptor, | |
| 99 gin::V8Initializer::GetOpenNativesFileForChildProcesses(®ion)); | |
| 100 maybe_register( | |
| 101 kV8SnapshotDataDescriptor32, | |
| 102 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, true)); | |
| 103 maybe_register( | |
| 104 kV8SnapshotDataDescriptor64, | |
| 105 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, false)); | |
| 106 | |
| 107 if (GetProcessType() != switches::kZygoteProcess) { | |
|
boliu
2017/01/12 02:00:07
this can be removed from android, zygote is not in
Jay Civelli
2017/01/12 23:05:41
Good point, done.
| |
| 108 command_line()->AppendSwitch(::switches::kV8NativesPassedByFD); | |
| 109 command_line()->AppendSwitch(::switches::kV8SnapshotPassedByFD); | |
| 110 } | |
| 111 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) | |
| 112 | |
| 113 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | |
| 114 int fd = base::i18n::GetIcuDataFileHandle(®ion); | |
| 115 files_to_register->ShareWithRegion(kAndroidICUDataDescriptor, fd, region); | |
| 116 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | |
| 117 | |
| 118 return files_to_register; | |
| 119 } | |
| 120 | |
| 121 bool ChildProcessLauncher::Helper::ShouldForkAsZygote() { | |
| 122 return false; | |
|
boliu
2017/01/12 02:00:07
indent
Jay Civelli
2017/01/12 23:05:41
Done.
| |
| 123 } | |
| 124 | |
| 125 ZygoteHandle ChildProcessLauncher::Helper::ForkAsZygote( | |
| 126 std::unique_ptr<FileDescriptorInfo> files_to_register, | |
| 127 base::Process* process) { | |
| 128 NOTREACHED(); | |
| 129 return nullptr; | |
| 130 } | |
| 131 | |
| 132 void ChildProcessLauncher::Helper::BeforeLaunchOnLauncherThread( | |
| 133 const FileDescriptorInfo& files_to_register, | |
| 134 base::LaunchOptions* options) { | |
| 135 } | |
| 136 | |
| 137 base::Process ChildProcessLauncher::Helper::LaunchProcessOnLauncherThread( | |
| 138 const base::LaunchOptions& options, | |
| 139 FileDescriptorInfo* files_to_register, | |
| 140 bool* is_synchronous_launch, | |
| 141 int* launch_result) { | |
| 142 *is_synchronous_launch = false; | |
| 143 | |
| 144 StartChildProcess(command_line()->argv(), | |
| 145 child_process_id(), | |
| 146 files_to_register, | |
| 147 base::Bind(&ChildProcessStartedCallback, | |
| 148 new ChildProcessHelperHolder(this))); | |
|
boliu
2017/01/12 02:00:07
what's responsible for deleting holder?
Can Child
Jay Civelli
2017/01/12 23:05:41
Good point, I can take care of increasing the ref
boliu
2017/01/13 01:33:50
This is not necessary, also not correct if the cal
Jay Civelli
2017/01/13 18:08:01
The reason we don't need to do this most of the ti
| |
| 149 | |
| 150 return base::Process(); | |
| 151 } | |
| 152 | |
| 153 void ChildProcessLauncher::Helper::AfterLaunchOnLauncherThread( | |
| 154 const base::Process& process, | |
| 155 const base::LaunchOptions& options) { | |
| 156 } | |
| 157 | |
| 158 // static | |
| 159 bool ChildProcessLauncher::TerminateProcess( | |
| 160 const base::Process& process, int exit_code, bool wait) { | |
| 161 StopChildProcess(process.Handle()); | |
| 162 return true; | |
| 163 } | |
| 164 | |
| 165 // static | |
| 166 void ChildProcessLauncher::TerminateOnLauncherThread( | |
| 167 ZygoteHandle zygote, base::Process process) { | |
| 168 DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER); | |
| 169 VLOG(1) << "ChromeProcess: Stopping process with handle " | |
| 170 << process.Handle(); | |
| 171 StopChildProcess(process.Handle()); | |
| 172 } | |
| 173 | |
| 174 // static | |
| 175 void ChildProcessLauncher::SetProcessBackgroundedOnLauncherThread( | |
| 176 base::Process process, bool background) { | |
| 177 SetChildProcessInForeground(process.Handle(), !background); | |
| 178 } | |
| 179 | |
| 180 void ChildProcessLauncher::UpdateTerminationStatus(bool known_dead) { | |
| 181 DCHECK(CalledOnValidThread()); | |
| 182 if (IsChildProcessOomProtected(process_.Handle())) { | |
| 183 termination_status_ = base::TERMINATION_STATUS_OOM_PROTECTED; | |
| 184 } else { | |
| 185 termination_status_ = | |
| 186 base::GetTerminationStatus(process_.Handle(), &exit_code_); | |
| 187 } | |
| 188 } | |
| 189 | |
| 190 } // namespace content | |
| OLD | NEW |