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/json/json_reader.h" |
9 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
10 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 12 #include "base/thread_task_runner_handle.h" |
11 #include "mojo/common/url_type_converters.h" | 13 #include "mojo/common/url_type_converters.h" |
12 #include "mojo/services/catalog/entry.h" | 14 #include "mojo/services/catalog/entry.h" |
13 #include "mojo/services/catalog/store.h" | 15 #include "mojo/services/catalog/store.h" |
14 #include "mojo/shell/public/cpp/names.h" | 16 #include "mojo/shell/public/cpp/names.h" |
15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
16 #include "url/url_util.h" | 18 #include "url/url_util.h" |
17 | 19 |
18 namespace catalog { | 20 namespace catalog { |
19 namespace { | 21 namespace { |
20 | 22 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 66 } |
65 | 67 |
66 } // namespace | 68 } // namespace |
67 | 69 |
68 ReadManifestResult::ReadManifestResult() {} | 70 ReadManifestResult::ReadManifestResult() {} |
69 ReadManifestResult::~ReadManifestResult() {} | 71 ReadManifestResult::~ReadManifestResult() {} |
70 | 72 |
71 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
72 // Catalog, public: | 74 // Catalog, public: |
73 | 75 |
74 Catalog::Catalog(scoped_ptr<Store> store, base::TaskRunner* file_task_runner) | 76 Catalog::Catalog(scoped_ptr<Store> store, |
75 : store_(std::move(store)), | 77 base::TaskRunner* file_task_runner, |
| 78 Delegate* delegate) |
| 79 : delegate_(delegate), |
| 80 store_(std::move(store)), |
76 file_task_runner_(file_task_runner), | 81 file_task_runner_(file_task_runner), |
77 weak_factory_(this) { | 82 weak_factory_(this) { |
78 PathService::Get(base::DIR_MODULE, &system_package_dir_); | 83 PathService::Get(base::DIR_MODULE, &system_package_dir_); |
79 DeserializeCatalog(); | 84 DeserializeCatalog(); |
80 } | 85 } |
81 | 86 |
82 Catalog::~Catalog() {} | 87 Catalog::~Catalog() {} |
83 | 88 |
84 void Catalog::BindResolver(mojom::ResolverRequest request) { | 89 void Catalog::BindResolver(mojom::ResolverRequest request) { |
85 resolver_bindings_.AddBinding(this, std::move(request)); | 90 resolver_bindings_.AddBinding(this, std::move(request)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 if (type != "mojo" && type != "exe") { | 132 if (type != "mojo" && type != "exe") { |
128 scoped_ptr<Entry> entry(new Entry(mojo_name)); | 133 scoped_ptr<Entry> entry(new Entry(mojo_name)); |
129 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry)); | 134 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry)); |
130 return; | 135 return; |
131 } | 136 } |
132 | 137 |
133 auto entry = catalog_.find(mojo_name); | 138 auto entry = catalog_.find(mojo_name); |
134 if (entry != catalog_.end()) { | 139 if (entry != catalog_.end()) { |
135 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry->second)); | 140 callback.Run(mojo::shell::mojom::ResolveResult::From(*entry->second)); |
136 } else { | 141 } else { |
137 base::PostTaskAndReplyWithResult( | 142 std::string manifest_contents; |
138 file_task_runner_, FROM_HERE, | 143 if (delegate_ && |
139 base::Bind(&ReadManifest, system_package_dir_, mojo_name), | 144 delegate_->GetApplicationManifest(mojo_name.To<std::string>(), |
140 base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(), | 145 &manifest_contents)) { |
141 mojo_name, callback)); | 146 // We don't invoke the callback synchronously in this case to avoid |
| 147 // surprising the caller with possible re-entry. |
| 148 scoped_ptr<ReadManifestResult> result(new ReadManifestResult); |
| 149 result->manifest_root = base::JSONReader::Read(manifest_contents); |
| 150 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 151 FROM_HERE, |
| 152 base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(), |
| 153 mojo_name, callback, base::Passed(&result))); |
| 154 } else { |
| 155 base::PostTaskAndReplyWithResult( |
| 156 file_task_runner_, FROM_HERE, |
| 157 base::Bind(&ReadManifest, system_package_dir_, mojo_name), |
| 158 base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(), |
| 159 mojo_name, callback)); |
| 160 } |
142 } | 161 } |
143 } | 162 } |
144 | 163 |
145 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
146 // Catalog, mojom::Catalog: | 165 // Catalog, mojom::Catalog: |
147 | 166 |
148 void Catalog::GetEntries(mojo::Array<mojo::String> names, | 167 void Catalog::GetEntries(mojo::Array<mojo::String> names, |
149 const GetEntriesCallback& callback) { | 168 const GetEntriesCallback& callback) { |
150 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries; | 169 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries; |
151 std::vector<mojo::String> names_vec = names.PassStorage(); | 170 std::vector<mojo::String> names_vec = names.PassStorage(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 DCHECK(entry); | 228 DCHECK(entry); |
210 if (catalog_.end() != catalog_.find(entry->name())) | 229 if (catalog_.end() != catalog_.find(entry->name())) |
211 return; | 230 return; |
212 for (auto child : entry->applications()) | 231 for (auto child : entry->applications()) |
213 AddEntryToCatalog(make_scoped_ptr(child)); | 232 AddEntryToCatalog(make_scoped_ptr(child)); |
214 catalog_[entry->name()] = std::move(entry); | 233 catalog_[entry->name()] = std::move(entry); |
215 SerializeCatalog(); | 234 SerializeCatalog(); |
216 } | 235 } |
217 | 236 |
218 } // namespace catalog | 237 } // namespace catalog |
OLD | NEW |