| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 247 |
| 248 const InterfaceProviderSpec& GetConnectionSpec() const { | 248 const InterfaceProviderSpec& GetConnectionSpec() const { |
| 249 auto it = interface_provider_specs_.find( | 249 auto it = interface_provider_specs_.find( |
| 250 mojom::kServiceManager_ConnectorSpec); | 250 mojom::kServiceManager_ConnectorSpec); |
| 251 return it != interface_provider_specs_.end() ? it->second : empty_spec_; | 251 return it != interface_provider_specs_.end() ? it->second : empty_spec_; |
| 252 } | 252 } |
| 253 const Identity& identity() const { return identity_; } | 253 const Identity& identity() const { return identity_; } |
| 254 uint32_t id() const { return id_; } | 254 uint32_t id() const { return id_; } |
| 255 | 255 |
| 256 // Service: | 256 // Service: |
| 257 bool OnConnect(const Identity& remote_identity, | 257 bool OnConnect(const ServiceInfo& remote_info, |
| 258 InterfaceRegistry* registry) override { | 258 InterfaceRegistry* registry) override { |
| 259 Instance* source = service_manager_->GetExistingInstance(remote_identity); | 259 Instance* source = |
| 260 service_manager_->GetExistingInstance(remote_info.identity); |
| 260 DCHECK(source); | 261 DCHECK(source); |
| 261 if (HasCapability(source->GetConnectionSpec(), | 262 if (HasCapability(source->GetConnectionSpec(), |
| 262 kCapability_ServiceManager)) { | 263 kCapability_ServiceManager)) { |
| 263 registry->AddInterface<mojom::ServiceManager>(this); | 264 registry->AddInterface<mojom::ServiceManager>(this); |
| 264 return true; | 265 return true; |
| 265 } | 266 } |
| 266 return false; | 267 return false; |
| 267 } | 268 } |
| 268 | 269 |
| 269 private: | 270 private: |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 mojom::ServicePtr service; | 568 mojom::ServicePtr service; |
| 568 mojom::ServiceRequest request = mojo::GetProxy(&service); | 569 mojom::ServiceRequest request = mojo::GetProxy(&service); |
| 569 Connect(std::move(params), std::move(service), nullptr); | 570 Connect(std::move(params), std::move(service), nullptr); |
| 570 | 571 |
| 571 return request; | 572 return request; |
| 572 } | 573 } |
| 573 | 574 |
| 574 //////////////////////////////////////////////////////////////////////////////// | 575 //////////////////////////////////////////////////////////////////////////////// |
| 575 // ServiceManager, Service implementation: | 576 // ServiceManager, Service implementation: |
| 576 | 577 |
| 577 bool ServiceManager::OnConnect(const Identity& remote_identity, | 578 bool ServiceManager::OnConnect(const ServiceInfo& remote_info, |
| 578 InterfaceRegistry* registry) { | 579 InterfaceRegistry* registry) { |
| 579 // The only interface we expose is mojom::ServiceManager, and access to this | 580 // The only interface we expose is mojom::ServiceManager, and access to this |
| 580 // interface is brokered by a policy specific to each caller, managed by the | 581 // interface is brokered by a policy specific to each caller, managed by the |
| 581 // caller's instance. Here we look to see who's calling, and forward to the | 582 // caller's instance. Here we look to see who's calling, and forward to the |
| 582 // caller's instance to continue. | 583 // caller's instance to continue. |
| 583 Instance* instance = nullptr; | 584 Instance* instance = nullptr; |
| 584 for (const auto& entry : identity_to_instance_) { | 585 for (const auto& entry : identity_to_instance_) { |
| 585 if (entry.first == remote_identity) { | 586 if (entry.first == remote_info.identity) { |
| 586 instance = entry.second; | 587 instance = entry.second; |
| 587 break; | 588 break; |
| 588 } | 589 } |
| 589 } | 590 } |
| 590 DCHECK(instance); | 591 DCHECK(instance); |
| 591 return instance->OnConnect(remote_identity, registry); | 592 return instance->OnConnect(remote_info, registry); |
| 592 } | 593 } |
| 593 | 594 |
| 594 //////////////////////////////////////////////////////////////////////////////// | 595 //////////////////////////////////////////////////////////////////////////////// |
| 595 // ServiceManager, private: | 596 // ServiceManager, private: |
| 596 | 597 |
| 597 void ServiceManager::InitCatalog(mojom::ServicePtr catalog) { | 598 void ServiceManager::InitCatalog(mojom::ServicePtr catalog) { |
| 598 // TODO(beng): It'd be great to build this from the manifest, however there's | 599 // TODO(beng): It'd be great to build this from the manifest, however there's |
| 599 // a bit of a chicken-and-egg problem. | 600 // a bit of a chicken-and-egg problem. |
| 600 InterfaceProviderSpec spec; | 601 InterfaceProviderSpec spec; |
| 601 spec.provides["app"].insert("filesystem::mojom::Directory"); | 602 spec.provides["app"].insert("filesystem::mojom::Directory"); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 // Now that the instance has a Service, we can connect to it. | 909 // Now that the instance has a Service, we can connect to it. |
| 909 bool connected = instance->ConnectToService(¶ms); | 910 bool connected = instance->ConnectToService(¶ms); |
| 910 DCHECK(connected); | 911 DCHECK(connected); |
| 911 } | 912 } |
| 912 | 913 |
| 913 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 914 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
| 914 return weak_ptr_factory_.GetWeakPtr(); | 915 return weak_ptr_factory_.GetWeakPtr(); |
| 915 } | 916 } |
| 916 | 917 |
| 917 } // namespace service_manager | 918 } // namespace service_manager |
| OLD | NEW |