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 <algorithm> | 5 #include <algorithm> |
6 #include <memory> | 6 #include <memory> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 service_manager_connection_closed_callback), | 33 service_manager_connection_closed_callback), |
34 destruct_callback_(destruct_callback) { | 34 destruct_callback_(destruct_callback) { |
35 bindings_.set_connection_error_handler(base::Bind(&PackagedApp::BindingLost, | 35 bindings_.set_connection_error_handler(base::Bind(&PackagedApp::BindingLost, |
36 base::Unretained(this))); | 36 base::Unretained(this))); |
37 } | 37 } |
38 | 38 |
39 ~PackagedApp() override {} | 39 ~PackagedApp() override {} |
40 | 40 |
41 private: | 41 private: |
42 // service_manager::Service: | 42 // service_manager::Service: |
43 void OnStart(service_manager::ServiceContext* context) override { | |
44 context_ = context; | |
45 } | |
46 | |
47 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 43 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
48 service_manager::InterfaceRegistry* registry) override { | 44 service_manager::InterfaceRegistry* registry) override { |
49 registry->AddInterface<service_manager::test::mojom::LifecycleControl>( | 45 registry->AddInterface<service_manager::test::mojom::LifecycleControl>( |
50 this); | 46 this); |
51 return true; | 47 return true; |
52 } | 48 } |
53 | 49 |
54 // service_manager::InterfaceFactory<LifecycleControl> | 50 // service_manager::InterfaceFactory<LifecycleControl> |
55 void Create( | 51 void Create( |
56 const service_manager::Identity& remote_identity, | 52 const service_manager::Identity& remote_identity, |
(...skipping 14 matching lines...) Expand all Loading... |
71 } | 67 } |
72 | 68 |
73 void Crash() override { | 69 void Crash() override { |
74 // When multiple instances are vended from the same package instance, this | 70 // When multiple instances are vended from the same package instance, this |
75 // will cause all instances to be quit. | 71 // will cause all instances to be quit. |
76 exit(1); | 72 exit(1); |
77 } | 73 } |
78 | 74 |
79 void CloseServiceManagerConnection() override { | 75 void CloseServiceManagerConnection() override { |
80 service_manager_connection_closed_callback_.Run(); | 76 service_manager_connection_closed_callback_.Run(); |
81 context_->QuitNow(); | 77 context()->QuitNow(); |
82 // This only closed our relationship with the service manager, existing | 78 // This only closed our relationship with the service manager, existing |
83 // |bindings_| | 79 // |bindings_| |
84 // remain active. | 80 // remain active. |
85 } | 81 } |
86 | 82 |
87 void BindingLost() { | 83 void BindingLost() { |
88 if (bindings_.empty()) { | 84 if (bindings_.empty()) { |
89 // Deletes |this|. | 85 // Deletes |this|. |
90 destruct_callback_.Run(); | 86 destruct_callback_.Run(); |
91 } | 87 } |
92 } | 88 } |
93 | 89 |
94 service_manager::ServiceContext* context_; | |
95 mojo::BindingSet<service_manager::test::mojom::LifecycleControl> bindings_; | 90 mojo::BindingSet<service_manager::test::mojom::LifecycleControl> bindings_; |
96 | 91 |
97 // Run when this object's connection to the service manager is closed. | 92 // Run when this object's connection to the service manager is closed. |
98 base::Closure service_manager_connection_closed_callback_; | 93 base::Closure service_manager_connection_closed_callback_; |
99 // Run when this object is destructed. | 94 // Run when this object is destructed. |
100 base::Closure destruct_callback_; | 95 base::Closure destruct_callback_; |
101 | 96 |
102 DISALLOW_COPY_AND_ASSIGN(PackagedApp); | 97 DISALLOW_COPY_AND_ASSIGN(PackagedApp); |
103 }; | 98 }; |
104 | 99 |
105 class Package : public service_manager::Service, | 100 class Package : public service_manager::Service, |
106 public service_manager::InterfaceFactory< | 101 public service_manager::InterfaceFactory< |
107 service_manager::mojom::ServiceFactory>, | 102 service_manager::mojom::ServiceFactory>, |
108 public service_manager::mojom::ServiceFactory { | 103 public service_manager::mojom::ServiceFactory { |
109 public: | 104 public: |
110 Package() {} | 105 Package() {} |
111 ~Package() override {} | 106 ~Package() override {} |
112 | 107 |
113 private: | 108 private: |
114 // service_manager::Service: | 109 // service_manager::Service: |
115 void OnStart(service_manager::ServiceContext* context) override { | 110 void OnStart() override { app_client_.OnStart(); } |
116 app_client_.OnStart(context); | |
117 } | |
118 | 111 |
119 bool OnConnect(const service_manager::ServiceInfo& remote_info, | 112 bool OnConnect(const service_manager::ServiceInfo& remote_info, |
120 service_manager::InterfaceRegistry* registry) override { | 113 service_manager::InterfaceRegistry* registry) override { |
121 registry->AddInterface<service_manager::mojom::ServiceFactory>(this); | 114 registry->AddInterface<service_manager::mojom::ServiceFactory>(this); |
122 return app_client_.OnConnect(remote_info, registry); | 115 return app_client_.OnConnect(remote_info, registry); |
123 } | 116 } |
124 | 117 |
125 // service_manager::InterfaceFactory<service_manager::mojom::ServiceFactory>: | 118 // service_manager::InterfaceFactory<service_manager::mojom::ServiceFactory>: |
126 void Create(const service_manager::Identity& remote_identity, | 119 void Create(const service_manager::Identity& remote_identity, |
127 service_manager::mojom::ServiceFactoryRequest request) override { | 120 service_manager::mojom::ServiceFactoryRequest request) override { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 170 |
178 DISALLOW_COPY_AND_ASSIGN(Package); | 171 DISALLOW_COPY_AND_ASSIGN(Package); |
179 }; | 172 }; |
180 | 173 |
181 } // namespace | 174 } // namespace |
182 | 175 |
183 MojoResult ServiceMain(MojoHandle service_request_handle) { | 176 MojoResult ServiceMain(MojoHandle service_request_handle) { |
184 service_manager::ServiceRunner runner(new Package); | 177 service_manager::ServiceRunner runner(new Package); |
185 return runner.Run(service_request_handle); | 178 return runner.Run(service_request_handle); |
186 } | 179 } |
OLD | NEW |