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 #ifndef MOJO_SERVICES_CATALOG_READER_H_ | 5 #ifndef MOJO_SERVICES_CATALOG_READER_H_ |
6 #define MOJO_SERVICES_CATALOG_READER_H_ | 6 #define MOJO_SERVICES_CATALOG_READER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string_piece.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class TaskRunner; | 17 class TaskRunner; |
17 } | 18 } |
18 | 19 |
19 namespace catalog { | 20 namespace catalog { |
20 | 21 |
21 class Entry; | 22 class Entry; |
22 | 23 |
23 // Encapsulates manifest reading. | 24 // Encapsulates manifest reading. |
24 class Reader { | 25 class Reader { |
25 public: | 26 public: |
26 using ReadManifestCallback = | 27 using ReadManifestCallback = |
27 base::Callback<void(scoped_ptr<Entry> entry)>; | 28 base::Callback<void(scoped_ptr<Entry> entry)>; |
28 | 29 |
29 // Loads manifests relative to |package_path|. Performs file operations on | 30 // Loads manifests relative to |package_path|. Performs file operations on |
30 // |file_task_runner|. | 31 // |file_task_runner|. |
31 Reader(const base::FilePath& package_path, | 32 Reader(const base::FilePath& package_path, |
32 base::TaskRunner* file_task_runner); | 33 base::TaskRunner* file_task_runner); |
33 ~Reader(); | 34 ~Reader(); |
34 | 35 |
35 // Attempts to load a manifest for |name|, and returns an Entry built from the | 36 // Attempts to load a manifest for |name|, and returns an Entry built from the |
36 // metadata it contains via |callback|. | 37 // metadata it contains via |callback|. |
37 void Read(const std::string& name, | 38 void Read(const std::string& name, |
38 const ReadManifestCallback& callback); | 39 const ReadManifestCallback& callback); |
39 | 40 |
| 41 // Parses manifest contents and returns an Entry built from the metadata it |
| 42 // contains. |
| 43 scoped_ptr<Entry> Parse(const base::StringPiece& manifest_contents); |
| 44 |
40 private: | 45 private: |
41 // Construct a manifest path for the application named |name| within | 46 // Construct a manifest path for the application named |name| within |
42 // |package_path_|. | 47 // |package_path_|. |
43 base::FilePath GetManifestPath(const std::string& name) const; | 48 base::FilePath GetManifestPath(const std::string& name) const; |
44 | 49 |
45 base::FilePath package_path_; | 50 base::FilePath package_path_; |
46 base::TaskRunner* file_task_runner_; | 51 base::TaskRunner* file_task_runner_; |
47 base::WeakPtrFactory<Reader> weak_factory_; | 52 base::WeakPtrFactory<Reader> weak_factory_; |
48 | 53 |
49 DISALLOW_COPY_AND_ASSIGN(Reader); | 54 DISALLOW_COPY_AND_ASSIGN(Reader); |
50 }; | 55 }; |
51 | 56 |
52 } // namespace catalog | 57 } // namespace catalog |
53 | 58 |
54 #endif // MOJO_SERVICES_CATALOG_READER_H_ | 59 #endif // MOJO_SERVICES_CATALOG_READER_H_ |
OLD | NEW |