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 <memory> | |
7 #include <utility> | 8 #include <utility> |
8 | 9 |
9 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
18 #include "base/process/process_handle.h" | 19 #include "base/process/process_handle.h" |
19 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
20 #include "base/sequenced_task_runner.h" | 21 #include "base/sequenced_task_runner.h" |
21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
22 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
23 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
26 #include "components/discardable_memory/service/discardable_shared_memory_manage r.h" | |
25 #include "content/browser/browser_child_process_host_impl.h" | 27 #include "content/browser/browser_child_process_host_impl.h" |
28 #include "content/browser/browser_main_loop.h" | |
26 #include "content/browser/renderer_host/render_process_host_impl.h" | 29 #include "content/browser/renderer_host/render_process_host_impl.h" |
27 #include "content/browser/service_manager/service_manager_context.h" | 30 #include "content/browser/service_manager/service_manager_context.h" |
28 #include "content/common/child_process_host_impl.h" | 31 #include "content/common/child_process_host_impl.h" |
29 #include "content/common/in_process_child_thread_params.h" | 32 #include "content/common/in_process_child_thread_params.h" |
30 #include "content/common/service_manager/child_connection.h" | 33 #include "content/common/service_manager/child_connection.h" |
31 #include "content/common/utility_messages.h" | 34 #include "content/common/utility_messages.h" |
32 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/content_browser_client.h" | 36 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/utility_process_host_client.h" | 37 #include "content/public/browser/utility_process_host_client.h" |
38 #include "content/public/common/connection_filter.h" | |
35 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
36 #include "content/public/common/mojo_channel_switches.h" | 40 #include "content/public/common/mojo_channel_switches.h" |
37 #include "content/public/common/process_type.h" | 41 #include "content/public/common/process_type.h" |
38 #include "content/public/common/sandbox_type.h" | 42 #include "content/public/common/sandbox_type.h" |
39 #include "content/public/common/sandboxed_process_launcher_delegate.h" | 43 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
40 #include "content/public/common/service_manager_connection.h" | 44 #include "content/public/common/service_manager_connection.h" |
41 #include "content/public/common/service_names.mojom.h" | 45 #include "content/public/common/service_names.mojom.h" |
42 #include "mojo/edk/embedder/embedder.h" | 46 #include "mojo/edk/embedder/embedder.h" |
47 #include "services/service_manager/public/cpp/binder_registry.h" | |
43 #include "services/service_manager/public/cpp/interface_provider.h" | 48 #include "services/service_manager/public/cpp/interface_provider.h" |
44 #include "ui/base/ui_base_switches.h" | 49 #include "ui/base/ui_base_switches.h" |
45 | 50 |
46 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 51 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
47 #include "content/public/browser/zygote_handle_linux.h" | 52 #include "content/public/browser/zygote_handle_linux.h" |
48 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 53 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
49 | 54 |
50 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
51 #include "sandbox/win/src/sandbox_policy.h" | 56 #include "sandbox/win/src/sandbox_policy.h" |
52 #include "sandbox/win/src/sandbox_types.h" | 57 #include "sandbox/win/src/sandbox_types.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 #elif defined(OS_POSIX) | 132 #elif defined(OS_POSIX) |
128 base::EnvironmentMap env_; | 133 base::EnvironmentMap env_; |
129 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 134 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
130 bool no_sandbox_; | 135 bool no_sandbox_; |
131 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) | 136 #endif // !defined(OS_MACOSX) && !defined(OS_ANDROID) |
132 #endif // OS_WIN | 137 #endif // OS_WIN |
133 }; | 138 }; |
134 | 139 |
135 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; | 140 UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; |
136 | 141 |
142 class UtilityProcessHost::ConnectionFilterImpl : public ConnectionFilter { | |
143 public: | |
144 ConnectionFilterImpl( | |
145 std::unique_ptr<service_manager::BinderRegistry> registry) | |
146 : registry_(std::move(registry)) {} | |
147 | |
148 private: | |
149 // ConnectionFilter: | |
150 void OnBindInterface(const service_manager::ServiceInfo& source_info, | |
151 const std::string& interface_name, | |
152 mojo::ScopedMessagePipeHandle* interface_pipe, | |
153 service_manager::Connector* connector) override { | |
154 if (registry_->CanBindInterface(interface_name)) { | |
155 registry_->BindInterface(source_info.identity, interface_name, | |
156 std::move(*interface_pipe)); | |
157 } | |
158 } | |
159 | |
160 std::unique_ptr<service_manager::BinderRegistry> registry_; | |
161 | |
162 DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); | |
163 }; | |
164 | |
137 UtilityProcessHost* UtilityProcessHost::Create( | 165 UtilityProcessHost* UtilityProcessHost::Create( |
138 const scoped_refptr<UtilityProcessHostClient>& client, | 166 const scoped_refptr<UtilityProcessHostClient>& client, |
139 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) { | 167 const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) { |
140 return new UtilityProcessHostImpl(client, client_task_runner); | 168 return new UtilityProcessHostImpl(client, client_task_runner); |
141 } | 169 } |
142 | 170 |
143 void UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( | 171 void UtilityProcessHostImpl::RegisterUtilityMainThreadFactory( |
144 UtilityMainThreadFactoryFunction create) { | 172 UtilityMainThreadFactoryFunction create) { |
145 g_utility_main_thread_factory = create; | 173 g_utility_main_thread_factory = create; |
146 } | 174 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 return StartProcess(); | 254 return StartProcess(); |
227 } | 255 } |
228 | 256 |
229 void UtilityProcessHostImpl::BindInterface( | 257 void UtilityProcessHostImpl::BindInterface( |
230 const std::string& interface_name, | 258 const std::string& interface_name, |
231 mojo::ScopedMessagePipeHandle interface_pipe) { | 259 mojo::ScopedMessagePipeHandle interface_pipe) { |
232 process_->child_connection()->BindInterface(interface_name, | 260 process_->child_connection()->BindInterface(interface_name, |
233 std::move(interface_pipe)); | 261 std::move(interface_pipe)); |
234 } | 262 } |
235 | 263 |
264 void UtilityProcessHostImpl::RegisterMojoServicesOnUIThread( | |
265 service_manager::BinderRegistry* registry) { | |
266 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
Lei Zhang
2017/04/22 00:12:26
Shouldn't the caller call this on the right thread
Wei Li
2017/04/27 05:34:16
Right now, all the utility functions are called on
Lei Zhang
2017/04/27 22:42:21
Whether it's the first or not, can we have callers
Wei Li
2017/04/29 04:35:18
oh, now I got it. Hope it looks better now.
| |
267 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI) | |
268 ->PostTask( | |
269 FROM_HERE, | |
270 base::Bind(&UtilityProcessHostImpl::RegisterMojoServicesOnUIThread, | |
271 base::Unretained(this), registry)); | |
272 } else { | |
273 registry->AddInterface( | |
274 base::Bind( | |
275 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, | |
276 base::Unretained( | |
277 memory_instrumentation::CoordinatorImpl::GetInstance())), | |
278 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)); | |
279 | |
280 discardable_memory::DiscardableSharedMemoryManager* manager = | |
281 BrowserMainLoop::GetInstance()->discardable_shared_memory_manager(); | |
282 registry->AddInterface( | |
283 base::Bind(&discardable_memory::DiscardableSharedMemoryManager::Bind, | |
284 base::Unretained(manager)), | |
285 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)); | |
286 } | |
287 } | |
288 | |
289 void UtilityProcessHostImpl::RegisterMojoServices() { | |
290 auto registry = base::MakeUnique<service_manager::BinderRegistry>(); | |
291 // May be null during test execution. | |
292 if (ServiceManagerConnection::GetForProcess()) { | |
293 RegisterMojoServicesOnUIThread(registry.get()); | |
294 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( | |
295 base::MakeUnique<ConnectionFilterImpl>(std::move(registry))); | |
296 } | |
297 } | |
298 | |
236 void UtilityProcessHostImpl::SetName(const base::string16& name) { | 299 void UtilityProcessHostImpl::SetName(const base::string16& name) { |
237 name_ = name; | 300 name_ = name; |
238 } | 301 } |
239 | 302 |
240 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 303 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
241 // static | 304 // static |
242 void UtilityProcessHostImpl::EarlyZygoteLaunch() { | 305 void UtilityProcessHostImpl::EarlyZygoteLaunch() { |
243 DCHECK(!g_utility_zygote); | 306 DCHECK(!g_utility_zygote); |
244 g_utility_zygote = CreateZygote(); | 307 g_utility_zygote = CreateZygote(); |
245 } | 308 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 base::WeakPtr<UtilityProcessHostImpl> host, | 465 base::WeakPtr<UtilityProcessHostImpl> host, |
403 int error_code) { | 466 int error_code) { |
404 if (!host) | 467 if (!host) |
405 return; | 468 return; |
406 | 469 |
407 host->OnProcessLaunchFailed(error_code); | 470 host->OnProcessLaunchFailed(error_code); |
408 delete host.get(); | 471 delete host.get(); |
409 } | 472 } |
410 | 473 |
411 } // namespace content | 474 } // namespace content |
OLD | NEW |