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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 public service_manager::test::mojom::Parent { | 29 public service_manager::test::mojom::Parent { |
30 public: | 30 public: |
31 Parent() {} | 31 Parent() {} |
32 ~Parent() override { | 32 ~Parent() override { |
33 child_connection_.reset(); | 33 child_connection_.reset(); |
34 parent_bindings_.CloseAllBindings(); | 34 parent_bindings_.CloseAllBindings(); |
35 } | 35 } |
36 | 36 |
37 private: | 37 private: |
38 // Service: | 38 // Service: |
| 39 void OnStart(service_manager::ServiceContext* context) override { |
| 40 context_ = context; |
| 41 } |
| 42 |
39 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 43 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
40 service_manager::InterfaceRegistry* registry) override { | 44 service_manager::InterfaceRegistry* registry) override { |
41 registry->AddInterface<service_manager::test::mojom::Parent>(this); | 45 registry->AddInterface<service_manager::test::mojom::Parent>(this); |
42 return true; | 46 return true; |
43 } | 47 } |
44 | 48 |
45 // InterfaceFactory<service_manager::test::mojom::Parent>: | 49 // InterfaceFactory<service_manager::test::mojom::Parent>: |
46 void Create(const service_manager::Identity& remote_identity, | 50 void Create(const service_manager::Identity& remote_identity, |
47 service_manager::test::mojom::ParentRequest request) override { | 51 service_manager::test::mojom::ParentRequest request) override { |
48 parent_bindings_.AddBinding(this, std::move(request)); | 52 parent_bindings_.AddBinding(this, std::move(request)); |
49 } | 53 } |
50 | 54 |
51 // service_manager::test::mojom::Parent: | 55 // service_manager::test::mojom::Parent: |
52 void ConnectToChild(const ConnectToChildCallback& callback) override { | 56 void ConnectToChild(const ConnectToChildCallback& callback) override { |
53 child_connection_ = | 57 child_connection_ = |
54 context()->connector()->Connect("service:lifecycle_unittest_app"); | 58 context_->connector()->Connect("service:lifecycle_unittest_app"); |
55 service_manager::test::mojom::LifecycleControlPtr lifecycle; | 59 service_manager::test::mojom::LifecycleControlPtr lifecycle; |
56 child_connection_->GetInterface(&lifecycle); | 60 child_connection_->GetInterface(&lifecycle); |
57 { | 61 { |
58 base::RunLoop loop; | 62 base::RunLoop loop; |
59 lifecycle->Ping(base::Bind(&QuitLoop, &loop)); | 63 lifecycle->Ping(base::Bind(&QuitLoop, &loop)); |
60 base::MessageLoop::ScopedNestableTaskAllower allow( | 64 base::MessageLoop::ScopedNestableTaskAllower allow( |
61 base::MessageLoop::current()); | 65 base::MessageLoop::current()); |
62 loop.Run(); | 66 loop.Run(); |
63 } | 67 } |
64 callback.Run(); | 68 callback.Run(); |
65 } | 69 } |
66 void Quit() override { | 70 void Quit() override { |
67 base::MessageLoop::current()->QuitWhenIdle(); | 71 base::MessageLoop::current()->QuitWhenIdle(); |
68 } | 72 } |
69 | 73 |
| 74 service_manager::ServiceContext* context_ = nullptr; |
70 std::unique_ptr<service_manager::Connection> child_connection_; | 75 std::unique_ptr<service_manager::Connection> child_connection_; |
71 mojo::BindingSet<service_manager::test::mojom::Parent> parent_bindings_; | 76 mojo::BindingSet<service_manager::test::mojom::Parent> parent_bindings_; |
72 | 77 |
73 DISALLOW_COPY_AND_ASSIGN(Parent); | 78 DISALLOW_COPY_AND_ASSIGN(Parent); |
74 }; | 79 }; |
75 | 80 |
76 } // namespace | 81 } // namespace |
77 | 82 |
78 MojoResult ServiceMain(MojoHandle service_request_handle) { | 83 MojoResult ServiceMain(MojoHandle service_request_handle) { |
79 Parent* parent = new Parent; | 84 Parent* parent = new Parent; |
80 return service_manager::ServiceRunner(parent).Run(service_request_handle); | 85 return service_manager::ServiceRunner(parent).Run(service_request_handle); |
81 } | 86 } |
OLD | NEW |