| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "content/common/utility_messages.h" | 29 #include "content/common/utility_messages.h" |
| 30 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
| 32 #include "content/public/browser/utility_process_host_client.h" | 32 #include "content/public/browser/utility_process_host_client.h" |
| 33 #include "content/public/common/content_switches.h" | 33 #include "content/public/common/content_switches.h" |
| 34 #include "content/public/common/mojo_channel_switches.h" | 34 #include "content/public/common/mojo_channel_switches.h" |
| 35 #include "content/public/common/process_type.h" | 35 #include "content/public/common/process_type.h" |
| 36 #include "content/public/common/sandbox_type.h" | 36 #include "content/public/common/sandbox_type.h" |
| 37 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 37 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 38 #include "ipc/ipc_switches.h" | 38 #include "ipc/ipc_switches.h" |
| 39 #include "mojo/edk/embedder/embedder.h" |
| 39 #include "ui/base/ui_base_switches.h" | 40 #include "ui/base/ui_base_switches.h" |
| 40 | 41 |
| 41 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 42 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
| 42 #include "content/public/browser/zygote_handle_linux.h" | 43 #include "content/public/browser/zygote_handle_linux.h" |
| 43 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 44 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
| 44 | 45 |
| 45 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
| 46 #include "sandbox/win/src/sandbox_policy.h" | 47 #include "sandbox/win/src/sandbox_policy.h" |
| 47 #include "sandbox/win/src/sandbox_types.h" | 48 #include "sandbox/win/src/sandbox_types.h" |
| 48 #endif | 49 #endif |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 is_batch_mode_(false), | 152 is_batch_mode_(false), |
| 152 no_sandbox_(false), | 153 no_sandbox_(false), |
| 153 run_elevated_(false), | 154 run_elevated_(false), |
| 154 #if defined(OS_LINUX) | 155 #if defined(OS_LINUX) |
| 155 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), | 156 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), |
| 156 #else | 157 #else |
| 157 child_flags_(ChildProcessHost::CHILD_NORMAL), | 158 child_flags_(ChildProcessHost::CHILD_NORMAL), |
| 158 #endif | 159 #endif |
| 159 started_(false), | 160 started_(false), |
| 160 name_(base::ASCIIToUTF16("utility process")), | 161 name_(base::ASCIIToUTF16("utility process")), |
| 161 mojo_application_host_(new MojoApplicationHost), | 162 child_token_(mojo::edk::GenerateRandomToken()), |
| 163 mojo_application_host_(new MojoApplicationHost(child_token_)), |
| 162 weak_ptr_factory_(this) { | 164 weak_ptr_factory_(this) { |
| 163 } | 165 } |
| 164 | 166 |
| 165 UtilityProcessHostImpl::~UtilityProcessHostImpl() { | 167 UtilityProcessHostImpl::~UtilityProcessHostImpl() { |
| 166 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 167 if (is_batch_mode_) | 169 if (is_batch_mode_) |
| 168 EndBatchMode(); | 170 EndBatchMode(); |
| 169 } | 171 } |
| 170 | 172 |
| 171 base::WeakPtr<UtilityProcessHost> UtilityProcessHostImpl::AsWeakPtr() { | 173 base::WeakPtr<UtilityProcessHost> UtilityProcessHostImpl::AsWeakPtr() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 bool UtilityProcessHostImpl::StartProcess() { | 245 bool UtilityProcessHostImpl::StartProcess() { |
| 244 if (started_) | 246 if (started_) |
| 245 return true; | 247 return true; |
| 246 started_ = true; | 248 started_ = true; |
| 247 | 249 |
| 248 if (is_batch_mode_) | 250 if (is_batch_mode_) |
| 249 return true; | 251 return true; |
| 250 | 252 |
| 251 // Name must be set or metrics_service will crash in any test which | 253 // Name must be set or metrics_service will crash in any test which |
| 252 // launches a UtilityProcessHost. | 254 // launches a UtilityProcessHost. |
| 253 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); | 255 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this, |
| 256 child_token_)); |
| 254 process_->SetName(name_); | 257 process_->SetName(name_); |
| 255 | 258 |
| 256 std::string channel_id = process_->GetHost()->CreateChannel(); | 259 std::string channel_id = process_->GetHost()->CreateChannel(); |
| 257 if (channel_id.empty()) { | 260 if (channel_id.empty()) { |
| 258 NotifyAndDelete(LAUNCH_RESULT_FAILURE); | 261 NotifyAndDelete(LAUNCH_RESULT_FAILURE); |
| 259 return false; | 262 return false; |
| 260 } | 263 } |
| 261 | 264 |
| 262 if (RenderProcessHost::run_renderer_in_process()) { | 265 if (RenderProcessHost::run_renderer_in_process()) { |
| 263 DCHECK(g_utility_main_thread_factory); | 266 DCHECK(g_utility_main_thread_factory); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 base::WeakPtr<UtilityProcessHostImpl> host, | 411 base::WeakPtr<UtilityProcessHostImpl> host, |
| 409 int error_code) { | 412 int error_code) { |
| 410 if (!host) | 413 if (!host) |
| 411 return; | 414 return; |
| 412 | 415 |
| 413 host->OnProcessLaunchFailed(error_code); | 416 host->OnProcessLaunchFailed(error_code); |
| 414 delete host.get(); | 417 delete host.get(); |
| 415 } | 418 } |
| 416 | 419 |
| 417 } // namespace content | 420 } // namespace content |
| OLD | NEW |