| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 base::SequencedTaskRunner* client_task_runner) { | 104 base::SequencedTaskRunner* client_task_runner) { |
| 105 return new UtilityProcessHostImpl(client, client_task_runner); | 105 return new UtilityProcessHostImpl(client, client_task_runner); |
| 106 } | 106 } |
| 107 | 107 |
| 108 UtilityProcessHostImpl::UtilityProcessHostImpl( | 108 UtilityProcessHostImpl::UtilityProcessHostImpl( |
| 109 UtilityProcessHostClient* client, | 109 UtilityProcessHostClient* client, |
| 110 base::SequencedTaskRunner* client_task_runner) | 110 base::SequencedTaskRunner* client_task_runner) |
| 111 : client_(client), | 111 : client_(client), |
| 112 client_task_runner_(client_task_runner), | 112 client_task_runner_(client_task_runner), |
| 113 is_batch_mode_(false), | 113 is_batch_mode_(false), |
| 114 is_mdns_enabled_(false), |
| 114 no_sandbox_(false), | 115 no_sandbox_(false), |
| 115 #if defined(OS_LINUX) | 116 #if defined(OS_LINUX) |
| 116 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), | 117 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), |
| 117 #else | 118 #else |
| 118 child_flags_(ChildProcessHost::CHILD_NORMAL), | 119 child_flags_(ChildProcessHost::CHILD_NORMAL), |
| 119 #endif | 120 #endif |
| 120 use_linux_zygote_(false), | 121 use_linux_zygote_(false), |
| 121 started_(false) { | 122 started_(false) { |
| 122 } | 123 } |
| 123 | 124 |
| 124 UtilityProcessHostImpl::~UtilityProcessHostImpl() { | 125 UtilityProcessHostImpl::~UtilityProcessHostImpl() { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 126 DCHECK(!is_batch_mode_); | 127 if (is_batch_mode_) |
| 128 EndBatchMode(); |
| 127 } | 129 } |
| 128 | 130 |
| 129 bool UtilityProcessHostImpl::Send(IPC::Message* message) { | 131 bool UtilityProcessHostImpl::Send(IPC::Message* message) { |
| 130 if (!StartProcess()) | 132 if (!StartProcess()) |
| 131 return false; | 133 return false; |
| 132 | 134 |
| 133 return process_->Send(message); | 135 return process_->Send(message); |
| 134 } | 136 } |
| 135 | 137 |
| 136 bool UtilityProcessHostImpl::StartBatchMode() { | 138 bool UtilityProcessHostImpl::StartBatchMode() { |
| 137 CHECK(!is_batch_mode_); | 139 CHECK(!is_batch_mode_); |
| 138 is_batch_mode_ = StartProcess(); | 140 is_batch_mode_ = StartProcess(); |
| 139 Send(new UtilityMsg_BatchMode_Started()); | 141 Send(new UtilityMsg_BatchMode_Started()); |
| 140 return is_batch_mode_; | 142 return is_batch_mode_; |
| 141 } | 143 } |
| 142 | 144 |
| 143 void UtilityProcessHostImpl::EndBatchMode() { | 145 void UtilityProcessHostImpl::EndBatchMode() { |
| 144 CHECK(is_batch_mode_); | 146 CHECK(is_batch_mode_); |
| 145 is_batch_mode_ = false; | 147 is_batch_mode_ = false; |
| 146 Send(new UtilityMsg_BatchMode_Finished()); | 148 Send(new UtilityMsg_BatchMode_Finished()); |
| 147 } | 149 } |
| 148 | 150 |
| 149 void UtilityProcessHostImpl::SetExposedDir(const base::FilePath& dir) { | 151 void UtilityProcessHostImpl::SetExposedDir(const base::FilePath& dir) { |
| 150 exposed_dir_ = dir; | 152 exposed_dir_ = dir; |
| 151 } | 153 } |
| 152 | 154 |
| 155 void UtilityProcessHostImpl::EnableMDns() { |
| 156 is_mdns_enabled_ = true; |
| 157 } |
| 158 |
| 153 void UtilityProcessHostImpl::DisableSandbox() { | 159 void UtilityProcessHostImpl::DisableSandbox() { |
| 154 no_sandbox_ = true; | 160 no_sandbox_ = true; |
| 155 } | 161 } |
| 156 | 162 |
| 157 void UtilityProcessHostImpl::EnableZygote() { | 163 void UtilityProcessHostImpl::EnableZygote() { |
| 158 use_linux_zygote_ = true; | 164 use_linux_zygote_ = true; |
| 159 } | 165 } |
| 160 | 166 |
| 161 const ChildProcessData& UtilityProcessHostImpl::GetData() { | 167 const ChildProcessData& UtilityProcessHostImpl::GetData() { |
| 162 return process_->GetData(); | 168 return process_->GetData(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 if (has_cmd_prefix) { | 243 if (has_cmd_prefix) { |
| 238 // launch the utility child process with some prefix (usually "xterm -e gd
b | 244 // launch the utility child process with some prefix (usually "xterm -e gd
b |
| 239 // --args"). | 245 // --args"). |
| 240 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( | 246 cmd_line->PrependWrapper(browser_command_line.GetSwitchValueNative( |
| 241 switches::kUtilityCmdPrefix)); | 247 switches::kUtilityCmdPrefix)); |
| 242 } | 248 } |
| 243 | 249 |
| 244 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, exposed_dir_
); | 250 cmd_line->AppendSwitchPath(switches::kUtilityProcessAllowedDir, exposed_dir_
); |
| 245 #endif | 251 #endif |
| 246 | 252 |
| 253 if (is_mdns_enabled_) |
| 254 cmd_line->AppendSwitch(switches::kUtilityProcessEnableMDns); |
| 255 |
| 247 bool use_zygote = false; | 256 bool use_zygote = false; |
| 248 | 257 |
| 249 #if defined(OS_LINUX) | 258 #if defined(OS_LINUX) |
| 250 use_zygote = !no_sandbox_ && use_linux_zygote_; | 259 use_zygote = !no_sandbox_ && use_linux_zygote_; |
| 251 #endif | 260 #endif |
| 252 | 261 |
| 253 process_->Launch( | 262 process_->Launch( |
| 254 #if defined(OS_WIN) | 263 #if defined(OS_WIN) |
| 255 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_), | 264 new UtilitySandboxedProcessLauncherDelegate(exposed_dir_), |
| 256 #elif defined(OS_POSIX) | 265 #elif defined(OS_POSIX) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 273 } | 282 } |
| 274 | 283 |
| 275 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 284 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
| 276 client_task_runner_->PostTask( | 285 client_task_runner_->PostTask( |
| 277 FROM_HERE, | 286 FROM_HERE, |
| 278 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 287 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
| 279 exit_code)); | 288 exit_code)); |
| 280 } | 289 } |
| 281 | 290 |
| 282 } // namespace content | 291 } // namespace content |
| OLD | NEW |