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_CATALOG_H_ | 5 #ifndef MOJO_SERVICES_CATALOG_CATALOG_H_ |
6 #define MOJO_SERVICES_CATALOG_CATALOG_H_ | 6 #define MOJO_SERVICES_CATALOG_CATALOG_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "mojo/public/cpp/bindings/binding_set.h" | 12 #include "mojo/public/cpp/bindings/binding_set.h" |
13 #include "mojo/services/catalog/entry.h" | 13 #include "mojo/services/catalog/entry.h" |
14 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h" | 14 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h" |
15 #include "mojo/services/catalog/public/interfaces/resolver.mojom.h" | 15 #include "mojo/services/catalog/public/interfaces/resolver.mojom.h" |
16 #include "mojo/services/catalog/store.h" | 16 #include "mojo/services/catalog/store.h" |
| 17 #include "mojo/services/catalog/types.h" |
17 #include "mojo/shell/public/cpp/interface_factory.h" | 18 #include "mojo/shell/public/cpp/interface_factory.h" |
18 #include "mojo/shell/public/interfaces/shell_resolver.mojom.h" | 19 #include "mojo/shell/public/interfaces/shell_resolver.mojom.h" |
19 | 20 |
20 namespace catalog { | 21 namespace catalog { |
21 | 22 |
22 class Store; | 23 class Store; |
23 | 24 |
24 struct ReadManifestResult { | 25 struct ReadManifestResult { |
25 ReadManifestResult(); | 26 ReadManifestResult(); |
26 ~ReadManifestResult(); | 27 ~ReadManifestResult(); |
27 scoped_ptr<base::Value> manifest_root; | 28 scoped_ptr<base::Value> manifest_root; |
28 base::FilePath package_dir; | 29 base::FilePath package_dir; |
29 }; | 30 }; |
30 | 31 |
31 class Catalog : public mojom::Resolver, | 32 class Catalog : public mojom::Resolver, |
32 public mojo::shell::mojom::ShellResolver, | 33 public mojo::shell::mojom::ShellResolver, |
33 public mojom::Catalog { | 34 public mojom::Catalog { |
34 public: | 35 public: |
35 Catalog(scoped_ptr<Store> store, base::TaskRunner* file_task_runner); | 36 Catalog(scoped_ptr<Store> store, |
| 37 base::TaskRunner* file_task_runner, |
| 38 EntryCache* system_catalog); |
36 ~Catalog() override; | 39 ~Catalog() override; |
37 | 40 |
38 void BindResolver(mojom::ResolverRequest request); | 41 void BindResolver(mojom::ResolverRequest request); |
39 void BindShellResolver(mojo::shell::mojom::ShellResolverRequest request); | 42 void BindShellResolver(mojo::shell::mojom::ShellResolverRequest request); |
40 void BindCatalog(mojom::CatalogRequest request); | 43 void BindCatalog(mojom::CatalogRequest request); |
41 | 44 |
42 private: | 45 private: |
43 using MojoNameAliasMap = | 46 using MojoNameAliasMap = |
44 std::map<std::string, std::pair<std::string, std::string>>; | 47 std::map<std::string, std::pair<std::string, std::string>>; |
45 | 48 |
(...skipping 23 matching lines...) Expand all Loading... |
69 | 72 |
70 // Receives the result of manifest parsing on |file_task_runner_|, may be | 73 // Receives the result of manifest parsing on |file_task_runner_|, may be |
71 // received after the catalog object that issued the request is destroyed. | 74 // received after the catalog object that issued the request is destroyed. |
72 static void OnReadManifest(base::WeakPtr<Catalog> catalog, | 75 static void OnReadManifest(base::WeakPtr<Catalog> catalog, |
73 const std::string& name, | 76 const std::string& name, |
74 const ResolveMojoNameCallback& callback, | 77 const ResolveMojoNameCallback& callback, |
75 scoped_ptr<ReadManifestResult> result); | 78 scoped_ptr<ReadManifestResult> result); |
76 | 79 |
77 // Populate the catalog with data from |entry|, and pass it to the client | 80 // Populate the catalog with data from |entry|, and pass it to the client |
78 // via callback. | 81 // via callback. |
79 void AddEntryToCatalog(scoped_ptr<Entry> entry); | 82 void AddEntryToCatalog(scoped_ptr<Entry> entry, bool is_system_catalog); |
80 | 83 |
81 // Directory that contains packages and executables visible to all users. | 84 // Directory that contains packages and executables visible to all users. |
82 base::FilePath system_package_dir_; | 85 base::FilePath system_package_dir_; |
83 | 86 // Directory that contains packages visible to this Catalog instance's user. |
84 // TODO(beng): add user package dir. | 87 base::FilePath user_package_dir_; |
85 | 88 |
86 // User-specific persistent storage of package manifests and other settings. | 89 // User-specific persistent storage of package manifests and other settings. |
87 scoped_ptr<Store> store_; | 90 scoped_ptr<Store> store_; |
88 | 91 |
89 // Task runner for performing file operations. | 92 // Task runner for performing file operations. |
90 base::TaskRunner* file_task_runner_; | 93 base::TaskRunner* file_task_runner_; |
91 | 94 |
92 mojo::BindingSet<mojom::Resolver> resolver_bindings_; | 95 mojo::BindingSet<mojom::Resolver> resolver_bindings_; |
93 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; | 96 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; |
94 mojo::BindingSet<mojom::Catalog> catalog_bindings_; | 97 mojo::BindingSet<mojom::Catalog> catalog_bindings_; |
95 | 98 |
96 // Mojo name -> Entry storage, constructed from Store/package manifests. | 99 // The current user's packages, constructed from Store/package manifests. |
97 std::map<std::string, scoped_ptr<Entry>> catalog_; | 100 EntryCache user_catalog_; |
| 101 // Same as above, but for system-level (visible to all-users) packages and |
| 102 // executables. |
| 103 EntryCache* system_catalog_; |
98 | 104 |
99 base::WeakPtrFactory<Catalog> weak_factory_; | 105 base::WeakPtrFactory<Catalog> weak_factory_; |
100 | 106 |
101 DISALLOW_COPY_AND_ASSIGN(Catalog); | 107 DISALLOW_COPY_AND_ASSIGN(Catalog); |
102 }; | 108 }; |
103 | 109 |
104 } // namespace catalog | 110 } // namespace catalog |
105 | 111 |
106 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ | 112 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ |
OLD | NEW |