OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_ | 5 #ifndef MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_ |
6 #define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_ | 6 #define MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "mojo/public/cpp/system/message_pipe.h" | 12 #include "mojo/public/cpp/system/message_pipe.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 | 15 |
16 class ApplicationConnection; | 16 struct ConnectionContext; |
17 class ServiceConnector; | 17 class ServiceConnector; |
18 | 18 |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 // ServiceConnectorRegistry maintains a default ServiceConnector as well as at | 21 // ServiceConnectorRegistry maintains a default ServiceConnector as well as at |
22 // most one ServiceConnector per interface name. When ConnectToService() is | 22 // most one ServiceConnector per interface name. When ConnectToService() is |
23 // invoked the ServiceConnector registered by name is given the request. | 23 // invoked the ServiceConnector registered by name is given the request. |
24 class ServiceConnectorRegistry { | 24 class ServiceConnectorRegistry { |
25 public: | 25 public: |
26 ServiceConnectorRegistry(); | 26 ServiceConnectorRegistry(); |
27 ~ServiceConnectorRegistry(); | 27 ~ServiceConnectorRegistry(); |
28 | 28 |
29 // Returns true if non ServiceConnectors have been registered by name. | 29 // Returns true if non ServiceConnectors have been registered by name. |
30 bool empty() const { return name_to_service_connector_.empty(); } | 30 bool empty() const { return name_to_service_connector_.empty(); } |
31 | 31 |
32 // Sets a ServiceConnector by name. This deletes any existing ServiceConnector | 32 // Sets a ServiceConnector by name. This deletes any existing ServiceConnector |
33 // of the same name. | 33 // of the same name. |
34 void SetServiceConnectorForName( | 34 void SetServiceConnectorForName( |
35 std::unique_ptr<ServiceConnector> service_connector, | 35 std::unique_ptr<ServiceConnector> service_connector, |
36 const std::string& interface_name); | 36 const std::string& interface_name); |
37 void RemoveServiceConnectorForName(const std::string& interface_name); | 37 void RemoveServiceConnectorForName(const std::string& interface_name); |
38 | 38 |
39 // ConnectToService returns true if this registery has an entry for | 39 // ConnectToService returns true if this registery has an entry for |
40 // |interface_name|. In that case, the |client_handle| is passed along | 40 // |interface_name|. In that case, the |client_handle| is passed along |
41 // to the |ServiceConnector|. Otherwise, this function returns false and | 41 // to the |ServiceConnector|. Otherwise, this function returns false and |
42 // |client_handle| is untouched. | 42 // |client_handle| is untouched. |
43 bool ConnectToService(ApplicationConnection* application_connection, | 43 bool ConnectToService(const ConnectionContext& connection_context, |
44 const std::string& interface_name, | 44 const std::string& interface_name, |
45 ScopedMessagePipeHandle* client_handle); | 45 ScopedMessagePipeHandle* client_handle); |
46 | 46 |
47 private: | 47 private: |
48 using NameToServiceConnectorMap = | 48 using NameToServiceConnectorMap = |
49 std::map<std::string, std::unique_ptr<ServiceConnector>>; | 49 std::map<std::string, std::unique_ptr<ServiceConnector>>; |
50 | 50 |
51 NameToServiceConnectorMap name_to_service_connector_; | 51 NameToServiceConnectorMap name_to_service_connector_; |
52 | 52 |
53 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorRegistry); | 53 MOJO_DISALLOW_COPY_AND_ASSIGN(ServiceConnectorRegistry); |
54 }; | 54 }; |
55 | 55 |
56 } // namespace internal | 56 } // namespace internal |
57 } // namespace mojo | 57 } // namespace mojo |
58 | 58 |
59 #endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_ | 59 #endif // MOJO_PUBLIC_CPP_APPLICATION_LIB_SERVICE_CONNECTOR_REGISTRY_H_ |
OLD | NEW |