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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 150 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
151 std::map<int, base::MemoryMappedFile::Region> regions; | 151 std::map<int, base::MemoryMappedFile::Region> regions; |
152 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( | 152 GetContentClient()->browser()->GetAdditionalMappedFilesForChildProcess( |
153 *cmd_line, child_process_id, files_to_register.get() | 153 *cmd_line, child_process_id, files_to_register.get() |
154 #if defined(OS_ANDROID) | 154 #if defined(OS_ANDROID) |
155 , ®ions | 155 , ®ions |
156 #endif | 156 #endif |
157 ); | 157 ); |
158 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) | 158 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) |
159 bool snapshot_loaded = false; | |
160 #if defined(OS_ANDROID) | |
161 base::MemoryMappedFile::Region region; | |
162 auto maybe_register = [®ion, ®ions, &files_to_register](int key, | |
163 int fd) { | |
164 if (fd != -1) { | |
165 files_to_register->Share(key, fd); | |
166 regions.insert(std::make_pair(key, region)); | |
167 } | |
168 }; | |
169 maybe_register( | |
170 kV8NativesDataDescriptor32, | |
171 gin::V8Initializer::GetOpenNativesFileForChildProcesses(®ion, true)); | |
172 maybe_register( | |
173 kV8NativesDataDescriptor64, | |
174 gin::V8Initializer::GetOpenNativesFileForChildProcesses(®ion, false)); | |
175 maybe_register( | |
176 kV8SnapshotDataDescriptor32, | |
177 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, true)); | |
178 maybe_register( | |
179 kV8SnapshotDataDescriptor64, | |
180 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses(®ion, false)); | |
181 | |
182 snapshot_loaded = true; | |
183 #else | |
184 base::PlatformFile natives_pf = | 159 base::PlatformFile natives_pf = |
185 gin::V8Initializer::GetOpenNativesFileForChildProcesses( | 160 gin::V8Initializer::GetOpenNativesFileForChildProcesses( |
186 ®ions[kV8NativesDataDescriptor]); | 161 ®ions[kV8NativesDataDescriptor]); |
187 DCHECK_GE(natives_pf, 0); | 162 DCHECK_GE(natives_pf, 0); |
188 files_to_register->Share(kV8NativesDataDescriptor, natives_pf); | 163 files_to_register->Share(kV8NativesDataDescriptor, natives_pf); |
189 | 164 |
190 base::MemoryMappedFile::Region snapshot_region; | 165 base::MemoryMappedFile::Region snapshot_region; |
191 base::PlatformFile snapshot_pf = | 166 base::PlatformFile snapshot_pf = |
192 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses( | 167 gin::V8Initializer::GetOpenSnapshotFileForChildProcesses( |
193 &snapshot_region); | 168 &snapshot_region); |
194 // Failure to load the V8 snapshot is not necessarily an error. V8 can start | 169 // Failure to load the V8 snapshot is not necessarily an error. V8 can start |
195 // up (slower) without the snapshot. | 170 // up (slower) without the snapshot. |
196 if (snapshot_pf != -1) { | 171 if (snapshot_pf != -1) { |
197 snapshot_loaded = true; | |
198 files_to_register->Share(kV8SnapshotDataDescriptor, snapshot_pf); | 172 files_to_register->Share(kV8SnapshotDataDescriptor, snapshot_pf); |
199 regions.insert(std::make_pair(kV8SnapshotDataDescriptor, snapshot_region)); | 173 regions.insert(std::make_pair(kV8SnapshotDataDescriptor, snapshot_region)); |
200 } | 174 } |
201 #endif | |
202 | 175 |
203 if (process_type != switches::kZygoteProcess) { | 176 if (process_type != switches::kZygoteProcess) { |
204 cmd_line->AppendSwitch(::switches::kV8NativesPassedByFD); | 177 cmd_line->AppendSwitch(::switches::kV8NativesPassedByFD); |
205 if (snapshot_loaded) { | 178 if (snapshot_pf != -1) { |
206 cmd_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); | 179 cmd_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); |
207 } | 180 } |
208 } | 181 } |
209 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) | 182 #endif // defined(V8_USE_EXTERNAL_STARTUP_DATA) |
210 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | 183 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
211 | 184 |
212 #if defined(OS_ANDROID) | 185 #if defined(OS_ANDROID) |
213 files_to_register->Share( | 186 files_to_register->Share( |
214 kAndroidICUDataDescriptor, | 187 kAndroidICUDataDescriptor, |
215 base::i18n::GetIcuDataFileHandle(®ions[kAndroidICUDataDescriptor])); | 188 base::i18n::GetIcuDataFileHandle(®ions[kAndroidICUDataDescriptor])); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 } | 527 } |
555 | 528 |
556 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( | 529 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( |
557 Client* client) { | 530 Client* client) { |
558 Client* ret = client_; | 531 Client* ret = client_; |
559 client_ = client; | 532 client_ = client; |
560 return ret; | 533 return ret; |
561 } | 534 } |
562 | 535 |
563 } // namespace content | 536 } // namespace content |
OLD | NEW |