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" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 161 } |
160 | 162 |
161 #if defined(OS_POSIX) | 163 #if defined(OS_POSIX) |
162 | 164 |
163 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { | 165 void UtilityProcessHostImpl::SetEnv(const base::EnvironmentMap& env) { |
164 env_ = env; | 166 env_ = env; |
165 } | 167 } |
166 | 168 |
167 #endif // OS_POSIX | 169 #endif // OS_POSIX |
168 | 170 |
| 171 bool UtilityProcessHostImpl::StartMojoMode() { |
| 172 return StartProcess(); |
| 173 } |
| 174 |
| 175 ServiceRegistry* UtilityProcessHostImpl::GetServiceRegistry() { |
| 176 return mojo_application_host_.service_registry(); |
| 177 } |
| 178 |
169 bool UtilityProcessHostImpl::StartProcess() { | 179 bool UtilityProcessHostImpl::StartProcess() { |
170 if (started_) | 180 if (started_) |
171 return true; | 181 return true; |
172 started_ = true; | 182 started_ = true; |
173 | 183 |
174 if (is_batch_mode_) | 184 if (is_batch_mode_) |
175 return true; | 185 return true; |
176 | 186 |
| 187 CHECK(mojo_application_host_.Init()) << "Unable to initialize Mojo host."; |
| 188 |
177 // Name must be set or metrics_service will crash in any test which | 189 // Name must be set or metrics_service will crash in any test which |
178 // launches a UtilityProcessHost. | 190 // launches a UtilityProcessHost. |
179 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); | 191 process_.reset(new BrowserChildProcessHostImpl(PROCESS_TYPE_UTILITY, this)); |
180 process_->SetName(base::ASCIIToUTF16("utility process")); | 192 process_->SetName(base::ASCIIToUTF16("utility process")); |
| 193 process_->SetServiceRegistry(GetServiceRegistry()); |
181 | 194 |
182 std::string channel_id = process_->GetHost()->CreateChannel(); | 195 std::string channel_id = process_->GetHost()->CreateChannel(); |
183 if (channel_id.empty()) | 196 if (channel_id.empty()) |
184 return false; | 197 return false; |
185 | 198 |
186 if (RenderProcessHost::run_renderer_in_process()) { | 199 if (RenderProcessHost::run_renderer_in_process()) { |
187 DCHECK(g_utility_main_thread_factory); | 200 DCHECK(g_utility_main_thread_factory); |
188 // See comment in RenderProcessHostImpl::Init() for the background on why we | 201 // See comment in RenderProcessHostImpl::Init() for the background on why we |
189 // support single process mode this way. | 202 // support single process mode this way. |
190 in_process_thread_.reset(g_utility_main_thread_factory(channel_id)); | 203 in_process_thread_.reset(g_utility_main_thread_factory(channel_id)); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { | 299 void UtilityProcessHostImpl::OnProcessCrashed(int exit_code) { |
287 if (!client_.get()) | 300 if (!client_.get()) |
288 return; | 301 return; |
289 | 302 |
290 client_task_runner_->PostTask( | 303 client_task_runner_->PostTask( |
291 FROM_HERE, | 304 FROM_HERE, |
292 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), | 305 base::Bind(&UtilityProcessHostClient::OnProcessCrashed, client_.get(), |
293 exit_code)); | 306 exit_code)); |
294 } | 307 } |
295 | 308 |
| 309 void UtilityProcessHostImpl::OnProcessLaunched() { |
| 310 base::ProcessHandle handle; |
| 311 if (RenderProcessHost::run_renderer_in_process()) |
| 312 handle = base::GetCurrentProcessHandle(); |
| 313 else |
| 314 handle = process_->GetData().handle; |
| 315 |
| 316 mojo_application_host_.Activate(this, handle); |
| 317 } |
| 318 |
296 } // namespace content | 319 } // namespace content |
OLD | NEW |