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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 "mojo/public/cpp/system/message_pipe.h"
9 #include "public/platform/WebCallbacks.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 = 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.
20
21 class BLINK_PLATFORM_EXPORT InterfaceRegistry {
22 public:
23 virtual void addInterface(const char* name,
24 std::unique_ptr<InterfaceFactory>) = 0;
25
26 #if INSIDE_BLINK
27 static InterfaceRegistry* getEmptyInterfaceRegistry();
28
29 template <typename Interface>
30 void addInterface(
31 std::unique_ptr<WTF::Function<void(mojo::InterfaceRequest<Interface>)>>
32 factory) {
33 addInterface(Interface::Name_,
34 std::unique_ptr<InterfaceFactory>(
35 new CallbackImpl<Interface>(std::move(factory))));
esprehn 2016/10/13 22:31:55 convertToBaseCallback ?
Sam McNally 2016/10/14 00:35:57 Done.
36 }
37
38 private:
39 template <typename Interface>
40 class CallbackImpl : public InterfaceFactory {
41 public:
42 CallbackImpl(
43 std::unique_ptr<WTF::Function<void(mojo::InterfaceRequest<Interface>)>>
44 factory)
45 : m_factory(std::move(factory)) {}
46
47 void onSuccess(mojo::ScopedMessagePipeHandle handle) override {
48 (*m_factory)(mojo::MakeRequest<Interface>(std::move(handle)));
49 }
50
51 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.
52
53 private:
54 std::unique_ptr<WTF::Function<void(mojo::InterfaceRequest<Interface>)>>
55 m_factory;
56 };
57 #endif // INSIDE_BLINK
58 };
59
60 } // namespace blink
61
62 #endif
OLDNEW
« 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