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