| 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 "mojo/services/catalog/entry.h" | 5 #include "mojo/services/catalog/entry.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "mojo/services/catalog/store.h" | 8 #include "mojo/services/catalog/store.h" |
| 9 #include "mojo/shell/public/cpp/names.h" | 9 #include "mojo/shell/public/cpp/names.h" |
| 10 #include "mojo/util/filename_util.h" |
| 11 #include "url/gurl.h" |
| 10 | 12 |
| 11 namespace catalog { | 13 namespace catalog { |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 mojo::CapabilitySpec BuildCapabilitiesV0( | 16 mojo::CapabilitySpec BuildCapabilitiesV0( |
| 15 const base::DictionaryValue& value) { | 17 const base::DictionaryValue& value) { |
| 16 mojo::CapabilitySpec capabilities; | 18 mojo::CapabilitySpec capabilities; |
| 17 base::DictionaryValue::Iterator it(value); | 19 base::DictionaryValue::Iterator it(value); |
| 18 for (; !it.IsAtEnd(); it.Advance()) { | 20 for (; !it.IsAtEnd(); it.Advance()) { |
| 19 const base::ListValue* values = nullptr; | 21 const base::ListValue* values = nullptr; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 *entry_value, Store::kCapabilities_InterfacesKey, &spec.interfaces); | 96 *entry_value, Store::kCapabilities_InterfacesKey, &spec.interfaces); |
| 95 capabilities.required[it.key()] = spec; | 97 capabilities.required[it.key()] = spec; |
| 96 } | 98 } |
| 97 } | 99 } |
| 98 return capabilities; | 100 return capabilities; |
| 99 } | 101 } |
| 100 | 102 |
| 101 } // namespace | 103 } // namespace |
| 102 | 104 |
| 103 Entry::Entry() {} | 105 Entry::Entry() {} |
| 106 Entry::Entry(const std::string& name) |
| 107 : name_(name), |
| 108 qualifier_(mojo::GetNamePath(name)), |
| 109 display_name_(name) {} |
| 104 Entry::Entry(const Entry& other) = default; | 110 Entry::Entry(const Entry& other) = default; |
| 105 Entry::~Entry() {} | 111 Entry::~Entry() {} |
| 106 | 112 |
| 107 scoped_ptr<base::DictionaryValue> Entry::Serialize() const { | 113 scoped_ptr<base::DictionaryValue> Entry::Serialize() const { |
| 108 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); | 114 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue); |
| 109 value->SetInteger(Store::kManifestVersionKey, 1); | 115 value->SetInteger(Store::kManifestVersionKey, 1); |
| 110 value->SetString(Store::kNameKey, name_); | 116 value->SetString(Store::kNameKey, name_); |
| 111 value->SetString(Store::kDisplayNameKey, display_name_); | 117 value->SetString(Store::kDisplayNameKey, display_name_); |
| 112 value->SetString(Store::kQualifierKey, qualifier_); | 118 value->SetString(Store::kQualifierKey, qualifier_); |
| 113 scoped_ptr<base::DictionaryValue> spec(new base::DictionaryValue); | 119 scoped_ptr<base::DictionaryValue> spec(new base::DictionaryValue); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 else | 186 else |
| 181 entry->set_capabilities(BuildCapabilitiesV1(*capabilities)); | 187 entry->set_capabilities(BuildCapabilitiesV1(*capabilities)); |
| 182 | 188 |
| 183 if (value.HasKey(Store::kApplicationsKey)) { | 189 if (value.HasKey(Store::kApplicationsKey)) { |
| 184 const base::ListValue* applications = nullptr; | 190 const base::ListValue* applications = nullptr; |
| 185 value.GetList(Store::kApplicationsKey, &applications); | 191 value.GetList(Store::kApplicationsKey, &applications); |
| 186 for (size_t i = 0; i < applications->GetSize(); ++i) { | 192 for (size_t i = 0; i < applications->GetSize(); ++i) { |
| 187 const base::DictionaryValue* application = nullptr; | 193 const base::DictionaryValue* application = nullptr; |
| 188 applications->GetDictionary(i, &application); | 194 applications->GetDictionary(i, &application); |
| 189 scoped_ptr<Entry> child = Entry::Deserialize(*application); | 195 scoped_ptr<Entry> child = Entry::Deserialize(*application); |
| 190 if (child) | 196 if (child) { |
| 191 entry->applications_.insert(*child); | 197 child->set_package(entry.get()); |
| 198 // Caller must assume ownership of these items. |
| 199 entry->applications_.insert(child.release()); |
| 200 } |
| 192 } | 201 } |
| 193 } | 202 } |
| 194 | 203 |
| 195 return entry; | 204 return entry; |
| 196 } | 205 } |
| 197 | 206 |
| 198 bool Entry::operator==(const Entry& other) const { | 207 bool Entry::operator==(const Entry& other) const { |
| 199 return other.name_ == name_ && other.qualifier_ == qualifier_ && | 208 return other.name_ == name_ && other.qualifier_ == qualifier_ && |
| 200 other.display_name_ == display_name_ && | 209 other.display_name_ == display_name_ && |
| 201 other.capabilities_ == capabilities_; | 210 other.capabilities_ == capabilities_; |
| 202 } | 211 } |
| 203 | 212 |
| 204 bool Entry::operator<(const Entry& other) const { | 213 bool Entry::operator<(const Entry& other) const { |
| 205 return std::tie(name_, qualifier_, display_name_, capabilities_) < | 214 return std::tie(name_, qualifier_, display_name_, capabilities_) < |
| 206 std::tie(other.name_, other.qualifier_, other.display_name_, | 215 std::tie(other.name_, other.qualifier_, other.display_name_, |
| 207 other.capabilities_); | 216 other.capabilities_); |
| 208 } | 217 } |
| 209 | 218 |
| 210 } // catalog | 219 } // catalog |
| 220 |
| 221 namespace mojo { |
| 222 |
| 223 // static |
| 224 shell::mojom::ResolveResultPtr |
| 225 TypeConverter<shell::mojom::ResolveResultPtr, catalog::Entry>::Convert( |
| 226 const catalog::Entry& input) { |
| 227 shell::mojom::ResolveResultPtr result(shell::mojom::ResolveResult::New()); |
| 228 result->name = input.name(); |
| 229 const catalog::Entry& package = input.package() ? *input.package() : input; |
| 230 result->resolved_name = package.name(); |
| 231 result->qualifier = input.qualifier(); |
| 232 result->capabilities = |
| 233 shell::mojom::CapabilitySpec::From(input.capabilities()); |
| 234 result->package_url = mojo::util::FilePathToFileURL(package.path()).spec(); |
| 235 return result; |
| 236 } |
| 237 |
| 238 } // namespace mojo |
| OLD | NEW |