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