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

Side by Side Diff: mojo/services/catalog/catalog.h

Issue 1779683002: Add catalog unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@43catalog
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 unified diff | Download patch
« no previous file with comments | « mojo/services/catalog/builder_unittest.cc ('k') | mojo/services/catalog/catalog.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/public/interfaces/catalog.mojom.h" 14 #include "mojo/services/catalog/public/interfaces/catalog.mojom.h"
14 #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"
15 #include "mojo/shell/public/cpp/interface_factory.h" 17 #include "mojo/shell/public/cpp/interface_factory.h"
16 #include "mojo/shell/public/cpp/shell_client.h" 18 #include "mojo/shell/public/cpp/shell_client.h"
17 #include "mojo/shell/public/interfaces/shell_resolver.mojom.h" 19 #include "mojo/shell/public/interfaces/shell_resolver.mojom.h"
18 #include "url/gurl.h" 20 #include "url/gurl.h"
19 21
20 namespace catalog { 22 namespace catalog {
21 // A set of names of interfaces that may be exposed to an application.
22 using AllowedInterfaces = std::set<std::string>;
23 // A map of allowed applications to allowed interface sets. See shell.mojom for
24 // more details.
25 using CapabilityFilter = std::map<std::string, AllowedInterfaces>;
26 23
27 // Static information about an application package known to the Catalog. 24 class Store;
28 struct ApplicationInfo {
29 ApplicationInfo();
30 ApplicationInfo(const ApplicationInfo& other);
31 ~ApplicationInfo();
32
33 std::string name;
34 std::string qualifier;
35 std::string display_name;
36 CapabilityFilter base_filter;
37 };
38
39 // Implemented by an object that provides storage for the application catalog
40 // (e.g. in Chrome, preferences). The Catalog is the canonical owner of the
41 // contents of the store, so no one else must modify its contents.
42 class Store {
43 public:
44 // Value is a string.
45 static const char kNameKey[];
46 // Value is a string.
47 static const char kQualifierKey[];
48 // Value is a string.
49 static const char kDisplayNameKey[];
50 // Value is a dictionary that maps from the filter to a list of string
51 // interfaces.
52 static const char kCapabilitiesKey[];
53
54 virtual ~Store() {}
55
56 // Called during initialization to construct the Catalog's catalog.
57 // Returns a serialized list of the apps. Each entry in the returned list
58 // corresponds to an app (as a dictionary). Each dictionary has a name,
59 // display name and capabilities. The return value is owned by the caller.
60 virtual const base::ListValue* GetStore() = 0;
61
62 // Write the catalog to the store. Called when the Catalog learns of a newly
63 // encountered application.
64 virtual void UpdateStore(scoped_ptr<base::ListValue> store) = 0;
65 };
66 25
67 class Catalog 26 class Catalog
68 : public mojo::ShellClient, 27 : public mojo::ShellClient,
69 public mojo::InterfaceFactory<mojom::Resolver>, 28 public mojo::InterfaceFactory<mojom::Resolver>,
70 public mojo::InterfaceFactory<mojo::shell::mojom::ShellResolver>, 29 public mojo::InterfaceFactory<mojo::shell::mojom::ShellResolver>,
71 public mojo::InterfaceFactory<mojom::Catalog>, 30 public mojo::InterfaceFactory<mojom::Catalog>,
72 public mojom::Resolver, 31 public mojom::Resolver,
73 public mojo::shell::mojom::ShellResolver, 32 public mojo::shell::mojom::ShellResolver,
74 public mojom::Catalog { 33 public mojom::Catalog {
75 public: 34 public:
76 // If |register_schemes| is true, mojo: and exe: schemes are registered as 35 // If |register_schemes| is true, mojo: and exe: schemes are registered as
77 // "standard". 36 // "standard".
78 Catalog(base::TaskRunner* blocking_pool, scoped_ptr<Store> store); 37 Catalog(base::TaskRunner* blocking_pool, scoped_ptr<Store> store);
79 ~Catalog() override; 38 ~Catalog() override;
80 39
81 private: 40 private:
82 using MojoNameAliasMap = 41 using MojoNameAliasMap =
83 std::map<std::string, std::pair<std::string, std::string>>; 42 std::map<std::string, std::pair<std::string, std::string>>;
84 43
85 // mojo::ShellClient: 44 // mojo::ShellClient:
86 bool AcceptConnection(mojo::Connection* connection) override; 45 bool AcceptConnection(mojo::Connection* connection) override;
87 46
88 // mojo::InterfaceFactory<mojom::Resolver>: 47 // mojo::InterfaceFactory<mojom::Resolver>:
89 void Create(mojo::Connection* connection, 48 void Create(mojo::Connection* connection,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Attempts to load a manifest for |name|, reads it and adds its metadata to 88 // Attempts to load a manifest for |name|, reads it and adds its metadata to
130 // the catalog. 89 // the catalog.
131 void AddNameToCatalog(const std::string& name, 90 void AddNameToCatalog(const std::string& name,
132 const ResolveMojoNameCallback& callback); 91 const ResolveMojoNameCallback& callback);
133 92
134 // Populate/serialize the catalog from/to the supplied store. 93 // Populate/serialize the catalog from/to the supplied store.
135 void DeserializeCatalog(); 94 void DeserializeCatalog();
136 void SerializeCatalog(); 95 void SerializeCatalog();
137 96
138 // Construct a catalog entry from |dictionary|. 97 // Construct a catalog entry from |dictionary|.
139 const ApplicationInfo& DeserializeApplication( 98 const Entry& DeserializeApplication(const base::DictionaryValue* dictionary);
140 const base::DictionaryValue* dictionary);
141 99
142 GURL GetManifestURL(const std::string& name); 100 GURL GetManifestURL(const std::string& name);
143 101
144 // Called once the manifest has been read. |pm| may be null at this point, 102 // Called once the manifest has been read. |pm| may be null at this point,
145 // but |callback| must be run. 103 // but |callback| must be run.
146 static void OnReadManifest(base::WeakPtr<Catalog> catalog, 104 static void OnReadManifest(base::WeakPtr<Catalog> catalog,
147 const std::string& name, 105 const std::string& name,
148 const ResolveMojoNameCallback& callback, 106 const ResolveMojoNameCallback& callback,
149 scoped_ptr<base::Value> manifest); 107 scoped_ptr<base::Value> manifest);
150 108
151 // Called once the manifest is read and |this| hasn't been deleted. 109 // Called once the manifest is read and |this| hasn't been deleted.
152 void OnReadManifestImpl(const std::string& name, 110 void OnReadManifestImpl(const std::string& name,
153 const ResolveMojoNameCallback& callback, 111 const ResolveMojoNameCallback& callback,
154 scoped_ptr<base::Value> manifest); 112 scoped_ptr<base::Value> manifest);
155 113
156 base::TaskRunner* blocking_pool_; 114 base::TaskRunner* blocking_pool_;
157 GURL system_package_dir_; 115 GURL system_package_dir_;
158 116
159 mojo::BindingSet<mojom::Resolver> resolver_bindings_; 117 mojo::BindingSet<mojom::Resolver> resolver_bindings_;
160 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_; 118 mojo::BindingSet<mojo::shell::mojom::ShellResolver> shell_resolver_bindings_;
161 mojo::BindingSet<mojom::Catalog> catalog_bindings_; 119 mojo::BindingSet<mojom::Catalog> catalog_bindings_;
162 120
163 scoped_ptr<Store> store_; 121 scoped_ptr<Store> store_;
164 std::map<std::string, ApplicationInfo> catalog_; 122 std::map<std::string, Entry> catalog_;
165 123
166 // Used when an app handles multiple names. Maps from app (as name) to name of 124 // Used when an app handles multiple names. Maps from app (as name) to name of
167 // app that is responsible for handling it. The value is a pair of the name of 125 // app that is responsible for handling it. The value is a pair of the name of
168 // the handler along with a qualifier. 126 // the handler along with a qualifier.
169 MojoNameAliasMap mojo_name_aliases_; 127 MojoNameAliasMap mojo_name_aliases_;
170 128
171 std::map<std::string, std::string> qualifiers_; 129 std::map<std::string, std::string> qualifiers_;
172 130
173 base::WeakPtrFactory<Catalog> weak_factory_; 131 base::WeakPtrFactory<Catalog> weak_factory_;
174 132
175 DISALLOW_COPY_AND_ASSIGN(Catalog); 133 DISALLOW_COPY_AND_ASSIGN(Catalog);
176 }; 134 };
177 135
178 } // namespace catalog 136 } // namespace catalog
179 137
180 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_ 138 #endif // MOJO_SERVICES_CATALOG_CATALOG_H_
OLDNEW
« no previous file with comments | « mojo/services/catalog/builder_unittest.cc ('k') | mojo/services/catalog/catalog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698