Chromium Code Reviews| Index: content/browser/utility_process_host_impl.cc |
| diff --git a/content/browser/utility_process_host_impl.cc b/content/browser/utility_process_host_impl.cc |
| index ca604b46f0445a946247cccde55798a26bc34d72..559761085f1171efead85a5138536c4312138248 100644 |
| --- a/content/browser/utility_process_host_impl.cc |
| +++ b/content/browser/utility_process_host_impl.cc |
| @@ -4,6 +4,7 @@ |
| #include "content/browser/utility_process_host_impl.h" |
| +#include <memory> |
| #include <utility> |
| #include "base/base_switches.h" |
| @@ -22,7 +23,9 @@ |
| #include "base/synchronization/lock.h" |
| #include "base/synchronization/waitable_event.h" |
| #include "build/build_config.h" |
| +#include "components/discardable_memory/service/discardable_shared_memory_manager.h" |
| #include "content/browser/browser_child_process_host_impl.h" |
| +#include "content/browser/browser_main_loop.h" |
| #include "content/browser/renderer_host/render_process_host_impl.h" |
| #include "content/browser/service_manager/service_manager_context.h" |
| #include "content/common/child_process_host_impl.h" |
| @@ -32,6 +35,7 @@ |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/content_browser_client.h" |
| #include "content/public/browser/utility_process_host_client.h" |
| +#include "content/public/common/connection_filter.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/public/common/mojo_channel_switches.h" |
| #include "content/public/common/process_type.h" |
| @@ -40,6 +44,8 @@ |
| #include "content/public/common/service_manager_connection.h" |
| #include "content/public/common/service_names.mojom.h" |
| #include "mojo/edk/embedder/embedder.h" |
| +#include "services/service_manager/public/cpp/bind_source_info.h" |
| +#include "services/service_manager/public/cpp/binder_registry.h" |
| #include "services/service_manager/public/cpp/interface_provider.h" |
| #include "ui/base/ui_base_switches.h" |
| @@ -128,6 +134,29 @@ class UtilitySandboxedProcessLauncherDelegate |
| UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; |
| +class UtilityProcessHostImpl::ConnectionFilterImpl : public ConnectionFilter { |
| + public: |
| + explicit ConnectionFilterImpl( |
| + std::unique_ptr<service_manager::BinderRegistry> registry) |
| + : registry_(std::move(registry)) {} |
| + |
| + private: |
| + // ConnectionFilter: |
| + void OnBindInterface(const service_manager::BindSourceInfo& source_info, |
| + const std::string& interface_name, |
| + mojo::ScopedMessagePipeHandle* interface_pipe, |
| + service_manager::Connector* connector) override { |
| + if (registry_->CanBindInterface(interface_name)) { |
| + registry_->BindInterface(source_info, interface_name, |
| + std::move(*interface_pipe)); |
| + } |
| + } |
| + |
| + std::unique_ptr<service_manager::BinderRegistry> registry_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ConnectionFilterImpl); |
| +}; |
| + |
| UtilityProcessHost* UtilityProcessHost::Create( |
| const scoped_refptr<UtilityProcessHostClient>& client, |
| const scoped_refptr<base::SequencedTaskRunner>& client_task_runner) { |
| @@ -227,6 +256,26 @@ void UtilityProcessHostImpl::BindInterface( |
| std::move(interface_pipe)); |
| } |
| +void UtilityProcessHostImpl::RegisterMojoServices() { |
| + auto registry = base::MakeUnique<service_manager::BinderRegistry>(); |
| + // May be null during test execution. |
| + if (ServiceManagerConnection::GetForProcess()) { |
| + registry->AddInterface(base::Bind( |
| + &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, |
| + base::Unretained( |
| + memory_instrumentation::CoordinatorImpl::GetInstance()))); |
|
dcheng
2017/05/10 07:36:48
Not entirely clear to me why memory_instrumentatio
Wei Li
2017/05/11 16:53:02
It is needed for some memory dump functions. Anywa
|
| + |
| + discardable_memory::DiscardableSharedMemoryManager* manager = |
| + BrowserMainLoop::GetInstance()->discardable_shared_memory_manager(); |
| + registry->AddInterface( |
| + base::Bind(&discardable_memory::DiscardableSharedMemoryManager::Bind, |
| + base::Unretained(manager))); |
| + |
| + ServiceManagerConnection::GetForProcess()->AddConnectionFilter( |
| + base::MakeUnique<ConnectionFilterImpl>(std::move(registry))); |
| + } |
| +} |
| + |
| void UtilityProcessHostImpl::SetName(const base::string16& name) { |
| name_ = name; |
| } |