OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "mojo/public/cpp/bindings/binding_set.h" | 9 #include "mojo/public/cpp/bindings/binding_set.h" |
10 #include "services/service_manager/public/c/main.h" | 10 #include "services/service_manager/public/c/main.h" |
| 11 #include "services/service_manager/public/cpp/binder_registry.h" |
11 #include "services/service_manager/public/cpp/interface_factory.h" | 12 #include "services/service_manager/public/cpp/interface_factory.h" |
12 #include "services/service_manager/public/cpp/interface_registry.h" | |
13 #include "services/service_manager/public/cpp/service.h" | 13 #include "services/service_manager/public/cpp/service.h" |
14 #include "services/service_manager/public/cpp/service_context.h" | 14 #include "services/service_manager/public/cpp/service_context.h" |
15 #include "services/service_manager/public/cpp/service_runner.h" | 15 #include "services/service_manager/public/cpp/service_runner.h" |
16 #include "services/service_manager/tests/connect/connect_test.mojom.h" | 16 #include "services/service_manager/tests/connect/connect_test.mojom.h" |
17 | 17 |
18 using service_manager::test::mojom::ConnectTestService; | 18 using service_manager::test::mojom::ConnectTestService; |
19 using service_manager::test::mojom::ConnectTestServiceRequest; | 19 using service_manager::test::mojom::ConnectTestServiceRequest; |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 class Target : public service_manager::Service, | 23 class Target : public service_manager::Service, |
24 public service_manager::InterfaceFactory<ConnectTestService>, | 24 public service_manager::InterfaceFactory<ConnectTestService>, |
25 public ConnectTestService { | 25 public ConnectTestService { |
26 public: | 26 public: |
27 Target() {} | 27 Target() { registry_.AddInterface<ConnectTestService>(this); } |
28 ~Target() override {} | 28 ~Target() override {} |
29 | 29 |
30 private: | 30 private: |
31 // service_manager::Service: | 31 // service_manager::Service: |
32 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 32 void OnBindInterface(const service_manager::ServiceInfo& source_info, |
33 service_manager::InterfaceRegistry* registry) override { | 33 const std::string& interface_name, |
34 registry->AddInterface<ConnectTestService>(this); | 34 mojo::ScopedMessagePipeHandle interface_pipe) override { |
35 return true; | 35 registry_.BindInterface(source_info.identity, interface_name, |
| 36 std::move(interface_pipe)); |
36 } | 37 } |
37 | 38 |
38 // service_manager::InterfaceFactory<ConnectTestService>: | 39 // service_manager::InterfaceFactory<ConnectTestService>: |
39 void Create(const service_manager::Identity& remote_identity, | 40 void Create(const service_manager::Identity& remote_identity, |
40 ConnectTestServiceRequest request) override { | 41 ConnectTestServiceRequest request) override { |
41 bindings_.AddBinding(this, std::move(request)); | 42 bindings_.AddBinding(this, std::move(request)); |
42 } | 43 } |
43 | 44 |
44 // ConnectTestService: | 45 // ConnectTestService: |
45 void GetTitle(const GetTitleCallback& callback) override { | 46 void GetTitle(const GetTitleCallback& callback) override { |
46 callback.Run("connect_test_exe"); | 47 callback.Run("connect_test_exe"); |
47 } | 48 } |
48 | 49 |
49 void GetInstance(const GetInstanceCallback& callback) override { | 50 void GetInstance(const GetInstanceCallback& callback) override { |
50 callback.Run(context()->identity().instance()); | 51 callback.Run(context()->identity().instance()); |
51 } | 52 } |
52 | 53 |
| 54 service_manager::BinderRegistry registry_; |
53 mojo::BindingSet<ConnectTestService> bindings_; | 55 mojo::BindingSet<ConnectTestService> bindings_; |
54 | 56 |
55 DISALLOW_COPY_AND_ASSIGN(Target); | 57 DISALLOW_COPY_AND_ASSIGN(Target); |
56 }; | 58 }; |
57 | 59 |
58 } // namespac | 60 } // namespac |
59 | 61 |
60 MojoResult ServiceMain(MojoHandle service_request_handle) { | 62 MojoResult ServiceMain(MojoHandle service_request_handle) { |
61 service_manager::ServiceRunner runner(new Target); | 63 service_manager::ServiceRunner runner(new Target); |
62 return runner.Run(service_request_handle); | 64 return runner.Run(service_request_handle); |
63 } | 65 } |
OLD | NEW |