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