| 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_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ | 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ |
| 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ | 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 struct BindSourceInfo; | 21 struct BindSourceInfo; |
| 22 | 22 |
| 23 class BinderRegistry { | 23 class BinderRegistry { |
| 24 public: | 24 public: |
| 25 using Binder = base::Callback<void(const std::string&, | 25 using Binder = base::Callback<void(const std::string&, |
| 26 mojo::ScopedMessagePipeHandle)>; | 26 mojo::ScopedMessagePipeHandle)>; |
| 27 | 27 |
| 28 BinderRegistry(); | 28 BinderRegistry(); |
| 29 ~BinderRegistry(); | 29 ~BinderRegistry(); |
| 30 | 30 |
| 31 // Provide a callback to be run when a request to bind |Interface| is received | |
| 32 // by this registry. | |
| 33 template <typename Interface> | 31 template <typename Interface> |
| 34 void AddInterface( | 32 void AddInterface( |
| 35 const base::Callback<void(mojo::InterfaceRequest<Interface>)>& callback, | 33 const base::Callback<void(const BindSourceInfo&, |
| 34 mojo::InterfaceRequest<Interface>)>& callback, |
| 36 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = | 35 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = |
| 37 nullptr) { | 36 nullptr) { |
| 38 SetInterfaceBinder(Interface::Name_, | 37 SetInterfaceBinder(Interface::Name_, |
| 39 base::MakeUnique<internal::CallbackBinder<Interface>>( | 38 base::MakeUnique<internal::CallbackBinder<Interface>>( |
| 40 callback, task_runner)); | 39 callback, task_runner)); |
| 41 } | 40 } |
| 42 template <typename Interface> | |
| 43 void AddInterface( | |
| 44 const base::Callback<void(const BindSourceInfo&, | |
| 45 mojo::InterfaceRequest<Interface>)>& callback, | |
| 46 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = | |
| 47 nullptr) { | |
| 48 SetInterfaceBinder( | |
| 49 Interface::Name_, | |
| 50 base::MakeUnique<internal::CallbackBinderWithSourceInfo<Interface>>( | |
| 51 callback, task_runner)); | |
| 52 } | |
| 53 void AddInterface( | 41 void AddInterface( |
| 54 const std::string& interface_name, | 42 const std::string& interface_name, |
| 55 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback, | 43 const base::Callback<void(mojo::ScopedMessagePipeHandle)>& callback, |
| 56 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = nullptr); | 44 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = nullptr); |
| 57 | 45 |
| 58 // Removes the specified interface from the registry. This has no effect on | 46 // Removes the specified interface from the registry. This has no effect on |
| 59 // bindings already completed. | 47 // bindings already completed. |
| 60 template <typename Interface> | 48 template <typename Interface> |
| 61 void RemoveInterface() { | 49 void RemoveInterface() { |
| 62 RemoveInterface(Interface::Name_); | 50 RemoveInterface(Interface::Name_); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 86 | 74 |
| 87 base::WeakPtrFactory<BinderRegistry> weak_factory_; | 75 base::WeakPtrFactory<BinderRegistry> weak_factory_; |
| 88 | 76 |
| 89 DISALLOW_COPY_AND_ASSIGN(BinderRegistry); | 77 DISALLOW_COPY_AND_ASSIGN(BinderRegistry); |
| 90 }; | 78 }; |
| 91 | 79 |
| 92 | 80 |
| 93 } // namespace service_manager | 81 } // namespace service_manager |
| 94 | 82 |
| 95 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ | 83 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_BINDER_REGISTRY_H_ |
| OLD | NEW |