| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "mojo/public/cpp/bindings/binding_set.h" | 10 #include "mojo/public/cpp/bindings/binding_set.h" |
| 11 #include "services/service_manager/public/c/main.h" | 11 #include "services/service_manager/public/c/main.h" |
| 12 #include "services/service_manager/public/cpp/connector.h" | 12 #include "services/service_manager/public/cpp/connector.h" |
| 13 #include "services/service_manager/public/cpp/interface_factory.h" | 13 #include "services/service_manager/public/cpp/interface_factory.h" |
| 14 #include "services/service_manager/public/cpp/interface_registry.h" | 14 #include "services/service_manager/public/cpp/interface_registry.h" |
| 15 #include "services/service_manager/public/cpp/service.h" | 15 #include "services/service_manager/public/cpp/service.h" |
| 16 #include "services/service_manager/public/cpp/service_runner.h" | 16 #include "services/service_manager/public/cpp/service_runner.h" |
| 17 #include "services/service_manager/tests/lifecycle/lifecycle_unittest.mojom.h" | 17 #include "services/service_manager/tests/lifecycle/lifecycle_unittest.mojom.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 void QuitLoop(base::RunLoop* loop) { | 21 void QuitLoop(base::RunLoop* loop) { |
| 22 loop->Quit(); | 22 loop->Quit(); |
| 23 } | 23 } |
| 24 | 24 |
| 25 class Parent : public shell::Service, | 25 class Parent : public service_manager::Service, |
| 26 public shell::InterfaceFactory<shell::test::mojom::Parent>, | 26 public service_manager::InterfaceFactory< |
| 27 public shell::test::mojom::Parent { | 27 service_manager::test::mojom::Parent>, |
| 28 public service_manager::test::mojom::Parent { |
| 28 public: | 29 public: |
| 29 Parent() {} | 30 Parent() {} |
| 30 ~Parent() override { | 31 ~Parent() override { |
| 31 child_connection_.reset(); | 32 child_connection_.reset(); |
| 32 parent_bindings_.CloseAllBindings(); | 33 parent_bindings_.CloseAllBindings(); |
| 33 } | 34 } |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 // Service: | 37 // Service: |
| 37 bool OnConnect(const shell::Identity& remote_identity, | 38 bool OnConnect(const service_manager::Identity& remote_identity, |
| 38 shell::InterfaceRegistry* registry) override { | 39 service_manager::InterfaceRegistry* registry) override { |
| 39 registry->AddInterface<shell::test::mojom::Parent>(this); | 40 registry->AddInterface<service_manager::test::mojom::Parent>(this); |
| 40 return true; | 41 return true; |
| 41 } | 42 } |
| 42 | 43 |
| 43 // InterfaceFactory<shell::test::mojom::Parent>: | 44 // InterfaceFactory<service_manager::test::mojom::Parent>: |
| 44 void Create(const shell::Identity& remote_identity, | 45 void Create(const service_manager::Identity& remote_identity, |
| 45 shell::test::mojom::ParentRequest request) override { | 46 service_manager::test::mojom::ParentRequest request) override { |
| 46 parent_bindings_.AddBinding(this, std::move(request)); | 47 parent_bindings_.AddBinding(this, std::move(request)); |
| 47 } | 48 } |
| 48 | 49 |
| 49 // Parent: | 50 // Parent: |
| 50 void ConnectToChild(const ConnectToChildCallback& callback) override { | 51 void ConnectToChild(const ConnectToChildCallback& callback) override { |
| 51 child_connection_ = connector()->Connect("service:lifecycle_unittest_app"); | 52 child_connection_ = connector()->Connect("service:lifecycle_unittest_app"); |
| 52 shell::test::mojom::LifecycleControlPtr lifecycle; | 53 service_manager::test::mojom::LifecycleControlPtr lifecycle; |
| 53 child_connection_->GetInterface(&lifecycle); | 54 child_connection_->GetInterface(&lifecycle); |
| 54 { | 55 { |
| 55 base::RunLoop loop; | 56 base::RunLoop loop; |
| 56 lifecycle->Ping(base::Bind(&QuitLoop, &loop)); | 57 lifecycle->Ping(base::Bind(&QuitLoop, &loop)); |
| 57 base::MessageLoop::ScopedNestableTaskAllower allow( | 58 base::MessageLoop::ScopedNestableTaskAllower allow( |
| 58 base::MessageLoop::current()); | 59 base::MessageLoop::current()); |
| 59 loop.Run(); | 60 loop.Run(); |
| 60 } | 61 } |
| 61 callback.Run(); | 62 callback.Run(); |
| 62 } | 63 } |
| 63 void Quit() override { | 64 void Quit() override { |
| 64 base::MessageLoop::current()->QuitWhenIdle(); | 65 base::MessageLoop::current()->QuitWhenIdle(); |
| 65 } | 66 } |
| 66 | 67 |
| 67 std::unique_ptr<shell::Connection> child_connection_; | 68 std::unique_ptr<service_manager::Connection> child_connection_; |
| 68 mojo::BindingSet<shell::test::mojom::Parent> parent_bindings_; | 69 mojo::BindingSet<service_manager::test::mojom::Parent> parent_bindings_; |
| 69 | 70 |
| 70 DISALLOW_COPY_AND_ASSIGN(Parent); | 71 DISALLOW_COPY_AND_ASSIGN(Parent); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 } // namespace | 74 } // namespace |
| 74 | 75 |
| 75 MojoResult ServiceMain(MojoHandle service_request_handle) { | 76 MojoResult ServiceMain(MojoHandle service_request_handle) { |
| 76 Parent* parent = new Parent; | 77 Parent* parent = new Parent; |
| 77 return shell::ServiceRunner(parent).Run(service_request_handle); | 78 return service_manager::ServiceRunner(parent).Run(service_request_handle); |
| 78 } | 79 } |
| OLD | NEW |