| 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 SERVICES_SHELL_SERVICE_MANAGER_H_ | 5 #ifndef SERVICES_SHELL_SERVICE_MANAGER_H_ |
| 6 #define SERVICES_SHELL_SERVICE_MANAGER_H_ | 6 #define SERVICES_SHELL_SERVICE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Service Manager's embedder to register itself. This must only be called | 72 // the Service Manager's embedder to register itself. This must only be called |
| 73 // once. | 73 // once. |
| 74 mojom::ServiceRequest StartEmbedderService(const std::string& name); | 74 mojom::ServiceRequest StartEmbedderService(const std::string& name); |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 enum class InstanceErrorType { | |
| 78 // The Instance has lost it's Service pointer, but still has connections. It | |
| 79 // should not be immediately deleted. | |
| 80 LOST_SERVICE, | |
| 81 | |
| 82 // The Instance should no longer be kept around. | |
| 83 DESTROY, | |
| 84 }; | |
| 85 | |
| 86 class Instance; | 77 class Instance; |
| 87 | 78 |
| 88 // Service: | 79 // Service: |
| 89 bool OnConnect(const Identity& remote_identity, | 80 bool OnConnect(const Identity& remote_identity, |
| 90 InterfaceRegistry* registry) override; | 81 InterfaceRegistry* registry) override; |
| 91 | 82 |
| 92 void InitCatalog(mojom::ServicePtr catalog); | 83 void InitCatalog(mojom::ServicePtr catalog); |
| 93 | 84 |
| 94 // Returns the resolver to use for the specified identity. | 85 // Returns the resolver to use for the specified identity. |
| 95 // NOTE: Resolvers are cached to ensure we service requests in order. If | 86 // NOTE: Resolvers are cached to ensure we service requests in order. If |
| 96 // we use a separate Resolver for each request ordering is not | 87 // we use a separate Resolver for each request ordering is not |
| 97 // guaranteed and can lead to random flake. | 88 // guaranteed and can lead to random flake. |
| 98 mojom::Resolver* GetResolver(const Identity& identity); | 89 mojom::Resolver* GetResolver(const Identity& identity); |
| 99 | 90 |
| 100 // Destroys all Service Manager-ends of connections established with Services. | 91 // Destroys all Service Manager-ends of connections established with Services. |
| 101 // Services connected by this Service Manager will observe pipe errors and | 92 // Services connected by this Service Manager will observe pipe errors and |
| 102 // have a chance to shut down. | 93 // have a chance to shut down. |
| 103 void TerminateServiceManagerConnections(); | 94 void TerminateServiceManagerConnections(); |
| 104 | 95 |
| 105 // Called when |instance| encounters an error. If |error_type| is DESTROY | 96 // Called when |instance| encounters an error. Deletes |instance|. |
| 106 // the instance is deleted immediately, otherwise it is moved to | 97 void OnInstanceError(Instance* instance); |
| 107 // |instances_without_service_|. | 98 |
| 108 void OnInstanceError(Instance* instance, InstanceErrorType error_type); | 99 // Called when |instance| becomes unreachable to new connections because it |
| 100 // no longer has any pipes to the ServiceManager. |
| 101 void OnInstanceUnreachable(Instance* instance); |
| 102 |
| 103 // Called by an Instance as it's being destroyed. |
| 104 void OnInstanceStopped(const Identity& identity); |
| 109 | 105 |
| 110 // Completes a connection between a source and target application as defined | 106 // Completes a connection between a source and target application as defined |
| 111 // by |params|, exchanging InterfaceProviders between them. If no existing | 107 // by |params|, exchanging InterfaceProviders between them. If no existing |
| 112 // instance of the target application is running, one will be loaded. | 108 // instance of the target application is running, one will be loaded. |
| 113 // | 109 // |
| 114 // If |service| is not null, there must not be an instance of the target | 110 // If |service| is not null, there must not be an instance of the target |
| 115 // application already running. The Service Manager will create a new instance | 111 // application already running. The Service Manager will create a new instance |
| 116 // and use |service| to control it. | 112 // and use |service| to control it. |
| 117 // | 113 // |
| 118 // If |instance| is not null, the lifetime of the connection request is | 114 // If |instance| is not null, the lifetime of the connection request is |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // new application instance. This may be null. | 151 // new application instance. This may be null. |
| 156 // |result| contains the result of the resolve operation. | 152 // |result| contains the result of the resolve operation. |
| 157 void OnGotResolvedName(std::unique_ptr<ConnectParams> params, | 153 void OnGotResolvedName(std::unique_ptr<ConnectParams> params, |
| 158 mojom::ServicePtr service, | 154 mojom::ServicePtr service, |
| 159 bool has_source_instance, | 155 bool has_source_instance, |
| 160 base::WeakPtr<Instance> source_instance, | 156 base::WeakPtr<Instance> source_instance, |
| 161 mojom::ResolveResultPtr result); | 157 mojom::ResolveResultPtr result); |
| 162 | 158 |
| 163 base::WeakPtr<ServiceManager> GetWeakPtr(); | 159 base::WeakPtr<ServiceManager> GetWeakPtr(); |
| 164 | 160 |
| 161 // Ownership of all root Instances. Non-root Instances are owned by their |
| 162 // parent Instance. |
| 163 using InstanceMap = std::map<Instance*, std::unique_ptr<Instance>>; |
| 164 InstanceMap root_instances_; |
| 165 |
| 166 // Maps service identities to reachable instances. Note that the Instance* |
| 167 // values here are NOT owned by this map. |
| 165 std::map<Identity, Instance*> identity_to_instance_; | 168 std::map<Identity, Instance*> identity_to_instance_; |
| 166 | 169 |
| 167 // 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 |
| 168 // from all users. | 171 // from all users. |
| 169 std::set<std::string> singletons_; | 172 std::set<std::string> singletons_; |
| 170 | 173 |
| 171 // See OnInstanceError() for details. | |
| 172 std::set<Instance*> instances_without_service_; | |
| 173 | |
| 174 std::map<Identity, mojom::ServiceFactoryPtr> service_factories_; | 174 std::map<Identity, mojom::ServiceFactoryPtr> service_factories_; |
| 175 std::map<Identity, mojom::ResolverPtr> identity_to_resolver_; | 175 std::map<Identity, mojom::ResolverPtr> identity_to_resolver_; |
| 176 mojo::InterfacePtrSet<mojom::ServiceManagerListener> listeners_; | 176 mojo::InterfacePtrSet<mojom::ServiceManagerListener> listeners_; |
| 177 base::Callback<void(const Identity&)> instance_quit_callback_; | 177 base::Callback<void(const Identity&)> instance_quit_callback_; |
| 178 std::unique_ptr<NativeRunnerFactory> native_runner_factory_; | 178 std::unique_ptr<NativeRunnerFactory> native_runner_factory_; |
| 179 std::unique_ptr<ServiceContext> service_context_; | 179 std::unique_ptr<ServiceContext> service_context_; |
| 180 base::WeakPtrFactory<ServiceManager> weak_ptr_factory_; | 180 base::WeakPtrFactory<ServiceManager> weak_ptr_factory_; |
| 181 | 181 |
| 182 DISALLOW_COPY_AND_ASSIGN(ServiceManager); | 182 DISALLOW_COPY_AND_ASSIGN(ServiceManager); |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 mojom::Connector::ConnectCallback EmptyConnectCallback(); | 185 mojom::Connector::ConnectCallback EmptyConnectCallback(); |
| 186 | 186 |
| 187 } // namespace shell | 187 } // namespace shell |
| 188 | 188 |
| 189 #endif // SERVICES_SHELL_SERVICE_MANAGER_H_ | 189 #endif // SERVICES_SHELL_SERVICE_MANAGER_H_ |
| OLD | NEW |