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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 UtilityProcessHostImpl::UtilityProcessHostImpl( | 68 UtilityProcessHostImpl::UtilityProcessHostImpl( |
69 UtilityProcessHostClient* client, | 69 UtilityProcessHostClient* client, |
70 base::SequencedTaskRunner* client_task_runner) | 70 base::SequencedTaskRunner* client_task_runner) |
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_WIN) |
| 77 run_elevated_(false), |
| 78 #endif |
76 #if defined(OS_LINUX) | 79 #if defined(OS_LINUX) |
77 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), | 80 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), |
78 #else | 81 #else |
79 child_flags_(ChildProcessHost::CHILD_NORMAL), | 82 child_flags_(ChildProcessHost::CHILD_NORMAL), |
80 #endif | 83 #endif |
81 started_(false) { | 84 started_(false) { |
82 } | 85 } |
83 | 86 |
84 UtilityProcessHostImpl::~UtilityProcessHostImpl() { | 87 UtilityProcessHostImpl::~UtilityProcessHostImpl() { |
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
(...skipping 26 matching lines...) Expand all Loading... |
112 } | 115 } |
113 | 116 |
114 void UtilityProcessHostImpl::EnableMDns() { | 117 void UtilityProcessHostImpl::EnableMDns() { |
115 is_mdns_enabled_ = true; | 118 is_mdns_enabled_ = true; |
116 } | 119 } |
117 | 120 |
118 void UtilityProcessHostImpl::DisableSandbox() { | 121 void UtilityProcessHostImpl::DisableSandbox() { |
119 no_sandbox_ = true; | 122 no_sandbox_ = true; |
120 } | 123 } |
121 | 124 |
| 125 #if defined(OS_WIN) |
| 126 void UtilityProcessHostImpl::ElevatePrivileges() { |
| 127 no_sandbox_ = true; |
| 128 run_elevated_ = true; |
| 129 } |
| 130 #endif |
| 131 |
122 const ChildProcessData& UtilityProcessHostImpl::GetData() { | 132 const ChildProcessData& UtilityProcessHostImpl::GetData() { |
123 return process_->GetData(); | 133 return process_->GetData(); |
124 } | 134 } |
125 | 135 |
126 #if defined(OS_POSIX) | 136 #if defined(OS_POSIX) |
127 | 137 |
128 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { | 138 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { |
129 env_ = env; | 139 env_ = env; |
130 } | 140 } |
131 | 141 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 213 |
204 if (!exposed_dir_.empty()) { | 214 if (!exposed_dir_.empty()) { |
205 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, | 215 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, |
206 exposed_dir_); | 216 exposed_dir_); |
207 } | 217 } |
208 #endif | 218 #endif |
209 | 219 |
210 if (is_mdns_enabled_) | 220 if (is_mdns_enabled_) |
211 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns); | 221 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns); |
212 | 222 |
| 223 #if defined(OS_WIN) |
| 224 // Let the utility process know if it is intended to be elevated. |
| 225 if (run_elevated_) |
| 226 cmd_line->AppendSwitch(switches::kUtilityProcessRunningElevated); |
| 227 #endif |
| 228 |
213 bool use_zygote = false; | 229 bool use_zygote = false; |
214 | 230 |
215 #if defined(OS_LINUX) | 231 #if defined(OS_LINUX) |
216 // The Linux sandbox does not support granting access to a single directory, | 232 // The Linux sandbox does not support granting access to a single directory, |
217 // so we need to bypass the zygote in that case. | 233 // so we need to bypass the zygote in that case. |
218 use_zygote = !no_sandbox_ && exposed_dir_.empty(); | 234 use_zygote = !no_sandbox_ && exposed_dir_.empty(); |
219 #endif | 235 #endif |
220 | 236 |
221 process_->Launch( | 237 process_->Launch( |
222 #if defined(OS_WIN) | 238 #if defined(OS_WIN) |
223 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_), | 239 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_), |
| 240 run_elevated_, |
224 #elif defined(OS_POSIX) | 241 #elif defined(OS_POSIX) |
225 use_zygote, | 242 use_zygote, |
226 env_, | 243 env_, |
227 #endif | 244 #endif |
228 cmd_line); | 245 cmd_line); |
229 } | 246 } |
230 | 247 |
231 return true; | 248 return true; |
232 } | 249 } |
233 | 250 |
234 bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) { | 251 bool UtilityProcessHostImpl::OnMessageReceived(const IPC::Message& message) { |
235 client_task_runner_->PostTask( | 252 client_task_runner_->PostTask( |
236 FROM_HERE, | 253 FROM_HERE, |
237 base::Bind(base::IgnoreResult( | 254 base::Bind(base::IgnoreResult( |
238 &UtilityProcessHostClient::OnMessageReceived), client_.get(), | 255 &UtilityProcessHostClient::OnMessageReceived), client_.get(), |
239 message)); | 256 message)); |
240 return true; | 257 return true; |
241 } | 258 } |
242 | 259 |
| 260 void UtilityProcessHostImpl::OnProcessLaunchFailed() { |
| 261 client_task_runner_->PostTask( |
| 262 FROM_HERE, |
| 263 base::Bind(&UtilityProcessHostClient::OnProcessLaunchFailed, |
| 264 client_.get())); |
| 265 } |
| 266 |
243 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 267 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
244 client_task_runner_->PostTask( | 268 client_task_runner_->PostTask( |
245 FROM_HERE, | 269 FROM_HERE, |
246 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 270 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
247 exit_code)); | 271 exit_code)); |
248 } | 272 } |
249 | 273 |
250 } // namespace content | 274 } // namespace content |
OLD | NEW |