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

Unified 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: rebase 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/catalog/catalog.cc
diff --git a/mojo/services/catalog/catalog.cc b/mojo/services/catalog/catalog.cc
index bb7285765e19996cf3ef0f11a0fe6eea9a8f30b5..a772ba61011f90ad953965d6c541b0397bd8efa4 100644
--- a/mojo/services/catalog/catalog.cc
+++ b/mojo/services/catalog/catalog.cc
@@ -6,8 +6,10 @@
#include "base/bind.h"
#include "base/json/json_file_value_serializer.h"
+#include "base/json/json_reader.h"
#include "base/strings/string_split.h"
#include "base/task_runner_util.h"
+#include "base/thread_task_runner_handle.h"
#include "mojo/common/url_type_converters.h"
#include "mojo/services/catalog/entry.h"
#include "mojo/services/catalog/store.h"
@@ -71,8 +73,11 @@ ReadManifestResult::~ReadManifestResult() {}
////////////////////////////////////////////////////////////////////////////////
// Catalog, public:
-Catalog::Catalog(scoped_ptr<Store> store, base::TaskRunner* file_task_runner)
- : store_(std::move(store)),
+Catalog::Catalog(scoped_ptr<Store> store,
+ base::TaskRunner* file_task_runner,
+ Delegate* delegate)
+ : delegate_(delegate),
+ store_(std::move(store)),
file_task_runner_(file_task_runner),
weak_factory_(this) {
PathService::Get(base::DIR_MODULE, &system_package_dir_);
@@ -134,11 +139,25 @@ void Catalog::ResolveMojoName(const mojo::String& mojo_name,
if (entry != catalog_.end()) {
callback.Run(mojo::shell::mojom::ResolveResult::From(*entry->second));
} else {
- base::PostTaskAndReplyWithResult(
- file_task_runner_, FROM_HERE,
- base::Bind(&ReadManifest, system_package_dir_, mojo_name),
- base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(),
- mojo_name, callback));
+ std::string manifest_contents;
+ if (delegate_ &&
+ delegate_->GetApplicationManifest(mojo_name.To<std::string>(),
+ &manifest_contents)) {
+ // We don't invoke the callback synchronously in this case to avoid
+ // surprising the caller with possible re-entry.
+ scoped_ptr<ReadManifestResult> result(new ReadManifestResult);
+ result->manifest_root = base::JSONReader::Read(manifest_contents);
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(),
+ mojo_name, callback, base::Passed(&result)));
+ } else {
+ base::PostTaskAndReplyWithResult(
+ file_task_runner_, FROM_HERE,
+ base::Bind(&ReadManifest, system_package_dir_, mojo_name),
+ base::Bind(&Catalog::OnReadManifest, weak_factory_.GetWeakPtr(),
+ mojo_name, callback));
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698