| 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 "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "mojo/public/cpp/bindings/binding_set.h" | 7 #include "mojo/public/cpp/bindings/binding_set.h" |
| 8 #include "services/service_manager/public/c/main.h" | 8 #include "services/service_manager/public/c/main.h" |
| 9 #include "services/service_manager/public/cpp/connector.h" | 9 #include "services/service_manager/public/cpp/connector.h" |
| 10 #include "services/service_manager/public/cpp/interface_factory.h" | 10 #include "services/service_manager/public/cpp/interface_factory.h" |
| 11 #include "services/service_manager/public/cpp/interface_registry.h" | 11 #include "services/service_manager/public/cpp/interface_registry.h" |
| 12 #include "services/service_manager/public/cpp/service.h" | 12 #include "services/service_manager/public/cpp/service.h" |
| 13 #include "services/service_manager/public/cpp/service_context.h" | 13 #include "services/service_manager/public/cpp/service_context.h" |
| 14 #include "services/service_manager/public/cpp/service_runner.h" | 14 #include "services/service_manager/public/cpp/service_runner.h" |
| 15 #include "services/service_manager/tests/shutdown/shutdown_unittest.mojom.h" | 15 #include "services/service_manager/tests/shutdown/shutdown_unittest.mojom.h" |
| 16 | 16 |
| 17 namespace service_manager { | 17 namespace service_manager { |
| 18 | 18 |
| 19 class ShutdownClientApp | 19 class ShutdownClientApp |
| 20 : public Service, | 20 : public Service, |
| 21 public InterfaceFactory<mojom::ShutdownTestClientController>, | 21 public InterfaceFactory<mojom::ShutdownTestClientController>, |
| 22 public mojom::ShutdownTestClientController, | 22 public mojom::ShutdownTestClientController, |
| 23 public mojom::ShutdownTestClient { | 23 public mojom::ShutdownTestClient { |
| 24 public: | 24 public: |
| 25 ShutdownClientApp() {} | 25 ShutdownClientApp() {} |
| 26 ~ShutdownClientApp() override {} | 26 ~ShutdownClientApp() override {} |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 // service_manager::Service: | 29 // service_manager::Service: |
| 30 void OnStart(ServiceContext* context) override { | |
| 31 context_ = context; | |
| 32 } | |
| 33 | |
| 34 bool OnConnect(const ServiceInfo& remote_info, | 30 bool OnConnect(const ServiceInfo& remote_info, |
| 35 InterfaceRegistry* registry) override { | 31 InterfaceRegistry* registry) override { |
| 36 registry->AddInterface<mojom::ShutdownTestClientController>(this); | 32 registry->AddInterface<mojom::ShutdownTestClientController>(this); |
| 37 return true; | 33 return true; |
| 38 } | 34 } |
| 39 | 35 |
| 40 // InterfaceFactory<mojom::ShutdownTestClientController>: | 36 // InterfaceFactory<mojom::ShutdownTestClientController>: |
| 41 void Create(const Identity& remote_identity, | 37 void Create(const Identity& remote_identity, |
| 42 mojom::ShutdownTestClientControllerRequest request) override { | 38 mojom::ShutdownTestClientControllerRequest request) override { |
| 43 bindings_.AddBinding(this, std::move(request)); | 39 bindings_.AddBinding(this, std::move(request)); |
| 44 } | 40 } |
| 45 | 41 |
| 46 // mojom::ShutdownTestClientController: | 42 // mojom::ShutdownTestClientController: |
| 47 void ConnectAndWait(const ConnectAndWaitCallback& callback) override { | 43 void ConnectAndWait(const ConnectAndWaitCallback& callback) override { |
| 48 mojom::ShutdownTestServicePtr service; | 44 mojom::ShutdownTestServicePtr service; |
| 49 context_->connector()->ConnectToInterface( | 45 context()->connector()->ConnectToInterface( |
| 50 "service:shutdown_service", &service); | 46 "service:shutdown_service", &service); |
| 51 | 47 |
| 52 mojo::Binding<mojom::ShutdownTestClient> client_binding(this); | 48 mojo::Binding<mojom::ShutdownTestClient> client_binding(this); |
| 53 | 49 |
| 54 mojom::ShutdownTestClientPtr client_ptr = | 50 mojom::ShutdownTestClientPtr client_ptr = |
| 55 client_binding.CreateInterfacePtrAndBind(); | 51 client_binding.CreateInterfacePtrAndBind(); |
| 56 | 52 |
| 57 service->SetClient(std::move(client_ptr)); | 53 service->SetClient(std::move(client_ptr)); |
| 58 | 54 |
| 59 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( | 55 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( |
| 60 base::MessageLoop::current()); | 56 base::MessageLoop::current()); |
| 61 base::RunLoop run_loop; | 57 base::RunLoop run_loop; |
| 62 client_binding.set_connection_error_handler(run_loop.QuitClosure()); | 58 client_binding.set_connection_error_handler(run_loop.QuitClosure()); |
| 63 run_loop.Run(); | 59 run_loop.Run(); |
| 64 | 60 |
| 65 callback.Run(); | 61 callback.Run(); |
| 66 } | 62 } |
| 67 | 63 |
| 68 ServiceContext* context_ = nullptr; | |
| 69 mojo::BindingSet<mojom::ShutdownTestClientController> bindings_; | 64 mojo::BindingSet<mojom::ShutdownTestClientController> bindings_; |
| 70 | 65 |
| 71 DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp); | 66 DISALLOW_COPY_AND_ASSIGN(ShutdownClientApp); |
| 72 }; | 67 }; |
| 73 | 68 |
| 74 } // namespace service_manager | 69 } // namespace service_manager |
| 75 | 70 |
| 76 MojoResult ServiceMain(MojoHandle service_request_handle) { | 71 MojoResult ServiceMain(MojoHandle service_request_handle) { |
| 77 service_manager::ServiceRunner runner(new service_manager::ShutdownClientApp); | 72 service_manager::ServiceRunner runner(new service_manager::ShutdownClientApp); |
| 78 return runner.Run(service_request_handle); | 73 return runner.Run(service_request_handle); |
| 79 } | 74 } |
| OLD | NEW |