OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef DispatcherBase_h | 5 #ifndef {{"_".join(config.protocol.namespace)}}_DispatcherBase_h |
6 #define DispatcherBase_h | 6 #define {{"_".join(config.protocol.namespace)}}_DispatcherBase_h |
7 | 7 |
8 //#include "BackendCallback.h" | 8 //#include "BackendCallback.h" |
9 //#include "Collections.h" | 9 //#include "Collections.h" |
10 //#include "ErrorSupport.h" | 10 //#include "ErrorSupport.h" |
| 11 //#include "FrontendChannel.h" |
11 //#include "Platform.h" | 12 //#include "Platform.h" |
12 //#include "String16.h" | 13 //#include "String.h" |
13 //#include "Values.h" | 14 //#include "Values.h" |
14 #include "{{config.class_export.header}}" | |
15 | 15 |
16 namespace blink { | 16 {% for namespace in config.protocol.namespace %} |
17 namespace protocol { | 17 namespace {{namespace}} { |
| 18 {% endfor %} |
18 | 19 |
19 class FrontendChannel; | |
20 class WeakPtr; | 20 class WeakPtr; |
21 | 21 |
22 class {{config.class_export.macro}} DispatcherBase { | 22 class {{config.class_export.macro}} DispatcherBase { |
23 PROTOCOL_DISALLOW_COPY(DispatcherBase); | 23 PROTOCOL_DISALLOW_COPY(DispatcherBase); |
24 public: | 24 public: |
25 static const char kInvalidRequest[]; | 25 static const char kInvalidRequest[]; |
26 class {{config.class_export.macro}} WeakPtr { | 26 class {{config.class_export.macro}} WeakPtr { |
27 public: | 27 public: |
28 explicit WeakPtr(DispatcherBase*); | 28 explicit WeakPtr(DispatcherBase*); |
29 ~WeakPtr(); | 29 ~WeakPtr(); |
(...skipping 23 matching lines...) Expand all Loading... |
53 | 53 |
54 enum CommonErrorCode { | 54 enum CommonErrorCode { |
55 ParseError = -32700, | 55 ParseError = -32700, |
56 InvalidRequest = -32600, | 56 InvalidRequest = -32600, |
57 MethodNotFound = -32601, | 57 MethodNotFound = -32601, |
58 InvalidParams = -32602, | 58 InvalidParams = -32602, |
59 InternalError = -32603, | 59 InternalError = -32603, |
60 ServerError = -32000, | 60 ServerError = -32000, |
61 }; | 61 }; |
62 | 62 |
63 static bool getCommandName(const String16& message, String16* result); | 63 static bool getCommandName(const String& message, String* result); |
64 | 64 |
65 virtual void dispatch(int callId, const String16& method, std::unique_ptr<pr
otocol::DictionaryValue> messageObject) = 0; | 65 virtual void dispatch(int callId, const String& method, std::unique_ptr<prot
ocol::DictionaryValue> messageObject) = 0; |
66 | 66 |
67 void sendResponse(int callId, const ErrorString&, ErrorSupport*, std::unique
_ptr<protocol::DictionaryValue> result); | 67 void sendResponse(int callId, const ErrorString&, ErrorSupport*, std::unique
_ptr<protocol::DictionaryValue> result); |
68 void sendResponse(int callId, const ErrorString&, std::unique_ptr<protocol::
DictionaryValue> result); | 68 void sendResponse(int callId, const ErrorString&, std::unique_ptr<protocol::
DictionaryValue> result); |
69 void sendResponse(int callId, const ErrorString&); | 69 void sendResponse(int callId, const ErrorString&); |
70 | 70 |
71 void reportProtocolError(int callId, CommonErrorCode, const String16& errorM
essage, ErrorSupport* errors); | 71 void reportProtocolError(int callId, CommonErrorCode, const String& errorMes
sage, ErrorSupport* errors); |
72 void clearFrontend(); | 72 void clearFrontend(); |
73 | 73 |
74 std::unique_ptr<WeakPtr> weakPtr(); | 74 std::unique_ptr<WeakPtr> weakPtr(); |
75 | 75 |
76 private: | 76 private: |
77 FrontendChannel* m_frontendChannel; | 77 FrontendChannel* m_frontendChannel; |
78 protocol::HashSet<WeakPtr*> m_weakPtrs; | 78 protocol::HashSet<WeakPtr*> m_weakPtrs; |
79 }; | 79 }; |
80 | 80 |
81 class {{config.class_export.macro}} UberDispatcher { | 81 class {{config.class_export.macro}} UberDispatcher { |
82 PROTOCOL_DISALLOW_COPY(UberDispatcher); | 82 PROTOCOL_DISALLOW_COPY(UberDispatcher); |
83 public: | 83 public: |
84 explicit UberDispatcher(FrontendChannel*); | 84 explicit UberDispatcher(FrontendChannel*); |
85 void registerBackend(const String16& name, std::unique_ptr<protocol::Dispatc
herBase>); | 85 void registerBackend(const String& name, std::unique_ptr<protocol::Dispatche
rBase>); |
86 void dispatch(const String16& message); | 86 void dispatch(const String& message); |
87 FrontendChannel* channel() { return m_frontendChannel; } | 87 FrontendChannel* channel() { return m_frontendChannel; } |
88 virtual ~UberDispatcher(); | 88 virtual ~UberDispatcher(); |
89 | 89 |
90 private: | 90 private: |
91 FrontendChannel* m_frontendChannel; | 91 FrontendChannel* m_frontendChannel; |
92 protocol::HashMap<String16, std::unique_ptr<protocol::DispatcherBase>> m_dis
patchers; | 92 protocol::HashMap<String, std::unique_ptr<protocol::DispatcherBase>> m_dispa
tchers; |
93 }; | 93 }; |
94 | 94 |
95 } // namespace platform | 95 {% for namespace in config.protocol.namespace %} |
96 } // namespace blink | 96 } // namespace {{namespace}} |
| 97 {% endfor %} |
97 | 98 |
98 #endif // !defined(DispatcherBase_h) | 99 #endif // !defined({{"_".join(config.protocol.namespace)}}_DispatcherBase_h) |
OLD | NEW |