OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef MOJO_SERVICES_CATALOG_CATALOG_H_ | |
6 #define MOJO_SERVICES_CATALOG_CATALOG_H_ | |
7 | |
8 #include "base/files/file_path.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "base/path_service.h" | |
11 #include "base/values.h" | |
12 #include "mojo/public/cpp/bindings/binding_set.h" | |
13 #include "mojo/services/catalog/entry.h" | |
14 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h" | |
15 #include "mojo/services/catalog/public/interfaces/resolver.mojom.h" | |
16 #include "mojo/services/catalog/store.h" | |
17 #include "mojo/services/catalog/types.h" | |
18 #include "services/shell/public/cpp/interface_factory.h" | |
19 #include "services/shell/public/interfaces/shell_resolver.mojom.h" | |
20 | |
21 namespace catalog { | |
22 | |
23 class ManifestProvider; | |
24 class Store; | |
25 | |
26 struct ReadManifestResult { | |
27 ReadManifestResult(); | |
28 ~ReadManifestResult(); | |
29 mojo::shell::mojom::ResolveResultPtr resolve_result; | |
30 scoped_ptr<Entry> catalog_entry; | |
31 base::FilePath package_dir; | |
32 }; | |
33 | |
34 class Catalog : public mojom::Resolver, | |
35 public mojo::shell::mojom::ShellResolver, | |
36 public mojom::Catalog { | |
37 public: | |
38 // |manifest_provider| may be null. | |
39 Catalog(scoped_ptr<Store> store, | |
40 base::TaskRunner* file_task_runner, | |
41 EntryCache* system_catalog, | |
42 ManifestProvider* manifest_provider); | |
43 ~Catalog() override; | |
44 | |
45 void BindResolver(mojom::ResolverRequest request); | |
46 void BindShellResolver(mojo::shell::mojom::ShellResolverRequest request); | |
47 void BindCatalog(mojom::CatalogRequest request); | |
48 | |
49 private: | |
50 using MojoNameAliasMap = | |
51 std::map<std::string, std::pair<std::string, std::string>>; | |
52 | |
53 // mojom::Resolver: | |
54 void ResolveInterfaces(mojo::Array<mojo::String> interfaces, | |
55 const ResolveInterfacesCallback& callback) override; | |
56 void ResolveMIMEType(const mojo::String& mime_type, | |
57 const ResolveMIMETypeCallback& callback) override; | |
58 void ResolveProtocolScheme( | |
59 const mojo::String& scheme, | |
60 const ResolveProtocolSchemeCallback& callback) override; | |
61 | |
62 // mojo::shell::mojom::ShellResolver: | |
63 void ResolveMojoName(const mojo::String& mojo_name, | |
64 const ResolveMojoNameCallback& callback) override; | |
65 | |
66 // mojom::Catalog: | |
67 void GetEntries(mojo::Array<mojo::String> names, | |
68 const GetEntriesCallback& callback) override; | |
69 | |
70 // Populate/serialize the catalog from/to the supplied store. | |
71 void DeserializeCatalog(); | |
72 void SerializeCatalog(); | |
73 | |
74 // Receives the result of manifest parsing on |file_task_runner_|, may be | |
75 // received after the catalog object that issued the request is destroyed. | |
76 static void OnReadManifest(base::WeakPtr<Catalog> catalog, | |
77 const std::string& name, | |
78 const ResolveMojoNameCallback& callback, | |
79 scoped_ptr<ReadManifestResult> result); | |
80 | |
81 // Populate the catalog with data from |entry|, and pass it to the client | |
82 // via callback. | |
83 void AddEntryToCatalog(scoped_ptr<Entry> entry, bool is_system_catalog); | |
84 | |
85 ManifestProvider* const manifest_provider_; | |
86 | |
87 // Directory that contains packages and executables visible to all users. | |
88 base::FilePath system_package_dir_; | |
89 // Directory that contains packages visible to this Catalog instance's user. | |
90 base::FilePath user_package_dir_; | |
91 | |
92 // User-specific persistent storage of package manifests and other settings. | |
93 scoped_ptr<Store> store_; | |
94 | |
95 // Task runner for performing file operations. | |
96 base::TaskRunner* const file_task_runner_; | |
97 | |
98 mojo::BindingSet<mojom::Resolver> resolver_bindings_; | |
99 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; | |
100 mojo::BindingSet<mojom::Catalog> catalog_bindings_; | |
101 | |
102 // The current user's packages, constructed from Store/package manifests. | |
103 EntryCache user_catalog_; | |
104 // Same as above, but for system-level (visible to all-users) packages and | |
105 // executables. | |
106 EntryCache* system_catalog_; | |
107 | |
108 base::WeakPtrFactory<Catalog> weak_factory_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(Catalog); | |
111 }; | |
112 | |
113 } // namespace catalog | |
114 | |
115 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ | |
OLD | NEW |