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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/Dispatcher_cpp.template

Issue 1758313002: DevTools: introduce collections shim to be backed by non-wtf in v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for landing Created 4 years, 9 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
1 // This file is generated 1 // This file is generated
2 2
3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be 4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file. 5 // found in the LICENSE file.
6 6
7 #include "platform/inspector_protocol/{{class_name}}.h" 7 #include "platform/inspector_protocol/{{class_name}}.h"
8 8
9 #include "platform/inspector_protocol/Collections.h"
9 #include "platform/inspector_protocol/FrontendChannel.h" 10 #include "platform/inspector_protocol/FrontendChannel.h"
10 #include "platform/inspector_protocol/Parser.h" 11 #include "platform/inspector_protocol/Parser.h"
11 #include "wtf/HashSet.h"
12 12
13 namespace blink { 13 namespace blink {
14 namespace protocol { 14 namespace protocol {
15 15
16 using protocol::Maybe; 16 using protocol::Maybe;
17 17
18 class DispatcherImpl; 18 class DispatcherImpl;
19 19
20 class DispatcherImplWeakPtr { 20 class DispatcherImplWeakPtr {
21 public: 21 public:
(...skipping 10 matching lines...) Expand all
32 DispatcherImpl(FrontendChannel* frontendChannel) 32 DispatcherImpl(FrontendChannel* frontendChannel)
33 : m_frontendChannel(frontendChannel) 33 : m_frontendChannel(frontendChannel)
34 {% for domain in api.domains %} 34 {% for domain in api.domains %}
35 , m_{{domain.domain | lower}}Agent(0) 35 , m_{{domain.domain | lower}}Agent(0)
36 {% endfor %} 36 {% endfor %}
37 { 37 {
38 {% for domain in api.domains %} 38 {% for domain in api.domains %}
39 {% for command in domain.commands %} 39 {% for command in domain.commands %}
40 {% if "redirect" in command %}{% continue %}{% endif %} 40 {% if "redirect" in command %}{% continue %}{% endif %}
41 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %} 41 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %}
42 m_dispatchMap.add("{{domain.domain}}.{{command.name}}", &DispatcherImpl: :{{domain.domain}}_{{command.name}}); 42 m_dispatchMap.set("{{domain.domain}}.{{command.name}}", &DispatcherImpl: :{{domain.domain}}_{{command.name}});
43 {% endfor %} 43 {% endfor %}
44 {% endfor %} 44 {% endfor %}
45 45
46 // Initialize common errors. 46 // Initialize common errors.
47 m_commonErrors.insert(ParseError, -32700); 47 m_commonErrors.insert(ParseError, -32700);
48 m_commonErrors.insert(InvalidRequest, -32600); 48 m_commonErrors.insert(InvalidRequest, -32600);
49 m_commonErrors.insert(MethodNotFound, -32601); 49 m_commonErrors.insert(MethodNotFound, -32601);
50 m_commonErrors.insert(InvalidParams, -32602); 50 m_commonErrors.insert(InvalidParams, -32602);
51 m_commonErrors.insert(InternalError, -32603); 51 m_commonErrors.insert(InternalError, -32603);
52 m_commonErrors.insert(ServerError, -32000); 52 m_commonErrors.insert(ServerError, -32000);
53 } 53 }
54 54
55 ~DispatcherImpl() { clearFrontend(); } 55 ~DispatcherImpl() { clearFrontend(); }
56 56
57 virtual void clearFrontend() 57 virtual void clearFrontend()
58 { 58 {
59 m_frontendChannel = nullptr; 59 m_frontendChannel = nullptr;
60 for (auto& weak : m_weakPtrs) 60 for (auto& weak : m_weakPtrs)
61 weak->dispose(); 61 weak.first->dispose();
62 m_weakPtrs.clear(); 62 m_weakPtrs.clear();
63 } 63 }
64 64
65 PassOwnPtr<DispatcherImplWeakPtr> weakPtr() 65 PassOwnPtr<DispatcherImplWeakPtr> weakPtr()
66 { 66 {
67 OwnPtr<DispatcherImplWeakPtr> weak = adoptPtr(new DispatcherImplWeakPtr( this)); 67 OwnPtr<DispatcherImplWeakPtr> weak = adoptPtr(new DispatcherImplWeakPtr( this));
68 m_weakPtrs.add(weak.get()); 68 m_weakPtrs.add(weak.get());
69 return weak.release(); 69 return weak.release();
70 } 70 }
71 71
72 virtual void dispatch(int sessionId, const String& message); 72 virtual void dispatch(int sessionId, const String& message);
73 virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode, const String& errorMessage, ErrorSupport* errors) const; 73 virtual void reportProtocolError(int sessionId, int callId, CommonErrorCode, const String& errorMessage, ErrorSupport* errors) const;
74 using Dispatcher::reportProtocolError; 74 using Dispatcher::reportProtocolError;
75 75
76 void sendResponse(int sessionId, int callId, const ErrorString& invocationEr ror, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result); 76 void sendResponse(int sessionId, int callId, const ErrorString& invocationEr ror, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> result);
77 77
78 {% for domain in api.domains %} 78 {% for domain in api.domains %}
79 virtual void registerAgent({{domain.domain}}CommandHandler* agent) { ASSERT( !m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent = agent; } 79 virtual void registerAgent({{domain.domain}}CommandHandler* agent) { ASSERT( !m_{{domain.domain | lower}}Agent); m_{{domain.domain | lower}}Agent = agent; }
80 {% endfor %} 80 {% endfor %}
81 81
82 private: 82 private:
83 friend class CallbackBase; 83 friend class CallbackBase;
84 friend class DispatcherImplWeakPtr; 84 friend class DispatcherImplWeakPtr;
85 using CallHandler = void (DispatcherImpl::*)(int sessionId, int callId, Pass OwnPtr<DictionaryValue> messageObject, ErrorSupport* errors); 85 using CallHandler = void (DispatcherImpl::*)(int sessionId, int callId, Pass OwnPtr<DictionaryValue> messageObject, ErrorSupport* errors);
86 using DispatchMap = HashMap<String, CallHandler>; 86 using DispatchMap = protocol::HashMap<String, CallHandler>;
87 87
88 {% for domain in api.domains %} 88 {% for domain in api.domains %}
89 {% for command in domain.commands %} 89 {% for command in domain.commands %}
90 {% if "redirect" in command %}{% continue %}{% endif %} 90 {% if "redirect" in command %}{% continue %}{% endif %}
91 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %} 91 {% if "handlers" in command and not ("renderer" in command["handlers"]) %}{% continue %}{% endif %}
92 void {{domain.domain}}_{{command.name}}(int sessionId, int callId, PassOwnPt r<DictionaryValue> requestMessageObject, ErrorSupport*); 92 void {{domain.domain}}_{{command.name}}(int sessionId, int callId, PassOwnPt r<DictionaryValue> requestMessageObject, ErrorSupport*);
93 {% endfor %} 93 {% endfor %}
94 {% endfor %} 94 {% endfor %}
95 95
96 FrontendChannel* m_frontendChannel; 96 FrontendChannel* m_frontendChannel;
97 97
98 {% for domain in api.domains %} 98 {% for domain in api.domains %}
99 {{domain.domain}}CommandHandler* m_{{domain.domain | lower}}Agent; 99 {{domain.domain}}CommandHandler* m_{{domain.domain | lower}}Agent;
100 {% endfor %} 100 {% endfor %}
101 101
102 void sendResponse(int sessionId, int callId, ErrorString invocationError, Pa ssOwnPtr<protocol::DictionaryValue> result) 102 void sendResponse(int sessionId, int callId, ErrorString invocationError, Pa ssOwnPtr<protocol::DictionaryValue> result)
103 { 103 {
104 sendResponse(sessionId, callId, invocationError, nullptr, result); 104 sendResponse(sessionId, callId, invocationError, nullptr, result);
105 } 105 }
106 106
107 void sendResponse(int sessionId, int callId, ErrorString invocationError) 107 void sendResponse(int sessionId, int callId, ErrorString invocationError)
108 { 108 {
109 sendResponse(sessionId, callId, invocationError, nullptr, DictionaryValu e::create()); 109 sendResponse(sessionId, callId, invocationError, nullptr, DictionaryValu e::create());
110 } 110 }
111 111
112 static const char InvalidParamsFormatString[]; 112 static const char InvalidParamsFormatString[];
113 113
114 DispatchMap m_dispatchMap; 114 DispatchMap m_dispatchMap;
115 Vector<int> m_commonErrors; 115 protocol::Vector<int> m_commonErrors;
116 HashSet<DispatcherImplWeakPtr*> m_weakPtrs; 116 protocol::HashSet<DispatcherImplWeakPtr*> m_weakPtrs;
117 }; 117 };
118 118
119 DispatcherImplWeakPtr::~DispatcherImplWeakPtr() 119 DispatcherImplWeakPtr::~DispatcherImplWeakPtr()
120 { 120 {
121 if (m_dispatcher) 121 if (m_dispatcher)
122 m_dispatcher->m_weakPtrs.remove(this); 122 m_dispatcher->m_weakPtrs.remove(this);
123 } 123 }
124 124
125 const char DispatcherImpl::InvalidParamsFormatString[] = "Some arguments of meth od '%s' can't be processed"; 125 const char DispatcherImpl::InvalidParamsFormatString[] = "Some arguments of meth od '%s' can't be processed";
126 {% for domain in api.domains %} 126 {% for domain in api.domains %}
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 protocol::Value* callIdValue = messageObject->get("id"); 256 protocol::Value* callIdValue = messageObject->get("id");
257 bool success = callIdValue->asNumber(&callId); 257 bool success = callIdValue->asNumber(&callId);
258 ASSERT_UNUSED(success, success); 258 ASSERT_UNUSED(success, success);
259 259
260 protocol::Value* methodValue = messageObject->get("method"); 260 protocol::Value* methodValue = messageObject->get("method");
261 String method; 261 String method;
262 success = methodValue && methodValue->asString(&method); 262 success = methodValue && methodValue->asString(&method);
263 ASSERT_UNUSED(success, success); 263 ASSERT_UNUSED(success, success);
264 264
265 HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method); 265 protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(met hod);
266 if (it == m_dispatchMap.end()) { 266 if (it == m_dispatchMap.end()) {
267 reportProtocolError(sessionId, callId, MethodNotFound, "'" + method + "' wasn't found"); 267 reportProtocolError(sessionId, callId, MethodNotFound, "'" + method + "' wasn't found");
268 return; 268 return;
269 } 269 }
270 270
271 protocol::ErrorSupport errors; 271 protocol::ErrorSupport errors;
272 ((*this).*it->value)(sessionId, callId, messageObject.release(), &errors); 272 ((*this).*(*it->second))(sessionId, callId, messageObject.release(), &errors );
273 } 273 }
274 274
275 void DispatcherImpl::sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> res ult) 275 void DispatcherImpl::sendResponse(int sessionId, int callId, const ErrorString& invocationError, ErrorSupport* errors, PassOwnPtr<protocol::DictionaryValue> res ult)
276 { 276 {
277 if (invocationError.length() || (errors && errors->hasErrors())) { 277 if (invocationError.length() || (errors && errors->hasErrors())) {
278 reportProtocolError(sessionId, callId, ServerError, invocationError, err ors); 278 reportProtocolError(sessionId, callId, ServerError, invocationError, err ors);
279 return; 279 return;
280 } 280 }
281 281
282 OwnPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create( ); 282 OwnPtr<protocol::DictionaryValue> responseMessage = DictionaryValue::create( );
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 void Dispatcher::CallbackBase::sendIfActive(PassOwnPtr<protocol::DictionaryValue > partialMessage, const ErrorString& invocationError) 345 void Dispatcher::CallbackBase::sendIfActive(PassOwnPtr<protocol::DictionaryValue > partialMessage, const ErrorString& invocationError)
346 { 346 {
347 if (!m_backendImpl->get()) 347 if (!m_backendImpl->get())
348 return; 348 return;
349 m_backendImpl->get()->sendResponse(m_sessionId, m_id, invocationError, nullp tr, partialMessage); 349 m_backendImpl->get()->sendResponse(m_sessionId, m_id, invocationError, nullp tr, partialMessage);
350 m_backendImpl = nullptr; 350 m_backendImpl = nullptr;
351 } 351 }
352 352
353 } // namespace protocol 353 } // namespace protocol
354 } // namespace blink 354 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698