| 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 DispatcherBase_h | |
| 6 #define DispatcherBase_h | |
| 7 | |
| 8 #include "platform/inspector_protocol/BackendCallback.h" | |
| 9 #include "platform/inspector_protocol/Collections.h" | |
| 10 #include "platform/inspector_protocol/ErrorSupport.h" | |
| 11 #include "platform/inspector_protocol/Platform.h" | |
| 12 #include "platform/inspector_protocol/String16.h" | |
| 13 #include "platform/inspector_protocol/Values.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 namespace protocol { | |
| 17 | |
| 18 class FrontendChannel; | |
| 19 class WeakPtr; | |
| 20 | |
| 21 class PLATFORM_EXPORT DispatcherBase { | |
| 22 PROTOCOL_DISALLOW_COPY(DispatcherBase); | |
| 23 public: | |
| 24 static const char kInvalidRequest[]; | |
| 25 class PLATFORM_EXPORT WeakPtr { | |
| 26 public: | |
| 27 explicit WeakPtr(DispatcherBase*); | |
| 28 ~WeakPtr(); | |
| 29 DispatcherBase* get() { return m_dispatcher; } | |
| 30 void dispose() { m_dispatcher = nullptr; } | |
| 31 | |
| 32 private: | |
| 33 DispatcherBase* m_dispatcher; | |
| 34 }; | |
| 35 | |
| 36 class PLATFORM_EXPORT Callback : public protocol::BackendCallback { | |
| 37 public: | |
| 38 Callback(std::unique_ptr<WeakPtr> backendImpl, int callId); | |
| 39 virtual ~Callback(); | |
| 40 void dispose(); | |
| 41 | |
| 42 protected: | |
| 43 void sendIfActive(std::unique_ptr<protocol::DictionaryValue> partialMess
age, const ErrorString& invocationError); | |
| 44 | |
| 45 private: | |
| 46 std::unique_ptr<WeakPtr> m_backendImpl; | |
| 47 int m_callId; | |
| 48 }; | |
| 49 | |
| 50 explicit DispatcherBase(FrontendChannel*); | |
| 51 virtual ~DispatcherBase(); | |
| 52 | |
| 53 enum CommonErrorCode { | |
| 54 ParseError = -32700, | |
| 55 InvalidRequest = -32600, | |
| 56 MethodNotFound = -32601, | |
| 57 InvalidParams = -32602, | |
| 58 InternalError = -32603, | |
| 59 ServerError = -32000, | |
| 60 }; | |
| 61 | |
| 62 static bool getCommandName(const String16& message, String16* result); | |
| 63 | |
| 64 virtual void dispatch(int callId, const String16& method, std::unique_ptr<pr
otocol::DictionaryValue> messageObject) = 0; | |
| 65 | |
| 66 void sendResponse(int callId, const ErrorString&, ErrorSupport*, std::unique
_ptr<protocol::DictionaryValue> result); | |
| 67 void sendResponse(int callId, const ErrorString&, std::unique_ptr<protocol::
DictionaryValue> result); | |
| 68 void sendResponse(int callId, const ErrorString&); | |
| 69 | |
| 70 void reportProtocolError(int callId, CommonErrorCode, const String16& errorM
essage, ErrorSupport* errors); | |
| 71 void clearFrontend(); | |
| 72 | |
| 73 std::unique_ptr<WeakPtr> weakPtr(); | |
| 74 | |
| 75 private: | |
| 76 FrontendChannel* m_frontendChannel; | |
| 77 protocol::HashSet<WeakPtr*> m_weakPtrs; | |
| 78 }; | |
| 79 | |
| 80 class PLATFORM_EXPORT UberDispatcher { | |
| 81 PROTOCOL_DISALLOW_COPY(UberDispatcher); | |
| 82 public: | |
| 83 explicit UberDispatcher(FrontendChannel*); | |
| 84 void registerBackend(const String16& name, std::unique_ptr<protocol::Dispatc
herBase>); | |
| 85 void dispatch(const String16& message); | |
| 86 FrontendChannel* channel() { return m_frontendChannel; } | |
| 87 virtual ~UberDispatcher(); | |
| 88 | |
| 89 private: | |
| 90 FrontendChannel* m_frontendChannel; | |
| 91 protocol::HashMap<String16, std::unique_ptr<protocol::DispatcherBase>> m_dis
patchers; | |
| 92 }; | |
| 93 | |
| 94 } // namespace platform | |
| 95 } // namespace blink | |
| 96 | |
| 97 #endif // !defined(DispatcherBase_h) | |
| OLD | NEW |