Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: mojo/services/catalog/catalog.cc

Issue 1828733004: Load application manifests from resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/task_runner_util.h" 9 #include "base/task_runner_util.h"
10 #include "base/thread_task_runner_handle.h"
10 #include "mojo/common/url_type_converters.h" 11 #include "mojo/common/url_type_converters.h"
11 #include "mojo/services/catalog/entry.h" 12 #include "mojo/services/catalog/entry.h"
12 #include "mojo/services/catalog/store.h" 13 #include "mojo/services/catalog/store.h"
13 #include "mojo/shell/public/cpp/names.h" 14 #include "mojo/shell/public/cpp/names.h"
14 #include "mojo/util/filename_util.h" 15 #include "mojo/util/filename_util.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 #include "url/url_util.h" 17 #include "url/url_util.h"
17 18
18 namespace catalog { 19 namespace catalog {
19 20
20 //////////////////////////////////////////////////////////////////////////////// 21 ////////////////////////////////////////////////////////////////////////////////
21 // Catalog, public: 22 // Catalog, public:
22 23
23 Catalog::Catalog(base::TaskRunner* blocking_pool, scoped_ptr<Store> store) 24 Catalog::Catalog(base::TaskRunner* blocking_pool,
24 : store_(std::move(store)), 25 scoped_ptr<Store> store,
26 Delegate* delegate)
27 : delegate_(delegate),
28 store_(std::move(store)),
25 weak_factory_(this) { 29 weak_factory_(this) {
26 PathService::Get(base::DIR_MODULE, &package_path_); 30 PathService::Get(base::DIR_MODULE, &package_path_);
27 reader_.reset(new Reader(package_path_, blocking_pool)); 31 reader_.reset(new Reader(package_path_, blocking_pool));
28 DeserializeCatalog(); 32 DeserializeCatalog();
29 } 33 }
30 34
31 Catalog::~Catalog() {} 35 Catalog::~Catalog() {}
32 36
33 void Catalog::BindResolver(mojom::ResolverRequest request) { 37 void Catalog::BindResolver(mojom::ResolverRequest request) {
34 resolver_bindings_.AddBinding(this, std::move(request)); 38 resolver_bindings_.AddBinding(this, std::move(request));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 resolved_name = alias_iter->second.first; 82 resolved_name = alias_iter->second.first;
79 83
80 std::string qualifier = mojo::GetNamePath(resolved_name); 84 std::string qualifier = mojo::GetNamePath(resolved_name);
81 auto qualifier_iter = qualifiers_.find(resolved_name); 85 auto qualifier_iter = qualifiers_.find(resolved_name);
82 if (qualifier_iter != qualifiers_.end()) 86 if (qualifier_iter != qualifiers_.end())
83 qualifier = qualifier_iter->second; 87 qualifier = qualifier_iter->second;
84 88
85 if (IsNameInCatalog(resolved_name)) { 89 if (IsNameInCatalog(resolved_name)) {
86 CompleteResolveMojoName(resolved_name, qualifier, callback); 90 CompleteResolveMojoName(resolved_name, qualifier, callback);
87 } else { 91 } else {
88 reader_->Read(resolved_name, 92 std::string manifest_contents;
89 base::Bind(&Catalog::OnReadEntry, weak_factory_.GetWeakPtr(), 93 if (delegate_ &&
90 resolved_name, callback)); 94 delegate_->GetApplicationManifest(resolved_name, &manifest_contents)) {
95 // We don't invoke the callback synchronously in this case to avoid
96 // surprising the caller with possible re-entry.
97 scoped_ptr<Entry> entry = reader_->Parse(manifest_contents);
98 base::ThreadTaskRunnerHandle::Get()->PostTask(
99 FROM_HERE,
100 base::Bind(&Catalog::OnReadEntry, weak_factory_.GetWeakPtr(),
101 resolved_name, callback, base::Passed(&entry)));
102 } else {
103 reader_->Read(
104 resolved_name,
105 base::Bind(&Catalog::OnReadEntry, weak_factory_.GetWeakPtr(),
106 resolved_name, callback));
107 }
91 } 108 }
92 } 109 }
93 110
94 //////////////////////////////////////////////////////////////////////////////// 111 ////////////////////////////////////////////////////////////////////////////////
95 // Catalog, mojom::Catalog: 112 // Catalog, mojom::Catalog:
96 113
97 void Catalog::GetEntries(mojo::Array<mojo::String> names, 114 void Catalog::GetEntries(mojo::Array<mojo::String> names,
98 const GetEntriesCallback& callback) { 115 const GetEntriesCallback& callback) {
99 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries; 116 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries;
100 std::vector<mojo::String> names_vec = names.PassStorage(); 117 std::vector<mojo::String> names_vec = names.PassStorage();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 227
211 SerializeCatalog(); 228 SerializeCatalog();
212 229
213 auto qualifier_iter = qualifiers_.find(name); 230 auto qualifier_iter = qualifiers_.find(name);
214 DCHECK(qualifier_iter != qualifiers_.end()); 231 DCHECK(qualifier_iter != qualifiers_.end());
215 std::string qualifier = qualifier_iter->second; 232 std::string qualifier = qualifier_iter->second;
216 CompleteResolveMojoName(name, qualifier, callback); 233 CompleteResolveMojoName(name, qualifier, callback);
217 } 234 }
218 235
219 } // namespace catalog 236 } // namespace catalog
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698