OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browser_child_process_host_impl.h" | 5 #include "content/browser/browser_child_process_host_impl.h" |
6 | 6 |
7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/dump_without_crashing.h" | 10 #include "base/debug/dump_without_crashing.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Make a copy since the BrowserChildProcessHost dtor mutates the original | 200 // Make a copy since the BrowserChildProcessHost dtor mutates the original |
201 // list. | 201 // list. |
202 BrowserChildProcessList copy = g_child_process_list.Get(); | 202 BrowserChildProcessList copy = g_child_process_list.Get(); |
203 for (BrowserChildProcessList::iterator it = copy.begin(); | 203 for (BrowserChildProcessList::iterator it = copy.begin(); |
204 it != copy.end(); ++it) { | 204 it != copy.end(); ++it) { |
205 delete (*it)->delegate(); // ~*HostDelegate deletes *HostImpl. | 205 delete (*it)->delegate(); // ~*HostDelegate deletes *HostImpl. |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 // static | 209 // static |
| 210 #if defined(OS_WIN) |
| 211 void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( |
| 212 base::CommandLine* cmd_line, base::SharedMemory* shared_memory) { |
| 213 #else |
210 void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( | 214 void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( |
211 base::CommandLine* cmd_line) { | 215 base::CommandLine* cmd_line) { |
| 216 #endif |
212 std::string enabled_features; | 217 std::string enabled_features; |
213 std::string disabled_features; | 218 std::string disabled_features; |
214 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, | 219 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, |
215 &disabled_features); | 220 &disabled_features); |
216 if (!enabled_features.empty()) | 221 if (!enabled_features.empty()) |
217 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, enabled_features); | 222 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, enabled_features); |
218 if (!disabled_features.empty()) | 223 if (!disabled_features.empty()) |
219 cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features); | 224 cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features); |
220 | 225 |
221 // If we run base::FieldTrials, we want to pass to their state to the | 226 // If we run base::FieldTrials, we want to pass to their state to the |
222 // child process so that it can act in accordance with each state. | 227 // child process so that it can act in accordance with each state. |
223 std::string field_trial_states; | 228 std::string field_trial_states; |
224 base::FieldTrialList::AllStatesToString(&field_trial_states); | 229 base::FieldTrialList::AllStatesToString(&field_trial_states); |
225 if (!field_trial_states.empty()) { | 230 if (!field_trial_states.empty()) { |
| 231 // Use shared memory to pass field_trial_states if we're on Windows, |
| 232 // otherwise fallback to the command line. |
| 233 #if defined(OS_WIN) |
| 234 size_t length = field_trial_states.size() + 1; |
| 235 shared_memory->CreateAndMapAnonymous(length); |
| 236 memcpy(shared_memory->memory(), field_trial_states.c_str(), length); |
| 237 |
| 238 // HANDLE is just typedef'd to void * |
| 239 HANDLE handle = shared_memory->handle().GetHandle(); |
| 240 auto uintptr_handle = reinterpret_cast<std::uintptr_t>(handle); |
| 241 std::string string_handle = std::to_string(uintptr_handle); |
| 242 cmd_line->AppendSwitchASCII("field_trial_handle", string_handle); |
| 243 cmd_line->AppendSwitchASCII("field_trial_length", std::to_string(length)); |
| 244 #else |
226 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, | 245 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, |
227 field_trial_states); | 246 field_trial_states); |
| 247 #endif |
228 } | 248 } |
229 } | 249 } |
230 | 250 |
231 void BrowserChildProcessHostImpl::Launch( | 251 void BrowserChildProcessHostImpl::Launch( |
232 SandboxedProcessLauncherDelegate* delegate, | 252 SandboxedProcessLauncherDelegate* delegate, |
| 253 base::SharedMemory* field_trial_state, |
233 base::CommandLine* cmd_line, | 254 base::CommandLine* cmd_line, |
234 bool terminate_on_shutdown) { | 255 bool terminate_on_shutdown) { |
235 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 256 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
236 | 257 |
237 GetContentClient()->browser()->AppendExtraCommandLineSwitches( | 258 GetContentClient()->browser()->AppendExtraCommandLineSwitches( |
238 cmd_line, data_.id); | 259 cmd_line, data_.id); |
239 | 260 |
240 const base::CommandLine& browser_command_line = | 261 const base::CommandLine& browser_command_line = |
241 *base::CommandLine::ForCurrentProcess(); | 262 *base::CommandLine::ForCurrentProcess(); |
242 static const char* const kForwardSwitches[] = { | 263 static const char* const kForwardSwitches[] = { |
243 switches::kDisableLogging, | 264 switches::kDisableLogging, |
244 switches::kEnableLogging, | 265 switches::kEnableLogging, |
245 switches::kIPCConnectionTimeout, | 266 switches::kIPCConnectionTimeout, |
246 switches::kLoggingLevel, | 267 switches::kLoggingLevel, |
247 switches::kTraceToConsole, | 268 switches::kTraceToConsole, |
248 switches::kV, | 269 switches::kV, |
249 switches::kVModule, | 270 switches::kVModule, |
250 }; | 271 }; |
251 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, | 272 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, |
252 arraysize(kForwardSwitches)); | 273 arraysize(kForwardSwitches)); |
253 | 274 |
254 if (child_connection_) { | 275 if (child_connection_) { |
255 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, | 276 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, |
256 child_connection_->service_token()); | 277 child_connection_->service_token()); |
257 } | 278 } |
258 | 279 |
259 notify_child_disconnected_ = true; | 280 notify_child_disconnected_ = true; |
260 child_process_.reset(new ChildProcessLauncher( | 281 child_process_.reset(new ChildProcessLauncher( |
261 delegate, | 282 delegate, |
| 283 field_trial_state, |
262 cmd_line, | 284 cmd_line, |
263 data_.id, | 285 data_.id, |
264 this, | 286 this, |
265 child_token_, | 287 child_token_, |
266 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, | 288 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, |
267 weak_factory_.GetWeakPtr(), | 289 weak_factory_.GetWeakPtr(), |
268 base::ThreadTaskRunnerHandle::Get()), | 290 base::ThreadTaskRunnerHandle::Get()), |
269 terminate_on_shutdown)); | 291 terminate_on_shutdown)); |
270 } | 292 } |
271 | 293 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 624 |
603 #if defined(OS_WIN) | 625 #if defined(OS_WIN) |
604 | 626 |
605 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { | 627 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { |
606 OnChildDisconnected(); | 628 OnChildDisconnected(); |
607 } | 629 } |
608 | 630 |
609 #endif | 631 #endif |
610 | 632 |
611 } // namespace content | 633 } // namespace content |
OLD | NEW |