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 4cb3c3dc3281cfe58dc3cebd339dd5bd10043d59..3e705d8913b6edc14980928d44cb49e72c465980 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,7 @@ |
| #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/binder_registry.h" |
| #include "services/service_manager/public/cpp/interface_provider.h" |
| #include "ui/base/ui_base_switches.h" |
| @@ -134,6 +139,29 @@ class UtilitySandboxedProcessLauncherDelegate |
| UtilityMainThreadFactoryFunction g_utility_main_thread_factory = NULL; |
| +class UtilityProcessHost::ConnectionFilterImpl : public ConnectionFilter { |
| + public: |
| + ConnectionFilterImpl( |
| + std::unique_ptr<service_manager::BinderRegistry> registry) |
| + : registry_(std::move(registry)) {} |
| + |
| + private: |
| + // ConnectionFilter: |
| + void OnBindInterface(const service_manager::ServiceInfo& 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.identity, 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) { |
| @@ -233,6 +261,41 @@ void UtilityProcessHostImpl::BindInterface( |
| std::move(interface_pipe)); |
| } |
| +void UtilityProcessHostImpl::RegisterMojoServicesOnUIThread( |
| + service_manager::BinderRegistry* registry) { |
| + 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.
|
| + BrowserThread::GetTaskRunnerForThread(BrowserThread::UI) |
| + ->PostTask( |
| + FROM_HERE, |
| + base::Bind(&UtilityProcessHostImpl::RegisterMojoServicesOnUIThread, |
| + base::Unretained(this), registry)); |
| + } else { |
| + registry->AddInterface( |
| + base::Bind( |
| + &memory_instrumentation::CoordinatorImpl::BindCoordinatorRequest, |
| + base::Unretained( |
| + memory_instrumentation::CoordinatorImpl::GetInstance())), |
| + BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)); |
| + |
| + discardable_memory::DiscardableSharedMemoryManager* manager = |
| + BrowserMainLoop::GetInstance()->discardable_shared_memory_manager(); |
| + registry->AddInterface( |
| + base::Bind(&discardable_memory::DiscardableSharedMemoryManager::Bind, |
| + base::Unretained(manager)), |
| + BrowserThread::GetTaskRunnerForThread(BrowserThread::UI)); |
| + } |
| +} |
| + |
| +void UtilityProcessHostImpl::RegisterMojoServices() { |
| + auto registry = base::MakeUnique<service_manager::BinderRegistry>(); |
| + // May be null during test execution. |
| + if (ServiceManagerConnection::GetForProcess()) { |
| + RegisterMojoServicesOnUIThread(registry.get()); |
| + ServiceManagerConnection::GetForProcess()->AddConnectionFilter( |
| + base::MakeUnique<ConnectionFilterImpl>(std::move(registry))); |
| + } |
| +} |
| + |
| void UtilityProcessHostImpl::SetName(const base::string16& name) { |
| name_ = name; |
| } |