| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef InterfaceRegistry_h |
| 6 #define InterfaceRegistry_h |
| 7 |
| 8 #include "base/callback_forward.h" |
| 9 #include "mojo/public/cpp/system/message_pipe.h" |
| 10 #include "public/platform/WebCommon.h" |
| 11 |
| 12 #if INSIDE_BLINK |
| 13 #include "mojo/public/cpp/bindings/interface_request.h" |
| 14 #include "wtf/Functional.h" |
| 15 #endif |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 using InterfaceFactory = base::Callback<void(mojo::ScopedMessagePipeHandle)>; |
| 20 |
| 21 class BLINK_PLATFORM_EXPORT InterfaceRegistry { |
| 22 public: |
| 23 virtual void addInterface(const char* name, const InterfaceFactory&) = 0; |
| 24 |
| 25 #if INSIDE_BLINK |
| 26 static InterfaceRegistry* getEmptyInterfaceRegistry(); |
| 27 |
| 28 template <typename Interface> |
| 29 void addInterface( |
| 30 std::unique_ptr<WTF::Function<void(mojo::InterfaceRequest<Interface>)>> |
| 31 factory) { |
| 32 addInterface(Interface::Name_, |
| 33 convertToBaseCallback(WTF::bind( |
| 34 &InterfaceRegistry::forwardToInterfaceFactory<Interface>, |
| 35 std::move(factory)))); |
| 36 } |
| 37 |
| 38 private: |
| 39 template <typename Interface> |
| 40 static void forwardToInterfaceFactory( |
| 41 const std::unique_ptr< |
| 42 WTF::Function<void(mojo::InterfaceRequest<Interface>)>>& factory, |
| 43 mojo::ScopedMessagePipeHandle handle) { |
| 44 (*factory)(mojo::MakeRequest<Interface>(std::move(handle))); |
| 45 } |
| 46 #endif // INSIDE_BLINK |
| 47 }; |
| 48 |
| 49 } // namespace blink |
| 50 |
| 51 #endif |
| OLD | NEW |