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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 const ConnectCallback& callback) { | 357 const ConnectCallback& callback) { |
358 // TODO(beng): Need to do the following additional policy validation of | 358 // TODO(beng): Need to do the following additional policy validation of |
359 // whether this instance is allowed to connect using: | 359 // whether this instance is allowed to connect using: |
360 // - a non-null client_process_connection. | 360 // - a non-null client_process_connection. |
361 if (target.user_id() != identity_.user_id() && | 361 if (target.user_id() != identity_.user_id() && |
362 target.user_id() != mojom::kRootUserID && | 362 target.user_id() != mojom::kRootUserID && |
363 !HasClass(capability_spec_, kCapabilityClass_UserID)) { | 363 !HasClass(capability_spec_, kCapabilityClass_UserID)) { |
364 LOG(ERROR) << "Instance: " << identity_.name() << " running as: " | 364 LOG(ERROR) << "Instance: " << identity_.name() << " running as: " |
365 << identity_.user_id() << " attempting to connect to: " | 365 << identity_.user_id() << " attempting to connect to: " |
366 << target.name() << " as: " << target.user_id() << " without " | 366 << target.name() << " as: " << target.user_id() << " without " |
367 << " the mojo:shell{user_id} capability class."; | 367 << " the service:shell{user_id} capability class."; |
368 callback.Run(mojom::ConnectResult::ACCESS_DENIED, | 368 callback.Run(mojom::ConnectResult::ACCESS_DENIED, |
369 mojom::kInheritUserID); | 369 mojom::kInheritUserID); |
370 return false; | 370 return false; |
371 } | 371 } |
372 if (!target.instance().empty() && | 372 if (!target.instance().empty() && |
373 target.instance() != GetNamePath(target.name()) && | 373 target.instance() != GetNamePath(target.name()) && |
374 !HasClass(capability_spec_, kCapabilityClass_InstanceName)) { | 374 !HasClass(capability_spec_, kCapabilityClass_InstanceName)) { |
375 LOG(ERROR) << "Instance: " << identity_.name() << " attempting to " | 375 LOG(ERROR) << "Instance: " << identity_.name() << " attempting to " |
376 << "connect to " << target.name() << " using Instance name: " | 376 << "connect to " << target.name() << " using Instance name: " |
377 << target.instance() << " without the " | 377 << target.instance() << " without the " |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 //////////////////////////////////////////////////////////////////////////////// | 480 //////////////////////////////////////////////////////////////////////////////// |
481 // ServiceManager, public: | 481 // ServiceManager, public: |
482 | 482 |
483 ServiceManager::ServiceManager( | 483 ServiceManager::ServiceManager( |
484 std::unique_ptr<NativeRunnerFactory> native_runner_factory, | 484 std::unique_ptr<NativeRunnerFactory> native_runner_factory, |
485 mojom::ServicePtr catalog) | 485 mojom::ServicePtr catalog) |
486 : native_runner_factory_(std::move(native_runner_factory)), | 486 : native_runner_factory_(std::move(native_runner_factory)), |
487 weak_ptr_factory_(this) { | 487 weak_ptr_factory_(this) { |
488 mojom::ServicePtr service; | 488 mojom::ServicePtr service; |
489 mojom::ServiceRequest request = mojo::GetProxy(&service); | 489 mojom::ServiceRequest request = mojo::GetProxy(&service); |
| 490 |
| 491 CapabilitySpec capabilities = GetPermissiveCapabilities(); |
| 492 capabilities.provided["control"].insert( |
| 493 "shell::mojom::ServiceManagerControl"); |
| 494 |
490 service_manager_instance_ = CreateInstance( | 495 service_manager_instance_ = CreateInstance( |
491 Identity(), CreateServiceManagerIdentity(), GetPermissiveCapabilities()); | 496 Identity(), CreateServiceManagerIdentity(), capabilities); |
492 service_manager_instance_->StartWithService(std::move(service)); | 497 service_manager_instance_->StartWithService(std::move(service)); |
493 singletons_.insert(kServiceManagerName); | 498 singletons_.insert(kServiceManagerName); |
494 service_context_.reset(new ServiceContext(this, std::move(request))); | 499 service_context_.reset(new ServiceContext(this, std::move(request))); |
495 | 500 |
496 if (catalog) | 501 if (catalog) |
497 InitCatalog(std::move(catalog)); | 502 InitCatalog(std::move(catalog)); |
498 } | 503 } |
499 | 504 |
500 ServiceManager::~ServiceManager() { | 505 ServiceManager::~ServiceManager() { |
501 // Ensure we tear down the ServiceManager instance last. This is to avoid | 506 // Ensure we tear down the ServiceManager instance last. This is to avoid |
(...skipping 29 matching lines...) Expand all Loading... |
531 Connect(std::move(params), std::move(service), nullptr); | 536 Connect(std::move(params), std::move(service), nullptr); |
532 | 537 |
533 return request; | 538 return request; |
534 } | 539 } |
535 | 540 |
536 //////////////////////////////////////////////////////////////////////////////// | 541 //////////////////////////////////////////////////////////////////////////////// |
537 // ServiceManager, Service implementation: | 542 // ServiceManager, Service implementation: |
538 | 543 |
539 bool ServiceManager::OnConnect(const Identity& remote_identity, | 544 bool ServiceManager::OnConnect(const Identity& remote_identity, |
540 InterfaceRegistry* registry) { | 545 InterfaceRegistry* registry) { |
541 // The only interface we expose is mojom::ServiceManager, and access to this | 546 registry->AddInterface<mojom::ServiceManagerControl>(this); |
542 // interface is brokered by a policy specific to each caller, managed by the | 547 |
543 // caller's instance. Here we look to see who's calling, and forward to the | 548 // Access to mojom::ServiceManager is brokered by a policy specific to each |
544 // caller's instance to continue. | 549 // caller, managed by the caller's instance. Here we look to see who's |
| 550 // calling, and forward to the caller's instance to continue. |
545 Instance* instance = nullptr; | 551 Instance* instance = nullptr; |
546 for (const auto& entry : identity_to_instance_) { | 552 for (const auto& entry : identity_to_instance_) { |
547 if (entry.first == remote_identity) { | 553 if (entry.first == remote_identity) { |
548 instance = entry.second; | 554 instance = entry.second; |
549 break; | 555 break; |
550 } | 556 } |
551 } | 557 } |
552 DCHECK(instance); | 558 DCHECK(instance); |
553 return instance->OnConnect(remote_identity, registry); | 559 return instance->OnConnect(remote_identity, registry); |
554 } | 560 } |
555 | 561 |
556 //////////////////////////////////////////////////////////////////////////////// | 562 //////////////////////////////////////////////////////////////////////////////// |
| 563 // ServiceManager, InterfaceFactory<mojom::ServiceManagerControl> implementation |
| 564 |
| 565 void ServiceManager::Create(const Identity& remote_identity, |
| 566 mojom::ServiceManagerControlRequest request) { |
| 567 control_bindings_.AddBinding(this, std::move(request)); |
| 568 } |
| 569 |
| 570 //////////////////////////////////////////////////////////////////////////////// |
| 571 // ServiceManager, ServiceManagerControl implementation |
| 572 |
| 573 void ServiceManager::OverridePackagePath( |
| 574 const std::string& service_name, |
| 575 const base::FilePath& path, |
| 576 const OverridePackagePathCallback& callback) { |
| 577 package_path_overrides_.insert(std::make_pair(service_name, path)); |
| 578 callback.Run(); |
| 579 } |
| 580 |
| 581 //////////////////////////////////////////////////////////////////////////////// |
557 // ServiceManager, private: | 582 // ServiceManager, private: |
558 | 583 |
559 void ServiceManager::InitCatalog(mojom::ServicePtr catalog) { | 584 void ServiceManager::InitCatalog(mojom::ServicePtr catalog) { |
560 // TODO(beng): It'd be great to build this from the manifest, however there's | 585 // TODO(beng): It'd be great to build this from the manifest, however there's |
561 // a bit of a chicken-and-egg problem. | 586 // a bit of a chicken-and-egg problem. |
562 CapabilitySpec spec; | 587 CapabilitySpec spec; |
563 Interfaces interfaces; | 588 spec.provided["app"].insert("filesystem::mojom::Directory"); |
564 interfaces.insert("filesystem::mojom::Directory"); | 589 spec.provided["control"].insert("catalog::mojom::CatalogControl"); |
565 spec.provided["app"] = interfaces; | 590 Instance* instance = CreateInstance( |
566 Instance* instance = CreateInstance(CreateServiceManagerIdentity(), | 591 CreateServiceManagerIdentity(), CreateCatalogIdentity(), spec); |
567 CreateCatalogIdentity(), | |
568 spec); | |
569 singletons_.insert(kCatalogName); | 592 singletons_.insert(kCatalogName); |
570 instance->StartWithService(std::move(catalog)); | 593 instance->StartWithService(std::move(catalog)); |
571 } | 594 } |
572 | 595 |
573 mojom::Resolver* ServiceManager::GetResolver(const Identity& identity) { | 596 mojom::Resolver* ServiceManager::GetResolver(const Identity& identity) { |
574 auto iter = identity_to_resolver_.find(identity); | 597 auto iter = identity_to_resolver_.find(identity); |
575 if (iter != identity_to_resolver_.end()) | 598 if (iter != identity_to_resolver_.end()) |
576 return iter->second.get(); | 599 return iter->second.get(); |
577 | 600 |
578 mojom::ResolverPtr resolver_ptr; | 601 mojom::ResolverPtr resolver_ptr; |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 params->set_target(target); | 803 params->set_target(target); |
781 | 804 |
782 // It's possible that when this manifest request was issued, another one was | 805 // It's possible that when this manifest request was issued, another one was |
783 // already in-progress and completed by the time this one did, and so the | 806 // already in-progress and completed by the time this one did, and so the |
784 // requested application may already be running. | 807 // requested application may already be running. |
785 if (ConnectToExistingInstance(¶ms)) | 808 if (ConnectToExistingInstance(¶ms)) |
786 return; | 809 return; |
787 | 810 |
788 Identity source = params->source(); | 811 Identity source = params->source(); |
789 | 812 |
| 813 auto override_iter = package_path_overrides_.find(target.name()); |
| 814 if (override_iter != package_path_overrides_.end()) |
| 815 result->package_path = override_iter->second; |
| 816 |
790 // Services that request "all_users" class from the Service Manager are | 817 // Services that request "all_users" class from the Service Manager are |
791 // allowed to field connection requests from any user. They also run with a | 818 // allowed to field connection requests from any user. They also run with a |
792 // synthetic user id generated here. The user id provided via Connect() is | 819 // synthetic user id generated here. The user id provided via Connect() is |
793 // ignored. Additionally services with the "all_users" class are not tied to | 820 // ignored. Additionally services with the "all_users" class are not tied to |
794 // the lifetime of the service that started them, instead they are owned by | 821 // the lifetime of the service that started them, instead they are owned by |
795 // the Service Manager. | 822 // the Service Manager. |
796 Identity source_identity_for_creation; | 823 Identity source_identity_for_creation; |
797 if (HasClass(capabilities, kCapabilityClass_AllUsers)) { | 824 if (HasClass(capabilities, kCapabilityClass_AllUsers)) { |
798 singletons_.insert(target.name()); | 825 singletons_.insert(target.name()); |
799 source_identity_for_creation = CreateServiceManagerIdentity(); | 826 source_identity_for_creation = CreateServiceManagerIdentity(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 // Now that the instance has a Service, we can connect to it. | 876 // Now that the instance has a Service, we can connect to it. |
850 bool connected = instance->ConnectToService(¶ms); | 877 bool connected = instance->ConnectToService(¶ms); |
851 DCHECK(connected); | 878 DCHECK(connected); |
852 } | 879 } |
853 | 880 |
854 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 881 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
855 return weak_ptr_factory_.GetWeakPtr(); | 882 return weak_ptr_factory_.GetWeakPtr(); |
856 } | 883 } |
857 | 884 |
858 } // namespace shell | 885 } // namespace shell |
OLD | NEW |