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" |
| 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" |
11 #include "mojo/public/cpp/bindings/binding_set.h" | 13 #include "mojo/public/cpp/bindings/binding_set.h" |
12 #include "services/service_manager/public/c/main.h" | 14 #include "services/service_manager/public/c/main.h" |
13 #include "services/service_manager/public/cpp/binder_registry.h" | 15 #include "services/service_manager/public/cpp/binder_registry.h" |
14 #include "services/service_manager/public/cpp/interface_factory.h" | 16 #include "services/service_manager/public/cpp/interface_factory.h" |
15 #include "services/service_manager/public/cpp/service_context.h" | 17 #include "services/service_manager/public/cpp/service_context.h" |
16 #include "services/service_manager/public/cpp/service_runner.h" | 18 #include "services/service_manager/public/cpp/service_runner.h" |
17 #include "services/service_manager/public/interfaces/service_factory.mojom.h" | 19 #include "services/service_manager/public/interfaces/service_factory.mojom.h" |
18 #include "services/service_manager/tests/lifecycle/app_client.h" | 20 #include "services/service_manager/tests/lifecycle/app_client.h" |
19 #include "services/service_manager/tests/lifecycle/lifecycle_unittest.mojom.h" | 21 #include "services/service_manager/tests/lifecycle/lifecycle_unittest.mojom.h" |
20 | 22 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 156 } |
155 | 157 |
156 void DestroyService(int id) { | 158 void DestroyService(int id) { |
157 auto id_it = id_to_context_.find(id); | 159 auto id_it = id_to_context_.find(id); |
158 DCHECK(id_it != id_to_context_.end()); | 160 DCHECK(id_it != id_to_context_.end()); |
159 | 161 |
160 auto it = contexts_.find(id_it->second); | 162 auto it = contexts_.find(id_it->second); |
161 DCHECK(it != contexts_.end()); | 163 DCHECK(it != contexts_.end()); |
162 contexts_.erase(it); | 164 contexts_.erase(it); |
163 id_to_context_.erase(id_it); | 165 id_to_context_.erase(id_it); |
164 if (contexts_.empty() && base::MessageLoop::current()->is_running()) | 166 if (contexts_.empty() && base::RunLoop::IsRunningOnCurrentThread()) |
165 base::MessageLoop::current()->QuitWhenIdle(); | 167 base::MessageLoop::current()->QuitWhenIdle(); |
166 } | 168 } |
167 | 169 |
168 service_manager::test::AppClient app_client_; | 170 service_manager::test::AppClient app_client_; |
169 int service_manager_connection_refcount_ = 0; | 171 int service_manager_connection_refcount_ = 0; |
170 service_manager::BinderRegistry registry_; | 172 service_manager::BinderRegistry registry_; |
171 mojo::BindingSet<service_manager::mojom::ServiceFactory> bindings_; | 173 mojo::BindingSet<service_manager::mojom::ServiceFactory> bindings_; |
172 | 174 |
173 using ServiceContextMap = | 175 using ServiceContextMap = |
174 std::map<service_manager::ServiceContext*, | 176 std::map<service_manager::ServiceContext*, |
175 std::unique_ptr<service_manager::ServiceContext>>; | 177 std::unique_ptr<service_manager::ServiceContext>>; |
176 ServiceContextMap contexts_; | 178 ServiceContextMap contexts_; |
177 | 179 |
178 int next_id_ = 0; | 180 int next_id_ = 0; |
179 std::map<int, service_manager::ServiceContext*> id_to_context_; | 181 std::map<int, service_manager::ServiceContext*> id_to_context_; |
180 | 182 |
181 DISALLOW_COPY_AND_ASSIGN(Package); | 183 DISALLOW_COPY_AND_ASSIGN(Package); |
182 }; | 184 }; |
183 | 185 |
184 } // namespace | 186 } // namespace |
185 | 187 |
186 MojoResult ServiceMain(MojoHandle service_request_handle) { | 188 MojoResult ServiceMain(MojoHandle service_request_handle) { |
187 service_manager::ServiceRunner runner(new Package); | 189 service_manager::ServiceRunner runner(new Package); |
188 return runner.Run(service_request_handle); | 190 return runner.Run(service_request_handle); |
189 } | 191 } |
OLD | NEW |