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/package_manager/package_manager.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" |
11 #include "mojo/common/url_type_converters.h" | 11 #include "mojo/common/url_type_converters.h" |
12 #include "mojo/shell/public/cpp/names.h" | 12 #include "mojo/shell/public/cpp/names.h" |
13 #include "mojo/util/filename_util.h" | 13 #include "mojo/util/filename_util.h" |
14 #include "net/base/filename_util.h" | 14 #include "net/base/filename_util.h" |
15 #include "url/url_util.h" | 15 #include "url/url_util.h" |
16 | 16 |
17 namespace package_manager { | 17 namespace catalog { |
18 namespace { | 18 namespace { |
19 | 19 |
20 CapabilityFilter BuildCapabilityFilterFromDictionary( | 20 CapabilityFilter BuildCapabilityFilterFromDictionary( |
21 const base::DictionaryValue& value) { | 21 const base::DictionaryValue& value) { |
22 CapabilityFilter filter; | 22 CapabilityFilter filter; |
23 base::DictionaryValue::Iterator it(value); | 23 base::DictionaryValue::Iterator it(value); |
24 for (; !it.IsAtEnd(); it.Advance()) { | 24 for (; !it.IsAtEnd(); it.Advance()) { |
25 const base::ListValue* values = nullptr; | 25 const base::ListValue* values = nullptr; |
26 CHECK(it.value().GetAsList(&values)); | 26 CHECK(it.value().GetAsList(&values)); |
27 AllowedInterfaces interfaces; | 27 AllowedInterfaces interfaces; |
28 for (auto i = values->begin(); i != values->end(); ++i) { | 28 for (auto i = values->begin(); i != values->end(); ++i) { |
29 std::string iface_name; | 29 std::string iface_name; |
30 const base::Value* v = *i; | 30 const base::Value* v = *i; |
31 CHECK(v->GetAsString(&iface_name)); | 31 CHECK(v->GetAsString(&iface_name)); |
32 interfaces.insert(iface_name); | 32 interfaces.insert(iface_name); |
33 } | 33 } |
34 filter[it.key()] = interfaces; | 34 filter[it.key()] = interfaces; |
35 } | 35 } |
36 return filter; | 36 return filter; |
37 } | 37 } |
38 | 38 |
39 ApplicationInfo BuildApplicationInfoFromDictionary( | 39 ApplicationInfo BuildApplicationInfoFromDictionary( |
40 const base::DictionaryValue& value) { | 40 const base::DictionaryValue& value) { |
41 ApplicationInfo info; | 41 ApplicationInfo info; |
42 std::string name_string; | 42 std::string name_string; |
43 CHECK(value.GetString(ApplicationCatalogStore::kNameKey, &name_string)); | 43 CHECK(value.GetString(Store::kNameKey, &name_string)); |
44 CHECK(mojo::IsValidName(name_string)) << "Invalid Name: " << name_string; | 44 CHECK(mojo::IsValidName(name_string)) << "Invalid Name: " << name_string; |
45 info.name = name_string; | 45 info.name = name_string; |
46 if (value.HasKey(ApplicationCatalogStore::kQualifierKey)) { | 46 if (value.HasKey(Store::kQualifierKey)) { |
47 CHECK(value.GetString(ApplicationCatalogStore::kQualifierKey, | 47 CHECK(value.GetString(Store::kQualifierKey, &info.qualifier)); |
48 &info.qualifier)); | |
49 } else { | 48 } else { |
50 info.qualifier = mojo::GetNamePath(name_string); | 49 info.qualifier = mojo::GetNamePath(name_string); |
51 } | 50 } |
52 CHECK(value.GetString(ApplicationCatalogStore::kDisplayNameKey, | 51 CHECK(value.GetString(Store::kDisplayNameKey, &info.display_name)); |
53 &info.display_name)); | |
54 const base::DictionaryValue* capabilities = nullptr; | 52 const base::DictionaryValue* capabilities = nullptr; |
55 CHECK(value.GetDictionary(ApplicationCatalogStore::kCapabilitiesKey, | 53 CHECK(value.GetDictionary(Store::kCapabilitiesKey, &capabilities)); |
56 &capabilities)); | |
57 info.base_filter = BuildCapabilityFilterFromDictionary(*capabilities); | 54 info.base_filter = BuildCapabilityFilterFromDictionary(*capabilities); |
58 return info; | 55 return info; |
59 } | 56 } |
60 | 57 |
61 void SerializeEntry(const ApplicationInfo& entry, | 58 void SerializeEntry(const ApplicationInfo& entry, |
62 base::DictionaryValue** value) { | 59 base::DictionaryValue** value) { |
63 *value = new base::DictionaryValue; | 60 *value = new base::DictionaryValue; |
64 (*value)->SetString(ApplicationCatalogStore::kNameKey, entry.name); | 61 (*value)->SetString(Store::kNameKey, entry.name); |
65 (*value)->SetString(ApplicationCatalogStore::kDisplayNameKey, | 62 (*value)->SetString(Store::kDisplayNameKey, entry.display_name); |
66 entry.display_name); | |
67 base::DictionaryValue* capabilities = new base::DictionaryValue; | 63 base::DictionaryValue* capabilities = new base::DictionaryValue; |
68 for (const auto& pair : entry.base_filter) { | 64 for (const auto& pair : entry.base_filter) { |
69 scoped_ptr<base::ListValue> interfaces(new base::ListValue); | 65 scoped_ptr<base::ListValue> interfaces(new base::ListValue); |
70 for (const auto& iface_name : pair.second) | 66 for (const auto& iface_name : pair.second) |
71 interfaces->AppendString(iface_name); | 67 interfaces->AppendString(iface_name); |
72 capabilities->Set(pair.first, std::move(interfaces)); | 68 capabilities->Set(pair.first, std::move(interfaces)); |
73 } | 69 } |
74 (*value)->Set(ApplicationCatalogStore::kCapabilitiesKey, | 70 (*value)->Set(Store::kCapabilitiesKey, make_scoped_ptr(capabilities)); |
75 make_scoped_ptr(capabilities)); | |
76 } | 71 } |
77 | 72 |
78 scoped_ptr<base::Value> ReadManifest(const base::FilePath& manifest_path) { | 73 scoped_ptr<base::Value> ReadManifest(const base::FilePath& manifest_path) { |
79 JSONFileValueDeserializer deserializer(manifest_path); | 74 JSONFileValueDeserializer deserializer(manifest_path); |
80 int error = 0; | 75 int error = 0; |
81 std::string message; | 76 std::string message; |
82 // TODO(beng): probably want to do more detailed error checking. This should | 77 // TODO(beng): probably want to do more detailed error checking. This should |
83 // be done when figuring out if to unblock connection completion. | 78 // be done when figuring out if to unblock connection completion. |
84 return deserializer.Deserialize(&error, &message); | 79 return deserializer.Deserialize(&error, &message); |
85 } | 80 } |
86 | 81 |
87 } // namespace | 82 } // namespace |
88 | 83 |
89 // static | 84 // static |
90 const char ApplicationCatalogStore::kNameKey[] = "name"; | 85 const char Store::kNameKey[] = "name"; |
91 // static | 86 // static |
92 const char ApplicationCatalogStore::kQualifierKey[] = "process-group"; | 87 const char Store::kQualifierKey[] = "process-group"; |
93 // static | 88 // static |
94 const char ApplicationCatalogStore::kDisplayNameKey[] = "display_name"; | 89 const char Store::kDisplayNameKey[] = "display_name"; |
95 // static | 90 // static |
96 const char ApplicationCatalogStore::kCapabilitiesKey[] = "capabilities"; | 91 const char Store::kCapabilitiesKey[] = "capabilities"; |
97 | 92 |
98 ApplicationInfo::ApplicationInfo() {} | 93 ApplicationInfo::ApplicationInfo() {} |
99 ApplicationInfo::ApplicationInfo(const ApplicationInfo& other) = default; | 94 ApplicationInfo::ApplicationInfo(const ApplicationInfo& other) = default; |
100 ApplicationInfo::~ApplicationInfo() {} | 95 ApplicationInfo::~ApplicationInfo() {} |
101 | 96 |
102 PackageManager::PackageManager(base::TaskRunner* blocking_pool, | 97 Catalog::Catalog(base::TaskRunner* blocking_pool, |
103 scoped_ptr<ApplicationCatalogStore> catalog) | 98 scoped_ptr<Store> catalog) |
104 : blocking_pool_(blocking_pool), | 99 : blocking_pool_(blocking_pool), |
105 catalog_store_(std::move(catalog)), | 100 store_(std::move(catalog)), |
106 weak_factory_(this) { | 101 weak_factory_(this) { |
107 base::FilePath shell_dir; | 102 base::FilePath shell_dir; |
108 PathService::Get(base::DIR_MODULE, &shell_dir); | 103 PathService::Get(base::DIR_MODULE, &shell_dir); |
109 | 104 |
110 system_package_dir_ = | 105 system_package_dir_ = |
111 mojo::util::FilePathToFileURL(shell_dir).Resolve(std::string()); | 106 mojo::util::FilePathToFileURL(shell_dir).Resolve(std::string()); |
112 system_package_dir_ = | 107 system_package_dir_ = |
113 mojo::util::AddTrailingSlashIfNeeded(system_package_dir_); | 108 mojo::util::AddTrailingSlashIfNeeded(system_package_dir_); |
114 | 109 |
115 DeserializeCatalog(); | 110 DeserializeCatalog(); |
116 } | 111 } |
117 PackageManager::~PackageManager() {} | 112 Catalog::~Catalog() {} |
118 | 113 |
119 bool PackageManager::AcceptConnection(mojo::Connection* connection) { | 114 bool Catalog::AcceptConnection(mojo::Connection* connection) { |
120 connection->AddInterface<mojom::Catalog>(this); | 115 connection->AddInterface<mojom::Catalog>(this); |
121 connection->AddInterface<mojom::Resolver>(this); | 116 connection->AddInterface<mojom::Resolver>(this); |
122 if (connection->GetRemoteIdentity().name() == "mojo:shell") | 117 if (connection->GetRemoteIdentity().name() == "mojo:shell") |
123 connection->AddInterface<mojo::shell::mojom::ShellResolver>(this); | 118 connection->AddInterface<mojo::shell::mojom::ShellResolver>(this); |
124 return true; | 119 return true; |
125 } | 120 } |
126 | 121 |
127 void PackageManager::Create(mojo::Connection* connection, | 122 void Catalog::Create(mojo::Connection* connection, |
128 mojom::ResolverRequest request) { | 123 mojom::ResolverRequest request) { |
129 resolver_bindings_.AddBinding(this, std::move(request)); | 124 resolver_bindings_.AddBinding(this, std::move(request)); |
130 } | 125 } |
131 | 126 |
132 void PackageManager::Create(mojo::Connection* connection, | 127 void Catalog::Create(mojo::Connection* connection, |
133 mojo::shell::mojom::ShellResolverRequest request) { | 128 mojo::shell::mojom::ShellResolverRequest request) { |
134 shell_resolver_bindings_.AddBinding(this, std::move(request)); | 129 shell_resolver_bindings_.AddBinding(this, std::move(request)); |
135 } | 130 } |
136 | 131 |
137 void PackageManager::Create(mojo::Connection* connection, | 132 void Catalog::Create(mojo::Connection* connection, |
138 mojom::CatalogRequest request) { | 133 mojom::CatalogRequest request) { |
139 catalog_bindings_.AddBinding(this, std::move(request)); | 134 catalog_bindings_.AddBinding(this, std::move(request)); |
140 } | 135 } |
141 | 136 |
142 void PackageManager::ResolveResponse(mojo::URLResponsePtr response, | 137 void Catalog::ResolveResponse(mojo::URLResponsePtr response, |
143 const ResolveResponseCallback& callback) { | 138 const ResolveResponseCallback& callback) { |
144 // TODO(beng): implement. | 139 // TODO(beng): implement. |
145 } | 140 } |
146 | 141 |
147 void PackageManager::ResolveInterfaces( | 142 void Catalog::ResolveInterfaces(mojo::Array<mojo::String> interfaces, |
148 mojo::Array<mojo::String> interfaces, | 143 const ResolveInterfacesCallback& callback) { |
149 const ResolveInterfacesCallback& callback) { | |
150 // TODO(beng): implement. | 144 // TODO(beng): implement. |
151 } | 145 } |
152 | 146 |
153 void PackageManager::ResolveMIMEType(const mojo::String& mime_type, | 147 void Catalog::ResolveMIMEType(const mojo::String& mime_type, |
154 const ResolveMIMETypeCallback& callback) { | 148 const ResolveMIMETypeCallback& callback) { |
155 // TODO(beng): implement. | 149 // TODO(beng): implement. |
156 } | 150 } |
157 | 151 |
158 void PackageManager::ResolveProtocolScheme( | 152 void Catalog::ResolveProtocolScheme( |
159 const mojo::String& scheme, | 153 const mojo::String& scheme, |
160 const ResolveProtocolSchemeCallback& callback) { | 154 const ResolveProtocolSchemeCallback& callback) { |
161 // TODO(beng): implement. | 155 // TODO(beng): implement. |
162 } | 156 } |
163 | 157 |
164 void PackageManager::ResolveMojoName(const mojo::String& mojo_name, | 158 void Catalog::ResolveMojoName(const mojo::String& mojo_name, |
165 const ResolveMojoNameCallback& callback) { | 159 const ResolveMojoNameCallback& callback) { |
166 std::string resolved_name = mojo_name; | 160 std::string resolved_name = mojo_name; |
167 auto alias_iter = mojo_name_aliases_.find(resolved_name); | 161 auto alias_iter = mojo_name_aliases_.find(resolved_name); |
168 if (alias_iter != mojo_name_aliases_.end()) | 162 if (alias_iter != mojo_name_aliases_.end()) |
169 resolved_name = alias_iter->second.first; | 163 resolved_name = alias_iter->second.first; |
170 | 164 |
171 std::string qualifier = mojo::GetNamePath(resolved_name); | 165 std::string qualifier = mojo::GetNamePath(resolved_name); |
172 auto qualifier_iter = qualifiers_.find(resolved_name); | 166 auto qualifier_iter = qualifiers_.find(resolved_name); |
173 if (qualifier_iter != qualifiers_.end()) | 167 if (qualifier_iter != qualifiers_.end()) |
174 qualifier = qualifier_iter->second; | 168 qualifier = qualifier_iter->second; |
175 | 169 |
176 if (IsNameInCatalog(resolved_name)) | 170 if (IsNameInCatalog(resolved_name)) |
177 CompleteResolveMojoName(resolved_name, qualifier, callback); | 171 CompleteResolveMojoName(resolved_name, qualifier, callback); |
178 else | 172 else |
179 AddNameToCatalog(resolved_name, callback); | 173 AddNameToCatalog(resolved_name, callback); |
180 } | 174 } |
181 | 175 |
182 void PackageManager::GetEntries( | 176 void Catalog::GetEntries(mojo::Array<mojo::String> names, |
183 mojo::Array<mojo::String> names, | 177 const GetEntriesCallback& callback) { |
184 const GetEntriesCallback& callback) { | |
185 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries; | 178 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries; |
186 std::vector<mojo::String> names_vec = names.PassStorage(); | 179 std::vector<mojo::String> names_vec = names.PassStorage(); |
187 for (const std::string& name : names_vec) { | 180 for (const std::string& name : names_vec) { |
188 if (catalog_.find(name) == catalog_.end()) | 181 if (catalog_.find(name) == catalog_.end()) |
189 continue; | 182 continue; |
190 const ApplicationInfo& info = catalog_[name]; | 183 const ApplicationInfo& info = catalog_[name]; |
191 mojom::CatalogEntryPtr entry(mojom::CatalogEntry::New()); | 184 mojom::CatalogEntryPtr entry(mojom::CatalogEntry::New()); |
192 entry->display_name = info.display_name; | 185 entry->display_name = info.display_name; |
193 entries[info.name] = std::move(entry); | 186 entries[info.name] = std::move(entry); |
194 } | 187 } |
195 callback.Run(std::move(entries)); | 188 callback.Run(std::move(entries)); |
196 } | 189 } |
197 | 190 |
198 void PackageManager::CompleteResolveMojoName( | 191 void Catalog::CompleteResolveMojoName( |
199 const std::string& resolved_name, | 192 const std::string& resolved_name, |
200 const std::string& qualifier, | 193 const std::string& qualifier, |
201 const ResolveMojoNameCallback& callback) { | 194 const ResolveMojoNameCallback& callback) { |
202 auto info_iter = catalog_.find(resolved_name); | 195 auto info_iter = catalog_.find(resolved_name); |
203 CHECK(info_iter != catalog_.end()); | 196 CHECK(info_iter != catalog_.end()); |
204 | 197 |
205 GURL file_url; | 198 GURL file_url; |
206 std::string type = mojo::GetNameType(resolved_name); | 199 std::string type = mojo::GetNameType(resolved_name); |
207 if (type == "mojo") { | 200 if (type == "mojo") { |
208 // It's still a mojo: URL, use the default mapping scheme. | 201 // It's still a mojo: URL, use the default mapping scheme. |
(...skipping 15 matching lines...) Expand all Loading... |
224 for (const auto& entry : info_iter->second.base_filter) { | 217 for (const auto& entry : info_iter->second.base_filter) { |
225 mojo::Array<mojo::String> interfaces; | 218 mojo::Array<mojo::String> interfaces; |
226 for (auto interface_name : entry.second) | 219 for (auto interface_name : entry.second) |
227 interfaces.push_back(interface_name); | 220 interfaces.push_back(interface_name); |
228 filter->filter.insert(entry.first, std::move(interfaces)); | 221 filter->filter.insert(entry.first, std::move(interfaces)); |
229 } | 222 } |
230 callback.Run(resolved_name, qualifier, std::move(filter), | 223 callback.Run(resolved_name, qualifier, std::move(filter), |
231 file_url.spec()); | 224 file_url.spec()); |
232 } | 225 } |
233 | 226 |
234 bool PackageManager::IsNameInCatalog(const std::string& name) const { | 227 bool Catalog::IsNameInCatalog(const std::string& name) const { |
235 return catalog_.find(name) != catalog_.end(); | 228 return catalog_.find(name) != catalog_.end(); |
236 } | 229 } |
237 | 230 |
238 void PackageManager::AddNameToCatalog( | 231 void Catalog::AddNameToCatalog(const std::string& name, |
239 const std::string& name, | 232 const ResolveMojoNameCallback& callback) { |
240 const ResolveMojoNameCallback& callback) { | |
241 GURL manifest_url = GetManifestURL(name); | 233 GURL manifest_url = GetManifestURL(name); |
242 if (manifest_url.is_empty()) { | 234 if (manifest_url.is_empty()) { |
243 // The name is of some form that can't be resolved to a manifest (e.g. some | 235 // The name is of some form that can't be resolved to a manifest (e.g. some |
244 // scheme used for tests). Just pass it back to the caller so it can be | 236 // scheme used for tests). Just pass it back to the caller so it can be |
245 // loaded with a custom loader. | 237 // loaded with a custom loader. |
246 callback.Run(name, mojo::GetNamePath(name), nullptr, nullptr); | 238 callback.Run(name, mojo::GetNamePath(name), nullptr, nullptr); |
247 return; | 239 return; |
248 } | 240 } |
249 | 241 |
250 std::string type = mojo::GetNameType(name); | 242 std::string type = mojo::GetNameType(name); |
251 CHECK(type == "mojo" || type == "exe"); | 243 CHECK(type == "mojo" || type == "exe"); |
252 base::FilePath manifest_path; | 244 base::FilePath manifest_path; |
253 CHECK(net::FileURLToFilePath(manifest_url, &manifest_path)); | 245 CHECK(net::FileURLToFilePath(manifest_url, &manifest_path)); |
254 base::PostTaskAndReplyWithResult( | 246 base::PostTaskAndReplyWithResult( |
255 blocking_pool_, FROM_HERE, base::Bind(&ReadManifest, manifest_path), | 247 blocking_pool_, FROM_HERE, base::Bind(&ReadManifest, manifest_path), |
256 base::Bind(&PackageManager::OnReadManifest, weak_factory_.GetWeakPtr(), | 248 base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(), |
257 name, callback)); | 249 name, callback)); |
258 } | 250 } |
259 | 251 |
260 void PackageManager::DeserializeCatalog() { | 252 void Catalog::DeserializeCatalog() { |
261 if (!catalog_store_) | 253 if (!store_) |
262 return; | 254 return; |
263 const base::ListValue* catalog = catalog_store_->GetStore(); | 255 const base::ListValue* catalog = store_->GetStore(); |
264 CHECK(catalog); | 256 CHECK(catalog); |
265 // TODO(sky): make this handle aliases. | 257 // TODO(sky): make this handle aliases. |
266 for (auto it = catalog->begin(); it != catalog->end(); ++it) { | 258 for (auto it = catalog->begin(); it != catalog->end(); ++it) { |
267 const base::DictionaryValue* dictionary = nullptr; | 259 const base::DictionaryValue* dictionary = nullptr; |
268 const base::Value* v = *it; | 260 const base::Value* v = *it; |
269 CHECK(v->GetAsDictionary(&dictionary)); | 261 CHECK(v->GetAsDictionary(&dictionary)); |
270 const ApplicationInfo app_info = | 262 const ApplicationInfo app_info = |
271 BuildApplicationInfoFromDictionary(*dictionary); | 263 BuildApplicationInfoFromDictionary(*dictionary); |
272 catalog_[app_info.name] = app_info; | 264 catalog_[app_info.name] = app_info; |
273 } | 265 } |
274 } | 266 } |
275 | 267 |
276 void PackageManager::SerializeCatalog() { | 268 void Catalog::SerializeCatalog() { |
277 scoped_ptr<base::ListValue> catalog(new base::ListValue); | 269 scoped_ptr<base::ListValue> catalog(new base::ListValue); |
278 for (const auto& info : catalog_) { | 270 for (const auto& info : catalog_) { |
279 base::DictionaryValue* dictionary = nullptr; | 271 base::DictionaryValue* dictionary = nullptr; |
280 SerializeEntry(info.second, &dictionary); | 272 SerializeEntry(info.second, &dictionary); |
281 catalog->Append(make_scoped_ptr(dictionary)); | 273 catalog->Append(make_scoped_ptr(dictionary)); |
282 } | 274 } |
283 if (catalog_store_) | 275 if (store_) |
284 catalog_store_->UpdateStore(std::move(catalog)); | 276 store_->UpdateStore(std::move(catalog)); |
285 } | 277 } |
286 | 278 |
287 const ApplicationInfo& PackageManager::DeserializeApplication( | 279 const ApplicationInfo& Catalog::DeserializeApplication( |
288 const base::DictionaryValue* dictionary) { | 280 const base::DictionaryValue* dictionary) { |
289 ApplicationInfo info = BuildApplicationInfoFromDictionary(*dictionary); | 281 ApplicationInfo info = BuildApplicationInfoFromDictionary(*dictionary); |
290 if (catalog_.find(info.name) == catalog_.end()) { | 282 if (catalog_.find(info.name) == catalog_.end()) { |
291 catalog_[info.name] = info; | 283 catalog_[info.name] = info; |
292 | 284 |
293 if (dictionary->HasKey("applications")) { | 285 if (dictionary->HasKey("applications")) { |
294 const base::ListValue* applications = nullptr; | 286 const base::ListValue* applications = nullptr; |
295 dictionary->GetList("applications", &applications); | 287 dictionary->GetList("applications", &applications); |
296 for (size_t i = 0; i < applications->GetSize(); ++i) { | 288 for (size_t i = 0; i < applications->GetSize(); ++i) { |
297 const base::DictionaryValue* child = nullptr; | 289 const base::DictionaryValue* child = nullptr; |
298 applications->GetDictionary(i, &child); | 290 applications->GetDictionary(i, &child); |
299 const ApplicationInfo& child_info = DeserializeApplication(child); | 291 const ApplicationInfo& child_info = DeserializeApplication(child); |
300 mojo_name_aliases_[child_info.name] = | 292 mojo_name_aliases_[child_info.name] = |
301 std::make_pair(info.name, child_info.qualifier); | 293 std::make_pair(info.name, child_info.qualifier); |
302 } | 294 } |
303 } | 295 } |
304 qualifiers_[info.name] = info.qualifier; | 296 qualifiers_[info.name] = info.qualifier; |
305 } | 297 } |
306 return catalog_[info.name]; | 298 return catalog_[info.name]; |
307 } | 299 } |
308 | 300 |
309 GURL PackageManager::GetManifestURL(const std::string& name) { | 301 GURL Catalog::GetManifestURL(const std::string& name) { |
310 // TODO(beng): think more about how this should be done for exe targets. | 302 // TODO(beng): think more about how this should be done for exe targets. |
311 std::string type = mojo::GetNameType(name); | 303 std::string type = mojo::GetNameType(name); |
312 std::string path = mojo::GetNamePath(name); | 304 std::string path = mojo::GetNamePath(name); |
313 if (type == "mojo") | 305 if (type == "mojo") |
314 return system_package_dir_.Resolve(path + "/manifest.json"); | 306 return system_package_dir_.Resolve(path + "/manifest.json"); |
315 else if (type == "exe") | 307 else if (type == "exe") |
316 return system_package_dir_.Resolve(path + "_manifest.json"); | 308 return system_package_dir_.Resolve(path + "_manifest.json"); |
317 return GURL(); | 309 return GURL(); |
318 } | 310 } |
319 | 311 |
320 // static | 312 // static |
321 void PackageManager::OnReadManifest(base::WeakPtr<PackageManager> pm, | 313 void Catalog::OnReadManifest(base::WeakPtr<Catalog> catalog, |
322 const std::string& name, | 314 const std::string& name, |
323 const ResolveMojoNameCallback& callback, | 315 const ResolveMojoNameCallback& callback, |
324 scoped_ptr<base::Value> manifest) { | 316 scoped_ptr<base::Value> manifest) { |
325 if (!pm) { | 317 if (!catalog) { |
326 // The PackageManager was destroyed, we're likely in shutdown. Run the | 318 // The Catalog was destroyed, we're likely in shutdown. Run the |
327 // callback so we don't trigger a DCHECK. | 319 // callback so we don't trigger a DCHECK. |
328 callback.Run(name, mojo::GetNamePath(name), nullptr, nullptr); | 320 callback.Run(name, mojo::GetNamePath(name), nullptr, nullptr); |
329 return; | 321 return; |
330 } | 322 } |
331 pm->OnReadManifestImpl(name, callback, std::move(manifest)); | 323 catalog->OnReadManifestImpl(name, callback, std::move(manifest)); |
332 } | 324 } |
333 | 325 |
334 void PackageManager::OnReadManifestImpl(const std::string& name, | 326 void Catalog::OnReadManifestImpl(const std::string& name, |
335 const ResolveMojoNameCallback& callback, | 327 const ResolveMojoNameCallback& callback, |
336 scoped_ptr<base::Value> manifest) { | 328 scoped_ptr<base::Value> manifest) { |
337 if (manifest) { | 329 if (manifest) { |
338 base::DictionaryValue* dictionary = nullptr; | 330 base::DictionaryValue* dictionary = nullptr; |
339 CHECK(manifest->GetAsDictionary(&dictionary)); | 331 CHECK(manifest->GetAsDictionary(&dictionary)); |
340 DeserializeApplication(dictionary); | 332 DeserializeApplication(dictionary); |
341 } else { | 333 } else { |
342 ApplicationInfo info; | 334 ApplicationInfo info; |
343 info.name = name; | 335 info.name = name; |
344 info.display_name = name; | 336 info.display_name = name; |
345 catalog_[info.name] = info; | 337 catalog_[info.name] = info; |
346 qualifiers_[info.name] = mojo::GetNamePath(name); | 338 qualifiers_[info.name] = mojo::GetNamePath(name); |
347 } | 339 } |
348 SerializeCatalog(); | 340 SerializeCatalog(); |
349 | 341 |
350 auto qualifier_iter = qualifiers_.find(name); | 342 auto qualifier_iter = qualifiers_.find(name); |
351 DCHECK(qualifier_iter != qualifiers_.end()); | 343 DCHECK(qualifier_iter != qualifiers_.end()); |
352 std::string qualifier = qualifier_iter->second; | 344 std::string qualifier = qualifier_iter->second; |
353 CompleteResolveMojoName(name, qualifier, callback); | 345 CompleteResolveMojoName(name, qualifier, callback); |
354 } | 346 } |
355 | 347 |
356 } // namespace package_manager | 348 } // namespace catalog |
OLD | NEW |