| 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 <map> |
| 8 #include <memory> | 9 #include <memory> |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 | 10 |
| 12 #include "base/callback.h" | 11 #include "base/callback.h" |
| 13 #include "base/macros.h" | 12 #include "base/macros.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 | 20 |
| 21 namespace service_manager { | 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: |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 Connector* connector() { return connector_.get(); } | 58 Connector* connector() { return connector_.get(); } |
| 59 const Identity& identity() { return local_info_.identity; } | 59 const Identity& identity() { return local_info_.identity; } |
| 60 | 60 |
| 61 // Specify a function to be called when the connection to the service manager | 61 // Specify a function to be called when the connection to the service manager |
| 62 // is lost. | 62 // is lost. |
| 63 // Note that if connection has already been lost, then |closure| is called | 63 // Note that if connection has already been lost, then |closure| is called |
| 64 // immediately. | 64 // immediately. |
| 65 void SetConnectionLostClosure(const base::Closure& closure); | 65 void SetConnectionLostClosure(const base::Closure& closure); |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 using InterfaceRegistryMap = |
| 69 std::map<InterfaceRegistry*, std::unique_ptr<InterfaceRegistry>>; |
| 70 |
| 68 // mojom::Service: | 71 // mojom::Service: |
| 69 void OnStart(const ServiceInfo& info, | 72 void OnStart(const ServiceInfo& info, |
| 70 const OnStartCallback& callback) override; | 73 const OnStartCallback& callback) override; |
| 71 void OnConnect(const ServiceInfo& source_info, | 74 void OnConnect(const ServiceInfo& source_info, |
| 72 mojom::InterfaceProviderRequest interfaces) override; | 75 mojom::InterfaceProviderRequest interfaces) override; |
| 73 | 76 |
| 74 void OnConnectionError(); | 77 void OnConnectionError(); |
| 78 void OnRegistryConnectionError(InterfaceRegistry* registry); |
| 79 void DestroyConnectionInterfaceRegistry(InterfaceRegistry* registry); |
| 75 | 80 |
| 76 // A callback called when OnStart() is run. | 81 // A callback called when OnStart() is run. |
| 77 base::Closure initialize_handler_; | 82 base::Closure initialize_handler_; |
| 78 | 83 |
| 79 // We track the lifetime of incoming connection registries as it more | 84 // We track the lifetime of incoming connection registries as a convenience |
| 80 // convenient for the client. | 85 // for the client. |
| 81 std::vector<std::unique_ptr<InterfaceRegistry>> incoming_connections_; | 86 InterfaceRegistryMap connection_interface_registries_; |
| 82 | 87 |
| 83 // A pending Connector request which will eventually be passed to the Service | 88 // A pending Connector request which will eventually be passed to the Service |
| 84 // Manager. | 89 // Manager. |
| 85 mojom::ConnectorRequest pending_connector_request_; | 90 mojom::ConnectorRequest pending_connector_request_; |
| 86 | 91 |
| 87 service_manager::Service* service_; | 92 service_manager::Service* service_; |
| 88 mojo::Binding<mojom::Service> binding_; | 93 mojo::Binding<mojom::Service> binding_; |
| 89 std::unique_ptr<Connector> connector_; | 94 std::unique_ptr<Connector> connector_; |
| 90 service_manager::ServiceInfo local_info_; | 95 service_manager::ServiceInfo local_info_; |
| 91 bool should_run_connection_lost_closure_ = false; | 96 bool should_run_connection_lost_closure_ = false; |
| 92 | 97 |
| 93 base::Closure connection_lost_closure_; | 98 base::Closure connection_lost_closure_; |
| 94 | 99 |
| 100 base::WeakPtrFactory<ServiceContext> weak_factory_; |
| 101 |
| 95 DISALLOW_COPY_AND_ASSIGN(ServiceContext); | 102 DISALLOW_COPY_AND_ASSIGN(ServiceContext); |
| 96 }; | 103 }; |
| 97 | 104 |
| 98 } // namespace service_manager | 105 } // namespace service_manager |
| 99 | 106 |
| 100 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_ | 107 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_CONTEXT_H_ |
| OLD | NEW |