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/bind_source_info.h" |
17 #include "services/service_manager/public/cpp/binder_registry.h" | 18 #include "services/service_manager/public/cpp/binder_registry.h" |
18 #include "services/service_manager/public/cpp/service.h" | 19 #include "services/service_manager/public/cpp/service.h" |
19 #include "services/service_manager/public/cpp/service_context.h" | 20 #include "services/service_manager/public/cpp/service_context.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 |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
(...skipping 27 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 void OnBindInterface(const service_manager::ServiceInfo& source_info, | 68 void OnBindInterface(const service_manager::BindSourceInfo& source_info, |
69 const std::string& interface_name, | 69 const std::string& interface_name, |
70 mojo::ScopedMessagePipeHandle interface_pipe) override; | 70 mojo::ScopedMessagePipeHandle interface_pipe) override; |
71 | 71 |
72 private: | 72 private: |
73 IPC::mojom::ChannelBootstrapPtrInfo ipc_channel_bootstrap_; | 73 IPC::mojom::ChannelBootstrapPtrInfo ipc_channel_bootstrap_; |
74 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support_; | 74 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support_; |
75 bool connected_ = false; | 75 bool connected_ = false; |
76 service_manager::BinderRegistry registry_; | 76 service_manager::BinderRegistry registry_; |
77 }; | 77 }; |
78 | 78 |
79 NaClService::NaClService( | 79 NaClService::NaClService( |
80 IPC::mojom::ChannelBootstrapPtrInfo bootstrap, | 80 IPC::mojom::ChannelBootstrapPtrInfo bootstrap, |
81 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support) | 81 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support) |
82 : ipc_channel_bootstrap_(std::move(bootstrap)), | 82 : ipc_channel_bootstrap_(std::move(bootstrap)), |
83 ipc_support_(std::move(ipc_support)) { | 83 ipc_support_(std::move(ipc_support)) { |
84 registry_.AddInterface(base::Bind(&ConnectBootstrapChannel, | 84 registry_.AddInterface(base::Bind(&ConnectBootstrapChannel, |
85 base::Passed(&ipc_channel_bootstrap_))); | 85 base::Passed(&ipc_channel_bootstrap_))); |
86 } | 86 } |
87 | 87 |
88 NaClService::~NaClService() = default; | 88 NaClService::~NaClService() = default; |
89 | 89 |
90 void NaClService::OnBindInterface( | 90 void NaClService::OnBindInterface( |
91 const service_manager::ServiceInfo& source_info, | 91 const service_manager::BindSourceInfo& source_info, |
92 const std::string& interface_name, | 92 const std::string& interface_name, |
93 mojo::ScopedMessagePipeHandle interface_pipe) { | 93 mojo::ScopedMessagePipeHandle interface_pipe) { |
94 if (source_info.identity.name() == content::mojom::kBrowserServiceName && | 94 if (source_info.identity.name() == content::mojom::kBrowserServiceName && |
95 !connected_) { | 95 !connected_) { |
96 connected_ = true; | 96 connected_ = true; |
97 registry_.BindInterface(source_info.identity, interface_name, | 97 registry_.BindInterface(source_info.identity, interface_name, |
98 std::move(interface_pipe)); | 98 std::move(interface_pipe)); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 } // namespace | 102 } // namespace |
103 | 103 |
104 std::unique_ptr<service_manager::ServiceContext> CreateNaClServiceContext( | 104 std::unique_ptr<service_manager::ServiceContext> CreateNaClServiceContext( |
105 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 105 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
106 mojo::ScopedMessagePipeHandle* ipc_channel) { | 106 mojo::ScopedMessagePipeHandle* ipc_channel) { |
107 auto ipc_support = base::MakeUnique<mojo::edk::ScopedIPCSupport>( | 107 auto ipc_support = base::MakeUnique<mojo::edk::ScopedIPCSupport>( |
108 std::move(io_task_runner), | 108 std::move(io_task_runner), |
109 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); | 109 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST); |
110 EstablishMojoConnection(); | 110 EstablishMojoConnection(); |
111 | 111 |
112 IPC::mojom::ChannelBootstrapPtr bootstrap; | 112 IPC::mojom::ChannelBootstrapPtr bootstrap; |
113 *ipc_channel = mojo::MakeRequest(&bootstrap).PassMessagePipe(); | 113 *ipc_channel = mojo::MakeRequest(&bootstrap).PassMessagePipe(); |
114 return base::MakeUnique<service_manager::ServiceContext>( | 114 return base::MakeUnique<service_manager::ServiceContext>( |
115 base::MakeUnique<NaClService>(bootstrap.PassInterface(), | 115 base::MakeUnique<NaClService>(bootstrap.PassInterface(), |
116 std::move(ipc_support)), | 116 std::move(ipc_support)), |
117 ConnectToServiceManager()); | 117 ConnectToServiceManager()); |
118 } | 118 } |
OLD | NEW |