Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 #include "content/browser/profiler_message_filter.h" | 31 #include "content/browser/profiler_message_filter.h" |
| 32 #include "content/browser/tracing/trace_message_filter.h" | 32 #include "content/browser/tracing/trace_message_filter.h" |
| 33 #include "content/common/child_process_host_impl.h" | 33 #include "content/common/child_process_host_impl.h" |
| 34 #include "content/common/child_process_messages.h" | 34 #include "content/common/child_process_messages.h" |
| 35 #include "content/common/mojo/mojo_child_connection.h" | 35 #include "content/common/mojo/mojo_child_connection.h" |
| 36 #include "content/public/browser/browser_child_process_host_delegate.h" | 36 #include "content/public/browser/browser_child_process_host_delegate.h" |
| 37 #include "content/public/browser/browser_child_process_observer.h" | 37 #include "content/public/browser/browser_child_process_observer.h" |
| 38 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 39 #include "content/public/browser/child_process_data.h" | 39 #include "content/public/browser/child_process_data.h" |
| 40 #include "content/public/browser/content_browser_client.h" | 40 #include "content/public/browser/content_browser_client.h" |
| 41 #include "content/public/common/content_features.h" | |
| 41 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
| 42 #include "content/public/common/mojo_channel_switches.h" | 43 #include "content/public/common/mojo_channel_switches.h" |
| 43 #include "content/public/common/process_type.h" | 44 #include "content/public/common/process_type.h" |
| 44 #include "content/public/common/result_codes.h" | 45 #include "content/public/common/result_codes.h" |
| 45 #include "ipc/attachment_broker.h" | 46 #include "ipc/attachment_broker.h" |
| 46 #include "ipc/attachment_broker_privileged.h" | 47 #include "ipc/attachment_broker_privileged.h" |
| 47 #include "mojo/edk/embedder/embedder.h" | 48 #include "mojo/edk/embedder/embedder.h" |
| 48 | 49 |
| 49 #if defined(OS_MACOSX) | 50 #if defined(OS_MACOSX) |
| 50 #include "content/browser/mach_broker_mac.h" | 51 #include "content/browser/mach_broker_mac.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 // Make a copy since the BrowserChildProcessHost dtor mutates the original | 201 // Make a copy since the BrowserChildProcessHost dtor mutates the original |
| 201 // list. | 202 // list. |
| 202 BrowserChildProcessList copy = g_child_process_list.Get(); | 203 BrowserChildProcessList copy = g_child_process_list.Get(); |
| 203 for (BrowserChildProcessList::iterator it = copy.begin(); | 204 for (BrowserChildProcessList::iterator it = copy.begin(); |
| 204 it != copy.end(); ++it) { | 205 it != copy.end(); ++it) { |
| 205 delete (*it)->delegate(); // ~*HostDelegate deletes *HostImpl. | 206 delete (*it)->delegate(); // ~*HostDelegate deletes *HostImpl. |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 | 209 |
| 209 // static | 210 // static |
| 210 void BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( | 211 std::unique_ptr<base::SharedMemory> |
| 212 BrowserChildProcessHostImpl::CopyFeatureAndFieldTrialFlags( | |
| 211 base::CommandLine* cmd_line) { | 213 base::CommandLine* cmd_line) { |
| 212 std::string enabled_features; | 214 std::string enabled_features; |
| 213 std::string disabled_features; | 215 std::string disabled_features; |
| 214 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, | 216 base::FeatureList::GetInstance()->GetFeatureOverrides(&enabled_features, |
| 215 &disabled_features); | 217 &disabled_features); |
| 216 if (!enabled_features.empty()) | 218 if (!enabled_features.empty()) |
| 217 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, enabled_features); | 219 cmd_line->AppendSwitchASCII(switches::kEnableFeatures, enabled_features); |
| 218 if (!disabled_features.empty()) | 220 if (!disabled_features.empty()) |
| 219 cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features); | 221 cmd_line->AppendSwitchASCII(switches::kDisableFeatures, disabled_features); |
| 220 | 222 |
| 221 // If we run base::FieldTrials, we want to pass to their state to the | 223 // 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. | 224 // child process so that it can act in accordance with each state. Use shared |
| 223 std::string field_trial_states; | 225 // memory to pass the state if the feature is enabled, otherwise fallback to |
| 224 base::FieldTrialList::AllStatesToString(&field_trial_states); | 226 // passing it via the command line as a string. |
| 225 if (!field_trial_states.empty()) { | 227 if (base::FeatureList::IsEnabled( |
|
Alexei Svitkine (slow)
2016/10/06 13:45:30
Can this whole logic live in the helper function (
lawrencewu
2016/10/06 20:14:57
Done.
| |
| 226 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, | 228 features::kShareFieldTrialStateViaSharedMemory)) { |
| 227 field_trial_states); | 229 return base::FieldTrialList::CopyFieldTrialStateToSharedMemory( |
| 230 cmd_line, switches::kFieldTrialHandle); | |
| 231 } else { | |
| 232 std::string field_trial_states; | |
| 233 base::FieldTrialList::AllStatesToString(&field_trial_states); | |
| 234 if (!field_trial_states.empty()) { | |
| 235 cmd_line->AppendSwitchASCII(switches::kForceFieldTrials, | |
| 236 field_trial_states); | |
| 237 } | |
| 238 return std::unique_ptr<base::SharedMemory>(nullptr); | |
| 228 } | 239 } |
| 229 } | 240 } |
| 230 | 241 |
| 231 void BrowserChildProcessHostImpl::Launch( | 242 void BrowserChildProcessHostImpl::Launch( |
| 232 SandboxedProcessLauncherDelegate* delegate, | 243 SandboxedProcessLauncherDelegate* delegate, |
| 233 base::CommandLine* cmd_line, | 244 base::CommandLine* cmd_line, |
| 245 const base::SharedMemory* field_trial_state, | |
| 234 bool terminate_on_shutdown) { | 246 bool terminate_on_shutdown) { |
| 235 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 247 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 236 | 248 |
| 237 GetContentClient()->browser()->AppendExtraCommandLineSwitches( | 249 GetContentClient()->browser()->AppendExtraCommandLineSwitches( |
| 238 cmd_line, data_.id); | 250 cmd_line, data_.id); |
| 239 | 251 |
| 240 const base::CommandLine& browser_command_line = | 252 const base::CommandLine& browser_command_line = |
| 241 *base::CommandLine::ForCurrentProcess(); | 253 *base::CommandLine::ForCurrentProcess(); |
| 242 static const char* const kForwardSwitches[] = { | 254 static const char* const kForwardSwitches[] = { |
| 243 switches::kDisableLogging, | 255 switches::kDisableLogging, |
| 244 switches::kEnableLogging, | 256 switches::kEnableLogging, |
| 245 switches::kIPCConnectionTimeout, | 257 switches::kIPCConnectionTimeout, |
| 246 switches::kLoggingLevel, | 258 switches::kLoggingLevel, |
| 247 switches::kTraceToConsole, | 259 switches::kTraceToConsole, |
| 248 switches::kV, | 260 switches::kV, |
| 249 switches::kVModule, | 261 switches::kVModule, |
| 250 }; | 262 }; |
| 251 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, | 263 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, |
| 252 arraysize(kForwardSwitches)); | 264 arraysize(kForwardSwitches)); |
| 253 | 265 |
| 254 if (child_connection_) { | 266 if (child_connection_) { |
| 255 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, | 267 cmd_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, |
| 256 child_connection_->service_token()); | 268 child_connection_->service_token()); |
| 257 } | 269 } |
| 258 | 270 |
| 259 notify_child_disconnected_ = true; | 271 notify_child_disconnected_ = true; |
| 260 child_process_.reset(new ChildProcessLauncher( | 272 child_process_.reset(new ChildProcessLauncher( |
| 261 delegate, | 273 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, | 274 base::Bind(&BrowserChildProcessHostImpl::OnMojoError, |
| 267 weak_factory_.GetWeakPtr(), | 275 weak_factory_.GetWeakPtr(), |
| 268 base::ThreadTaskRunnerHandle::Get()), | 276 base::ThreadTaskRunnerHandle::Get()), |
| 269 terminate_on_shutdown)); | 277 terminate_on_shutdown)); |
| 270 } | 278 } |
| 271 | 279 |
| 272 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { | 280 const ChildProcessData& BrowserChildProcessHostImpl::GetData() const { |
| 273 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 281 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 274 return data_; | 282 return data_; |
| 275 } | 283 } |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 602 | 610 |
| 603 #if defined(OS_WIN) | 611 #if defined(OS_WIN) |
| 604 | 612 |
| 605 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { | 613 void BrowserChildProcessHostImpl::OnObjectSignaled(HANDLE object) { |
| 606 OnChildDisconnected(); | 614 OnChildDisconnected(); |
| 607 } | 615 } |
| 608 | 616 |
| 609 #endif | 617 #endif |
| 610 | 618 |
| 611 } // namespace content | 619 } // namespace content |
| OLD | NEW |