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::RegisterMojoServices() { |
| 265 auto registry = base::MakeUnique<service_manager::BinderRegistry>(); |
| 266 // May be null during test execution. |
| 267 if (ServiceManagerConnection::GetForProcess()) { |
| 268 registry->AddInterface( |
| 269 base::Bind( |
| 270 &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, |
| 271 base::Unretained( |
| 272 memory_instrumentation::CoordinatorImpl::GetInstance())), |
| 273 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)); |
| 274 |
| 275 discardable_memory::DiscardableSharedMemoryManager* manager = |
| 276 BrowserMainLoop::GetInstance()->discardable_shared_memory_manager(); |
| 277 registry->AddInterface( |
| 278 base::Bind(&discardable_memory::DiscardableSharedMemoryManager::Bind, |
| 279 base::Unretained(manager)), |
| 280 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)); |
| 281 |
| 282 ServiceManagerConnection::GetForProcess()->AddConnectionFilter( |
| 283 base::MakeUnique<ConnectionFilterImpl>(std::move(registry))); |
| 284 } |
| 285 } |
| 286 |
236 void UtilityProcessHostImpl::SetName(const base::string16& name) { | 287 void UtilityProcessHostImpl::SetName(const base::string16& name) { |
237 name_ = name; | 288 name_ = name; |
238 } | 289 } |
239 | 290 |
240 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) | 291 #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MACOSX) |
241 // static | 292 // static |
242 void UtilityProcessHostImpl::EarlyZygoteLaunch() { | 293 void UtilityProcessHostImpl::EarlyZygoteLaunch() { |
243 DCHECK(!g_utility_zygote); | 294 DCHECK(!g_utility_zygote); |
244 g_utility_zygote = CreateZygote(); | 295 g_utility_zygote = CreateZygote(); |
245 } | 296 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 base::WeakPtr<UtilityProcessHostImpl> host, | 454 base::WeakPtr<UtilityProcessHostImpl> host, |
404 int error_code) { | 455 int error_code) { |
405 if (!host) | 456 if (!host) |
406 return; | 457 return; |
407 | 458 |
408 host->OnProcessLaunchFailed(error_code); | 459 host->OnProcessLaunchFailed(error_code); |
409 delete host.get(); | 460 delete host.get(); |
410 } | 461 } |
411 | 462 |
412 } // namespace content | 463 } // namespace content |
OLD | NEW |