| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_CONNECTOR_REGISTRY_H_ | |
| 6 #define MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_CONNECTOR_REGISTRY_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "mojo/public/cpp/system/message_pipe.h" | |
| 12 | |
| 13 namespace mojo { | |
| 14 | |
| 15 class ApplicationConnection; | |
| 16 class ServiceConnector; | |
| 17 | |
| 18 namespace internal { | |
| 19 | |
| 20 // ServiceConnectorRegistry maintains a default ServiceConnector as well as at | |
| 21 // most one ServiceConnector per interface name. When ConnectToService() is | |
| 22 // invoked the ServiceConnector registered by name is given the request. If | |
| 23 // a ServiceConnector has not been registered by name than the default | |
| 24 // ServiceConnector is given the request. | |
| 25 class ServiceConnectorRegistry { | |
| 26 public: | |
| 27 ServiceConnectorRegistry(); | |
| 28 ~ServiceConnectorRegistry(); | |
| 29 | |
| 30 // Sets the default ServiceConnector. ServiceConnectorRegistry does *not* | |
| 31 // take ownership of |service_connector|. | |
| 32 void set_service_connector(ServiceConnector* service_connector) { | |
| 33 service_connector_ = service_connector; | |
| 34 } | |
| 35 | |
| 36 // Returns true if non ServiceConnectors have been registered by name. | |
| 37 bool empty() const { return name_to_service_connector_.empty(); } | |
| 38 | |
| 39 // Sets a ServiceConnector by name. This deletes the existing ServiceConnector | |
| 40 // and takes ownership of |service_connector|. | |
| 41 void SetServiceConnectorForName(ServiceConnector* service_connector, | |
| 42 const std::string& interface_name); | |
| 43 void RemoveServiceConnectorForName(const std::string& interface_name); | |
| 44 | |
| 45 void ConnectToService(ApplicationConnection* application_connection, | |
| 46 const std::string& interface_name, | |
| 47 ScopedMessagePipeHandle client_handle); | |
| 48 | |
| 49 private: | |
| 50 using NameToServiceConnectorMap = std::map<std::string, ServiceConnector*>; | |
| 51 | |
| 52 ServiceConnector* service_connector_; | |
| 53 | |
| 54 NameToServiceConnectorMap name_to_service_connector_; | |
| 55 | |
| 56 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorRegistry); | |
| 57 }; | |
| 58 | |
| 59 } // namespace internal | |
| 60 } // namespace mojo | |
| 61 | |
| 62 #endif // MOJO_APPLICATION_PUBLIC_CPP_LIB_SERVICE_CONNECTOR_REGISTRY_H_ | |
| OLD | NEW |