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

Side by Side Diff: templates/TypeBuilder_cpp.template

Issue 2509573006: [inspector_protocol] Support features for content/ generator. (Closed)
Patch Set: DCHECK Created 4 years, 1 month 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
« no previous file with comments | « lib/DispatcherBase_h.template ('k') | templates/TypeBuilder_h.template » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {{format_include(config.protocol.package, domain.domain)}} 7 #include {{format_include(config.protocol.package, domain.domain)}}
8 8
9 #include {{format_include(config.protocol.package, "Protocol")}} 9 #include {{format_include(config.protocol.package, "Protocol")}}
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 if (m_frontendChannel) 171 if (m_frontendChannel)
172 m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()) ; 172 m_frontendChannel->sendProtocolNotification(jsonMessage->toJSONString()) ;
173 } 173 }
174 {% endfor %} 174 {% endfor %}
175 175
176 void Frontend::flush() 176 void Frontend::flush()
177 { 177 {
178 m_frontendChannel->flushProtocolNotifications(); 178 m_frontendChannel->flushProtocolNotifications();
179 } 179 }
180 180
181 void Frontend::sendRawNotification(const String& notification)
182 {
183 m_frontendChannel->sendProtocolNotification(notification);
184 }
185
181 // --------------------- Dispatcher. 186 // --------------------- Dispatcher.
182 187
183 class DispatcherImpl : public protocol::DispatcherBase { 188 class DispatcherImpl : public protocol::DispatcherBase {
184 public: 189 public:
185 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend) 190 DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fall ThroughForNotFound)
186 : DispatcherBase(frontendChannel) 191 : DispatcherBase(frontendChannel)
187 , m_backend(backend) { 192 , m_backend(backend)
193 , m_fallThroughForNotFound(fallThroughForNotFound) {
188 {% for command in domain.commands %} 194 {% for command in domain.commands %}
189 {% if "redirect" in command %}{% continue %}{% endif %} 195 {% if "redirect" in command %}{% continue %}{% endif %}
190 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e ndif %} 196 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e ndif %}
191 m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{ {command.name}}; 197 m_dispatchMap["{{domain.domain}}.{{command.name}}"] = &DispatcherImpl::{ {command.name}};
192 {% endfor %} 198 {% endfor %}
193 } 199 }
194 ~DispatcherImpl() override { } 200 ~DispatcherImpl() override { }
195 DispatchResponse::Status dispatch(int callId, const String& method, std::uni que_ptr<protocol::DictionaryValue> messageObject) override; 201 DispatchResponse::Status dispatch(int callId, const String& method, std::uni que_ptr<protocol::DictionaryValue> messageObject) override;
196 202
197 protected: 203 protected:
198 using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors); 204 using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
199 using DispatchMap = protocol::HashMap<String, CallHandler>; 205 using DispatchMap = protocol::HashMap<String, CallHandler>;
200 DispatchMap m_dispatchMap; 206 DispatchMap m_dispatchMap;
201 207
202 {% for command in domain.commands %} 208 {% for command in domain.commands %}
203 {% if "redirect" in command %}{% continue %}{% endif %} 209 {% if "redirect" in command %}{% continue %}{% endif %}
204 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e ndif %} 210 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e ndif %}
205 DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<Dictio naryValue> requestMessageObject, ErrorSupport*); 211 DispatchResponse::Status {{command.name}}(int callId, std::unique_ptr<Dictio naryValue> requestMessageObject, ErrorSupport*);
206 {% endfor %} 212 {% endfor %}
207 213
208 Backend* m_backend; 214 Backend* m_backend;
215 bool m_fallThroughForNotFound;
209 }; 216 };
210 217
211 DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& meth od, std::unique_ptr<protocol::DictionaryValue> messageObject) 218 DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& meth od, std::unique_ptr<protocol::DictionaryValue> messageObject)
212 { 219 {
213 protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(met hod); 220 protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(met hod);
214 if (it == m_dispatchMap.end()) { 221 if (it == m_dispatchMap.end()) {
222 if (m_fallThroughForNotFound)
223 return DispatchResponse::kFallThrough;
215 reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + met hod + "' wasn't found", nullptr); 224 reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + met hod + "' wasn't found", nullptr);
216 return DispatchResponse::kError; 225 return DispatchResponse::kError;
217 } 226 }
218 227
219 protocol::ErrorSupport errors; 228 protocol::ErrorSupport errors;
220 return (this->*(it->second))(callId, std::move(messageObject), &errors); 229 return (this->*(it->second))(callId, std::move(messageObject), &errors);
221 } 230 }
222 231
223 {% for command in domain.commands %} 232 {% for command in domain.commands %}
224 {% if "redirect" in command %}{% continue %}{% endif %} 233 {% if "redirect" in command %}{% continue %}{% endif %}
225 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e ndif %} 234 {% if not generate_command(domain.domain, command.name) %}{% continue %}{% e ndif %}
226 {% if is_async_command(domain.domain, command.name) %} 235 {% if is_async_command(domain.domain, command.name) %}
227 236
228 class {{command.name | to_title_case}}CallbackImpl : public Backend::{{command.n ame | to_title_case}}Callback, public DispatcherBase::Callback { 237 class {{command.name | to_title_case}}CallbackImpl : public Backend::{{command.n ame | to_title_case}}Callback, public DispatcherBase::Callback {
229 public: 238 public:
230 {{command.name | to_title_case}}CallbackImpl(std::unique_ptr<DispatcherBase: :WeakPtr> backendImpl, int callId) 239 {{command.name | to_title_case}}CallbackImpl(std::unique_ptr<DispatcherBase: :WeakPtr> backendImpl, int callId, int callbackId)
231 : DispatcherBase::Callback(std::move(backendImpl), callId) { } 240 : DispatcherBase::Callback(std::move(backendImpl), callId, callbackId) { }
232 241
233 void sendSuccess( 242 void sendSuccess(
234 {%- for parameter in command.returns -%} 243 {%- for parameter in command.returns -%}
235 {%- if "optional" in parameter -%} 244 {%- if "optional" in parameter -%}
236 Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}} 245 Maybe<{{resolve_type(parameter).raw_type}}> {{parameter.name}}
237 {%- else -%} 246 {%- else -%}
238 {{resolve_type(parameter).pass_type}} {{parameter.name}} 247 {{resolve_type(parameter).pass_type}} {{parameter.name}}
239 {%- endif -%} 248 {%- endif -%}
240 {%- if not loop.last -%}, {% endif -%} 249 {%- if not loop.last -%}, {% endif -%}
241 {%- endfor -%}) override 250 {%- endfor -%}) override
242 { 251 {
243 std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValu e::create(); 252 std::unique_ptr<protocol::DictionaryValue> resultObject = DictionaryValu e::create();
244 {% for parameter in command.returns %} 253 {% for parameter in command.returns %}
245 {% if "optional" in parameter %} 254 {% if "optional" in parameter %}
246 if ({{parameter.name}}.isJust()) 255 if ({{parameter.name}}.isJust())
247 resultObject->setValue("{{parameter.name}}", ValueConversions<{{reso lve_type(parameter).raw_type}}>::serialize({{parameter.name}}.fromJust())); 256 resultObject->setValue("{{parameter.name}}", ValueConversions<{{reso lve_type(parameter).raw_type}}>::serialize({{parameter.name}}.fromJust()));
248 {% else %} 257 {% else %}
249 resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_ type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % p arameter.name}})); 258 resultObject->setValue("{{parameter.name}}", ValueConversions<{{resolve_ type(parameter).raw_type}}>::serialize({{resolve_type(parameter).to_raw_type % p arameter.name}}));
250 {% endif %} 259 {% endif %}
251 {% endfor %} 260 {% endfor %}
252 sendIfActive(std::move(resultObject), DispatchResponse::OK()); 261 sendIfActive(std::move(resultObject), DispatchResponse::OK());
253 } 262 }
254 263
264 void fallThrough() override
265 {
266 fallThroughIfActive();
267 }
268
255 void sendFailure(const DispatchResponse& response) override 269 void sendFailure(const DispatchResponse& response) override
256 { 270 {
257 DCHECK(response.status() == DispatchResponse::kError); 271 DCHECK(response.status() == DispatchResponse::kError);
258 sendIfActive(nullptr, response); 272 sendIfActive(nullptr, response);
259 } 273 }
260 }; 274 };
261 {% endif %} 275 {% endif %}
262 276
263 DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu e_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors) 277 DispatchResponse::Status DispatcherImpl::{{command.name}}(int callId, std::uniqu e_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
264 { 278 {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 {% endfor %} 342 {% endfor %}
329 } 343 }
330 if (weak->get()) 344 if (weak->get())
331 weak->get()->sendResponse(callId, response, std::move(result)); 345 weak->get()->sendResponse(callId, response, std::move(result));
332 {% else %} 346 {% else %}
333 if (weak->get()) 347 if (weak->get())
334 weak->get()->sendResponse(callId, response); 348 weak->get()->sendResponse(callId, response);
335 {% endif %} 349 {% endif %}
336 return response.status(); 350 return response.status();
337 {% else %} 351 {% else %}
338 std::unique_ptr<{{command.name | to_title_case}}CallbackImpl> callback(new { {command.name | to_title_case}}CallbackImpl(weakPtr(), callId)); 352 std::unique_ptr<{{command.name | to_title_case}}CallbackImpl> callback(new { {command.name | to_title_case}}CallbackImpl(weakPtr(), callId, nextCallbackId()) );
339 m_backend->{{command.name | to_method_case}}( 353 m_backend->{{command.name | to_method_case}}(
340 {%- for property in command.parameters -%} 354 {%- for property in command.parameters -%}
341 {%- if not loop.first -%}, {% endif -%} 355 {%- if not loop.first -%}, {% endif -%}
342 {%- if "optional" in property -%} 356 {%- if "optional" in property -%}
343 std::move(in_{{property.name}}) 357 std::move(in_{{property.name}})
344 {%- else -%} 358 {%- else -%}
345 {{resolve_type(property).to_pass_type % ("in_" + property.name)}} 359 {{resolve_type(property).to_pass_type % ("in_" + property.name)}}
346 {%- endif -%} 360 {%- endif -%}
347 {%- endfor -%} 361 {%- endfor -%}
348 {%- if command.parameters -%}, {% endif -%} 362 {%- if command.parameters -%}, {% endif -%}
349 std::move(callback)); 363 std::move(callback));
350 return DispatchResponse::kAsync; 364 return lastCallbackFallThrough() ? DispatchResponse::kFallThrough : Dispatch Response::kAsync;
351 {% endif %} 365 {% endif %}
352 } 366 }
353 {% endfor %} 367 {% endfor %}
354 368
355 // static 369 // static
356 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend) 370 void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend)
357 { 371 {
358 dispatcher->registerBackend("{{domain.domain}}", std::unique_ptr<protocol::D ispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend))); 372 dispatcher->registerBackend("{{domain.domain}}", std::unique_ptr<protocol::D ispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fa llThroughForNotFound())));
359 } 373 }
360 374
361 } // {{domain.domain}} 375 } // {{domain.domain}}
362 {% for namespace in config.protocol.namespace %} 376 {% for namespace in config.protocol.namespace %}
363 } // namespace {{namespace}} 377 } // namespace {{namespace}}
364 {% endfor %} 378 {% endfor %}
OLDNEW
« no previous file with comments | « lib/DispatcherBase_h.template ('k') | templates/TypeBuilder_h.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698