| 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 "base/macros.h" | 5 #include "base/macros.h" |
| 6 #include "mojo/public/cpp/bindings/binding_set.h" | 6 #include "mojo/public/cpp/bindings/binding_set.h" |
| 7 #include "services/service_manager/public/c/main.h" | 7 #include "services/service_manager/public/c/main.h" |
| 8 #include "services/service_manager/public/cpp/binder_registry.h" |
| 8 #include "services/service_manager/public/cpp/interface_factory.h" | 9 #include "services/service_manager/public/cpp/interface_factory.h" |
| 9 #include "services/service_manager/public/cpp/interface_registry.h" | |
| 10 #include "services/service_manager/public/cpp/service.h" | 10 #include "services/service_manager/public/cpp/service.h" |
| 11 #include "services/service_manager/public/cpp/service_info.h" |
| 11 #include "services/service_manager/public/cpp/service_runner.h" | 12 #include "services/service_manager/public/cpp/service_runner.h" |
| 12 #include "services/service_manager/tests/shutdown/shutdown_unittest.mojom.h" | 13 #include "services/service_manager/tests/shutdown/shutdown_unittest.mojom.h" |
| 13 | 14 |
| 14 namespace service_manager { | 15 namespace service_manager { |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 service_manager::ServiceRunner* g_app = nullptr; | 18 service_manager::ServiceRunner* g_app = nullptr; |
| 18 | 19 |
| 19 class ShutdownServiceApp | 20 class ShutdownServiceApp |
| 20 : public Service, | 21 : public Service, |
| 21 public InterfaceFactory<mojom::ShutdownTestService>, | 22 public InterfaceFactory<mojom::ShutdownTestService>, |
| 22 public mojom::ShutdownTestService { | 23 public mojom::ShutdownTestService { |
| 23 public: | 24 public: |
| 24 ShutdownServiceApp() {} | 25 ShutdownServiceApp() { |
| 26 registry_.AddInterface<mojom::ShutdownTestService>(this); |
| 27 } |
| 25 ~ShutdownServiceApp() override {} | 28 ~ShutdownServiceApp() override {} |
| 26 | 29 |
| 27 private: | 30 private: |
| 28 // service_manager::Service: | 31 // service_manager::Service: |
| 29 bool OnConnect(const ServiceInfo& remote_info, | 32 void OnBindInterface(const ServiceInfo& source_info, |
| 30 InterfaceRegistry* registry) override { | 33 const std::string& interface_name, |
| 31 registry->AddInterface<mojom::ShutdownTestService>(this); | 34 mojo::ScopedMessagePipeHandle interface_pipe) override { |
| 32 return true; | 35 registry_.BindInterface(source_info.identity, interface_name, |
| 36 std::move(interface_pipe)); |
| 33 } | 37 } |
| 34 | 38 |
| 35 // InterfaceFactory<mojom::ShutdownTestService>: | 39 // InterfaceFactory<mojom::ShutdownTestService>: |
| 36 void Create(const Identity& remote_identity, | 40 void Create(const Identity& remote_identity, |
| 37 mojom::ShutdownTestServiceRequest request) override { | 41 mojom::ShutdownTestServiceRequest request) override { |
| 38 bindings_.AddBinding(this, std::move(request)); | 42 bindings_.AddBinding(this, std::move(request)); |
| 39 } | 43 } |
| 40 | 44 |
| 41 // mojom::ShutdownTestService: | 45 // mojom::ShutdownTestService: |
| 42 void SetClient(mojom::ShutdownTestClientPtr client) override {} | 46 void SetClient(mojom::ShutdownTestClientPtr client) override {} |
| 43 void ShutDown() override { g_app->Quit(); } | 47 void ShutDown() override { g_app->Quit(); } |
| 44 | 48 |
| 49 BinderRegistry registry_; |
| 45 mojo::BindingSet<mojom::ShutdownTestService> bindings_; | 50 mojo::BindingSet<mojom::ShutdownTestService> bindings_; |
| 46 | 51 |
| 47 DISALLOW_COPY_AND_ASSIGN(ShutdownServiceApp); | 52 DISALLOW_COPY_AND_ASSIGN(ShutdownServiceApp); |
| 48 }; | 53 }; |
| 49 | 54 |
| 50 } // namespace | 55 } // namespace |
| 51 } // namespace service_manager | 56 } // namespace service_manager |
| 52 | 57 |
| 53 MojoResult ServiceMain(MojoHandle service_request_handle) { | 58 MojoResult ServiceMain(MojoHandle service_request_handle) { |
| 54 service_manager::ServiceRunner runner( | 59 service_manager::ServiceRunner runner( |
| 55 new service_manager::ShutdownServiceApp); | 60 new service_manager::ShutdownServiceApp); |
| 56 service_manager::g_app = &runner; | 61 service_manager::g_app = &runner; |
| 57 return runner.Run(service_request_handle); | 62 return runner.Run(service_request_handle); |
| 58 } | 63 } |
| OLD | NEW |