| OLD | NEW |
| 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/values.h" | 7 #include "base/values.h" |
| 8 #include "services/catalog/store.h" | 8 #include "services/catalog/store.h" |
| 9 #include "services/service_manager/public/cpp/names.h" | 9 #include "services/service_manager/public/cpp/names.h" |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 std::set<std::string>* string_set) { | 29 std::set<std::string>* string_set) { |
| 30 const base::ListValue* list_value = nullptr; | 30 const base::ListValue* list_value = nullptr; |
| 31 if (!value.GetAsList(&list_value)) { | 31 if (!value.GetAsList(&list_value)) { |
| 32 LOG(ERROR) << "Entry::Deserialize: Value must be a list."; | 32 LOG(ERROR) << "Entry::Deserialize: Value must be a list."; |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 return ReadStringSet(*list_value, string_set); | 35 return ReadStringSet(*list_value, string_set); |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool BuildCapabilities(const base::DictionaryValue& value, | 38 bool BuildCapabilities(const base::DictionaryValue& value, |
| 39 shell::CapabilitySpec* capabilities) { | 39 service_manager::CapabilitySpec* capabilities) { |
| 40 DCHECK(capabilities); | 40 DCHECK(capabilities); |
| 41 const base::DictionaryValue* provided_value = nullptr; | 41 const base::DictionaryValue* provided_value = nullptr; |
| 42 if (value.HasKey(Store::kCapabilities_ProvidedKey) && | 42 if (value.HasKey(Store::kCapabilities_ProvidedKey) && |
| 43 !value.GetDictionary(Store::kCapabilities_ProvidedKey, | 43 !value.GetDictionary(Store::kCapabilities_ProvidedKey, |
| 44 &provided_value)) { | 44 &provided_value)) { |
| 45 LOG(ERROR) << "Entry::Deserialize: " << Store::kCapabilities_ProvidedKey | 45 LOG(ERROR) << "Entry::Deserialize: " << Store::kCapabilities_ProvidedKey |
| 46 << " must be a dictionary."; | 46 << " must be a dictionary."; |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 if (provided_value) { | 49 if (provided_value) { |
| 50 base::DictionaryValue::Iterator it(*provided_value); | 50 base::DictionaryValue::Iterator it(*provided_value); |
| 51 for(; !it.IsAtEnd(); it.Advance()) { | 51 for(; !it.IsAtEnd(); it.Advance()) { |
| 52 shell::Interfaces interfaces; | 52 service_manager::Interfaces interfaces; |
| 53 if (!ReadStringSetFromValue(it.value(), &interfaces)) { | 53 if (!ReadStringSetFromValue(it.value(), &interfaces)) { |
| 54 LOG(ERROR) << "Entry::Deserialize: Invalid interface list in provided " | 54 LOG(ERROR) << "Entry::Deserialize: Invalid interface list in provided " |
| 55 << " classes dictionary"; | 55 << " classes dictionary"; |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 capabilities->provided[it.key()] = interfaces; | 58 capabilities->provided[it.key()] = interfaces; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 const base::DictionaryValue* required_value = nullptr; | 62 const base::DictionaryValue* required_value = nullptr; |
| 63 if (value.HasKey(Store::kCapabilities_RequiredKey) && | 63 if (value.HasKey(Store::kCapabilities_RequiredKey) && |
| 64 !value.GetDictionary(Store::kCapabilities_RequiredKey, | 64 !value.GetDictionary(Store::kCapabilities_RequiredKey, |
| 65 &required_value)) { | 65 &required_value)) { |
| 66 LOG(ERROR) << "Entry::Deserialize: " << Store::kCapabilities_RequiredKey | 66 LOG(ERROR) << "Entry::Deserialize: " << Store::kCapabilities_RequiredKey |
| 67 << " must be a dictionary."; | 67 << " must be a dictionary."; |
| 68 return false; | 68 return false; |
| 69 } | 69 } |
| 70 if (required_value) { | 70 if (required_value) { |
| 71 base::DictionaryValue::Iterator it(*required_value); | 71 base::DictionaryValue::Iterator it(*required_value); |
| 72 for (; !it.IsAtEnd(); it.Advance()) { | 72 for (; !it.IsAtEnd(); it.Advance()) { |
| 73 shell::Classes classes; | 73 service_manager::Classes classes; |
| 74 const base::ListValue* entry_value = nullptr; | 74 const base::ListValue* entry_value = nullptr; |
| 75 if (!it.value().GetAsList(&entry_value)) { | 75 if (!it.value().GetAsList(&entry_value)) { |
| 76 LOG(ERROR) << "Entry::Deserialize: " << Store::kCapabilities_RequiredKey | 76 LOG(ERROR) << "Entry::Deserialize: " << Store::kCapabilities_RequiredKey |
| 77 << " entry must be a list."; | 77 << " entry must be a list."; |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 if (!ReadStringSet(*entry_value, &classes)) { | 80 if (!ReadStringSet(*entry_value, &classes)) { |
| 81 LOG(ERROR) << "Entry::Deserialize: Invalid classes list in required " | 81 LOG(ERROR) << "Entry::Deserialize: Invalid classes list in required " |
| 82 << "capabilities dictionary."; | 82 << "capabilities dictionary."; |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 capabilities->required[it.key()] = classes; | 86 capabilities->required[it.key()] = classes; |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 return true; | 89 return true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 Entry::Entry() {} | 94 Entry::Entry() {} |
| 95 Entry::Entry(const std::string& name) | 95 Entry::Entry(const std::string& name) |
| 96 : name_(name), qualifier_(shell::GetNamePath(name)), display_name_(name) {} | 96 : name_(name), |
| 97 qualifier_(service_manager::GetNamePath(name)), |
| 98 display_name_(name) {} |
| 97 Entry::~Entry() {} | 99 Entry::~Entry() {} |
| 98 | 100 |
| 99 std::unique_ptr<base::DictionaryValue> Entry::Serialize() const { | 101 std::unique_ptr<base::DictionaryValue> Entry::Serialize() const { |
| 100 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 102 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 101 value->SetInteger(Store::kManifestVersionKey, 1); | 103 value->SetInteger(Store::kManifestVersionKey, 1); |
| 102 value->SetString(Store::kNameKey, name_); | 104 value->SetString(Store::kNameKey, name_); |
| 103 value->SetString(Store::kDisplayNameKey, display_name_); | 105 value->SetString(Store::kDisplayNameKey, display_name_); |
| 104 value->SetString(Store::kQualifierKey, qualifier_); | 106 value->SetString(Store::kQualifierKey, qualifier_); |
| 105 std::unique_ptr<base::DictionaryValue> spec(new base::DictionaryValue); | 107 std::unique_ptr<base::DictionaryValue> spec(new base::DictionaryValue); |
| 106 | 108 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return nullptr; | 145 return nullptr; |
| 144 } | 146 } |
| 145 | 147 |
| 146 // Name. | 148 // Name. |
| 147 std::string name_string; | 149 std::string name_string; |
| 148 if (!value.GetString(Store::kNameKey, &name_string)) { | 150 if (!value.GetString(Store::kNameKey, &name_string)) { |
| 149 LOG(ERROR) << "Entry::Deserialize: dictionary has no " | 151 LOG(ERROR) << "Entry::Deserialize: dictionary has no " |
| 150 << Store::kNameKey << " key"; | 152 << Store::kNameKey << " key"; |
| 151 return nullptr; | 153 return nullptr; |
| 152 } | 154 } |
| 153 if (!shell::IsValidName(name_string)) { | 155 if (!service_manager::IsValidName(name_string)) { |
| 154 LOG(ERROR) << "Entry::Deserialize: " << name_string << " is not a valid " | 156 LOG(ERROR) << "Entry::Deserialize: " << name_string << " is not a valid " |
| 155 << "Mojo name"; | 157 << "Mojo name"; |
| 156 return nullptr; | 158 return nullptr; |
| 157 } | 159 } |
| 158 entry->set_name(name_string); | 160 entry->set_name(name_string); |
| 159 | 161 |
| 160 // Process group. | 162 // Process group. |
| 161 if (value.HasKey(Store::kQualifierKey)) { | 163 if (value.HasKey(Store::kQualifierKey)) { |
| 162 std::string qualifier; | 164 std::string qualifier; |
| 163 if (!value.GetString(Store::kQualifierKey, &qualifier)) { | 165 if (!value.GetString(Store::kQualifierKey, &qualifier)) { |
| 164 LOG(ERROR) << "Entry::Deserialize: " << Store::kQualifierKey << " must " | 166 LOG(ERROR) << "Entry::Deserialize: " << Store::kQualifierKey << " must " |
| 165 << "be a string."; | 167 << "be a string."; |
| 166 return nullptr; | 168 return nullptr; |
| 167 } | 169 } |
| 168 entry->set_qualifier(qualifier); | 170 entry->set_qualifier(qualifier); |
| 169 } else { | 171 } else { |
| 170 entry->set_qualifier(shell::GetNamePath(name_string)); | 172 entry->set_qualifier(service_manager::GetNamePath(name_string)); |
| 171 } | 173 } |
| 172 | 174 |
| 173 // Human-readable name. | 175 // Human-readable name. |
| 174 std::string display_name; | 176 std::string display_name; |
| 175 if (!value.GetString(Store::kDisplayNameKey, &display_name)) { | 177 if (!value.GetString(Store::kDisplayNameKey, &display_name)) { |
| 176 LOG(ERROR) << "Entry::Deserialize: dictionary has no " | 178 LOG(ERROR) << "Entry::Deserialize: dictionary has no " |
| 177 << Store::kDisplayNameKey << " key"; | 179 << Store::kDisplayNameKey << " key"; |
| 178 return nullptr; | 180 return nullptr; |
| 179 } | 181 } |
| 180 entry->set_display_name(display_name); | 182 entry->set_display_name(display_name); |
| 181 | 183 |
| 182 // Capability spec. | 184 // Capability spec. |
| 183 const base::DictionaryValue* capabilities = nullptr; | 185 const base::DictionaryValue* capabilities = nullptr; |
| 184 if (!value.GetDictionary(Store::kCapabilitiesKey, &capabilities)) { | 186 if (!value.GetDictionary(Store::kCapabilitiesKey, &capabilities)) { |
| 185 LOG(ERROR) << "Entry::Deserialize: dictionary has no " | 187 LOG(ERROR) << "Entry::Deserialize: dictionary has no " |
| 186 << Store::kCapabilitiesKey << " key"; | 188 << Store::kCapabilitiesKey << " key"; |
| 187 return nullptr; | 189 return nullptr; |
| 188 } | 190 } |
| 189 | 191 |
| 190 shell::CapabilitySpec spec; | 192 service_manager::CapabilitySpec spec; |
| 191 if (!BuildCapabilities(*capabilities, &spec)) { | 193 if (!BuildCapabilities(*capabilities, &spec)) { |
| 192 LOG(ERROR) << "Entry::Deserialize: failed to build capability spec for " | 194 LOG(ERROR) << "Entry::Deserialize: failed to build capability spec for " |
| 193 << entry->name(); | 195 << entry->name(); |
| 194 return nullptr; | 196 return nullptr; |
| 195 } | 197 } |
| 196 entry->set_capabilities(spec); | 198 entry->set_capabilities(spec); |
| 197 | 199 |
| 198 if (value.HasKey(Store::kServicesKey)) { | 200 if (value.HasKey(Store::kServicesKey)) { |
| 199 const base::ListValue* services = nullptr; | 201 const base::ListValue* services = nullptr; |
| 200 value.GetList(Store::kServicesKey, &services); | 202 value.GetList(Store::kServicesKey, &services); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 227 return std::tie(name_, qualifier_, display_name_, capabilities_) < | 229 return std::tie(name_, qualifier_, display_name_, capabilities_) < |
| 228 std::tie(other.name_, other.qualifier_, other.display_name_, | 230 std::tie(other.name_, other.qualifier_, other.display_name_, |
| 229 other.capabilities_); | 231 other.capabilities_); |
| 230 } | 232 } |
| 231 | 233 |
| 232 } // catalog | 234 } // catalog |
| 233 | 235 |
| 234 namespace mojo { | 236 namespace mojo { |
| 235 | 237 |
| 236 // static | 238 // static |
| 237 shell::mojom::ResolveResultPtr | 239 service_manager::mojom::ResolveResultPtr |
| 238 TypeConverter<shell::mojom::ResolveResultPtr, catalog::Entry>::Convert( | 240 TypeConverter<service_manager::mojom::ResolveResultPtr, |
| 239 const catalog::Entry& input) { | 241 catalog::Entry>::Convert(const catalog::Entry& input) { |
| 240 shell::mojom::ResolveResultPtr result(shell::mojom::ResolveResult::New()); | 242 service_manager::mojom::ResolveResultPtr result( |
| 243 service_manager::mojom::ResolveResult::New()); |
| 241 result->name = input.name(); | 244 result->name = input.name(); |
| 242 const catalog::Entry& package = input.package() ? *input.package() : input; | 245 const catalog::Entry& package = input.package() ? *input.package() : input; |
| 243 result->resolved_name = package.name(); | 246 result->resolved_name = package.name(); |
| 244 result->qualifier = input.qualifier(); | 247 result->qualifier = input.qualifier(); |
| 245 result->capabilities = input.capabilities(); | 248 result->capabilities = input.capabilities(); |
| 246 result->package_path = package.path(); | 249 result->package_path = package.path(); |
| 247 return result; | 250 return result; |
| 248 } | 251 } |
| 249 | 252 |
| 250 // static | 253 // static |
| 251 catalog::mojom::EntryPtr | 254 catalog::mojom::EntryPtr |
| 252 TypeConverter<catalog::mojom::EntryPtr, catalog::Entry>::Convert( | 255 TypeConverter<catalog::mojom::EntryPtr, catalog::Entry>::Convert( |
| 253 const catalog::Entry& input) { | 256 const catalog::Entry& input) { |
| 254 catalog::mojom::EntryPtr result(catalog::mojom::Entry::New()); | 257 catalog::mojom::EntryPtr result(catalog::mojom::Entry::New()); |
| 255 result->name = input.name(); | 258 result->name = input.name(); |
| 256 result->display_name = input.display_name(); | 259 result->display_name = input.display_name(); |
| 257 return result; | 260 return result; |
| 258 } | 261 } |
| 259 | 262 |
| 260 } // namespace mojo | 263 } // namespace mojo |
| OLD | NEW |