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

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

Issue 1791663002: Allow Catalogs to be constructed per-user (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@49catalog
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/catalog.h ('k') | mojo/services/catalog/factory.h » ('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 #include "mojo/services/catalog/catalog.h" 5 #include "mojo/services/catalog/catalog.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 12 matching lines...) Expand all
23 JSONFileValueDeserializer deserializer(manifest_path); 23 JSONFileValueDeserializer deserializer(manifest_path);
24 int error = 0; 24 int error = 0;
25 std::string message; 25 std::string message;
26 // TODO(beng): probably want to do more detailed error checking. This should 26 // TODO(beng): probably want to do more detailed error checking. This should
27 // be done when figuring out if to unblock connection completion. 27 // be done when figuring out if to unblock connection completion.
28 return deserializer.Deserialize(&error, &message); 28 return deserializer.Deserialize(&error, &message);
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 Catalog::Catalog(base::TaskRunner* blocking_pool, 33 ////////////////////////////////////////////////////////////////////////////////
34 scoped_ptr<Store> catalog) 34 // Catalog, public:
35
36 Catalog::Catalog(base::TaskRunner* blocking_pool, scoped_ptr<Store> store)
35 : blocking_pool_(blocking_pool), 37 : blocking_pool_(blocking_pool),
36 store_(std::move(catalog)), 38 store_(std::move(store)),
37 weak_factory_(this) { 39 weak_factory_(this) {
38 base::FilePath shell_dir; 40 base::FilePath shell_dir;
39 PathService::Get(base::DIR_MODULE, &shell_dir); 41 PathService::Get(base::DIR_MODULE, &shell_dir);
40 42
41 system_package_dir_ = 43 system_package_dir_ =
42 mojo::util::FilePathToFileURL(shell_dir).Resolve(std::string()); 44 mojo::util::FilePathToFileURL(shell_dir).Resolve(std::string());
43 system_package_dir_ = 45 system_package_dir_ =
44 mojo::util::AddTrailingSlashIfNeeded(system_package_dir_); 46 mojo::util::AddTrailingSlashIfNeeded(system_package_dir_);
45 47
46 DeserializeCatalog(); 48 DeserializeCatalog();
47 } 49 }
50
48 Catalog::~Catalog() {} 51 Catalog::~Catalog() {}
49 52
50 bool Catalog::AcceptConnection(mojo::Connection* connection) { 53 void Catalog::BindResolver(mojom::ResolverRequest request) {
51 connection->AddInterface<mojom::Catalog>(this);
52 connection->AddInterface<mojom::Resolver>(this);
53 if (connection->GetRemoteIdentity().name() == "mojo:shell")
54 connection->AddInterface<mojo::shell::mojom::ShellResolver>(this);
55 return true;
56 }
57
58 void Catalog::Create(mojo::Connection* connection,
59 mojom::ResolverRequest request) {
60 resolver_bindings_.AddBinding(this, std::move(request)); 54 resolver_bindings_.AddBinding(this, std::move(request));
61 } 55 }
62 56
63 void Catalog::Create(mojo::Connection* connection, 57 void Catalog::BindShellResolver(
64 mojo::shell::mojom::ShellResolverRequest request) { 58 mojo::shell::mojom::ShellResolverRequest request) {
65 shell_resolver_bindings_.AddBinding(this, std::move(request)); 59 shell_resolver_bindings_.AddBinding(this, std::move(request));
66 } 60 }
67 61
68 void Catalog::Create(mojo::Connection* connection, 62 void Catalog::BindCatalog(mojom::CatalogRequest request) {
69 mojom::CatalogRequest request) {
70 catalog_bindings_.AddBinding(this, std::move(request)); 63 catalog_bindings_.AddBinding(this, std::move(request));
71 } 64 }
72 65
66 ////////////////////////////////////////////////////////////////////////////////
67 // Catalog, mojom::Resolver:
68
73 void Catalog::ResolveResponse(mojo::URLResponsePtr response, 69 void Catalog::ResolveResponse(mojo::URLResponsePtr response,
74 const ResolveResponseCallback& callback) { 70 const ResolveResponseCallback& callback) {
75 // TODO(beng): implement. 71 // TODO(beng): implement.
76 } 72 }
77 73
78 void Catalog::ResolveInterfaces(mojo::Array<mojo::String> interfaces, 74 void Catalog::ResolveInterfaces(mojo::Array<mojo::String> interfaces,
79 const ResolveInterfacesCallback& callback) { 75 const ResolveInterfacesCallback& callback) {
80 // TODO(beng): implement. 76 // TODO(beng): implement.
81 } 77 }
82 78
83 void Catalog::ResolveMIMEType(const mojo::String& mime_type, 79 void Catalog::ResolveMIMEType(const mojo::String& mime_type,
84 const ResolveMIMETypeCallback& callback) { 80 const ResolveMIMETypeCallback& callback) {
85 // TODO(beng): implement. 81 // TODO(beng): implement.
86 } 82 }
87 83
88 void Catalog::ResolveProtocolScheme( 84 void Catalog::ResolveProtocolScheme(
89 const mojo::String& scheme, 85 const mojo::String& scheme,
90 const ResolveProtocolSchemeCallback& callback) { 86 const ResolveProtocolSchemeCallback& callback) {
91 // TODO(beng): implement. 87 // TODO(beng): implement.
92 } 88 }
93 89
90 ////////////////////////////////////////////////////////////////////////////////
91 // Catalog, mojo::shell::mojom::ShellResolver:
92
94 void Catalog::ResolveMojoName(const mojo::String& mojo_name, 93 void Catalog::ResolveMojoName(const mojo::String& mojo_name,
95 const ResolveMojoNameCallback& callback) { 94 const ResolveMojoNameCallback& callback) {
96 std::string resolved_name = mojo_name; 95 std::string resolved_name = mojo_name;
97 auto alias_iter = mojo_name_aliases_.find(resolved_name); 96 auto alias_iter = mojo_name_aliases_.find(resolved_name);
98 if (alias_iter != mojo_name_aliases_.end()) 97 if (alias_iter != mojo_name_aliases_.end())
99 resolved_name = alias_iter->second.first; 98 resolved_name = alias_iter->second.first;
100 99
101 std::string qualifier = mojo::GetNamePath(resolved_name); 100 std::string qualifier = mojo::GetNamePath(resolved_name);
102 auto qualifier_iter = qualifiers_.find(resolved_name); 101 auto qualifier_iter = qualifiers_.find(resolved_name);
103 if (qualifier_iter != qualifiers_.end()) 102 if (qualifier_iter != qualifiers_.end())
104 qualifier = qualifier_iter->second; 103 qualifier = qualifier_iter->second;
105 104
106 if (IsNameInCatalog(resolved_name)) 105 if (IsNameInCatalog(resolved_name))
107 CompleteResolveMojoName(resolved_name, qualifier, callback); 106 CompleteResolveMojoName(resolved_name, qualifier, callback);
108 else 107 else
109 AddNameToCatalog(resolved_name, callback); 108 AddNameToCatalog(resolved_name, callback);
110 } 109 }
111 110
111 ////////////////////////////////////////////////////////////////////////////////
112 // Catalog, mojom::Catalog:
113
112 void Catalog::GetEntries(mojo::Array<mojo::String> names, 114 void Catalog::GetEntries(mojo::Array<mojo::String> names,
113 const GetEntriesCallback& callback) { 115 const GetEntriesCallback& callback) {
114 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries; 116 mojo::Map<mojo::String, mojom::CatalogEntryPtr> entries;
115 std::vector<mojo::String> names_vec = names.PassStorage(); 117 std::vector<mojo::String> names_vec = names.PassStorage();
116 for (const std::string& name : names_vec) { 118 for (const std::string& name : names_vec) {
117 if (catalog_.find(name) == catalog_.end()) 119 if (catalog_.find(name) == catalog_.end())
118 continue; 120 continue;
119 const Entry& entry = catalog_[name]; 121 const Entry& entry = catalog_[name];
120 mojom::CatalogEntryPtr entry_ptr(mojom::CatalogEntry::New()); 122 mojom::CatalogEntryPtr entry_ptr(mojom::CatalogEntry::New());
121 entry_ptr->display_name = entry.display_name; 123 entry_ptr->display_name = entry.display_name;
122 entries[entry.name] = std::move(entry_ptr); 124 entries[entry.name] = std::move(entry_ptr);
123 } 125 }
124 callback.Run(std::move(entries)); 126 callback.Run(std::move(entries));
125 } 127 }
126 128
129 ////////////////////////////////////////////////////////////////////////////////
130 // Catalog, private:
131
127 void Catalog::CompleteResolveMojoName( 132 void Catalog::CompleteResolveMojoName(
128 const std::string& resolved_name, 133 const std::string& resolved_name,
129 const std::string& qualifier, 134 const std::string& qualifier,
130 const ResolveMojoNameCallback& callback) { 135 const ResolveMojoNameCallback& callback) {
131 auto entry_iter = catalog_.find(resolved_name); 136 auto entry_iter = catalog_.find(resolved_name);
132 CHECK(entry_iter != catalog_.end()); 137 CHECK(entry_iter != catalog_.end());
133 138
134 GURL file_url; 139 GURL file_url;
135 std::string type = mojo::GetNameType(resolved_name); 140 std::string type = mojo::GetNameType(resolved_name);
136 if (type == "mojo") { 141 if (type == "mojo") {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 269 }
265 SerializeCatalog(); 270 SerializeCatalog();
266 271
267 auto qualifier_iter = qualifiers_.find(name); 272 auto qualifier_iter = qualifiers_.find(name);
268 DCHECK(qualifier_iter != qualifiers_.end()); 273 DCHECK(qualifier_iter != qualifiers_.end());
269 std::string qualifier = qualifier_iter->second; 274 std::string qualifier = qualifier_iter->second;
270 CompleteResolveMojoName(name, qualifier, callback); 275 CompleteResolveMojoName(name, qualifier, callback);
271 } 276 }
272 277
273 } // namespace catalog 278 } // namespace catalog
OLDNEW
« no previous file with comments | « mojo/services/catalog/catalog.h ('k') | mojo/services/catalog/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698