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/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" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/process/process_handle.h" | |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 16 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 17 #include "content/browser/browser_child_process_host_impl.h" | 18 #include "content/browser/browser_child_process_host_impl.h" |
| 19 #include "content/browser/mojo/mojo_application_host.h" | |
| 18 #include "content/browser/renderer_host/render_process_host_impl.h" | 20 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 19 #include "content/common/child_process_host_impl.h" | 21 #include "content/common/child_process_host_impl.h" |
| 20 #include "content/common/utility_messages.h" | 22 #include "content/common/utility_messages.h" |
| 21 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
| 23 #include "content/public/browser/utility_process_host_client.h" | 25 #include "content/public/browser/utility_process_host_client.h" |
| 24 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 25 #include "content/public/common/process_type.h" | 27 #include "content/public/common/process_type.h" |
| 26 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 28 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 27 #include "ipc/ipc_switches.h" | 29 #include "ipc/ipc_switches.h" |
| 28 #include "ui/base/ui_base_switches.h" | 30 #include "ui/base/ui_base_switches.h" |
| 29 | 31 |
| 30 namespace content { | 32 namespace content { |
| 31 | 33 |
| 32 // NOTE: changes to this class need to be reviewed by the security team. | 34 // NOTE: changes to this class need to be reviewed by the security team. |
| 33 class UtilitySandboxedProcessLauncherDelegate | 35 class UtilitySandboxedProcessLauncherDelegate |
| 34 : public SandboxedProcessLauncherDelegate { | 36 : public SandboxedProcessLauncherDelegate { |
| 35 public: | 37 public: |
| 36 UtilitySandboxedProcessLauncherDelegate(const base::FilePath& exposed_dir, | 38 UtilitySandboxedProcessLauncherDelegate(const base::FilePath& exposed_dir, |
| 37 bool launch_elevated, bool no_sandbox, | 39 bool launch_elevated, |
| 40 bool no_sandbox, | |
| 38 const base::EnvironmentMap& env, | 41 const base::EnvironmentMap& env, |
| 39 ChildProcessHost* host) | 42 ChildProcessHost* host) |
| 40 : exposed_dir_(exposed_dir), | 43 : exposed_dir_(exposed_dir), |
| 41 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
| 42 launch_elevated_(launch_elevated) | 45 launch_elevated_(launch_elevated) |
| 43 #elif defined(OS_POSIX) | 46 #elif defined(OS_POSIX) |
| 44 env_(env), | 47 env_(env), |
| 45 no_sandbox_(no_sandbox), | 48 no_sandbox_(no_sandbox), |
| 46 ipc_fd_(host->TakeClientFileDescriptor()) | 49 ipc_fd_(host->TakeClientFileDescriptor()) |
| 47 #endif // OS_WIN | 50 #endif // OS_WIN |
| 48 {} | 51 {} |
| 49 | 52 |
| 50 ~UtilitySandboxedProcessLauncherDelegate() override {} | 53 ~UtilitySandboxedProcessLauncherDelegate() override {} |
| 51 | 54 |
| 52 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 53 bool ShouldLaunchElevated() override { | 56 bool ShouldLaunchElevated() override { return launch_elevated_; } |
| 54 return launch_elevated_; | |
| 55 } | |
| 56 void PreSandbox(bool* disable_default_policy, | 57 void PreSandbox(bool* disable_default_policy, |
| 57 base::FilePath* exposed_dir) override { | 58 base::FilePath* exposed_dir) override { |
| 58 *exposed_dir = exposed_dir_; | 59 *exposed_dir = exposed_dir_; |
| 59 } | 60 } |
| 60 #elif defined(OS_POSIX) | 61 #elif defined(OS_POSIX) |
| 61 | 62 |
| 62 bool ShouldUseZygote() override { | 63 bool ShouldUseZygote() override { |
| 63 return !no_sandbox_ && exposed_dir_.empty(); | 64 return !no_sandbox_ && exposed_dir_.empty(); |
| 64 } | 65 } |
| 65 base::EnvironmentMap GetEnvironment() override { return env_; } | 66 base::EnvironmentMap GetEnvironment() override { return env_; } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 } | 159 } |
| 159 | 160 |
| 160 #if defined(OS_POSIX) | 161 #if defined(OS_POSIX) |
| 161 | 162 |
| 162 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { | 163 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { |
| 163 env_ = env; | 164 env_ = env; |
| 164 } | 165 } |
| 165 | 166 |
| 166 #endif // OS_POSIX | 167 #endif // OS_POSIX |
| 167 | 168 |
| 169 bool UtilityProcessHostImpl::StartMojoMode() { | |
| 170 CHECK(!mojo_application_host_); | |
| 171 mojo_application_host_.reset(new MojoApplicationHost); | |
| 172 return StartProcess(); | |
| 173 } | |
| 174 | |
| 175 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() { | |
| 176 return mojo_application_host_->service_registry(); | |
|
Sam McNally
2015/03/09 03:36:15
DCHECK(mojo_application_host_);
Anand Mistry (off Chromium)
2015/03/10 07:24:23
Done.
| |
| 177 } | |
| 178 | |
| 168 bool UtilityProcessHostImpl::StartProcess() { | 179 bool UtilityProcessHostImpl::StartProcess() { |
| 169 if (started_) | 180 if (started_) |
| 170 return true; | 181 return true; |
| 171 started_ = true; | 182 started_ = true; |
| 172 | 183 |
| 173 if (is_batch_mode_) | 184 if (is_batch_mode_) |
| 174 return true; | 185 return true; |
| 175 | 186 |
| 187 if (mojo_application_host_) { | |
| 188 bool mojo_result = mojo_application_host_->Init(); | |
|
Sam McNally
2015/03/09 03:36:15
Why not do this in StartMojoMode()?
Anand Mistry (off Chromium)
2015/03/10 07:24:24
No particular reason.
| |
| 189 if (!mojo_result) | |
| 190 return false; | |
| 191 } | |
| 192 | |
| 176 // Name must be set or metrics_service will crash in any test which | 193 // Name must be set or metrics_service will crash in any test which |
| 177 // launches a UtilityProcessHost. | 194 // launches a UtilityProcessHost. |
| 178 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); | 195 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); |
| 179 process_->SetName(base::ASCIIToUTF16("utility process")); | 196 process_->SetName(base::ASCIIToUTF16("utility process")); |
| 180 | 197 |
| 181 std::string channel_id = process_->GetHost()->CreateChannel(); | 198 std::string channel_id = process_->GetHost()->CreateChannel(); |
| 182 if (channel_id.empty()) | 199 if (channel_id.empty()) |
| 183 return false; | 200 return false; |
| 184 | 201 |
| 185 if (RenderProcessHost::run_renderer_in_process()) { | 202 if (RenderProcessHost::run_renderer_in_process()) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 302 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
| 286 if (!client_.get()) | 303 if (!client_.get()) |
| 287 return; | 304 return; |
| 288 | 305 |
| 289 client_task_runner_->PostTask( | 306 client_task_runner_->PostTask( |
| 290 FROM_HERE, | 307 FROM_HERE, |
| 291 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 308 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
| 292 exit_code)); | 309 exit_code)); |
| 293 } | 310 } |
| 294 | 311 |
| 312 void UtilityProcessHostImpl::OnProcessLaunched() { | |
| 313 if (mojo_application_host_) { | |
| 314 base::ProcessHandle handle; | |
| 315 if (RenderProcessHost::run_renderer_in_process()) | |
| 316 handle = base::GetCurrentProcessHandle(); | |
| 317 else | |
| 318 handle = process_->GetData().handle; | |
| 319 | |
| 320 mojo_application_host_->Activate(this, handle); | |
| 321 } | |
| 322 } | |
| 323 | |
| 295 } // namespace content | 324 } // namespace content |
| OLD | NEW |