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

Side by Side Diff: services/catalog/entry.cc

Issue 2425563004: Support reading multiple InterfaceProviderSpecs from manifests (Closed)
Patch Set: . Created 4 years, 1 month 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/catalog/entry.h ('k') | services/catalog/entry_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/catalog/entry.h" 5 #include "services/catalog/entry.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "services/catalog/store.h" 9 #include "services/catalog/store.h"
10 #include "services/service_manager/public/cpp/names.h" 10 #include "services/service_manager/public/cpp/names.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 display_name_(name) {} 103 display_name_(name) {}
104 Entry::~Entry() {} 104 Entry::~Entry() {}
105 105
106 std::unique_ptr<base::DictionaryValue> Entry::Serialize() const { 106 std::unique_ptr<base::DictionaryValue> Entry::Serialize() const {
107 auto value = base::MakeUnique<base::DictionaryValue>(); 107 auto value = base::MakeUnique<base::DictionaryValue>();
108 value->SetString(Store::kNameKey, name_); 108 value->SetString(Store::kNameKey, name_);
109 value->SetString(Store::kDisplayNameKey, display_name_); 109 value->SetString(Store::kDisplayNameKey, display_name_);
110 value->SetString(Store::kQualifierKey, qualifier_); 110 value->SetString(Store::kQualifierKey, qualifier_);
111 111
112 auto specs = base::MakeUnique<base::DictionaryValue>(); 112 auto specs = base::MakeUnique<base::DictionaryValue>();
113 auto connection_spec = base::MakeUnique<base::DictionaryValue>(); 113 for (const auto& it : interface_provider_specs_) {
114 auto spec = base::MakeUnique<base::DictionaryValue>();
114 115
115 auto provides = base::MakeUnique<base::DictionaryValue>(); 116 auto provides = base::MakeUnique<base::DictionaryValue>();
116 for (const auto& i : connection_spec_.provides) { 117 for (const auto& i : it.second.provides) {
117 auto interfaces = base::MakeUnique<base::ListValue>(); 118 auto interfaces = base::MakeUnique<base::ListValue>();
118 for (const auto& interface_name : i.second) 119 for (const auto& interface_name : i.second)
119 interfaces->AppendString(interface_name); 120 interfaces->AppendString(interface_name);
120 provides->Set(i.first, std::move(interfaces)); 121 provides->Set(i.first, std::move(interfaces));
122 }
123 spec->Set(Store::kInterfaceProviderSpecs_ProvidesKey, std::move(provides));
124
125 auto requires = base::MakeUnique<base::DictionaryValue>();
126 for (const auto& i : it.second.requires) {
127 auto capabilities = base::MakeUnique<base::ListValue>();
128 for (const auto& capability : i.second)
129 capabilities->AppendString(capability);
130 requires->Set(i.first, std::move(capabilities));
131 }
132 spec->Set(Store::kInterfaceProviderSpecs_RequiresKey, std::move(requires));
133 specs->Set(it.first, std::move(spec));
121 } 134 }
122 connection_spec->Set(Store::kInterfaceProviderSpecs_ProvidesKey,
123 std::move(provides));
124
125 auto requires = base::MakeUnique<base::DictionaryValue>();
126 for (const auto& i : connection_spec_.requires) {
127 auto capabilities = base::MakeUnique<base::ListValue>();
128 for (const auto& class_name : i.second)
129 capabilities->AppendString(class_name);
130 requires->Set(i.first, std::move(capabilities));
131 }
132 connection_spec->Set(Store::kInterfaceProviderSpecs_RequiresKey,
133 std::move(requires));
134
135 specs->Set(Store::kInterfaceProvider_ConnectionSpecKey,
136 std::move(connection_spec));
137 value->Set(Store::kInterfaceProviderSpecsKey, std::move(specs)); 135 value->Set(Store::kInterfaceProviderSpecsKey, std::move(specs));
138 return value; 136 return value;
139 } 137 }
140 138
141 // static 139 // static
142 std::unique_ptr<Entry> Entry::Deserialize(const base::DictionaryValue& value) { 140 std::unique_ptr<Entry> Entry::Deserialize(const base::DictionaryValue& value) {
143 auto entry = base::MakeUnique<Entry>(); 141 auto entry = base::MakeUnique<Entry>();
144 142
145 // Name. 143 // Name.
146 std::string name_string; 144 std::string name_string;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 178
181 // InterfaceProvider specs. 179 // InterfaceProvider specs.
182 const base::DictionaryValue* interface_provider_specs = nullptr; 180 const base::DictionaryValue* interface_provider_specs = nullptr;
183 if (!value.GetDictionary(Store::kInterfaceProviderSpecsKey, 181 if (!value.GetDictionary(Store::kInterfaceProviderSpecsKey,
184 &interface_provider_specs)) { 182 &interface_provider_specs)) {
185 LOG(ERROR) << "Entry::Deserialize: dictionary has no " 183 LOG(ERROR) << "Entry::Deserialize: dictionary has no "
186 << Store::kInterfaceProviderSpecsKey << " key"; 184 << Store::kInterfaceProviderSpecsKey << " key";
187 return nullptr; 185 return nullptr;
188 } 186 }
189 187
190 const base::DictionaryValue* connection_spec = nullptr; 188 base::DictionaryValue::Iterator it(*interface_provider_specs);
191 if (interface_provider_specs->GetDictionary( 189 for (; !it.IsAtEnd(); it.Advance()) {
192 Store::kInterfaceProvider_ConnectionSpecKey, &connection_spec)) { 190 const base::DictionaryValue* spec_value = nullptr;
193 service_manager::InterfaceProviderSpec spec; 191 if (!interface_provider_specs->GetDictionary(it.key(), &spec_value)) {
194 if (!BuildInterfaceProviderSpec(*connection_spec, &spec)) { 192 LOG(ERROR) << "Entry::Deserialize: value of InterfaceProvider map for "
195 LOG(ERROR) << "Entry::Deserialize: failed to build InterfaceProvider " 193 << "key: " << it.key() << " not a dictionary.";
196 << "spec for " << entry->name();
197 return nullptr; 194 return nullptr;
198 } 195 }
199 entry->set_connection_spec(spec); 196
197 service_manager::InterfaceProviderSpec spec;
198 if (!BuildInterfaceProviderSpec(*spec_value, &spec)) {
199 LOG(ERROR) << "Entry::Deserialize: failed to build InterfaceProvider "
200 << "spec for key: " << it.key();
201 return nullptr;
202 }
203 entry->AddInterfaceProviderSpec(it.key(), spec);
200 } 204 }
201 205
202 if (value.HasKey(Store::kServicesKey)) { 206 if (value.HasKey(Store::kServicesKey)) {
203 const base::ListValue* services = nullptr; 207 const base::ListValue* services = nullptr;
204 value.GetList(Store::kServicesKey, &services); 208 value.GetList(Store::kServicesKey, &services);
205 for (size_t i = 0; i < services->GetSize(); ++i) { 209 for (size_t i = 0; i < services->GetSize(); ++i) {
206 const base::DictionaryValue* service = nullptr; 210 const base::DictionaryValue* service = nullptr;
207 services->GetDictionary(i, &service); 211 services->GetDictionary(i, &service);
208 std::unique_ptr<Entry> child = Entry::Deserialize(*service); 212 std::unique_ptr<Entry> child = Entry::Deserialize(*service);
209 if (child) { 213 if (child) {
210 child->set_package(entry.get()); 214 child->set_package(entry.get());
211 // Caller must assume ownership of these items. 215 // Caller must assume ownership of these items.
212 entry->children_.emplace_back(std::move(child)); 216 entry->children_.emplace_back(std::move(child));
213 } 217 }
214 } 218 }
215 } 219 }
216 220
217 return entry; 221 return entry;
218 } 222 }
219 223
220 bool Entry::ProvidesClass(const std::string& clazz) const { 224 bool Entry::ProvidesCapability(const std::string& capability) const {
221 return connection_spec_.provides.find(clazz) != 225 auto it = interface_provider_specs_.find(
222 connection_spec_.provides.end(); 226 service_manager::mojom::kServiceManager_ConnectorSpec);
227 if (it == interface_provider_specs_.end())
228 return false;
229
230 auto connection_spec = it->second;
231 return connection_spec.provides.find(capability) !=
232 connection_spec.provides.end();
223 } 233 }
224 234
225 bool Entry::operator==(const Entry& other) const { 235 bool Entry::operator==(const Entry& other) const {
226 return other.name_ == name_ && other.qualifier_ == qualifier_ && 236 return other.name_ == name_ && other.qualifier_ == qualifier_ &&
227 other.display_name_ == display_name_ && 237 other.display_name_ == display_name_ &&
228 other.connection_spec_ == connection_spec_; 238 other.interface_provider_specs_ == interface_provider_specs_;
229 } 239 }
230 240
231 bool Entry::operator<(const Entry& other) const { 241 void Entry::AddInterfaceProviderSpec(
232 return std::tie(name_, qualifier_, display_name_, connection_spec_) < 242 const std::string& name,
233 std::tie(other.name_, other.qualifier_, other.display_name_, 243 const service_manager::InterfaceProviderSpec& spec) {
234 other.connection_spec_); 244 interface_provider_specs_[name] = spec;
235 } 245 }
236 246
237 } // catalog 247 } // catalog
238 248
239 namespace mojo { 249 namespace mojo {
240 250
241 // static 251 // static
242 service_manager::mojom::ResolveResultPtr 252 service_manager::mojom::ResolveResultPtr
243 TypeConverter<service_manager::mojom::ResolveResultPtr, 253 TypeConverter<service_manager::mojom::ResolveResultPtr,
244 catalog::Entry>::Convert(const catalog::Entry& input) { 254 catalog::Entry>::Convert(const catalog::Entry& input) {
245 service_manager::mojom::ResolveResultPtr result( 255 service_manager::mojom::ResolveResultPtr result(
246 service_manager::mojom::ResolveResult::New()); 256 service_manager::mojom::ResolveResult::New());
247 result->name = input.name(); 257 result->name = input.name();
248 const catalog::Entry& package = input.package() ? *input.package() : input; 258 const catalog::Entry& package = input.package() ? *input.package() : input;
249 result->resolved_name = package.name(); 259 result->resolved_name = package.name();
250 result->qualifier = input.qualifier(); 260 result->qualifier = input.qualifier();
251 result->connection_spec = input.connection_spec(); 261 result->interface_provider_specs = input.interface_provider_specs();
252 result->package_path = package.path(); 262 result->package_path = package.path();
253 return result; 263 return result;
254 } 264 }
255 265
256 // static 266 // static
257 catalog::mojom::EntryPtr 267 catalog::mojom::EntryPtr
258 TypeConverter<catalog::mojom::EntryPtr, catalog::Entry>::Convert( 268 TypeConverter<catalog::mojom::EntryPtr, catalog::Entry>::Convert(
259 const catalog::Entry& input) { 269 const catalog::Entry& input) {
260 catalog::mojom::EntryPtr result(catalog::mojom::Entry::New()); 270 catalog::mojom::EntryPtr result(catalog::mojom::Entry::New());
261 result->name = input.name(); 271 result->name = input.name();
262 result->display_name = input.display_name(); 272 result->display_name = input.display_name();
263 return result; 273 return result;
264 } 274 }
265 275
266 } // namespace mojo 276 } // namespace mojo
OLDNEW
« no previous file with comments | « services/catalog/entry.h ('k') | services/catalog/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698