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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/guid.h" | 13 #include "base/guid.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
18 #include "base/process/process_handle.h" | 18 #include "base/process/process_handle.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
21 #include "base/trace_event/trace_event.h" | 21 #include "base/trace_event/trace_event.h" |
22 #include "mojo/public/cpp/bindings/associated_binding.h" | 22 #include "mojo/public/cpp/bindings/associated_binding.h" |
23 #include "mojo/public/cpp/bindings/binding.h" | 23 #include "mojo/public/cpp/bindings/binding.h" |
24 #include "mojo/public/cpp/bindings/binding_set.h" | 24 #include "mojo/public/cpp/bindings/binding_set.h" |
25 #include "mojo/public/cpp/bindings/strong_binding.h" | 25 #include "mojo/public/cpp/bindings/strong_binding.h" |
26 #include "services/catalog/public/interfaces/constants.mojom.h" | 26 #include "services/catalog/public/interfaces/constants.mojom.h" |
27 #include "services/service_manager/connect_util.h" | 27 #include "services/service_manager/connect_util.h" |
28 #include "services/service_manager/public/cpp/connector.h" | 28 #include "services/service_manager/public/cpp/connector.h" |
29 #include "services/service_manager/public/cpp/interface_registry.h" | |
30 #include "services/service_manager/public/cpp/service.h" | 29 #include "services/service_manager/public/cpp/service.h" |
31 #include "services/service_manager/public/cpp/service_context.h" | 30 #include "services/service_manager/public/cpp/service_context.h" |
32 #include "services/service_manager/public/interfaces/connector.mojom.h" | 31 #include "services/service_manager/public/interfaces/connector.mojom.h" |
33 #include "services/service_manager/public/interfaces/constants.mojom.h" | 32 #include "services/service_manager/public/interfaces/constants.mojom.h" |
34 #include "services/service_manager/public/interfaces/service.mojom.h" | 33 #include "services/service_manager/public/interfaces/service.mojom.h" |
35 #include "services/service_manager/public/interfaces/service_control.mojom.h" | 34 #include "services/service_manager/public/interfaces/service_control.mojom.h" |
36 #include "services/service_manager/public/interfaces/service_manager.mojom.h" | 35 #include "services/service_manager/public/interfaces/service_manager.mojom.h" |
37 #include "services/tracing/public/interfaces/constants.mojom.h" | 36 #include "services/tracing/public/interfaces/constants.mojom.h" |
38 | 37 |
39 namespace service_manager { | 38 namespace service_manager { |
40 | 39 |
41 namespace { | 40 namespace { |
42 | 41 |
43 const char kCapability_UserID[] = "service_manager:user_id"; | 42 const char kCapability_UserID[] = "service_manager:user_id"; |
44 const char kCapability_ClientProcess[] = "service_manager:client_process"; | 43 const char kCapability_ClientProcess[] = "service_manager:client_process"; |
45 const char kCapability_InstanceName[] = "service_manager:instance_name"; | 44 const char kCapability_InstanceName[] = "service_manager:instance_name"; |
46 const char kCapability_AllUsers[] = "service_manager:all_users"; | 45 const char kCapability_AllUsers[] = "service_manager:all_users"; |
47 const char kCapability_InstancePerChild[] = | 46 const char kCapability_InstancePerChild[] = |
48 "service_manager:instance_per_child"; | 47 "service_manager:instance_per_child"; |
49 const char kCapability_ServiceManager[] = "service_manager:service_manager"; | 48 const char kCapability_ServiceManager[] = "service_manager:service_manager"; |
50 | 49 |
51 bool Succeeded(mojom::ConnectResult result) { | 50 bool Succeeded(mojom::ConnectResult result) { |
52 return result == mojom::ConnectResult::SUCCEEDED; | 51 return result == mojom::ConnectResult::SUCCEEDED; |
53 } | 52 } |
54 | 53 |
54 // Returns the set of capabilities required from the target. | |
55 CapabilitySet GetRequestedCapabilities(const InterfaceProviderSpec& source_spec, | |
56 const Identity& target) { | |
57 CapabilitySet capabilities; | |
58 | |
59 // Start by looking for specs specific to the supplied identity. | |
60 auto it = source_spec.requires.find(target.name()); | |
61 if (it != source_spec.requires.end()) { | |
62 std::copy(it->second.begin(), it->second.end(), | |
63 std::inserter(capabilities, capabilities.begin())); | |
64 } | |
65 | |
66 // Apply wild card rules too. | |
67 it = source_spec.requires.find("*"); | |
68 if (it != source_spec.requires.end()) { | |
69 std::copy(it->second.begin(), it->second.end(), | |
70 std::inserter(capabilities, capabilities.begin())); | |
71 } | |
72 return capabilities; | |
73 } | |
74 | |
75 // Generates a single set of interfaces that is the union of all interfaces | |
76 // exposed by the target for the capabilities requested by the source. | |
77 InterfaceSet GetInterfacesToExpose(const InterfaceProviderSpec& source_spec, | |
Ken Rockot(use gerrit already)
2017/04/27 19:30:45
nit: Remove this from interface_registry.h too? Th
| |
78 const Identity& target, | |
79 const InterfaceProviderSpec& target_spec) { | |
80 InterfaceSet exposed_interfaces; | |
81 // TODO(beng): remove this once we can assert that an InterfaceRegistry must | |
82 // always be constructed with a valid identity. | |
83 if (!target.IsValid()) { | |
84 exposed_interfaces.insert("*"); | |
85 return exposed_interfaces; | |
86 } | |
87 CapabilitySet capabilities = GetRequestedCapabilities(source_spec, target); | |
88 for (const auto& capability : capabilities) { | |
89 auto it = target_spec.provides.find(capability); | |
90 if (it != target_spec.provides.end()) { | |
91 for (const auto& interface_name : it->second) | |
92 exposed_interfaces.insert(interface_name); | |
93 } | |
94 } | |
95 return exposed_interfaces; | |
96 } | |
97 | |
55 } // namespace | 98 } // namespace |
56 | 99 |
57 Identity CreateServiceManagerIdentity() { | 100 Identity CreateServiceManagerIdentity() { |
58 return Identity(service_manager::mojom::kServiceName, mojom::kRootUserID); | 101 return Identity(service_manager::mojom::kServiceName, mojom::kRootUserID); |
59 } | 102 } |
60 | 103 |
61 Identity CreateCatalogIdentity() { | 104 Identity CreateCatalogIdentity() { |
62 return Identity(catalog::mojom::kServiceName, mojom::kRootUserID); | 105 return Identity(catalog::mojom::kServiceName, mojom::kRootUserID); |
63 } | 106 } |
64 | 107 |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1097 instance->identity()); | 1140 instance->identity()); |
1098 if (params->HasInterfaceRequestInfo()) | 1141 if (params->HasInterfaceRequestInfo()) |
1099 instance->CallOnBindInterface(¶ms); | 1142 instance->CallOnBindInterface(¶ms); |
1100 } | 1143 } |
1101 | 1144 |
1102 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { | 1145 base::WeakPtr<ServiceManager> ServiceManager::GetWeakPtr() { |
1103 return weak_ptr_factory_.GetWeakPtr(); | 1146 return weak_ptr_factory_.GetWeakPtr(); |
1104 } | 1147 } |
1105 | 1148 |
1106 } // namespace service_manager | 1149 } // namespace service_manager |
OLD | NEW |