Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: third_party/WebKit/public/platform/InterfaceRegistry.h

Issue 2401333002: Add a blink InterfaceRegistry. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/web/WebLocalFrameImpl.cpp ('k') | third_party/WebKit/public/web/WebFrameClient.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « third_party/WebKit/Source/web/WebLocalFrameImpl.cpp ('k') | third_party/WebKit/public/web/WebFrameClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698