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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( | 210 void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( |
211 base::CommandLine* cmd_line) { | 211 base::CommandLine* cmd_line, |
212 base::SharedMemory* shared_memory) { | |
212 std::string enabled_features; | 213 std::string enabled_features; |
213 std::string disabled_features; | 214 std::string disabled_features; |
214 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, | 215 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, |
215 &disabled_features); | 216 &disabled_features); |
216 if (!enabled_features.empty()) | 217 if (!enabled_features.empty()) |
217 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, enabled_features); | 218 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, enabled_features); |
218 if (!disabled_features.empty()) | 219 if (!disabled_features.empty()) |
219 cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features); | 220 cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features); |
220 | 221 |
221 // If we run base::FieldTrials, we want to pass to their state to the | 222 // 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. | 223 // child process so that it can act in accordance with each state. |
223 std::string field_trial_states; | 224 std::string field_trial_states; |
224 base::FieldTrialList::AllStatesToString(&field_trial_states); | 225 base::FieldTrialList::AllStatesToString(&field_trial_states); |
225 if (!field_trial_states.empty()) { | 226 if (!field_trial_states.empty()) { |
226 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, | 227 // Use shared memory to pass field_trial_states if we can, otherwise |
227 field_trial_states); | 228 // fallback to the command line. |
229 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.
| |
230 #if defined(OS_WIN) | |
231 size_t length = field_trial_states.size() + 1; | |
232 shared_memory->CreateAndMapAnonymous(length); | |
233 memcpy(shared_memory->memory(), field_trial_states.c_str(), length); | |
234 | |
235 // HANDLE is just typedef'd to void * | |
236 auto uintptr_handle = | |
237 reinterpret_cast<std::uintptr_t>(shared_memory->handle().GetHandle()); | |
238 std::string field_trial_handle = | |
239 std::to_string(uintptr_handle) + "," + std::to_string(length); | |
240 | |
241 cmd_line->AppendSwitchASCII(switches::kFieldTrialHandle, | |
242 field_trial_handle); | |
243 #endif | |
244 } else { | |
245 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, | |
246 field_trial_states); | |
247 } | |
228 } | 248 } |
229 } | 249 } |
230 | 250 |
231 void BrowserChildProcessHostImpl::Launch( | 251 void BrowserChildProcessHostImpl::Launch( |
232 SandboxedProcessLauncherDelegate* delegate, | 252 SandboxedProcessLauncherDelegate* delegate, |
233 base::CommandLine* cmd_line, | 253 base::CommandLine* cmd_line, |
254 const base::SharedMemory* field_trial_state, | |
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, cmd_line, data_.id, this, field_trial_state, child_token_, |
262 cmd_line, | |
263 data_.id, | |
264 this, | |
265 child_token_, | |
266 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, | 283 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, |
267 weak_factory_.GetWeakPtr(), | 284 weak_factory_.GetWeakPtr(), |
268 base::ThreadTaskRunnerHandle::Get()), | 285 base::ThreadTaskRunnerHandle::Get()), |
269 terminate_on_shutdown)); | 286 terminate_on_shutdown)); |
270 } | 287 } |
271 | 288 |
272 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { | 289 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { |
273 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 290 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
274 return data_; | 291 return data_; |
275 } | 292 } |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 | 619 |
603 #if defined(OS_WIN) | 620 #if defined(OS_WIN) |
604 | 621 |
605 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { | 622 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { |
606 OnChildDisconnected(); | 623 OnChildDisconnected(); |
607 } | 624 } |
608 | 625 |
609 #endif | 626 #endif |
610 | 627 |
611 } // namespace content | 628 } // namespace content |
OLD | NEW |