OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 5 #ifndef SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
6 #define SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 6 #define SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // Construct with a Connection (which may be null), and create an | 59 // Construct with a Connection (which may be null), and create an |
60 // InterfaceProvider pipe, the client end of which may be obtained by calling | 60 // InterfaceProvider pipe, the client end of which may be obtained by calling |
61 // TakeClientHandle(). If |connection| is non-null, the Mojo Shell's | 61 // TakeClientHandle(). If |connection| is non-null, the Mojo Shell's |
62 // rules filtering which interfaces are allowed to be exposed to clients are | 62 // rules filtering which interfaces are allowed to be exposed to clients are |
63 // imposed on this registry. If null, they are not. | 63 // imposed on this registry. If null, they are not. |
64 explicit InterfaceRegistry(Connection* connection); | 64 explicit InterfaceRegistry(Connection* connection); |
65 ~InterfaceRegistry() override; | 65 ~InterfaceRegistry() override; |
66 | 66 |
67 void Bind(mojom::InterfaceProviderRequest local_interfaces_request); | 67 void Bind(mojom::InterfaceProviderRequest local_interfaces_request); |
68 | 68 |
| 69 base::WeakPtr<InterfaceRegistry> GetWeakPtr(); |
| 70 |
69 // Allows |Interface| to be exposed via this registry. Requests to bind will | 71 // Allows |Interface| to be exposed via this registry. Requests to bind will |
70 // be handled by |factory|. Returns true if the interface was exposed, false | 72 // be handled by |factory|. Returns true if the interface was exposed, false |
71 // if Connection policy prevented exposure. | 73 // if Connection policy prevented exposure. |
72 template <typename Interface> | 74 template <typename Interface> |
73 bool AddInterface(InterfaceFactory<Interface>* factory) { | 75 bool AddInterface(InterfaceFactory<Interface>* factory) { |
74 return SetInterfaceBinderForName( | 76 return SetInterfaceBinderForName( |
75 base::WrapUnique( | 77 base::WrapUnique( |
76 new internal::InterfaceFactoryBinder<Interface>(factory)), | 78 new internal::InterfaceFactoryBinder<Interface>(factory)), |
77 Interface::Name_); | 79 Interface::Name_); |
78 } | 80 } |
(...skipping 29 matching lines...) Expand all Loading... |
108 // Returns true if the binder was set, false if it was not set (e.g. by | 110 // Returns true if the binder was set, false if it was not set (e.g. by |
109 // some filtering policy preventing this interface from being exposed). | 111 // some filtering policy preventing this interface from being exposed). |
110 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, | 112 bool SetInterfaceBinderForName(std::unique_ptr<InterfaceBinder> binder, |
111 const std::string& name); | 113 const std::string& name); |
112 | 114 |
113 mojo::Binding<mojom::InterfaceProvider> binding_; | 115 mojo::Binding<mojom::InterfaceProvider> binding_; |
114 Connection* connection_; | 116 Connection* connection_; |
115 | 117 |
116 NameToInterfaceBinderMap name_to_binder_; | 118 NameToInterfaceBinderMap name_to_binder_; |
117 | 119 |
| 120 base::WeakPtrFactory<InterfaceRegistry> weak_factory_; |
| 121 |
118 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); | 122 DISALLOW_COPY_AND_ASSIGN(InterfaceRegistry); |
119 }; | 123 }; |
120 | 124 |
121 } // namespace shell | 125 } // namespace shell |
122 | 126 |
123 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ | 127 #endif // SERVICES_SHELL_PUBLIC_CPP_INTERFACE_REGISTRY_H_ |
OLD | NEW |