LCOV - code coverage report
Current view: top level - out/Release/gen/src/inspector/protocol - Schema.cpp (source / functions) Hit Total Coverage
Test: app.info Lines: 10 63 15.9 %
Date: 2019-01-20 Functions: 4 14 28.6 %

          Line data    Source code
       1             : // This file is generated
       2             : 
       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
       5             : // found in the LICENSE file.
       6             : 
       7             : #include "src/inspector/protocol/Schema.h"
       8             : 
       9             : #include "src/inspector/protocol/Protocol.h"
      10             : 
      11             : namespace v8_inspector {
      12             : namespace protocol {
      13             : namespace Schema {
      14             : 
      15             : // ------------- Enum values from types.
      16             : 
      17             : const char Metainfo::domainName[] = "Schema";
      18             : const char Metainfo::commandPrefix[] = "Schema.";
      19             : const char Metainfo::version[] = "1.3";
      20             : 
      21           0 : std::unique_ptr<Domain> Domain::fromValue(protocol::Value* value, ErrorSupport* errors)
      22             : {
      23           0 :     if (!value || value->type() != protocol::Value::TypeObject) {
      24           0 :         errors->addError("object expected");
      25             :         return nullptr;
      26             :     }
      27             : 
      28           0 :     std::unique_ptr<Domain> result(new Domain());
      29             :     protocol::DictionaryValue* object = DictionaryValue::cast(value);
      30           0 :     errors->push();
      31           0 :     protocol::Value* nameValue = object->get("name");
      32           0 :     errors->setName("name");
      33           0 :     result->m_name = ValueConversions<String>::fromValue(nameValue, errors);
      34           0 :     protocol::Value* versionValue = object->get("version");
      35           0 :     errors->setName("version");
      36           0 :     result->m_version = ValueConversions<String>::fromValue(versionValue, errors);
      37           0 :     errors->pop();
      38           0 :     if (errors->hasErrors())
      39             :         return nullptr;
      40             :     return result;
      41             : }
      42             : 
      43           0 : std::unique_ptr<protocol::DictionaryValue> Domain::toValue() const
      44             : {
      45           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
      46           0 :     result->setValue("name", ValueConversions<String>::toValue(m_name));
      47           0 :     result->setValue("version", ValueConversions<String>::toValue(m_version));
      48           0 :     return result;
      49             : }
      50             : 
      51           0 : std::unique_ptr<Domain> Domain::clone() const
      52             : {
      53           0 :     ErrorSupport errors;
      54           0 :     return fromValue(toValue().get(), &errors);
      55             : }
      56             : 
      57           0 : std::unique_ptr<StringBuffer> Domain::toJSONString() const
      58             : {
      59           0 :     String json = toValue()->serialize();
      60           0 :     return StringBufferImpl::adopt(json);
      61             : }
      62             : 
      63             : // static
      64           0 : std::unique_ptr<API::Domain> API::Domain::fromJSONString(const StringView& json)
      65             : {
      66           0 :     ErrorSupport errors;
      67           0 :     std::unique_ptr<Value> value = StringUtil::parseJSON(json);
      68           0 :     if (!value)
      69             :         return nullptr;
      70           0 :     return protocol::Schema::Domain::fromValue(value.get(), &errors);
      71             : }
      72             : 
      73             : // ------------- Enum values from params.
      74             : 
      75             : 
      76             : // ------------- Frontend notifications.
      77             : 
      78           0 : void Frontend::flush()
      79             : {
      80           0 :     m_frontendChannel->flushProtocolNotifications();
      81           0 : }
      82             : 
      83           0 : void Frontend::sendRawNotification(const String& notification)
      84             : {
      85           0 :     m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
      86           0 : }
      87             : 
      88             : // --------------------- Dispatcher.
      89             : 
      90             : class DispatcherImpl : public protocol::DispatcherBase {
      91             : public:
      92        3834 :     DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
      93             :         : DispatcherBase(frontendChannel)
      94       11502 :         , m_backend(backend) {
      95       11502 :         m_dispatchMap["Schema.getDomains"] = &DispatcherImpl::getDomains;
      96        3834 :     }
      97       11502 :     ~DispatcherImpl() override { }
      98             :     bool canDispatch(const String& method) override;
      99             :     void dispatch(int callId, const String& method, const String& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
     100             :     std::unordered_map<String, String>& redirects() { return m_redirects; }
     101             : 
     102             : protected:
     103             :     using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
     104             :     using DispatchMap = std::unordered_map<String, CallHandler>;
     105             :     DispatchMap m_dispatchMap;
     106             :     std::unordered_map<String, String> m_redirects;
     107             : 
     108             :     void getDomains(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
     109             : 
     110             :     Backend* m_backend;
     111             : };
     112             : 
     113           0 : bool DispatcherImpl::canDispatch(const String& method) {
     114           0 :     return m_dispatchMap.find(method) != m_dispatchMap.end();
     115             : }
     116             : 
     117           0 : void DispatcherImpl::dispatch(int callId, const String& method, const String& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
     118             : {
     119             :     std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
     120             :     DCHECK(it != m_dispatchMap.end());
     121           0 :     protocol::ErrorSupport errors;
     122           0 :     (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
     123           0 : }
     124             : 
     125             : 
     126           0 : void DispatcherImpl::getDomains(int callId, const String& method, const String& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
     127             : {
     128             :     // Declare output parameters.
     129           0 :     std::unique_ptr<protocol::Array<protocol::Schema::Domain>> out_domains;
     130             : 
     131           0 :     std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
     132           0 :     DispatchResponse response = m_backend->getDomains(&out_domains);
     133           0 :     if (response.status() == DispatchResponse::kFallThrough) {
     134           0 :         channel()->fallThrough(callId, method, message);
     135           0 :         return;
     136             :     }
     137           0 :     std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
     138           0 :     if (response.status() == DispatchResponse::kSuccess) {
     139           0 :         result->setValue("domains", ValueConversions<protocol::Array<protocol::Schema::Domain>>::toValue(out_domains.get()));
     140             :     }
     141           0 :     if (weak->get())
     142           0 :         weak->get()->sendResponse(callId, response, std::move(result));
     143             :     return;
     144             : }
     145             : 
     146             : // static
     147        3834 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
     148             : {
     149        3834 :     std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
     150        3834 :     uber->setupRedirects(dispatcher->redirects());
     151       11502 :     uber->registerBackend("Schema", std::move(dispatcher));
     152        3834 : }
     153             : 
     154             : } // Schema
     155             : } // namespace v8_inspector
     156             : } // namespace protocol

Generated by: LCOV version 1.10