| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/nacl/common/nacl_service.h" | 5 #include "components/nacl/common/nacl_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "content/public/common/mojo_channel_switches.h" | 11 #include "content/public/common/mojo_channel_switches.h" |
| 12 #include "content/public/common/service_names.mojom.h" | 12 #include "content/public/common/service_names.mojom.h" |
| 13 #include "ipc/ipc.mojom.h" | 13 #include "ipc/ipc.mojom.h" |
| 14 #include "mojo/edk/embedder/embedder.h" | 14 #include "mojo/edk/embedder/embedder.h" |
| 15 #include "mojo/edk/embedder/scoped_ipc_support.h" | 15 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 16 #include "mojo/edk/embedder/scoped_platform_handle.h" | 16 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 17 #include "services/service_manager/public/cpp/interface_registry.h" | 17 #include "services/service_manager/public/cpp/binder_registry.h" |
| 18 #include "services/service_manager/public/cpp/service.h" | 18 #include "services/service_manager/public/cpp/service.h" |
| 19 #include "services/service_manager/public/cpp/service_context.h" | 19 #include "services/service_manager/public/cpp/service_context.h" |
| 20 #include "services/service_manager/public/cpp/service_info.h" | 20 #include "services/service_manager/public/cpp/service_info.h" |
| 21 | 21 |
| 22 #if defined(OS_POSIX) | 22 #if defined(OS_POSIX) |
| 23 #include "base/posix/global_descriptors.h" | 23 #include "base/posix/global_descriptors.h" |
| 24 #include "content/public/common/content_descriptors.h" | 24 #include "content/public/common/content_descriptors.h" |
| 25 #elif defined(OS_WIN) | 25 #elif defined(OS_WIN) |
| 26 #include "mojo/edk/embedder/platform_channel_pair.h" | 26 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 27 #endif | 27 #endif |
| (...skipping 30 matching lines...) Expand all Loading... |
| 58 mojo::FuseInterface(std::move(request), std::move(ptr)); | 58 mojo::FuseInterface(std::move(request), std::move(ptr)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 class NaClService : public service_manager::Service { | 61 class NaClService : public service_manager::Service { |
| 62 public: | 62 public: |
| 63 NaClService(IPC::mojom::ChannelBootstrapPtrInfo bootstrap, | 63 NaClService(IPC::mojom::ChannelBootstrapPtrInfo bootstrap, |
| 64 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support); | 64 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support); |
| 65 ~NaClService() override; | 65 ~NaClService() override; |
| 66 | 66 |
| 67 // Service overrides. | 67 // Service overrides. |
| 68 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 68 void OnBindInterface(const service_manager::ServiceInfo& source_info, |
| 69 service_manager::InterfaceRegistry* registry) override; | 69 const std::string& interface_name, |
| 70 mojo::ScopedMessagePipeHandle interface_pipe) override; |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 IPC::mojom::ChannelBootstrapPtrInfo ipc_channel_bootstrap_; | 73 IPC::mojom::ChannelBootstrapPtrInfo ipc_channel_bootstrap_; |
| 73 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support_; | 74 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support_; |
| 74 bool connected_ = false; | 75 bool connected_ = false; |
| 76 service_manager::BinderRegistry registry_; |
| 75 }; | 77 }; |
| 76 | 78 |
| 77 NaClService::NaClService( | 79 NaClService::NaClService( |
| 78 IPC::mojom::ChannelBootstrapPtrInfo bootstrap, | 80 IPC::mojom::ChannelBootstrapPtrInfo bootstrap, |
| 79 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support) | 81 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support) |
| 80 : ipc_channel_bootstrap_(std::move(bootstrap)), | 82 : ipc_channel_bootstrap_(std::move(bootstrap)), |
| 81 ipc_support_(std::move(ipc_support)) {} | 83 ipc_support_(std::move(ipc_support)) { |
| 84 registry_.AddInterface(base::Bind(&ConnectBootstrapChannel, |
| 85 base::Passed(&ipc_channel_bootstrap_))); |
| 86 } |
| 82 | 87 |
| 83 NaClService::~NaClService() = default; | 88 NaClService::~NaClService() = default; |
| 84 | 89 |
| 85 bool NaClService::OnConnect(const service_manager::ServiceInfo& remote_info, | 90 void NaClService::OnBindInterface( |
| 86 service_manager::InterfaceRegistry* registry) { | 91 const service_manager::ServiceInfo& source_info, |
| 87 if (remote_info.identity.name() != content::mojom::kBrowserServiceName) | 92 const std::string& interface_name, |
| 88 return false; | 93 mojo::ScopedMessagePipeHandle interface_pipe) { |
| 89 | 94 if (source_info.identity.name() == content::mojom::kBrowserServiceName && |
| 90 if (connected_) | 95 !connected_) { |
| 91 return false; | 96 connected_ = true; |
| 92 | 97 registry_.BindInterface(source_info.identity, interface_name, |
| 93 connected_ = true; | 98 std::move(interface_pipe)); |
| 94 registry->AddInterface(base::Bind(&ConnectBootstrapChannel, | 99 } |
| 95 base::Passed(&ipc_channel_bootstrap_))); | |
| 96 return true; | |
| 97 } | 100 } |
| 98 | 101 |
| 99 } // namespace | 102 } // namespace |
| 100 | 103 |
| 101 std::unique_ptr<service_manager::ServiceContext> CreateNaClServiceContext( | 104 std::unique_ptr<service_manager::ServiceContext> CreateNaClServiceContext( |
| 102 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 105 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 103 mojo::ScopedMessagePipeHandle* ipc_channel) { | 106 mojo::ScopedMessagePipeHandle* ipc_channel) { |
| 104 auto ipc_support = base::MakeUnique<mojo::edk::ScopedIPCSupport>( | 107 auto ipc_support = base::MakeUnique<mojo::edk::ScopedIPCSupport>( |
| 105 std::move(io_task_runner), | 108 std::move(io_task_runner), |
| 106 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); | 109 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); |
| 107 EstablishMojoConnection(); | 110 EstablishMojoConnection(); |
| 108 | 111 |
| 109 IPC::mojom::ChannelBootstrapPtr bootstrap; | 112 IPC::mojom::ChannelBootstrapPtr bootstrap; |
| 110 *ipc_channel = mojo::MakeRequest(&bootstrap).PassMessagePipe(); | 113 *ipc_channel = mojo::MakeRequest(&bootstrap).PassMessagePipe(); |
| 111 return base::MakeUnique<service_manager::ServiceContext>( | 114 return base::MakeUnique<service_manager::ServiceContext>( |
| 112 base::MakeUnique<NaClService>(bootstrap.PassInterface(), | 115 base::MakeUnique<NaClService>(bootstrap.PassInterface(), |
| 113 std::move(ipc_support)), | 116 std::move(ipc_support)), |
| 114 ConnectToServiceManager()); | 117 ConnectToServiceManager()); |
| 115 } | 118 } |
| OLD | NEW |