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

Side by Side Diff: services/service_manager/public/cpp/service_context.h

Issue 2480603004: Service Manager: Implement graceful service termination (Closed)
Patch Set: Created 4 years, 1 month 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
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_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_ 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_
6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_ 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
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.h" 14 #include "mojo/public/cpp/bindings/binding.h"
15 #include "mojo/public/cpp/system/core.h" 15 #include "mojo/public/cpp/system/core.h"
16 #include "services/service_manager/public/cpp/connector.h" 16 #include "services/service_manager/public/cpp/connector.h"
17 #include "services/service_manager/public/cpp/service.h" 17 #include "services/service_manager/public/cpp/service.h"
18 #include "services/service_manager/public/interfaces/connector.mojom.h" 18 #include "services/service_manager/public/interfaces/connector.mojom.h"
19 #include "services/service_manager/public/interfaces/service.mojom.h" 19 #include "services/service_manager/public/interfaces/service.mojom.h"
20 #include "services/service_manager/public/interfaces/service_control.mojom.h"
20 21
21 namespace service_manager { 22 namespace service_manager {
22 23
23 // Encapsulates a connection to the Service Manager in two parts: 24 // Encapsulates a connection to the Service Manager in two parts:
24 // - a bound InterfacePtr to mojom::Connector, the primary mechanism 25 // - a bound InterfacePtr to mojom::Connector, the primary mechanism
25 // by which the instantiating service connects to other services, 26 // by which the instantiating service connects to other services,
26 // brokered by the Service Manager. 27 // brokered by the Service Manager.
27 // - a bound InterfaceRequest of mojom::Service, an interface used by the 28 // - a bound InterfaceRequest of mojom::Service, an interface used by the
28 // Service Manager to inform this service of lifecycle events and 29 // Service Manager to inform this service of lifecycle events and
29 // inbound connections brokered by it. 30 // inbound connections brokered by it.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 void DestroyService(); 103 void DestroyService();
103 104
104 private: 105 private:
105 using InterfaceRegistryMap = 106 using InterfaceRegistryMap =
106 std::map<InterfaceRegistry*, std::unique_ptr<InterfaceRegistry>>; 107 std::map<InterfaceRegistry*, std::unique_ptr<InterfaceRegistry>>;
107 108
108 // mojom::Service: 109 // mojom::Service:
109 void OnStart(const ServiceInfo& info, 110 void OnStart(const ServiceInfo& info,
110 const OnStartCallback& callback) override; 111 const OnStartCallback& callback) override;
111 void OnConnect(const ServiceInfo& source_info, 112 void OnConnect(const ServiceInfo& source_info,
112 mojom::InterfaceProviderRequest interfaces) override; 113 mojom::InterfaceProviderRequest interfaces,
114 const OnConnectCallback& callback) override;
113 115
114 void OnConnectionError(); 116 void OnConnectionError();
115 void OnRegistryConnectionError(InterfaceRegistry* registry); 117 void OnRegistryConnectionError(InterfaceRegistry* registry);
116 void DestroyConnectionInterfaceRegistry(InterfaceRegistry* registry); 118 void DestroyConnectionInterfaceRegistry(InterfaceRegistry* registry);
117 119
118 // We track the lifetime of incoming connection registries as a convenience 120 // We track the lifetime of incoming connection registries as a convenience
119 // for the client. 121 // for the client.
120 InterfaceRegistryMap connection_interface_registries_; 122 InterfaceRegistryMap connection_interface_registries_;
121 123
122 // A pending Connector request which will eventually be passed to the Service 124 // A pending Connector request which will eventually be passed to the Service
123 // Manager. 125 // Manager.
124 mojom::ConnectorRequest pending_connector_request_; 126 mojom::ConnectorRequest pending_connector_request_;
125 127
126 std::unique_ptr<service_manager::Service> service_; 128 std::unique_ptr<service_manager::Service> service_;
127 mojo::Binding<mojom::Service> binding_; 129 mojo::Binding<mojom::Service> binding_;
128 std::unique_ptr<Connector> connector_; 130 std::unique_ptr<Connector> connector_;
129 service_manager::ServiceInfo local_info_; 131 service_manager::ServiceInfo local_info_;
130 132
133 // This instance's control interface to the service manager. Note that this
134 // is unbound and therefore invalid until OnStart() is called.
135 mojom::ServiceControlAssociatedPtr service_control_;
136
131 bool service_quit_ = false; 137 bool service_quit_ = false;
132 138
133 base::Closure connection_lost_closure_; 139 base::Closure connection_lost_closure_;
134 140
135 base::WeakPtrFactory<ServiceContext> weak_factory_; 141 base::WeakPtrFactory<ServiceContext> weak_factory_;
136 142
137 DISALLOW_COPY_AND_ASSIGN(ServiceContext); 143 DISALLOW_COPY_AND_ASSIGN(ServiceContext);
138 }; 144 };
139 145
140 } // namespace service_manager 146 } // namespace service_manager
141 147
142 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_ 148 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698