| 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/shell/service_manager.h" | 5 #include "services/shell/service_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return info; | 238 return info; |
| 239 } | 239 } |
| 240 | 240 |
| 241 const CapabilitySpec& capability_spec() const { | 241 const CapabilitySpec& capability_spec() const { |
| 242 return capability_spec_; | 242 return capability_spec_; |
| 243 } | 243 } |
| 244 const Identity& identity() const { return identity_; } | 244 const Identity& identity() const { return identity_; } |
| 245 uint32_t id() const { return id_; } | 245 uint32_t id() const { return id_; } |
| 246 | 246 |
| 247 // Service: | 247 // Service: |
| 248 bool OnConnect(Connection* connection) override { | 248 bool OnConnect(const Identity& remote_identity, |
| 249 connection->AddInterface<mojom::ServiceManager>(this); | 249 InterfaceRegistry* registry) override { |
| 250 registry->AddInterface<mojom::ServiceManager>(this); |
| 250 return true; | 251 return true; |
| 251 } | 252 } |
| 252 | 253 |
| 253 private: | 254 private: |
| 254 // mojom::Connector implementation: | 255 // mojom::Connector implementation: |
| 255 void Connect(mojom::IdentityPtr target_ptr, | 256 void Connect(mojom::IdentityPtr target_ptr, |
| 256 mojom::InterfaceProviderRequest remote_interfaces, | 257 mojom::InterfaceProviderRequest remote_interfaces, |
| 257 mojom::ClientProcessConnectionPtr client_process_connection, | 258 mojom::ClientProcessConnectionPtr client_process_connection, |
| 258 const ConnectCallback& callback) override { | 259 const ConnectCallback& callback) override { |
| 259 Identity target = target_ptr.To<Identity>(); | 260 Identity target = target_ptr.To<Identity>(); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 mojom::ServicePtr service; | 525 mojom::ServicePtr service; |
| 525 mojom::ServiceRequest request = mojo::GetProxy(&service); | 526 mojom::ServiceRequest request = mojo::GetProxy(&service); |
| 526 Connect(std::move(params), std::move(service), nullptr); | 527 Connect(std::move(params), std::move(service), nullptr); |
| 527 | 528 |
| 528 return request; | 529 return request; |
| 529 } | 530 } |
| 530 | 531 |
| 531 //////////////////////////////////////////////////////////////////////////////// | 532 //////////////////////////////////////////////////////////////////////////////// |
| 532 // ServiceManager, Service implementation: | 533 // ServiceManager, Service implementation: |
| 533 | 534 |
| 534 bool ServiceManager::OnConnect(Connection* connection) { | 535 bool ServiceManager::OnConnect(const Identity& remote_identity, |
| 536 InterfaceRegistry* registry) { |
| 535 // The only interface we expose is mojom::ServiceManager, and access to this | 537 // The only interface we expose is mojom::ServiceManager, and access to this |
| 536 // interface is brokered by a policy specific to each caller, managed by the | 538 // interface is brokered by a policy specific to each caller, managed by the |
| 537 // caller's instance. Here we look to see who's calling, and forward to the | 539 // caller's instance. Here we look to see who's calling, and forward to the |
| 538 // caller's instance to continue. | 540 // caller's instance to continue. |
| 539 Instance* instance = nullptr; | 541 Instance* instance = nullptr; |
| 540 for (const auto& entry : identity_to_instance_) { | 542 for (const auto& entry : identity_to_instance_) { |
| 541 if (entry.first == connection->GetRemoteIdentity()) { | 543 if (entry.first == remote_identity) { |
| 542 instance = entry.second; | 544 instance = entry.second; |
| 543 break; | 545 break; |
| 544 } | 546 } |
| 545 } | 547 } |
| 546 DCHECK(instance); | 548 DCHECK(instance); |
| 547 return instance->OnConnect(connection); | 549 return instance->OnConnect(remote_identity, registry); |
| 548 } | 550 } |
| 549 | 551 |
| 550 //////////////////////////////////////////////////////////////////////////////// | 552 //////////////////////////////////////////////////////////////////////////////// |
| 551 // ServiceManager, private: | 553 // ServiceManager, private: |
| 552 | 554 |
| 553 void ServiceManager::InitCatalog(mojom::ServicePtr catalog) { | 555 void ServiceManager::InitCatalog(mojom::ServicePtr catalog) { |
| 554 // TODO(beng): It'd be great to build this from the manifest, however there's | 556 // TODO(beng): It'd be great to build this from the manifest, however there's |
| 555 // a bit of a chicken-and-egg problem. | 557 // a bit of a chicken-and-egg problem. |
| 556 CapabilitySpec spec; | 558 CapabilitySpec spec; |
| 557 Interfaces interfaces; | 559 Interfaces interfaces; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 // Now that the instance has a Service, we can connect to it. | 803 // Now that the instance has a Service, we can connect to it. |
| 802 bool connected = instance->ConnectToService(¶ms); | 804 bool connected = instance->ConnectToService(¶ms); |
| 803 DCHECK(connected); | 805 DCHECK(connected); |
| 804 } | 806 } |
| 805 | 807 |
| 806 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 808 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
| 807 return weak_ptr_factory_.GetWeakPtr(); | 809 return weak_ptr_factory_.GetWeakPtr(); |
| 808 } | 810 } |
| 809 | 811 |
| 810 } // namespace shell | 812 } // namespace shell |
| OLD | NEW |