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

Unified Diff: mojo/services/catalog/reader.h

Issue 1821383002: Moves manifest parsing to a new class, Reader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@60catref
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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/catalog/reader.h
diff --git a/mojo/services/catalog/reader.h b/mojo/services/catalog/reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..6255c7b85b281836eb88718aa63babb83b36da37
--- /dev/null
+++ b/mojo/services/catalog/reader.h
@@ -0,0 +1,63 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SERVICES_CATALOG_READER_H_
+#define MOJO_SERVICES_CATALOG_READER_H_
+
+#include "base/callback.h"
+#include "base/files/file_path.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/values.h"
+
+namespace base {
+class TaskRunner;
+}
+
+namespace catalog {
+
+class Entry;
+
+// Encapsulates manifest reading.
+class Reader {
+ public:
+ using ReadManifestCallback =
+ base::Callback<void(scoped_ptr<Entry> entry)>;
+
+ // Loads manifests relative to |package_path|. Performs file operations on
+ // |file_task_runner|.
+ Reader(const base::FilePath& package_path,
+ base::TaskRunner* file_task_runner);
+ ~Reader();
+
+ // Attempts to load a manifest for |name|, and returns an Entry built from the
+ // metadata it contains via |callback|.
+ void Read(const std::string& name,
+ const ReadManifestCallback& callback);
+
+ private:
+ // Construct a manifest path for the application named |name| within
+ // |package_path_|.
+ base::FilePath GetManifestPath(const std::string& name) const;
+
+ // Callback from the manifest JSON deserialize operation performed on
+ // |file_task_runner_|.
+ static void OnReadManifest(base::WeakPtr<Reader> reader,
+ const std::string& name,
+ const ReadManifestCallback& callback,
+ scoped_ptr<base::Value> manifest);
+ void OnReadManifestImpl(const ReadManifestCallback& callback,
+ scoped_ptr<base::Value> manifest);
+
+ base::FilePath package_path_;
+ base::TaskRunner* file_task_runner_;
+ base::WeakPtrFactory<Reader> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(Reader);
+};
+
+} // namespace catalog
+
+#endif // MOJO_SERVICES_CATALOG_READER_H_

Powered by Google App Engine
This is Rietveld 408576698