Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: services/service_manager/service_manager.cc

Issue 2611183006: Service Manager: Miscellaneous catalog cleanup (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/service_manager/service_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 // Remove the mapping. 807 // Remove the mapping.
808 auto it = service_factories_.find(which); 808 auto it = service_factories_.find(which);
809 DCHECK(it != service_factories_.end()); 809 DCHECK(it != service_factories_.end());
810 service_factories_.erase(it); 810 service_factories_.erase(it);
811 } 811 }
812 812
813 void ServiceManager::OnGotResolvedName(std::unique_ptr<ConnectParams> params, 813 void ServiceManager::OnGotResolvedName(std::unique_ptr<ConnectParams> params,
814 mojom::ServicePtr service, 814 mojom::ServicePtr service,
815 bool has_source_instance, 815 bool has_source_instance,
816 base::WeakPtr<Instance> source_instance, 816 base::WeakPtr<Instance> source_instance,
817 mojom::ResolveResultPtr result) { 817 mojom::ResolveResultPtr result,
818 mojom::ResolveResultPtr parent) {
818 // If this request was originated by a specific Instance and that Instance is 819 // If this request was originated by a specific Instance and that Instance is
819 // no longer around, we ignore this response. 820 // no longer around, we ignore this response.
820 if (has_source_instance && !source_instance) 821 if (has_source_instance && !source_instance)
821 return; 822 return;
822 823
823 // If name resolution failed, we drop the connection. 824 // If name resolution failed, we drop the connection.
824 if (!result) { 825 if (!result) {
825 LOG(ERROR) << "Failed to resolve service name: " << params->target().name(); 826 LOG(ERROR) << "Failed to resolve service name: " << params->target().name();
826 if (!params->connect_callback().is_null()) { 827 if (!params->connect_callback().is_null()) {
827 params->connect_callback().Run( 828 params->connect_callback().Run(
828 mojom::ConnectResult::INVALID_ARGUMENT, ""); 829 mojom::ConnectResult::INVALID_ARGUMENT, "");
829 } 830 }
830 return; 831 return;
831 } 832 }
832 833
833 std::string instance_name = params->target().instance(); 834 std::string instance_name = params->target().instance();
834 if (instance_name == params->target().name() && 835
835 result->qualifier != result->resolved_name) { 836 // |result->interface_provider_specs| can be empty when there is no manifest.
836 instance_name = result->qualifier;
Ben Goodger (Google) 2017/01/07 19:29:55 so this means it's not possible to specify an inst
837 }
838 // |result->interface_provider_specs| can be empty when there is no manifest,
839 // e.g. for URL types not resolvable by the resolver.
840 InterfaceProviderSpec connection_spec = GetPermissiveInterfaceProviderSpec(); 837 InterfaceProviderSpec connection_spec = GetPermissiveInterfaceProviderSpec();
841 auto it = result->interface_provider_specs.find( 838 auto it = result->interface_provider_specs.find(
842 mojom::kServiceManager_ConnectorSpec); 839 mojom::kServiceManager_ConnectorSpec);
843 if (it != result->interface_provider_specs.end()) 840 if (it != result->interface_provider_specs.end())
844 connection_spec = it->second; 841 connection_spec = it->second;
845 842
846 const Identity original_target(params->target()); 843 const Identity original_target(params->target());
847 const std::string user_id = 844 const std::string user_id =
848 HasCapability(connection_spec, kCapability_AllUsers) 845 HasCapability(connection_spec, kCapability_AllUsers)
849 ? base::GenerateGUID() : params->target().user_id(); 846 ? base::GenerateGUID() : params->target().user_id();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 // is already holding a corresponding ServiceRequest. 881 // is already holding a corresponding ServiceRequest.
885 instance->StartWithService(std::move(service)); 882 instance->StartWithService(std::move(service));
886 } else if (!client_process_connection.is_null()) { 883 } else if (!client_process_connection.is_null()) {
887 // Likewise if a ClientProcessConnection was given via Connect(), it 884 // Likewise if a ClientProcessConnection was given via Connect(), it
888 // provides the Service proxy to use. 885 // provides the Service proxy to use.
889 instance->StartWithClientProcessConnection( 886 instance->StartWithClientProcessConnection(
890 std::move(client_process_connection)); 887 std::move(client_process_connection));
891 } else { 888 } else {
892 // Otherwise we create a new Service pipe. 889 // Otherwise we create a new Service pipe.
893 mojom::ServiceRequest request(&service); 890 mojom::ServiceRequest request(&service);
894 CHECK(!result->package_path.empty());
895 891
896 // The catalog was unable to read a manifest for this service. We can't do 892 // The catalog was unable to read a manifest for this service. We can't do
897 // anything more. 893 // anything more.
898 // TODO(beng): There may be some cases where it's valid to have an empty 894 // TODO(beng): There may be some cases where it's valid to have an empty
899 // spec, so we should probably include a return value in |result|. 895 // spec, so we should probably include a return value in |result|.
900 if (result->interface_provider_specs.empty()) { 896 if (result->interface_provider_specs.empty()) {
901 LOG(ERROR) 897 LOG(ERROR)
902 << "Error: The catalog was unable to read a manifest for service \"" 898 << "Error: The catalog was unable to read a manifest for service \""
903 << result->name << "\"."; 899 << result->name << "\".";
904 if (!params->connect_callback().is_null()) 900 if (!params->connect_callback().is_null())
905 params->connect_callback().Run(mojom::ConnectResult::ACCESS_DENIED, ""); 901 params->connect_callback().Run(mojom::ConnectResult::ACCESS_DENIED, "");
906 return; 902 return;
907 } 903 }
908 904
909 if (target.name() != result->resolved_name) { 905 if (parent) {
910 // This service is part of a package. 906 // This service is provided by another service via a ServiceFactory.
911 std::string target_user_id = target.user_id(); 907 std::string target_user_id = target.user_id();
912 std::string factory_instance_name = instance_name; 908 std::string factory_instance_name = instance_name;
913 bool instance_per_child = result->package_spec.has_value() && 909
914 HasCapability(result->package_spec.value(), 910 auto spec_iter = parent->interface_provider_specs.find(
915 kCapability_InstancePerChild); 911 mojom::kServiceManager_ConnectorSpec);
916 if (instance_per_child) { 912 if (spec_iter != parent->interface_provider_specs.end() &&
913 HasCapability(spec_iter->second, kCapability_InstancePerChild)) {
917 // If configured to start a new instance, create a random instance name 914 // If configured to start a new instance, create a random instance name
918 // for the factory so that we don't reuse an existing process. 915 // for the factory so that we don't reuse an existing process.
919 factory_instance_name = base::GenerateGUID(); 916 factory_instance_name = base::GenerateGUID();
920 } else { 917 } else {
921 // Use the original user ID so the existing embedder factory can 918 // Use the original user ID so the existing embedder factory can
922 // be found and used to create the new service. 919 // be found and used to create the new service.
923 target_user_id = original_target.user_id(); 920 target_user_id = original_target.user_id();
924 Identity packaged_service_target(target); 921 Identity packaged_service_target(target);
925 packaged_service_target.set_user_id(original_target.user_id()); 922 packaged_service_target.set_user_id(original_target.user_id());
926 instance->set_identity(packaged_service_target); 923 instance->set_identity(packaged_service_target);
927 } 924 }
928 instance->StartWithService(std::move(service)); 925 instance->StartWithService(std::move(service));
929 926
930 Identity factory(result->resolved_name, target_user_id, 927 Identity factory(parent->name, target_user_id, factory_instance_name);
931 factory_instance_name);
932 CreateServiceWithFactory(factory, target.name(), std::move(request)); 928 CreateServiceWithFactory(factory, target.name(), std::move(request));
933 } else { 929 } else {
934 base::FilePath package_path; 930 base::FilePath package_path;
935 if (!service_overrides_ || !service_overrides_->GetExecutablePathOverride( 931 if (!service_overrides_ || !service_overrides_->GetExecutablePathOverride(
936 target.name(), &package_path)) { 932 target.name(), &package_path)) {
937 package_path = result->package_path; 933 package_path = result->package_path;
938 } 934 }
935 DCHECK(!package_path.empty());
939 936
940 if (!instance->StartWithFilePath(package_path)) { 937 if (!instance->StartWithFilePath(package_path)) {
941 OnInstanceError(instance); 938 OnInstanceError(instance);
942 if (!params->connect_callback().is_null()) { 939 if (!params->connect_callback().is_null()) {
943 params->connect_callback().Run( 940 params->connect_callback().Run(
944 mojom::ConnectResult::INVALID_ARGUMENT, ""); 941 mojom::ConnectResult::INVALID_ARGUMENT, "");
945 } 942 }
946 return; 943 return;
947 } 944 }
948 } 945 }
949 } 946 }
950 947
951 // Now that the instance has a Service, we can connect to it. 948 // Now that the instance has a Service, we can connect to it.
952 bool connected = instance->ConnectToService(&params); 949 bool connected = instance->ConnectToService(&params);
953 DCHECK(connected); 950 DCHECK(connected);
954 } 951 }
955 952
956 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { 953 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() {
957 return weak_ptr_factory_.GetWeakPtr(); 954 return weak_ptr_factory_.GetWeakPtr();
958 } 955 }
959 956
960 } // namespace service_manager 957 } // namespace service_manager
OLDNEW
« no previous file with comments | « services/service_manager/service_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698