OLD | NEW |
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 MOJO_SHELL_SHELL_H_ | 5 #ifndef MOJO_SHELL_SHELL_H_ |
6 #define MOJO_SHELL_SHELL_H_ | 6 #define MOJO_SHELL_SHELL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void set_default_loader(scoped_ptr<Loader> loader) { | 80 void set_default_loader(scoped_ptr<Loader> loader) { |
81 default_loader_ = std::move(loader); | 81 default_loader_ = std::move(loader); |
82 } | 82 } |
83 | 83 |
84 // Sets a Loader to be used for a specific name. | 84 // Sets a Loader to be used for a specific name. |
85 void SetLoaderForName(scoped_ptr<Loader> loader, const std::string& name); | 85 void SetLoaderForName(scoped_ptr<Loader> loader, const std::string& name); |
86 | 86 |
87 private: | 87 private: |
88 class Instance; | 88 class Instance; |
89 | 89 |
90 using IdentityToInstanceMap = std::map<Identity, Instance*>; | |
91 using NameToLoaderMap = std::map<std::string, Loader*>; | |
92 using IdentityToShellClientFactoryMap = | |
93 std::map<Identity, mojom::ShellClientFactoryPtr>; | |
94 | |
95 // ShellClient: | 90 // ShellClient: |
96 bool AcceptConnection(Connection* connection) override; | 91 bool AcceptConnection(Connection* connection) override; |
97 | 92 |
98 void InitCatalog(mojom::ShellClientPtr catalog); | 93 void InitCatalog(mojom::ShellClientPtr catalog); |
99 | 94 |
100 // Destroys all Shell-ends of connections established with Applications. | 95 // Destroys all Shell-ends of connections established with Applications. |
101 // 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 |
102 // chance to shutdown. | 97 // chance to shutdown. |
103 void TerminateShellConnections(); | 98 void TerminateShellConnections(); |
104 | 99 |
(...skipping 13 matching lines...) Expand all Loading... |
118 // running as a different user if one is available that services all users. | 113 // running as a different user if one is available that services all users. |
119 Instance* GetExistingInstance(const Identity& identity) const; | 114 Instance* GetExistingInstance(const Identity& identity) const; |
120 | 115 |
121 void NotifyPIDAvailable(uint32_t id, base::ProcessId pid); | 116 void NotifyPIDAvailable(uint32_t id, base::ProcessId pid); |
122 | 117 |
123 // Attempt to complete the connection requested by |params| by connecting to | 118 // Attempt to complete the connection requested by |params| by connecting to |
124 // an existing instance. If there is an existing instance, |params| is taken, | 119 // an existing instance. If there is an existing instance, |params| is taken, |
125 // and this function returns true. | 120 // and this function returns true. |
126 bool ConnectToExistingInstance(scoped_ptr<ConnectParams>* params); | 121 bool ConnectToExistingInstance(scoped_ptr<ConnectParams>* params); |
127 | 122 |
128 Instance* CreateInstance(const Identity& target, | 123 Instance* CreateInstance(const Identity& source, |
| 124 const Identity& target, |
129 const CapabilitySpec& spec); | 125 const CapabilitySpec& spec); |
130 | 126 |
131 // Called from the instance implementing mojom::Shell. | 127 // Called from the instance implementing mojom::Shell. |
132 void AddInstanceListener(mojom::InstanceListenerPtr listener); | 128 void AddInstanceListener(mojom::InstanceListenerPtr listener); |
133 | 129 |
134 void CreateShellClientWithFactory(const Identity& source, | 130 void CreateShellClientWithFactory(const Identity& source, |
135 const Identity& shell_client_factory, | 131 const Identity& shell_client_factory, |
136 const std::string& name, | 132 const std::string& name, |
137 mojom::ShellClientRequest request); | 133 mojom::ShellClientRequest request); |
138 // Returns a running ShellClientFactory for |shell_client_factory_identity|. | 134 // Returns a running ShellClientFactory for |shell_client_factory_identity|. |
(...skipping 22 matching lines...) Expand all Loading... |
161 | 157 |
162 // Tries to load |target| with an Loader. Returns true if one was registered | 158 // Tries to load |target| with an Loader. Returns true if one was registered |
163 // and it was loaded, in which case |request| is taken. | 159 // and it was loaded, in which case |request| is taken. |
164 bool LoadWithLoader(const Identity& target, | 160 bool LoadWithLoader(const Identity& target, |
165 mojom::ShellClientRequest* request); | 161 mojom::ShellClientRequest* request); |
166 | 162 |
167 // Returns the appropriate loader for |name|, or the default loader if there | 163 // Returns the appropriate loader for |name|, or the default loader if there |
168 // is no loader configured for the name. | 164 // is no loader configured for the name. |
169 Loader* GetLoaderForName(const std::string& name); | 165 Loader* GetLoaderForName(const std::string& name); |
170 | 166 |
| 167 base::WeakPtr<Shell> GetWeakPtr(); |
| 168 |
171 void CleanupRunner(NativeRunner* runner); | 169 void CleanupRunner(NativeRunner* runner); |
172 | 170 |
173 // Loader management. | 171 // Loader management. |
174 // Loaders are chosen in the order they are listed here. | 172 // Loaders are chosen in the order they are listed here. |
175 NameToLoaderMap name_to_loader_; | 173 std::map<std::string, Loader*> name_to_loader_; |
176 scoped_ptr<Loader> default_loader_; | 174 scoped_ptr<Loader> default_loader_; |
177 | 175 |
178 IdentityToInstanceMap identity_to_instance_; | 176 std::map<Identity, Instance*> identity_to_instance_; |
179 | 177 |
180 // Tracks the names of instances that are allowed to field connection requests | 178 // Tracks the names of instances that are allowed to field connection requests |
181 // from all users. | 179 // from all users. |
182 std::set<std::string> singletons_; | 180 std::set<std::string> singletons_; |
183 | 181 |
184 IdentityToShellClientFactoryMap shell_client_factories_; | 182 std::map<Identity, mojom::ShellClientFactoryPtr> shell_client_factories_; |
185 // Counter used to assign ids to client factories. | 183 // Counter used to assign ids to client factories. |
186 uint32_t shell_client_factory_id_counter_; | 184 uint32_t shell_client_factory_id_counter_; |
187 | 185 |
188 InterfacePtrSet<mojom::InstanceListener> instance_listeners_; | 186 InterfacePtrSet<mojom::InstanceListener> instance_listeners_; |
189 | 187 |
190 base::Callback<void(const Identity&)> instance_quit_callback_; | 188 base::Callback<void(const Identity&)> instance_quit_callback_; |
191 scoped_ptr<NativeRunnerFactory> native_runner_factory_; | 189 scoped_ptr<NativeRunnerFactory> native_runner_factory_; |
192 std::vector<scoped_ptr<NativeRunner>> native_runners_; | 190 std::vector<scoped_ptr<NativeRunner>> native_runners_; |
193 scoped_ptr<ShellConnection> shell_connection_; | 191 scoped_ptr<ShellConnection> shell_connection_; |
194 base::WeakPtrFactory<Shell> weak_ptr_factory_; | 192 base::WeakPtrFactory<Shell> weak_ptr_factory_; |
195 | 193 |
196 DISALLOW_COPY_AND_ASSIGN(Shell); | 194 DISALLOW_COPY_AND_ASSIGN(Shell); |
197 }; | 195 }; |
198 | 196 |
199 mojom::Connector::ConnectCallback EmptyConnectCallback(); | 197 mojom::Connector::ConnectCallback EmptyConnectCallback(); |
200 | 198 |
201 } // namespace shell | 199 } // namespace shell |
202 } // namespace mojo | 200 } // namespace mojo |
203 | 201 |
204 #endif // MOJO_SHELL_SHELL_H_ | 202 #endif // MOJO_SHELL_SHELL_H_ |
OLD | NEW |