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/utility_process_host_impl.h" | 5 #include "content/browser/utility_process_host_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 : client_(client), | 71 : client_(client), |
72 client_task_runner_(client_task_runner), | 72 client_task_runner_(client_task_runner), |
73 is_batch_mode_(false), | 73 is_batch_mode_(false), |
74 is_mdns_enabled_(false), | 74 is_mdns_enabled_(false), |
75 no_sandbox_(false), | 75 no_sandbox_(false), |
76 #if defined(OS_LINUX) | 76 #if defined(OS_LINUX) |
77 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), | 77 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), |
78 #else | 78 #else |
79 child_flags_(ChildProcessHost::CHILD_NORMAL), | 79 child_flags_(ChildProcessHost::CHILD_NORMAL), |
80 #endif | 80 #endif |
81 use_linux_zygote_(false), | |
82 started_(false) { | 81 started_(false) { |
83 } | 82 } |
84 | 83 |
85 UtilityProcessHostImpl::~UtilityProcessHostImpl() { | 84 UtilityProcessHostImpl::~UtilityProcessHostImpl() { |
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
87 if (is_batch_mode_) | 86 if (is_batch_mode_) |
88 EndBatchMode(); | 87 EndBatchMode(); |
89 } | 88 } |
90 | 89 |
91 bool UtilityProcessHostImpl::Send(IPC::Message* message) { | 90 bool UtilityProcessHostImpl::Send(IPC::Message* message) { |
(...skipping 21 matching lines...) Expand all Loading... |
113 } | 112 } |
114 | 113 |
115 void UtilityProcessHostImpl::EnableMDns() { | 114 void UtilityProcessHostImpl::EnableMDns() { |
116 is_mdns_enabled_ = true; | 115 is_mdns_enabled_ = true; |
117 } | 116 } |
118 | 117 |
119 void UtilityProcessHostImpl::DisableSandbox() { | 118 void UtilityProcessHostImpl::DisableSandbox() { |
120 no_sandbox_ = true; | 119 no_sandbox_ = true; |
121 } | 120 } |
122 | 121 |
123 void UtilityProcessHostImpl::EnableZygote() { | |
124 use_linux_zygote_ = true; | |
125 } | |
126 | |
127 const ChildProcessData& UtilityProcessHostImpl::GetData() { | 122 const ChildProcessData& UtilityProcessHostImpl::GetData() { |
128 return process_->GetData(); | 123 return process_->GetData(); |
129 } | 124 } |
130 | 125 |
131 #if defined(OS_POSIX) | 126 #if defined(OS_POSIX) |
132 | 127 |
133 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { | 128 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { |
134 env_ = env; | 129 env_ = env; |
135 } | 130 } |
136 | 131 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) | 188 if (no_sandbox_ || browser_command_line.HasSwitch(switches::kNoSandbox)) |
194 cmd_line->AppendSwitch(switches::kNoSandbox); | 189 cmd_line->AppendSwitch(switches::kNoSandbox); |
195 #if defined(OS_MACOSX) | 190 #if defined(OS_MACOSX) |
196 if (browser_command_line.HasSwitch(switches::kEnableSandboxLogging)) | 191 if (browser_command_line.HasSwitch(switches::kEnableSandboxLogging)) |
197 cmd_line->AppendSwitch(switches::kEnableSandboxLogging); | 192 cmd_line->AppendSwitch(switches::kEnableSandboxLogging); |
198 #endif | 193 #endif |
199 if (browser_command_line.HasSwitch(switches::kDebugPluginLoading)) | 194 if (browser_command_line.HasSwitch(switches::kDebugPluginLoading)) |
200 cmd_line->AppendSwitch(switches::kDebugPluginLoading); | 195 cmd_line->AppendSwitch(switches::kDebugPluginLoading); |
201 | 196 |
202 #if defined(OS_POSIX) | 197 #if defined(OS_POSIX) |
203 // TODO(port): Sandbox this on Linux. Also, zygote this to work with | |
204 // Linux updating. | |
205 if (has_cmd_prefix) { | 198 if (has_cmd_prefix) { |
206 // launch the utility child process with some prefix | 199 // Launch the utility child process with some prefix |
207 // (usually "xterm -e gdb --args"). | 200 // (usually "xterm -e gdb --args"). |
208 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( | 201 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( |
209 switches::kUtilityCmdPrefix)); | 202 switches::kUtilityCmdPrefix)); |
210 } | 203 } |
211 | 204 |
212 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, | 205 if (!exposed_dir_.empty()) { |
213 exposed_dir_); | 206 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, |
| 207 exposed_dir_); |
| 208 } |
214 #endif | 209 #endif |
215 | 210 |
216 if (is_mdns_enabled_) | 211 if (is_mdns_enabled_) |
217 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns); | 212 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns); |
218 | 213 |
219 bool use_zygote = false; | 214 bool use_zygote = false; |
220 | 215 |
221 #if defined(OS_LINUX) | 216 #if defined(OS_LINUX) |
222 use_zygote = !no_sandbox_ && use_linux_zygote_; | 217 // The Linux sandbox does not support granting access to a single directory, |
| 218 // so we need to bypass the zygote in that case. |
| 219 use_zygote = !no_sandbox_ && exposed_dir_.empty(); |
223 #endif | 220 #endif |
224 | 221 |
225 process_->Launch( | 222 process_->Launch( |
226 #if defined(OS_WIN) | 223 #if defined(OS_WIN) |
227 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_), | 224 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_), |
228 #elif defined(OS_POSIX) | 225 #elif defined(OS_POSIX) |
229 use_zygote, | 226 use_zygote, |
230 env_, | 227 env_, |
231 #endif | 228 #endif |
232 cmd_line); | 229 cmd_line); |
(...skipping 12 matching lines...) Expand all Loading... |
245 } | 242 } |
246 | 243 |
247 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 244 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
248 client_task_runner_->PostTask( | 245 client_task_runner_->PostTask( |
249 FROM_HERE, | 246 FROM_HERE, |
250 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 247 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
251 exit_code)); | 248 exit_code)); |
252 } | 249 } |
253 | 250 |
254 } // namespace content | 251 } // namespace content |
OLD | NEW |