| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 client_task_runner_(client_task_runner), | 99 client_task_runner_(client_task_runner), |
| 100 is_batch_mode_(false), | 100 is_batch_mode_(false), |
| 101 is_mdns_enabled_(false), | 101 is_mdns_enabled_(false), |
| 102 no_sandbox_(false), | 102 no_sandbox_(false), |
| 103 run_elevated_(false), | 103 run_elevated_(false), |
| 104 #if defined(OS_LINUX) | 104 #if defined(OS_LINUX) |
| 105 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), | 105 child_flags_(ChildProcessHost::CHILD_ALLOW_SELF), |
| 106 #else | 106 #else |
| 107 child_flags_(ChildProcessHost::CHILD_NORMAL), | 107 child_flags_(ChildProcessHost::CHILD_NORMAL), |
| 108 #endif | 108 #endif |
| 109 started_(false) { | 109 started_(false), |
| 110 name_("utility process") { |
| 110 } | 111 } |
| 111 | 112 |
| 112 UtilityProcessHostImpl::~UtilityProcessHostImpl() { | 113 UtilityProcessHostImpl::~UtilityProcessHostImpl() { |
| 113 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 114 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 114 if (is_batch_mode_) | 115 if (is_batch_mode_) |
| 115 EndBatchMode(); | 116 EndBatchMode(); |
| 116 | 117 |
| 117 // We could be destroyed as a result of Chrome shutdown. When that happens, | 118 // We could be destroyed as a result of Chrome shutdown. When that happens, |
| 118 // the Mojo channel doesn't get the opportunity to shut down cleanly because | 119 // the Mojo channel doesn't get the opportunity to shut down cleanly because |
| 119 // it posts to the IO thread (the current thread) which is being destroyed. | 120 // it posts to the IO thread (the current thread) which is being destroyed. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return false; | 183 return false; |
| 183 | 184 |
| 184 return StartProcess(); | 185 return StartProcess(); |
| 185 } | 186 } |
| 186 | 187 |
| 187 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() { | 188 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() { |
| 188 DCHECK(mojo_application_host_); | 189 DCHECK(mojo_application_host_); |
| 189 return mojo_application_host_->service_registry(); | 190 return mojo_application_host_->service_registry(); |
| 190 } | 191 } |
| 191 | 192 |
| 193 void UtilityProcessHostImpl::SetName(const std::string& name) { |
| 194 name_ = name; |
| 195 } |
| 196 |
| 192 bool UtilityProcessHostImpl::StartProcess() { | 197 bool UtilityProcessHostImpl::StartProcess() { |
| 193 if (started_) | 198 if (started_) |
| 194 return true; | 199 return true; |
| 195 started_ = true; | 200 started_ = true; |
| 196 | 201 |
| 197 if (is_batch_mode_) | 202 if (is_batch_mode_) |
| 198 return true; | 203 return true; |
| 199 | 204 |
| 200 // Name must be set or metrics_service will crash in any test which | 205 // Name must be set or metrics_service will crash in any test which |
| 201 // launches a UtilityProcessHost. | 206 // launches a UtilityProcessHost. |
| 202 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); | 207 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); |
| 203 process_->SetName(base::ASCIIToUTF16("utility process")); | 208 process_->SetName(base::UTF8ToUTF16(name_)); |
| 204 | 209 |
| 205 std::string channel_id = process_->GetHost()->CreateChannel(); | 210 std::string channel_id = process_->GetHost()->CreateChannel(); |
| 206 if (channel_id.empty()) | 211 if (channel_id.empty()) |
| 207 return false; | 212 return false; |
| 208 | 213 |
| 209 if (RenderProcessHost::run_renderer_in_process()) { | 214 if (RenderProcessHost::run_renderer_in_process()) { |
| 210 DCHECK(g_utility_main_thread_factory); | 215 DCHECK(g_utility_main_thread_factory); |
| 211 // See comment in RenderProcessHostImpl::Init() for the background on why we | 216 // See comment in RenderProcessHostImpl::Init() for the background on why we |
| 212 // support single process mode this way. | 217 // support single process mode this way. |
| 213 in_process_thread_.reset(g_utility_main_thread_factory(channel_id)); | 218 in_process_thread_.reset(g_utility_main_thread_factory(channel_id)); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 if (RenderProcessHost::run_renderer_in_process()) | 327 if (RenderProcessHost::run_renderer_in_process()) |
| 323 handle = base::GetCurrentProcessHandle(); | 328 handle = base::GetCurrentProcessHandle(); |
| 324 else | 329 else |
| 325 handle = process_->GetData().handle; | 330 handle = process_->GetData().handle; |
| 326 | 331 |
| 327 mojo_application_host_->Activate(this, handle); | 332 mojo_application_host_->Activate(this, handle); |
| 328 } | 333 } |
| 329 } | 334 } |
| 330 | 335 |
| 331 } // namespace content | 336 } // namespace content |
| OLD | NEW |