| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "services/service_manager/service_manager.h" | 5 #include "services/service_manager/service_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 // The service was started but the service manager hasn't received the | 222 // The service was started but the service manager hasn't received the |
| 223 // initial response from it yet. | 223 // initial response from it yet. |
| 224 STARTING, | 224 STARTING, |
| 225 | 225 |
| 226 // The service was started successfully. | 226 // The service was started successfully. |
| 227 STARTED | 227 STARTED |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 // mojom::Connector implementation: | 230 // mojom::Connector implementation: |
| 231 void Start( | 231 void StartService( |
| 232 const Identity& target, | 232 const Identity& target, |
| 233 mojo::ScopedMessagePipeHandle service_handle, | 233 mojo::ScopedMessagePipeHandle service_handle, |
| 234 mojom::PIDReceiverRequest pid_receiver_request) override { | 234 mojom::PIDReceiverRequest pid_receiver_request) override { |
| 235 mojom::ServicePtr service; | 235 mojom::ServicePtr service; |
| 236 service.Bind(mojom::ServicePtrInfo(std::move(service_handle), 0)); | 236 service.Bind(mojom::ServicePtrInfo(std::move(service_handle), 0)); |
| 237 ConnectImpl( | 237 ConnectImpl( |
| 238 target, | 238 target, |
| 239 mojom::InterfaceProviderRequest(), | 239 mojom::InterfaceProviderRequest(), |
| 240 std::move(service), | 240 std::move(service), |
| 241 std::move(pid_receiver_request), | 241 std::move(pid_receiver_request), |
| 242 base::Bind( | 242 base::Bind( |
| 243 &service_manager::ServiceManager::Instance::EmptyConnectCallback, | 243 &service_manager::ServiceManager::Instance::EmptyConnectCallback, |
| 244 weak_factory_.GetWeakPtr())); | 244 weak_factory_.GetWeakPtr())); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void Connect(const service_manager::Identity& target, | 247 void Connect(const service_manager::Identity& target, |
| 248 mojom::InterfaceProviderRequest remote_interfaces, | 248 mojom::InterfaceProviderRequest remote_interfaces, |
| 249 const ConnectCallback& callback) override { | 249 const ConnectCallback& callback) override { |
| 250 ConnectImpl(target, std::move(remote_interfaces), mojom::ServicePtr(), | 250 ConnectImpl(target, std::move(remote_interfaces), mojom::ServicePtr(), |
| 251 mojom::PIDReceiverRequest(), callback); | 251 mojom::PIDReceiverRequest(), callback); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void BindInterface(const service_manager::Identity& target, |
| 255 const std::string& interface_name, |
| 256 mojo::ScopedMessagePipeHandle interface_pipe, |
| 257 const BindInterfaceCallback& callback) override { |
| 258 mojom::InterfaceProviderPtr remote_interfaces; |
| 259 ConnectImpl( |
| 260 target, |
| 261 MakeRequest(&remote_interfaces), |
| 262 mojom::ServicePtr(), |
| 263 mojom::PIDReceiverRequest(), |
| 264 base::Bind( |
| 265 &service_manager::ServiceManager::Instance::BindCallbackWrapper, |
| 266 weak_factory_.GetWeakPtr(), |
| 267 callback)); |
| 268 remote_interfaces->GetInterface(interface_name, std::move(interface_pipe)); |
| 269 // TODO(beng): Rather than just forwarding thru to InterfaceProvider, do |
| 270 // manifest policy intersection here. |
| 271 } |
| 272 |
| 254 void ConnectImpl(const service_manager::Identity& in_target, | 273 void ConnectImpl(const service_manager::Identity& in_target, |
| 255 mojom::InterfaceProviderRequest remote_interfaces, | 274 mojom::InterfaceProviderRequest remote_interfaces, |
| 256 mojom::ServicePtr service, | 275 mojom::ServicePtr service, |
| 257 mojom::PIDReceiverRequest pid_receiver_request, | 276 mojom::PIDReceiverRequest pid_receiver_request, |
| 258 const ConnectCallback& callback) { | 277 const ConnectCallback& callback) { |
| 259 Identity target = in_target; | 278 Identity target = in_target; |
| 260 if (target.user_id() == mojom::kInheritUserID) | 279 if (target.user_id() == mojom::kInheritUserID) |
| 261 target.set_user_id(identity_.user_id()); | 280 target.set_user_id(identity_.user_id()); |
| 262 | 281 |
| 263 if (!ValidateIdentity(target, callback)) | 282 if (!ValidateIdentity(target, callback)) |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 464 |
| 446 // mojom::ServiceControl: | 465 // mojom::ServiceControl: |
| 447 void RequestQuit() override { | 466 void RequestQuit() override { |
| 448 // If quit is requested, oblige when there are no pending OnConnects. | 467 // If quit is requested, oblige when there are no pending OnConnects. |
| 449 if (!pending_service_connections_) | 468 if (!pending_service_connections_) |
| 450 OnServiceLost(service_manager_->GetWeakPtr()); | 469 OnServiceLost(service_manager_->GetWeakPtr()); |
| 451 } | 470 } |
| 452 | 471 |
| 453 void EmptyConnectCallback(mojom::ConnectResult result, | 472 void EmptyConnectCallback(mojom::ConnectResult result, |
| 454 const std::string& user_id) {} | 473 const std::string& user_id) {} |
| 474 void BindCallbackWrapper(const BindInterfaceCallback& wrapped, |
| 475 mojom::ConnectResult result, |
| 476 const std::string& user_id) { |
| 477 wrapped.Run(result, user_id); |
| 478 } |
| 455 | 479 |
| 456 service_manager::ServiceManager* const service_manager_; | 480 service_manager::ServiceManager* const service_manager_; |
| 457 | 481 |
| 458 // An id that identifies this instance. Distinct from pid, as a single process | 482 // An id that identifies this instance. Distinct from pid, as a single process |
| 459 // may vend multiple application instances, and this object may exist before a | 483 // may vend multiple application instances, and this object may exist before a |
| 460 // process is launched. | 484 // process is launched. |
| 461 const uint32_t id_; | 485 const uint32_t id_; |
| 462 Identity identity_; | 486 Identity identity_; |
| 463 const InterfaceProviderSpecMap interface_provider_specs_; | 487 const InterfaceProviderSpecMap interface_provider_specs_; |
| 464 const InterfaceProviderSpec empty_spec_; | 488 const InterfaceProviderSpec empty_spec_; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 singletons_.insert(catalog::mojom::kServiceName); | 653 singletons_.insert(catalog::mojom::kServiceName); |
| 630 instance->StartWithService(std::move(catalog)); | 654 instance->StartWithService(std::move(catalog)); |
| 631 } | 655 } |
| 632 | 656 |
| 633 mojom::Resolver* ServiceManager::GetResolver(const Identity& identity) { | 657 mojom::Resolver* ServiceManager::GetResolver(const Identity& identity) { |
| 634 auto iter = identity_to_resolver_.find(identity); | 658 auto iter = identity_to_resolver_.find(identity); |
| 635 if (iter != identity_to_resolver_.end()) | 659 if (iter != identity_to_resolver_.end()) |
| 636 return iter->second.get(); | 660 return iter->second.get(); |
| 637 | 661 |
| 638 mojom::ResolverPtr resolver_ptr; | 662 mojom::ResolverPtr resolver_ptr; |
| 639 ConnectToInterface(this, identity, CreateCatalogIdentity(), &resolver_ptr); | 663 BindInterface(this, identity, CreateCatalogIdentity(), &resolver_ptr); |
| 640 mojom::Resolver* resolver = resolver_ptr.get(); | 664 mojom::Resolver* resolver = resolver_ptr.get(); |
| 641 identity_to_resolver_[identity] = std::move(resolver_ptr); | 665 identity_to_resolver_[identity] = std::move(resolver_ptr); |
| 642 return resolver; | 666 return resolver; |
| 643 } | 667 } |
| 644 | 668 |
| 645 void ServiceManager::OnInstanceError(Instance* instance) { | 669 void ServiceManager::OnInstanceError(Instance* instance) { |
| 646 // We never clean up the ServiceManager's own instance. | 670 // We never clean up the ServiceManager's own instance. |
| 647 if (instance == service_manager_instance_) | 671 if (instance == service_manager_instance_) |
| 648 return; | 672 return; |
| 649 | 673 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 | 831 |
| 808 mojom::ServiceFactory* ServiceManager::GetServiceFactory( | 832 mojom::ServiceFactory* ServiceManager::GetServiceFactory( |
| 809 const Identity& service_factory_identity) { | 833 const Identity& service_factory_identity) { |
| 810 auto it = service_factories_.find(service_factory_identity); | 834 auto it = service_factories_.find(service_factory_identity); |
| 811 if (it != service_factories_.end()) | 835 if (it != service_factories_.end()) |
| 812 return it->second.get(); | 836 return it->second.get(); |
| 813 | 837 |
| 814 Identity source_identity(service_manager::mojom::kServiceName, | 838 Identity source_identity(service_manager::mojom::kServiceName, |
| 815 mojom::kInheritUserID); | 839 mojom::kInheritUserID); |
| 816 mojom::ServiceFactoryPtr factory; | 840 mojom::ServiceFactoryPtr factory; |
| 817 ConnectToInterface(this, source_identity, service_factory_identity, | 841 BindInterface(this, source_identity, service_factory_identity, &factory); |
| 818 &factory); | |
| 819 mojom::ServiceFactory* factory_interface = factory.get(); | 842 mojom::ServiceFactory* factory_interface = factory.get(); |
| 820 factory.set_connection_error_handler( | 843 factory.set_connection_error_handler( |
| 821 base::Bind(&service_manager::ServiceManager::OnServiceFactoryLost, | 844 base::Bind(&service_manager::ServiceManager::OnServiceFactoryLost, |
| 822 weak_ptr_factory_.GetWeakPtr(), service_factory_identity)); | 845 weak_ptr_factory_.GetWeakPtr(), service_factory_identity)); |
| 823 service_factories_[service_factory_identity] = std::move(factory); | 846 service_factories_[service_factory_identity] = std::move(factory); |
| 824 return factory_interface; | 847 return factory_interface; |
| 825 } | 848 } |
| 826 | 849 |
| 827 void ServiceManager::OnServiceFactoryLost(const Identity& which) { | 850 void ServiceManager::OnServiceFactoryLost(const Identity& which) { |
| 828 // Remove the mapping. | 851 // Remove the mapping. |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 // Now that the instance has a Service, we can connect to it. | 995 // Now that the instance has a Service, we can connect to it. |
| 973 bool connected = instance->ConnectToService(¶ms); | 996 bool connected = instance->ConnectToService(¶ms); |
| 974 DCHECK(connected); | 997 DCHECK(connected); |
| 975 } | 998 } |
| 976 | 999 |
| 977 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 1000 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
| 978 return weak_ptr_factory_.GetWeakPtr(); | 1001 return weak_ptr_factory_.GetWeakPtr(); |
| 979 } | 1002 } |
| 980 | 1003 |
| 981 } // namespace service_manager | 1004 } // namespace service_manager |
| OLD | NEW |