| 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_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 <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.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 | 20 |
| 21 namespace shell { | 21 namespace service_manager { |
| 22 | 22 |
| 23 // Encapsulates a connection to the Service Manager in two parts: | 23 // Encapsulates a connection to the Service Manager in two parts: |
| 24 // - a bound InterfacePtr to mojom::Connector, the primary mechanism | 24 // - a bound InterfacePtr to mojom::Connector, the primary mechanism |
| 25 // by which the instantiating service connects to other services, | 25 // by which the instantiating service connects to other services, |
| 26 // brokered by the Service Manager. | 26 // brokered by the Service Manager. |
| 27 // - a bound InterfaceRequest of mojom::Service, an interface used by the | 27 // - a bound InterfaceRequest of mojom::Service, an interface used by the |
| 28 // Service Manager to inform this service of lifecycle events and | 28 // Service Manager to inform this service of lifecycle events and |
| 29 // inbound connections brokered by it. | 29 // inbound connections brokered by it. |
| 30 // | 30 // |
| 31 // This class should be used in two scenarios: | 31 // This class should be used in two scenarios: |
| 32 // - During early startup to bind the mojom::ServiceRequest obtained from | 32 // - During early startup to bind the mojom::ServiceRequest obtained from |
| 33 // the Service Manager, typically in response to either ServiceMain() or | 33 // the Service Manager, typically in response to either ServiceMain() or |
| 34 // main(). | 34 // main(). |
| 35 // - In an implementation of mojom::ServiceFactory to bind the | 35 // - In an implementation of mojom::ServiceFactory to bind the |
| 36 // mojom::ServiceRequest passed via CreateService. In this scenario there can | 36 // mojom::ServiceRequest passed via CreateService. In this scenario there can |
| 37 // be many instances of this class per process. | 37 // be many instances of this class per process. |
| 38 // | 38 // |
| 39 // Instances of this class are constructed with an implementation of the Service | 39 // Instances of this class are constructed with an implementation of the Service |
| 40 // Manager Client Lib's Service interface. See documentation in service.h | 40 // Manager Client Lib's Service interface. See documentation in service.h |
| 41 // for details. | 41 // for details. |
| 42 // | 42 // |
| 43 class ServiceContext : public mojom::Service { | 43 class ServiceContext : public mojom::Service { |
| 44 public: | 44 public: |
| 45 // Creates a new ServiceContext bound to |request|. This connection may be | 45 // Creates a new ServiceContext bound to |request|. This connection may be |
| 46 // used immediately to make outgoing connections via connector(). Does not | 46 // used immediately to make outgoing connections via connector(). Does not |
| 47 // take ownership of |service|, which must remain valid for the lifetime of | 47 // take ownership of |service|, which must remain valid for the lifetime of |
| 48 // ServiceContext. If either |connector| or |connector_request| is non-null | 48 // ServiceContext. If either |connector| or |connector_request| is non-null |
| 49 // both must be non-null. If both are null, the connection will create its own | 49 // both must be non-null. If both are null, the connection will create its own |
| 50 // Connector and request to pass to the Service Manager on initialization. | 50 // Connector and request to pass to the Service Manager on initialization. |
| 51 ServiceContext(shell::Service* service, | 51 ServiceContext(service_manager::Service* service, |
| 52 mojom::ServiceRequest request, | 52 mojom::ServiceRequest request, |
| 53 std::unique_ptr<Connector> connector = nullptr, | 53 std::unique_ptr<Connector> connector = nullptr, |
| 54 mojom::ConnectorRequest connector_request = nullptr); | 54 mojom::ConnectorRequest connector_request = nullptr); |
| 55 | 55 |
| 56 ~ServiceContext() override; | 56 ~ServiceContext() override; |
| 57 | 57 |
| 58 Connector* connector() { return connector_.get(); } | 58 Connector* connector() { return connector_.get(); } |
| 59 const Identity& identity() { return identity_; } | 59 const Identity& identity() { return identity_; } |
| 60 | 60 |
| 61 // Specify a function to be called when the connection to the shell is lost. | 61 // Specify a function to be called when the connection to the shell is lost. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 78 base::Closure initialize_handler_; | 78 base::Closure initialize_handler_; |
| 79 | 79 |
| 80 // We track the lifetime of incoming connection registries as it more | 80 // We track the lifetime of incoming connection registries as it more |
| 81 // convenient for the client. | 81 // convenient for the client. |
| 82 std::vector<std::unique_ptr<InterfaceRegistry>> incoming_connections_; | 82 std::vector<std::unique_ptr<InterfaceRegistry>> incoming_connections_; |
| 83 | 83 |
| 84 // A pending Connector request which will eventually be passed to the Service | 84 // A pending Connector request which will eventually be passed to the Service |
| 85 // Manager. | 85 // Manager. |
| 86 mojom::ConnectorRequest pending_connector_request_; | 86 mojom::ConnectorRequest pending_connector_request_; |
| 87 | 87 |
| 88 shell::Service* service_; | 88 service_manager::Service* service_; |
| 89 mojo::Binding<mojom::Service> binding_; | 89 mojo::Binding<mojom::Service> binding_; |
| 90 std::unique_ptr<Connector> connector_; | 90 std::unique_ptr<Connector> connector_; |
| 91 shell::Identity identity_; | 91 service_manager::Identity identity_; |
| 92 bool should_run_connection_lost_closure_ = false; | 92 bool should_run_connection_lost_closure_ = false; |
| 93 | 93 |
| 94 base::Closure connection_lost_closure_; | 94 base::Closure connection_lost_closure_; |
| 95 | 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(ServiceContext); | 96 DISALLOW_COPY_AND_ASSIGN(ServiceContext); |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 } // namespace shell | 99 } // namespace service_manager |
| 100 | 100 |
| 101 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_ | 101 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_ |
| OLD | NEW |