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

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

Issue 2118083002: ShellClient -> Service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mus2
Patch Set: . Created 4 years, 5 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/runner/host/out_of_process_native_runner.cc ('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/native_runner.h" 17 #include "services/shell/native_runner.h"
18 #include "services/shell/public/cpp/capabilities.h" 18 #include "services/shell/public/cpp/capabilities.h"
19 #include "services/shell/public/cpp/identity.h" 19 #include "services/shell/public/cpp/identity.h"
20 #include "services/shell/public/cpp/interface_factory.h" 20 #include "services/shell/public/cpp/interface_factory.h"
21 #include "services/shell/public/cpp/shell_client.h" 21 #include "services/shell/public/cpp/service.h"
22 #include "services/shell/public/interfaces/connector.mojom.h" 22 #include "services/shell/public/interfaces/connector.mojom.h"
23 #include "services/shell/public/interfaces/interface_provider.mojom.h" 23 #include "services/shell/public/interfaces/interface_provider.mojom.h"
24 #include "services/shell/public/interfaces/service.mojom.h"
25 #include "services/shell/public/interfaces/service_factory.mojom.h"
24 #include "services/shell/public/interfaces/shell.mojom.h" 26 #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_factory.mojom.h"
27 #include "services/shell/public/interfaces/shell_resolver.mojom.h" 27 #include "services/shell/public/interfaces/shell_resolver.mojom.h"
28 28
29 namespace shell { 29 namespace shell {
30 class ShellConnection; 30 class ShellConnection;
31 31
32 // Creates an identity for the Shell, used when the Shell connects to 32 // Creates an identity for the Shell, used when the Shell connects to
33 // applications. 33 // applications.
34 Identity CreateShellIdentity(); 34 Identity CreateShellIdentity();
35 35
36 class Shell : public ShellClient { 36 class Shell : public Service {
37 public: 37 public:
38 // API for testing. 38 // API for testing.
39 class TestAPI { 39 class TestAPI {
40 public: 40 public:
41 explicit TestAPI(Shell* shell); 41 explicit TestAPI(Shell* shell);
42 ~TestAPI(); 42 ~TestAPI();
43 43
44 // Returns true if there is a Instance for this name. 44 // Returns true if there is a Instance for this name.
45 bool HasRunningInstanceForName(const std::string& name) const; 45 bool HasRunningInstanceForName(const std::string& name) const;
46 private: 46 private:
47 Shell* shell_; 47 Shell* shell_;
48 48
49 DISALLOW_COPY_AND_ASSIGN(TestAPI); 49 DISALLOW_COPY_AND_ASSIGN(TestAPI);
50 }; 50 };
51 51
52 // |native_runner_factory| is an instance of an object capable of vending 52 // |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. 53 // implementations of NativeRunner, e.g. for in or out-of-process execution.
54 // See native_runner.h and RunNativeApplication(). 54 // See native_runner.h and RunNativeApplication().
55 // |file_task_runner| provides access to a thread to perform file copy 55 // |file_task_runner| provides access to a thread to perform file copy
56 // operations on. 56 // operations on.
57 Shell(std::unique_ptr<NativeRunnerFactory> native_runner_factory, 57 Shell(std::unique_ptr<NativeRunnerFactory> native_runner_factory,
58 mojom::ShellClientPtr catalog); 58 mojom::ServicePtr catalog);
59 ~Shell() override; 59 ~Shell() override;
60 60
61 // Provide a callback to be notified whenever an instance is destroyed. 61 // 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 62 // 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. 63 // of instances it created are destroyed, so it can shut down.
64 void SetInstanceQuitCallback(base::Callback<void(const Identity&)> callback); 64 void SetInstanceQuitCallback(base::Callback<void(const Identity&)> callback);
65 65
66 // Completes a connection between a source and target application as defined 66 // Completes a connection between a source and target application as defined
67 // by |params|, exchanging InterfaceProviders between them. If no existing 67 // by |params|, exchanging InterfaceProviders between them. If no existing
68 // instance of the target application is running, one will be loaded. 68 // instance of the target application is running, one will be loaded.
69 void Connect(std::unique_ptr<ConnectParams> params); 69 void Connect(std::unique_ptr<ConnectParams> params);
70 70
71 // Creates a new Instance identified as |name|. This is intended for use by 71 // 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 72 // the Shell's embedder to register itself with the shell. This must only be
73 // called once. 73 // called once.
74 mojom::ShellClientRequest InitInstanceForEmbedder(const std::string& name); 74 mojom::ServiceRequest InitInstanceForEmbedder(const std::string& name);
75 75
76 private: 76 private:
77 class Instance; 77 class Instance;
78 78
79 // ShellClient: 79 // Service:
80 bool AcceptConnection(Connection* connection) override; 80 bool OnConnect(Connection* connection) override;
81 81
82 void InitCatalog(mojom::ShellClientPtr catalog); 82 void InitCatalog(mojom::ServicePtr catalog);
83 83
84 // Returns the resolver to use for the specified identity. 84 // Returns the resolver to use for the specified identity.
85 // NOTE: ShellResolvers are cached to ensure we service requests in order. If 85 // NOTE: ShellResolvers are cached to ensure we service requests in order. If
86 // we use a separate ShellResolver for each request ordering is not 86 // we use a separate ShellResolver for each request ordering is not
87 // guaranteed and can lead to random flake. 87 // guaranteed and can lead to random flake.
88 mojom::ShellResolver* GetResolver(const Identity& identity); 88 mojom::ShellResolver* GetResolver(const Identity& identity);
89 89
90 // Destroys all Shell-ends of connections established with Applications. 90 // Destroys all Shell-ends of connections established with Applications.
91 // Applications connected by this Shell will observe pipe errors and have a 91 // Applications connected by this Shell will observe pipe errors and have a
92 // chance to shutdown. 92 // chance to shutdown.
93 void TerminateShellConnections(); 93 void TerminateShellConnections();
94 94
95 // Removes a Instance when it encounters an error. 95 // Removes a Instance when it encounters an error.
96 void OnInstanceError(Instance* instance); 96 void OnInstanceError(Instance* instance);
97 97
98 // Completes a connection between a source and target application as defined 98 // Completes a connection between a source and target application as defined
99 // by |params|, exchanging InterfaceProviders between them. If no existing 99 // by |params|, exchanging InterfaceProviders between them. If no existing
100 // instance of the target application is running, one will be loaded. 100 // instance of the target application is running, one will be loaded.
101 // 101 //
102 // If |client| is not null, there must not be an instance of the target 102 // If |client| is not null, there must not be an instance of the target
103 // application already running. The shell will create a new instance and use 103 // application already running. The shell will create a new instance and use
104 // |client| to control it. 104 // |client| to control it.
105 void Connect(std::unique_ptr<ConnectParams> params, 105 void Connect(std::unique_ptr<ConnectParams> params,
106 mojom::ShellClientPtr client); 106 mojom::ServicePtr client);
107 107
108 // Returns a running instance matching |identity|. This might be an instance 108 // Returns a running instance matching |identity|. This might be an instance
109 // running as a different user if one is available that services all users. 109 // running as a different user if one is available that services all users.
110 Instance* GetExistingInstance(const Identity& identity) const; 110 Instance* GetExistingInstance(const Identity& identity) const;
111 111
112 void NotifyPIDAvailable(uint32_t id, base::ProcessId pid); 112 void NotifyPIDAvailable(uint32_t id, base::ProcessId pid);
113 113
114 // Attempt to complete the connection requested by |params| by connecting to 114 // Attempt to complete the connection requested by |params| by connecting to
115 // an existing instance. If there is an existing instance, |params| is taken, 115 // an existing instance. If there is an existing instance, |params| is taken,
116 // and this function returns true. 116 // and this function returns true.
117 bool ConnectToExistingInstance(std::unique_ptr<ConnectParams>* params); 117 bool ConnectToExistingInstance(std::unique_ptr<ConnectParams>* params);
118 118
119 Instance* CreateInstance(const Identity& source, 119 Instance* CreateInstance(const Identity& source,
120 const Identity& target, 120 const Identity& target,
121 const CapabilitySpec& spec); 121 const CapabilitySpec& spec);
122 122
123 // Called from the instance implementing mojom::Shell. 123 // Called from the instance implementing mojom::Shell.
124 void AddInstanceListener(mojom::InstanceListenerPtr listener); 124 void AddInstanceListener(mojom::InstanceListenerPtr listener);
125 125
126 void CreateShellClientWithFactory(const Identity& shell_client_factory, 126 void CreateServiceWithFactory(const Identity& service_factory,
127 const std::string& name, 127 const std::string& name,
128 mojom::ShellClientRequest request); 128 mojom::ServiceRequest request);
129 // Returns a running ShellClientFactory for |shell_client_factory_identity|. 129 // Returns a running ServiceFactory for |service_factory_identity|.
130 // If there is not one running one is started for |source_identity|. 130 // If there is not one running one is started for |source_identity|.
131 mojom::ShellClientFactory* GetShellClientFactory( 131 mojom::ServiceFactory* GetServiceFactory(
132 const Identity& shell_client_factory_identity); 132 const Identity& service_factory_identity);
133 void OnShellClientFactoryLost(const Identity& which); 133 void OnServiceFactoryLost(const Identity& which);
134 134
135 // Callback when remote Catalog resolves mojo:foo to mojo:bar. 135 // Callback when remote Catalog resolves mojo:foo to mojo:bar.
136 // |params| are the params passed to Connect(). 136 // |params| are the params passed to Connect().
137 // |client| if provided is a ShellClientPtr which should be used to manage the 137 // |client| if provided is a ServicePtr which should be used to manage the
138 // new application instance. This may be null. 138 // new application instance. This may be null.
139 // |result| contains the result of the resolve operation. 139 // |result| contains the result of the resolve operation.
140 void OnGotResolvedName(std::unique_ptr<ConnectParams> params, 140 void OnGotResolvedName(std::unique_ptr<ConnectParams> params,
141 mojom::ShellClientPtr client, 141 mojom::ServicePtr client,
142 mojom::ResolveResultPtr result); 142 mojom::ResolveResultPtr result);
143 143
144 base::WeakPtr<Shell> GetWeakPtr(); 144 base::WeakPtr<Shell> GetWeakPtr();
145 145
146 std::map<Identity, Instance*> identity_to_instance_; 146 std::map<Identity, Instance*> identity_to_instance_;
147 147
148 // Tracks the names of instances that are allowed to field connection requests 148 // Tracks the names of instances that are allowed to field connection requests
149 // from all users. 149 // from all users.
150 std::set<std::string> singletons_; 150 std::set<std::string> singletons_;
151 151
152 std::map<Identity, mojom::ShellClientFactoryPtr> shell_client_factories_; 152 std::map<Identity, mojom::ServiceFactoryPtr> service_factories_;
153 std::map<Identity, mojom::ShellResolverPtr> identity_to_resolver_; 153 std::map<Identity, mojom::ShellResolverPtr> identity_to_resolver_;
154 mojo::InterfacePtrSet<mojom::InstanceListener> instance_listeners_; 154 mojo::InterfacePtrSet<mojom::InstanceListener> instance_listeners_;
155 base::Callback<void(const Identity&)> instance_quit_callback_; 155 base::Callback<void(const Identity&)> instance_quit_callback_;
156 std::unique_ptr<NativeRunnerFactory> native_runner_factory_; 156 std::unique_ptr<NativeRunnerFactory> native_runner_factory_;
157 std::unique_ptr<ShellConnection> shell_connection_; 157 std::unique_ptr<ShellConnection> shell_connection_;
158 base::WeakPtrFactory<Shell> weak_ptr_factory_; 158 base::WeakPtrFactory<Shell> weak_ptr_factory_;
159 159
160 DISALLOW_COPY_AND_ASSIGN(Shell); 160 DISALLOW_COPY_AND_ASSIGN(Shell);
161 }; 161 };
162 162
163 mojom::Connector::ConnectCallback EmptyConnectCallback(); 163 mojom::Connector::ConnectCallback EmptyConnectCallback();
164 164
165 } // namespace shell 165 } // namespace shell
166 166
167 #endif // SERVICES_SHELL_SHELL_H_ 167 #endif // SERVICES_SHELL_SHELL_H_
OLDNEW
« no previous file with comments | « services/shell/runner/host/out_of_process_native_runner.cc ('k') | services/shell/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698