| 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/catalog.h" | 5 #include "mojo/services/catalog/catalog.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } else if (type == "exe") { | 141 } else if (type == "exe") { |
| 142 #if defined OS_WIN | 142 #if defined OS_WIN |
| 143 std::string extension = ".exe"; | 143 std::string extension = ".exe"; |
| 144 #else | 144 #else |
| 145 std::string extension; | 145 std::string extension; |
| 146 #endif | 146 #endif |
| 147 file_url = system_package_dir_.Resolve( | 147 file_url = system_package_dir_.Resolve( |
| 148 mojo::GetNamePath(resolved_name) + extension); | 148 mojo::GetNamePath(resolved_name) + extension); |
| 149 } | 149 } |
| 150 | 150 |
| 151 mojo::shell::mojom::CapabilityFilterPtr filter( | 151 mojo::shell::mojom::CapabilitySpecPtr capabilities_ptr = |
| 152 mojo::shell::mojom::CapabilityFilter::New()); | 152 mojo::shell::mojom::CapabilitySpec::From(entry_iter->second.capabilities); |
| 153 filter->filter = mojo::Map<mojo::String, mojo::Array<mojo::String>>(); | 153 |
| 154 for (const auto& entry : entry_iter->second.capabilities) { | 154 callback.Run(resolved_name, qualifier, std::move(capabilities_ptr), |
| 155 mojo::Array<mojo::String> interfaces; | |
| 156 for (auto interface_name : entry.second) | |
| 157 interfaces.push_back(interface_name); | |
| 158 filter->filter.insert(entry.first, std::move(interfaces)); | |
| 159 } | |
| 160 callback.Run(resolved_name, qualifier, std::move(filter), | |
| 161 file_url.spec()); | 155 file_url.spec()); |
| 162 } | 156 } |
| 163 | 157 |
| 164 bool Catalog::IsNameInCatalog(const std::string& name) const { | 158 bool Catalog::IsNameInCatalog(const std::string& name) const { |
| 165 return catalog_.find(name) != catalog_.end(); | 159 return catalog_.find(name) != catalog_.end(); |
| 166 } | 160 } |
| 167 | 161 |
| 168 void Catalog::AddNameToCatalog(const std::string& name, | 162 void Catalog::AddNameToCatalog(const std::string& name, |
| 169 const ResolveMojoNameCallback& callback) { | 163 const ResolveMojoNameCallback& callback) { |
| 170 GURL manifest_url = GetManifestURL(name); | 164 GURL manifest_url = GetManifestURL(name); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 196 const base::DictionaryValue* dictionary = nullptr; | 190 const base::DictionaryValue* dictionary = nullptr; |
| 197 const base::Value* v = *it; | 191 const base::Value* v = *it; |
| 198 CHECK(v->GetAsDictionary(&dictionary)); | 192 CHECK(v->GetAsDictionary(&dictionary)); |
| 199 const Entry entry = BuildEntry(*dictionary); | 193 const Entry entry = BuildEntry(*dictionary); |
| 200 catalog_[entry.name] = entry; | 194 catalog_[entry.name] = entry; |
| 201 } | 195 } |
| 202 } | 196 } |
| 203 | 197 |
| 204 void Catalog::SerializeCatalog() { | 198 void Catalog::SerializeCatalog() { |
| 205 scoped_ptr<base::ListValue> catalog(new base::ListValue); | 199 scoped_ptr<base::ListValue> catalog(new base::ListValue); |
| 206 for (const auto& entry : catalog_) { | 200 for (const auto& entry : catalog_) |
| 207 base::DictionaryValue* dictionary = nullptr; | 201 catalog->Append(SerializeEntry(entry.second)); |
| 208 SerializeEntry(entry.second, &dictionary); | |
| 209 catalog->Append(make_scoped_ptr(dictionary)); | |
| 210 } | |
| 211 if (store_) | 202 if (store_) |
| 212 store_->UpdateStore(std::move(catalog)); | 203 store_->UpdateStore(std::move(catalog)); |
| 213 } | 204 } |
| 214 | 205 |
| 215 const Entry& Catalog::DeserializeApplication( | 206 const Entry& Catalog::DeserializeApplication( |
| 216 const base::DictionaryValue* dictionary) { | 207 const base::DictionaryValue* dictionary) { |
| 217 Entry entry = BuildEntry(*dictionary); | 208 Entry entry = BuildEntry(*dictionary); |
| 218 if (catalog_.find(entry.name) == catalog_.end()) { | 209 if (catalog_.find(entry.name) == catalog_.end()) { |
| 219 catalog_[entry.name] = entry; | 210 catalog_[entry.name] = entry; |
| 220 | 211 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 266 } |
| 276 SerializeCatalog(); | 267 SerializeCatalog(); |
| 277 | 268 |
| 278 auto qualifier_iter = qualifiers_.find(name); | 269 auto qualifier_iter = qualifiers_.find(name); |
| 279 DCHECK(qualifier_iter != qualifiers_.end()); | 270 DCHECK(qualifier_iter != qualifiers_.end()); |
| 280 std::string qualifier = qualifier_iter->second; | 271 std::string qualifier = qualifier_iter->second; |
| 281 CompleteResolveMojoName(name, qualifier, callback); | 272 CompleteResolveMojoName(name, qualifier, callback); |
| 282 } | 273 } |
| 283 | 274 |
| 284 } // namespace catalog | 275 } // namespace catalog |
| OLD | NEW |