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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 return false; | 100 return false; |
101 return it->second.find(capability) != it->second.end(); | 101 return it->second.find(capability) != it->second.end(); |
102 } | 102 } |
103 | 103 |
104 // Encapsulates a connection to an instance of a service, tracked by the | 104 // Encapsulates a connection to an instance of a service, tracked by the |
105 // Service Manager. | 105 // Service Manager. |
106 class ServiceManager::Instance | 106 class ServiceManager::Instance |
107 : public mojom::Connector, | 107 : public mojom::Connector, |
108 public mojom::PIDReceiver, | 108 public mojom::PIDReceiver, |
109 public Service, | 109 public Service, |
110 public InterfaceFactory<mojom::ServiceManager>, | |
111 public mojom::ServiceManager, | 110 public mojom::ServiceManager, |
112 public mojom::ServiceControl { | 111 public mojom::ServiceControl { |
113 public: | 112 public: |
114 Instance(service_manager::ServiceManager* service_manager, | 113 Instance(service_manager::ServiceManager* service_manager, |
115 const Identity& identity, | 114 const Identity& identity, |
116 const InterfaceProviderSpecMap& interface_provider_specs) | 115 const InterfaceProviderSpecMap& interface_provider_specs) |
117 : service_manager_(service_manager), | 116 : service_manager_(service_manager), |
118 id_(GenerateUniqueID()), | 117 id_(GenerateUniqueID()), |
119 identity_(identity), | 118 identity_(identity), |
120 interface_provider_specs_(interface_provider_specs), | 119 interface_provider_specs_(interface_provider_specs), |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 const InterfaceProviderSpec& GetConnectionSpec() const { | 271 const InterfaceProviderSpec& GetConnectionSpec() const { |
273 auto it = interface_provider_specs_.find( | 272 auto it = interface_provider_specs_.find( |
274 mojom::kServiceManager_ConnectorSpec); | 273 mojom::kServiceManager_ConnectorSpec); |
275 return it != interface_provider_specs_.end() ? it->second : empty_spec_; | 274 return it != interface_provider_specs_.end() ? it->second : empty_spec_; |
276 } | 275 } |
277 const Identity& identity() const { return identity_; } | 276 const Identity& identity() const { return identity_; } |
278 void set_identity(const Identity& identity) { identity_ = identity; } | 277 void set_identity(const Identity& identity) { identity_ = identity; } |
279 uint32_t id() const { return id_; } | 278 uint32_t id() const { return id_; } |
280 | 279 |
281 // Service: | 280 // Service: |
282 bool OnConnect(const ServiceInfo& remote_info, | 281 void OnBindInterface(const ServiceInfo& source_info, |
283 InterfaceRegistry* registry) override { | 282 const std::string& interface_name, |
| 283 mojo::ScopedMessagePipeHandle interface_pipe) override { |
284 Instance* source = | 284 Instance* source = |
285 service_manager_->GetExistingInstance(remote_info.identity); | 285 service_manager_->GetExistingInstance(source_info.identity); |
286 DCHECK(source); | 286 DCHECK(source); |
287 if (HasCapability(source->GetConnectionSpec(), | 287 if (interface_name == mojom::ServiceManager::Name_ && |
| 288 HasCapability(source->GetConnectionSpec(), |
288 kCapability_ServiceManager)) { | 289 kCapability_ServiceManager)) { |
289 registry->AddInterface<mojom::ServiceManager>(this); | 290 mojom::ServiceManagerRequest request = |
290 return true; | 291 mojo::MakeRequest<mojom::ServiceManager>(std::move(interface_pipe)); |
| 292 service_manager_bindings_.AddBinding(this, std::move(request)); |
291 } | 293 } |
292 return false; | |
293 } | 294 } |
294 | 295 |
295 private: | 296 private: |
296 enum class State { | 297 enum class State { |
297 // The service was not started yet. | 298 // The service was not started yet. |
298 IDLE, | 299 IDLE, |
299 | 300 |
300 // The service was started but the service manager hasn't received the | 301 // The service was started but the service manager hasn't received the |
301 // initial response from it yet. | 302 // initial response from it yet. |
302 STARTING, | 303 STARTING, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 370 |
370 void Clone(mojom::ConnectorRequest request) override { | 371 void Clone(mojom::ConnectorRequest request) override { |
371 connectors_.AddBinding(this, std::move(request)); | 372 connectors_.AddBinding(this, std::move(request)); |
372 } | 373 } |
373 | 374 |
374 // mojom::PIDReceiver: | 375 // mojom::PIDReceiver: |
375 void SetPID(uint32_t pid) override { | 376 void SetPID(uint32_t pid) override { |
376 PIDAvailable(pid); | 377 PIDAvailable(pid); |
377 } | 378 } |
378 | 379 |
379 // InterfaceFactory<mojom::ServiceManager>: | |
380 void Create(const Identity& remote_identity, | |
381 mojom::ServiceManagerRequest request) override { | |
382 service_manager_bindings_.AddBinding(this, std::move(request)); | |
383 } | |
384 | |
385 // mojom::ServiceManager implementation: | 380 // mojom::ServiceManager implementation: |
386 void AddListener(mojom::ServiceManagerListenerPtr listener) override { | 381 void AddListener(mojom::ServiceManagerListenerPtr listener) override { |
387 // TODO(beng): this should only track the instances matching this user, and | 382 // TODO(beng): this should only track the instances matching this user, and |
388 // root. | 383 // root. |
389 service_manager_->AddListener(std::move(listener)); | 384 service_manager_->AddListener(std::move(listener)); |
390 } | 385 } |
391 | 386 |
392 mojom::ConnectResult ValidateConnectParams( | 387 mojom::ConnectResult ValidateConnectParams( |
393 Identity* target, | 388 Identity* target, |
394 mojom::ServicePtr* service, | 389 mojom::ServicePtr* service, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 DISALLOW_COPY_AND_ASSIGN(Instance); | 568 DISALLOW_COPY_AND_ASSIGN(Instance); |
574 }; | 569 }; |
575 | 570 |
576 class ServiceManager::ServiceImpl : public Service { | 571 class ServiceManager::ServiceImpl : public Service { |
577 public: | 572 public: |
578 explicit ServiceImpl(ServiceManager* service_manager) | 573 explicit ServiceImpl(ServiceManager* service_manager) |
579 : service_manager_(service_manager) {} | 574 : service_manager_(service_manager) {} |
580 ~ServiceImpl() override {} | 575 ~ServiceImpl() override {} |
581 | 576 |
582 // Service: | 577 // Service: |
583 bool OnConnect(const ServiceInfo& remote_info, | 578 void OnBindInterface(const ServiceInfo& source_info, |
584 InterfaceRegistry* registry) override { | 579 const std::string& interface_name, |
| 580 mojo::ScopedMessagePipeHandle interface_pipe) override { |
585 // The only interface ServiceManager exposes is mojom::ServiceManager, and | 581 // The only interface ServiceManager exposes is mojom::ServiceManager, and |
586 // access to this interface is brokered by a policy specific to each caller, | 582 // access to this interface is brokered by a policy specific to each caller, |
587 // managed by the caller's instance. Here we look to see who's calling, | 583 // managed by the caller's instance. Here we look to see who's calling, |
588 // and forward to the caller's instance to continue. | 584 // and forward to the caller's instance to continue. |
589 Instance* instance = nullptr; | 585 Instance* instance = nullptr; |
590 for (const auto& entry : service_manager_->identity_to_instance_) { | 586 for (const auto& entry : service_manager_->identity_to_instance_) { |
591 if (entry.first == remote_info.identity) { | 587 if (entry.first == source_info.identity) { |
592 instance = entry.second; | 588 instance = entry.second; |
593 break; | 589 break; |
594 } | 590 } |
595 } | 591 } |
596 | 592 |
597 DCHECK(instance); | 593 DCHECK(instance); |
598 return instance->OnConnect(remote_info, registry); | 594 instance->OnBindInterface(source_info, interface_name, |
| 595 std::move(interface_pipe)); |
599 } | 596 } |
600 | 597 |
601 private: | 598 private: |
602 ServiceManager* const service_manager_; | 599 ServiceManager* const service_manager_; |
603 | 600 |
604 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); | 601 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); |
605 }; | 602 }; |
606 | 603 |
607 // static | 604 // static |
608 ServiceManager::TestAPI::TestAPI(ServiceManager* service_manager) | 605 ServiceManager::TestAPI::TestAPI(ServiceManager* service_manager) |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 bool connected = instance->CallOnConnect(¶ms); | 1062 bool connected = instance->CallOnConnect(¶ms); |
1066 DCHECK(connected); | 1063 DCHECK(connected); |
1067 } | 1064 } |
1068 } | 1065 } |
1069 | 1066 |
1070 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 1067 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
1071 return weak_ptr_factory_.GetWeakPtr(); | 1068 return weak_ptr_factory_.GetWeakPtr(); |
1072 } | 1069 } |
1073 | 1070 |
1074 } // namespace service_manager | 1071 } // namespace service_manager |
OLD | NEW |