Chromium Code Reviews| Index: third_party/WebKit/public/platform/InterfaceRegistry.h |
| diff --git a/third_party/WebKit/public/platform/InterfaceRegistry.h b/third_party/WebKit/public/platform/InterfaceRegistry.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c2537a246d4984d5a43ba42d1d5629dd5b9b621d |
| --- /dev/null |
| +++ b/third_party/WebKit/public/platform/InterfaceRegistry.h |
| @@ -0,0 +1,62 @@ |
| +// 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 InterfaceRegistry_h |
| +#define InterfaceRegistry_h |
| + |
| +#include "mojo/public/cpp/system/message_pipe.h" |
| +#include "public/platform/WebCallbacks.h" |
| +#include "public/platform/WebCommon.h" |
| + |
| +#if INSIDE_BLINK |
| +#include "mojo/public/cpp/bindings/interface_request.h" |
| +#include "wtf/Functional.h" |
| +#endif |
| + |
| +namespace blink { |
| + |
| +using InterfaceFactory = WebCallbacks<mojo::ScopedMessagePipeHandle, void>; |
|
esprehn
2016/10/13 22:31:55
Can we use Function and Closure directly instead?
Sam McNally
2016/10/14 00:35:57
Done.
|
| + |
| +class BLINK_PLATFORM_EXPORT InterfaceRegistry { |
| + public: |
| + virtual void addInterface(const char* name, |
| + std::unique_ptr<InterfaceFactory>) = 0; |
| + |
| +#if INSIDE_BLINK |
| + static InterfaceRegistry* getEmptyInterfaceRegistry(); |
| + |
| + template <typename Interface> |
| + void addInterface( |
| + std::unique_ptr<WTF::Function<void(mojo::InterfaceRequest<Interface>)>> |
| + factory) { |
| + addInterface(Interface::Name_, |
| + std::unique_ptr<InterfaceFactory>( |
| + new CallbackImpl<Interface>(std::move(factory)))); |
|
esprehn
2016/10/13 22:31:55
convertToBaseCallback ?
Sam McNally
2016/10/14 00:35:57
Done.
|
| + } |
| + |
| + private: |
| + template <typename Interface> |
| + class CallbackImpl : public InterfaceFactory { |
| + public: |
| + CallbackImpl( |
| + std::unique_ptr<WTF::Function<void(mojo::InterfaceRequest<Interface>)>> |
| + factory) |
| + : m_factory(std::move(factory)) {} |
| + |
| + void onSuccess(mojo::ScopedMessagePipeHandle handle) override { |
| + (*m_factory)(mojo::MakeRequest<Interface>(std::move(handle))); |
| + } |
| + |
| + void onError() {} |
|
esprehn
2016/10/13 22:31:55
Yeah you definitely want to use convertToBaseCallb
Sam McNally
2016/10/14 00:35:57
Done.
|
| + |
| + private: |
| + std::unique_ptr<WTF::Function<void(mojo::InterfaceRequest<Interface>)>> |
| + m_factory; |
| + }; |
| +#endif // INSIDE_BLINK |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif |