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

Side by Side Diff: services/shell/shell.h

Issue 1899583002: Revert of Remove shell::Loader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « services/shell/loader.h ('k') | services/shell/shell.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 SERVICES_SHELL_SHELL_H_ 5 #ifndef SERVICES_SHELL_SHELL_H_
6 #define SERVICES_SHELL_SHELL_H_ 6 #define SERVICES_SHELL_SHELL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "mojo/public/cpp/bindings/binding_set.h" 14 #include "mojo/public/cpp/bindings/binding_set.h"
15 #include "mojo/public/cpp/bindings/interface_ptr_set.h" 15 #include "mojo/public/cpp/bindings/interface_ptr_set.h"
16 #include "services/shell/connect_params.h" 16 #include "services/shell/connect_params.h"
17 #include "services/shell/loader.h"
17 #include "services/shell/native_runner.h" 18 #include "services/shell/native_runner.h"
18 #include "services/shell/public/cpp/capabilities.h" 19 #include "services/shell/public/cpp/capabilities.h"
19 #include "services/shell/public/cpp/identity.h" 20 #include "services/shell/public/cpp/identity.h"
20 #include "services/shell/public/cpp/interface_factory.h" 21 #include "services/shell/public/cpp/interface_factory.h"
21 #include "services/shell/public/cpp/shell_client.h" 22 #include "services/shell/public/cpp/shell_client.h"
22 #include "services/shell/public/interfaces/connector.mojom.h" 23 #include "services/shell/public/interfaces/connector.mojom.h"
23 #include "services/shell/public/interfaces/interface_provider.mojom.h" 24 #include "services/shell/public/interfaces/interface_provider.mojom.h"
24 #include "services/shell/public/interfaces/shell.mojom.h" 25 #include "services/shell/public/interfaces/shell.mojom.h"
25 #include "services/shell/public/interfaces/shell_client.mojom.h" 26 #include "services/shell/public/interfaces/shell_client.mojom.h"
26 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" 27 #include "services/shell/public/interfaces/shell_client_factory.mojom.h"
(...skipping 19 matching lines...) Expand all
46 private: 47 private:
47 Shell* shell_; 48 Shell* shell_;
48 49
49 DISALLOW_COPY_AND_ASSIGN(TestAPI); 50 DISALLOW_COPY_AND_ASSIGN(TestAPI);
50 }; 51 };
51 52
52 // |native_runner_factory| is an instance of an object capable of vending 53 // |native_runner_factory| is an instance of an object capable of vending
53 // implementations of NativeRunner, e.g. for in or out-of-process execution. 54 // implementations of NativeRunner, e.g. for in or out-of-process execution.
54 // See native_runner.h and RunNativeApplication(). 55 // See native_runner.h and RunNativeApplication().
55 // |file_task_runner| provides access to a thread to perform file copy 56 // |file_task_runner| provides access to a thread to perform file copy
56 // operations on. 57 // operations on. This may be null only in testing environments where
58 // applications are loaded via Loader implementations.
57 Shell(std::unique_ptr<NativeRunnerFactory> native_runner_factory, 59 Shell(std::unique_ptr<NativeRunnerFactory> native_runner_factory,
58 mojom::ShellClientPtr catalog); 60 mojom::ShellClientPtr catalog);
59 ~Shell() override; 61 ~Shell() override;
60 62
61 // Provide a callback to be notified whenever an instance is destroyed. 63 // Provide a callback to be notified whenever an instance is destroyed.
62 // Typically the creator of the Shell will use this to determine when some set 64 // Typically the creator of the Shell will use this to determine when some set
63 // of instances it created are destroyed, so it can shut down. 65 // of instances it created are destroyed, so it can shut down.
64 void SetInstanceQuitCallback(base::Callback<void(const Identity&)> callback); 66 void SetInstanceQuitCallback(base::Callback<void(const Identity&)> callback);
65 67
66 // Completes a connection between a source and target application as defined 68 // Completes a connection between a source and target application as defined
67 // by |params|, exchanging InterfaceProviders between them. If no existing 69 // by |params|, exchanging InterfaceProviders between them. If no existing
68 // instance of the target application is running, one will be loaded. 70 // instance of the target application is running, one will be loaded.
69 void Connect(std::unique_ptr<ConnectParams> params); 71 void Connect(std::unique_ptr<ConnectParams> params);
70 72
71 // Creates a new Instance identified as |name|. This is intended for use by 73 // Creates a new Instance identified as |name|. This is intended for use by
72 // the Shell's embedder to register itself with the shell. This must only be 74 // the Shell's embedder to register itself with the shell. This must only be
73 // called once. 75 // called once.
74 mojom::ShellClientRequest InitInstanceForEmbedder(const std::string& name); 76 mojom::ShellClientRequest InitInstanceForEmbedder(const std::string& name);
75 77
78 // Sets the default Loader to be used if not overridden by SetLoaderForName().
79 void set_default_loader(std::unique_ptr<Loader> loader) {
80 default_loader_ = std::move(loader);
81 }
82
83 // Sets a Loader to be used for a specific name.
84 void SetLoaderForName(std::unique_ptr<Loader> loader,
85 const std::string& name);
86
76 private: 87 private:
77 class Instance; 88 class Instance;
78 89
79 // ShellClient: 90 // ShellClient:
80 bool AcceptConnection(Connection* connection) override; 91 bool AcceptConnection(Connection* connection) override;
81 92
82 void InitCatalog(mojom::ShellClientPtr catalog); 93 void InitCatalog(mojom::ShellClientPtr catalog);
83 94
84 // Destroys all Shell-ends of connections established with Applications. 95 // Destroys all Shell-ends of connections established with Applications.
85 // Applications connected by this Shell will observe pipe errors and have a 96 // Applications connected by this Shell will observe pipe errors and have a
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Callback when remote Catalog resolves mojo:foo to mojo:bar. 140 // Callback when remote Catalog resolves mojo:foo to mojo:bar.
130 // |params| are the params passed to Connect(). 141 // |params| are the params passed to Connect().
131 // |client| if provided is a ShellClientPtr which should be used to manage the 142 // |client| if provided is a ShellClientPtr which should be used to manage the
132 // new application instance. This may be null. 143 // new application instance. This may be null.
133 // |result| contains the result of the resolve operation. 144 // |result| contains the result of the resolve operation.
134 void OnGotResolvedName(mojom::ShellResolverPtr resolver, 145 void OnGotResolvedName(mojom::ShellResolverPtr resolver,
135 std::unique_ptr<ConnectParams> params, 146 std::unique_ptr<ConnectParams> params,
136 mojom::ShellClientPtr client, 147 mojom::ShellClientPtr client,
137 mojom::ResolveResultPtr result); 148 mojom::ResolveResultPtr result);
138 149
150 // Tries to load |target| with an Loader. Returns true if one was registered
151 // and it was loaded, in which case |request| is taken.
152 bool LoadWithLoader(const Identity& target,
153 mojom::ShellClientRequest* request);
154
155 // Returns the appropriate loader for |name|, or the default loader if there
156 // is no loader configured for the name.
157 Loader* GetLoaderForName(const std::string& name);
158
139 base::WeakPtr<Shell> GetWeakPtr(); 159 base::WeakPtr<Shell> GetWeakPtr();
140 160
141 void CleanupRunner(NativeRunner* runner); 161 void CleanupRunner(NativeRunner* runner);
142 162
163 // Loader management.
164 // Loaders are chosen in the order they are listed here.
165 std::map<std::string, Loader*> name_to_loader_;
166 std::unique_ptr<Loader> default_loader_;
167
143 std::map<Identity, Instance*> identity_to_instance_; 168 std::map<Identity, Instance*> identity_to_instance_;
144 169
145 // Tracks the names of instances that are allowed to field connection requests 170 // Tracks the names of instances that are allowed to field connection requests
146 // from all users. 171 // from all users.
147 std::set<std::string> singletons_; 172 std::set<std::string> singletons_;
148 173
149 std::map<Identity, mojom::ShellClientFactoryPtr> shell_client_factories_; 174 std::map<Identity, mojom::ShellClientFactoryPtr> shell_client_factories_;
150 // Counter used to assign ids to client factories. 175 // Counter used to assign ids to client factories.
151 uint32_t shell_client_factory_id_counter_; 176 uint32_t shell_client_factory_id_counter_;
152 177
153 mojo::InterfacePtrSet<mojom::InstanceListener> instance_listeners_; 178 mojo::InterfacePtrSet<mojom::InstanceListener> instance_listeners_;
154 179
155 base::Callback<void(const Identity&)> instance_quit_callback_; 180 base::Callback<void(const Identity&)> instance_quit_callback_;
156 std::unique_ptr<NativeRunnerFactory> native_runner_factory_; 181 std::unique_ptr<NativeRunnerFactory> native_runner_factory_;
157 std::vector<std::unique_ptr<NativeRunner>> native_runners_; 182 std::vector<std::unique_ptr<NativeRunner>> native_runners_;
158 std::unique_ptr<ShellConnection> shell_connection_; 183 std::unique_ptr<ShellConnection> shell_connection_;
159 base::WeakPtrFactory<Shell> weak_ptr_factory_; 184 base::WeakPtrFactory<Shell> weak_ptr_factory_;
160 185
161 DISALLOW_COPY_AND_ASSIGN(Shell); 186 DISALLOW_COPY_AND_ASSIGN(Shell);
162 }; 187 };
163 188
164 mojom::Connector::ConnectCallback EmptyConnectCallback(); 189 mojom::Connector::ConnectCallback EmptyConnectCallback();
165 190
166 } // namespace shell 191 } // namespace shell
167 192
168 #endif // SERVICES_SHELL_SHELL_H_ 193 #endif // SERVICES_SHELL_SHELL_H_
OLDNEW
« no previous file with comments | « services/shell/loader.h ('k') | services/shell/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698