| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 info->id = id_; | 237 info->id = id_; |
| 238 info->identity = identity_; | 238 info->identity = identity_; |
| 239 info->pid = pid_; | 239 info->pid = pid_; |
| 240 return info; | 240 return info; |
| 241 } | 241 } |
| 242 | 242 |
| 243 const InterfaceProviderSpec& connection_spec() const { | 243 const InterfaceProviderSpec& connection_spec() const { |
| 244 return connection_spec_; | 244 return connection_spec_; |
| 245 } | 245 } |
| 246 const Identity& identity() const { return identity_; } | 246 const Identity& identity() const { return identity_; } |
| 247 void set_identity(const Identity& identity) { identity_ = identity; } |
| 247 uint32_t id() const { return id_; } | 248 uint32_t id() const { return id_; } |
| 248 | 249 |
| 249 // Service: | 250 // Service: |
| 250 bool OnConnect(const Identity& remote_identity, | 251 bool OnConnect(const Identity& remote_identity, |
| 251 InterfaceRegistry* registry) override { | 252 InterfaceRegistry* registry) override { |
| 252 Instance* source = service_manager_->GetExistingInstance(remote_identity); | 253 Instance* source = service_manager_->GetExistingInstance(remote_identity); |
| 253 DCHECK(source); | 254 DCHECK(source); |
| 254 if (HasCapability(source->connection_spec_, kCapability_ServiceManager)) { | 255 if (HasCapability(source->connection_spec_, kCapability_ServiceManager)) { |
| 255 registry->AddInterface<mojom::ServiceManager>(this); | 256 registry->AddInterface<mojom::ServiceManager>(this); |
| 256 return true; | 257 return true; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 | 454 |
| 454 service_manager_->OnInstanceError(this); | 455 service_manager_->OnInstanceError(this); |
| 455 } | 456 } |
| 456 | 457 |
| 457 service_manager::ServiceManager* const service_manager_; | 458 service_manager::ServiceManager* const service_manager_; |
| 458 | 459 |
| 459 // An id that identifies this instance. Distinct from pid, as a single process | 460 // An id that identifies this instance. Distinct from pid, as a single process |
| 460 // may vend multiple application instances, and this object may exist before a | 461 // may vend multiple application instances, and this object may exist before a |
| 461 // process is launched. | 462 // process is launched. |
| 462 const uint32_t id_; | 463 const uint32_t id_; |
| 463 const Identity identity_; | 464 Identity identity_; |
| 464 const InterfaceProviderSpec connection_spec_; | 465 const InterfaceProviderSpec connection_spec_; |
| 465 const bool allow_any_application_; | 466 const bool allow_any_application_; |
| 466 std::unique_ptr<NativeRunner> runner_; | 467 std::unique_ptr<NativeRunner> runner_; |
| 467 mojom::ServicePtr service_; | 468 mojom::ServicePtr service_; |
| 468 mojo::Binding<mojom::PIDReceiver> pid_receiver_binding_; | 469 mojo::Binding<mojom::PIDReceiver> pid_receiver_binding_; |
| 469 mojo::BindingSet<mojom::Connector> connectors_; | 470 mojo::BindingSet<mojom::Connector> connectors_; |
| 470 mojo::BindingSet<mojom::ServiceManager> service_manager_bindings_; | 471 mojo::BindingSet<mojom::ServiceManager> service_manager_bindings_; |
| 471 base::ProcessId pid_ = base::kNullProcessId; | 472 base::ProcessId pid_ = base::kNullProcessId; |
| 472 Instance* parent_ = nullptr; | 473 Instance* parent_ = nullptr; |
| 473 InstanceMap children_; | 474 InstanceMap children_; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 if (instance_name == GetNamePath(params->target().name()) && | 794 if (instance_name == GetNamePath(params->target().name()) && |
| 794 result->qualifier != GetNamePath(result->resolved_name)) { | 795 result->qualifier != GetNamePath(result->resolved_name)) { |
| 795 instance_name = result->qualifier; | 796 instance_name = result->qualifier; |
| 796 } | 797 } |
| 797 // |result->connection_spec| can be null when there is no manifest, e.g. for | 798 // |result->connection_spec| can be null when there is no manifest, e.g. for |
| 798 // URL types not resolvable by the resolver. | 799 // URL types not resolvable by the resolver. |
| 799 InterfaceProviderSpec connection_spec = GetPermissiveInterfaceProviderSpec(); | 800 InterfaceProviderSpec connection_spec = GetPermissiveInterfaceProviderSpec(); |
| 800 if (result->connection_spec.has_value()) | 801 if (result->connection_spec.has_value()) |
| 801 connection_spec = result->connection_spec.value(); | 802 connection_spec = result->connection_spec.value(); |
| 802 | 803 |
| 804 const Identity original_target(params->target()); |
| 803 const std::string user_id = | 805 const std::string user_id = |
| 804 HasCapability(connection_spec, kCapability_AllUsers) | 806 HasCapability(connection_spec, kCapability_AllUsers) |
| 805 ? base::GenerateGUID() : params->target().user_id(); | 807 ? base::GenerateGUID() : params->target().user_id(); |
| 806 const Identity target(params->target().name(), user_id, instance_name); | 808 const Identity target(params->target().name(), user_id, instance_name); |
| 807 params->set_target(target); | 809 params->set_target(target); |
| 808 | 810 |
| 809 // It's possible that when this manifest request was issued, another one was | 811 // It's possible that when this manifest request was issued, another one was |
| 810 // already in-progress and completed by the time this one did, and so the | 812 // already in-progress and completed by the time this one did, and so the |
| 811 // requested application may already be running. | 813 // requested application may already be running. |
| 812 if (ConnectToExistingInstance(¶ms)) | 814 if (ConnectToExistingInstance(¶ms)) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 843 // Likewise if a ClientProcessConnection was given via Connect(), it | 845 // Likewise if a ClientProcessConnection was given via Connect(), it |
| 844 // provides the Service proxy to use. | 846 // provides the Service proxy to use. |
| 845 instance->StartWithClientProcessConnection( | 847 instance->StartWithClientProcessConnection( |
| 846 std::move(client_process_connection)); | 848 std::move(client_process_connection)); |
| 847 } else { | 849 } else { |
| 848 // Otherwise we create a new Service pipe. | 850 // Otherwise we create a new Service pipe. |
| 849 mojom::ServiceRequest request = GetProxy(&service); | 851 mojom::ServiceRequest request = GetProxy(&service); |
| 850 CHECK(!result->package_path.empty() && result->connection_spec.has_value()); | 852 CHECK(!result->package_path.empty() && result->connection_spec.has_value()); |
| 851 | 853 |
| 852 if (target.name() != result->resolved_name) { | 854 if (target.name() != result->resolved_name) { |
| 855 // When part of a packaged app, use the original user ID. |
| 856 Identity packaged_app_target(target); |
| 857 packaged_app_target.set_user_id(original_target.user_id()); |
| 858 instance->set_identity(packaged_app_target); |
| 853 instance->StartWithService(std::move(service)); | 859 instance->StartWithService(std::move(service)); |
| 854 Identity factory(result->resolved_name, target.user_id(), | 860 Identity factory(result->resolved_name, original_target.user_id(), |
| 855 instance_name); | 861 instance_name); |
| 856 CreateServiceWithFactory(factory, target.name(), std::move(request)); | 862 CreateServiceWithFactory(factory, target.name(), std::move(request)); |
| 857 } else { | 863 } else { |
| 858 base::FilePath package_path; | 864 base::FilePath package_path; |
| 859 if (!service_overrides_ || !service_overrides_->GetExecutablePathOverride( | 865 if (!service_overrides_ || !service_overrides_->GetExecutablePathOverride( |
| 860 target.name(), &package_path)) { | 866 target.name(), &package_path)) { |
| 861 package_path = result->package_path; | 867 package_path = result->package_path; |
| 862 } | 868 } |
| 863 | 869 |
| 864 Identity source_instance_identity; | 870 Identity source_instance_identity; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 881 // Now that the instance has a Service, we can connect to it. | 887 // Now that the instance has a Service, we can connect to it. |
| 882 bool connected = instance->ConnectToService(¶ms); | 888 bool connected = instance->ConnectToService(¶ms); |
| 883 DCHECK(connected); | 889 DCHECK(connected); |
| 884 } | 890 } |
| 885 | 891 |
| 886 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 892 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
| 887 return weak_ptr_factory_.GetWeakPtr(); | 893 return weak_ptr_factory_.GetWeakPtr(); |
| 888 } | 894 } |
| 889 | 895 |
| 890 } // namespace service_manager | 896 } // namespace service_manager |
| OLD | NEW |