Chromium Code Reviews| Index: content/browser/browser_child_process_host_impl.cc |
| diff --git a/content/browser/browser_child_process_host_impl.cc b/content/browser/browser_child_process_host_impl.cc |
| index e3eacd3ce01dead3132bee37df83760295395796..8cb7c71ad83ea1c25830ba3dc3057d1a82b39bf4 100644 |
| --- a/content/browser/browser_child_process_host_impl.cc |
| +++ b/content/browser/browser_child_process_host_impl.cc |
| @@ -208,7 +208,8 @@ void BrowserChildProcessHostImpl::TerminateAll() { |
| // static |
| void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( |
| - base::CommandLine* cmd_line) { |
| + base::CommandLine* cmd_line, |
| + base::SharedMemory* shared_memory) { |
| std::string enabled_features; |
| std::string disabled_features; |
| base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, |
| @@ -223,14 +224,34 @@ void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( |
| std::string field_trial_states; |
| base::FieldTrialList::AllStatesToString(&field_trial_states); |
| if (!field_trial_states.empty()) { |
| - cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| - field_trial_states); |
| + // Use shared memory to pass field_trial_states if we can, otherwise |
| + // fallback to the command line. |
| + if (shared_memory) { |
|
Alexei Svitkine (slow)
2016/10/04 18:49:35
I also suggest putting this code in base/metrics a
lawrencewu
2016/10/05 20:57:56
Done.
|
| +#if defined(OS_WIN) |
| + size_t length = field_trial_states.size() + 1; |
| + shared_memory->CreateAndMapAnonymous(length); |
| + memcpy(shared_memory->memory(), field_trial_states.c_str(), length); |
| + |
| + // HANDLE is just typedef'd to void * |
| + auto uintptr_handle = |
| + reinterpret_cast<std::uintptr_t>(shared_memory->handle().GetHandle()); |
| + std::string field_trial_handle = |
| + std::to_string(uintptr_handle) + "," + std::to_string(length); |
| + |
| + cmd_line->AppendSwitchASCII(switches::kFieldTrialHandle, |
| + field_trial_handle); |
| +#endif |
| + } else { |
| + cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, |
| + field_trial_states); |
| + } |
| } |
| } |
| void BrowserChildProcessHostImpl::Launch( |
| SandboxedProcessLauncherDelegate* delegate, |
| base::CommandLine* cmd_line, |
| + const base::SharedMemory* field_trial_state, |
| bool terminate_on_shutdown) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| @@ -258,11 +279,7 @@ void BrowserChildProcessHostImpl::Launch( |
| notify_child_disconnected_ = true; |
| child_process_.reset(new ChildProcessLauncher( |
| - delegate, |
| - cmd_line, |
| - data_.id, |
| - this, |
| - child_token_, |
| + delegate, cmd_line, data_.id, this, field_trial_state, child_token_, |
| base::Bind(&BrowserChildProcessHostImpl::OnMojoError, |
| weak_factory_.GetWeakPtr(), |
| base::ThreadTaskRunnerHandle::Get()), |