| Index: content/public/common/associated_interface_registry.h
|
| diff --git a/content/public/common/associated_interface_registry.h b/content/public/common/associated_interface_registry.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..42c89bc57e33d67a60544f0af94bb36cd9299d1c
|
| --- /dev/null
|
| +++ b/content/public/common/associated_interface_registry.h
|
| @@ -0,0 +1,52 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_REGISTRY_H_
|
| +#define CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_REGISTRY_H_
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/callback.h"
|
| +#include "mojo/public/cpp/bindings/associated_interface_request.h"
|
| +#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
|
| +
|
| +namespace content {
|
| +
|
| +class AssociatedInterfaceRegistry {
|
| + public:
|
| + using Binder = base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>;
|
| +
|
| + virtual ~AssociatedInterfaceRegistry() {}
|
| +
|
| + // Adds an interface binder to the registry.
|
| + virtual void AddInterface(const std::string& name, const Binder& binder) = 0;
|
| +
|
| + // Removes an interface binder from the registry.
|
| + virtual void RemoveInterface(const std::string& name) = 0;
|
| +
|
| + template <typename Interface>
|
| + using InterfaceBinder =
|
| + base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>;
|
| +
|
| + // Templated helper for AddInterface() above.
|
| + template <typename Interface>
|
| + void AddInterface(const InterfaceBinder<Interface>& binder) {
|
| + AddInterface(Interface::Name_,
|
| + base::Bind(&BindInterface<Interface>, binder));
|
| + }
|
| +
|
| + private:
|
| + template <typename Interface>
|
| + static void BindInterface(const InterfaceBinder<Interface>& binder,
|
| + mojo::ScopedInterfaceEndpointHandle handle) {
|
| + mojo::AssociatedInterfaceRequest<Interface> request;
|
| + request.Bind(std::move(handle));
|
| + binder.Run(std::move(request));
|
| + }
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_PUBLIC_COMMON_ASSOCIATED_INTERFACE_REGISTRY_H_
|
|
|