// third_party/blink/public/mojom/conversions/conversions.mojom-blink.cc is auto generated by mojom_bindings_generator.py, do not edit

// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif

#include "third_party/blink/public/mojom/conversions/conversions.mojom-blink.h"

#include <math.h>
#include <stdint.h>
#include <utility>

#include "base/hash/md5_constexpr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/common/task_annotator.h"
#include "base/trace_event/trace_conversion_helper.h"
#include "base/trace_event/traced_value.h"
#include "mojo/public/cpp/bindings/lib/generated_code_util.h"
#include "mojo/public/cpp/bindings/lib/message_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization_util.h"
#include "mojo/public/cpp/bindings/lib/unserialized_message_context.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_context.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"

#include "third_party/blink/public/mojom/conversions/conversions.mojom-params-data.h"
#include "third_party/blink/public/mojom/conversions/conversions.mojom-shared-message-ids.h"

#include "third_party/blink/public/mojom/conversions/conversions.mojom-blink-import-headers.h"
#include "mojo/public/cpp/bindings/lib/wtf_serialization.h"


#ifndef THIRD_PARTY_BLINK_PUBLIC_MOJOM_CONVERSIONS_CONVERSIONS_MOJOM_BLINK_JUMBO_H_
#define THIRD_PARTY_BLINK_PUBLIC_MOJOM_CONVERSIONS_CONVERSIONS_MOJOM_BLINK_JUMBO_H_
#endif
namespace blink {
namespace mojom {
namespace blink {
Conversion::Conversion()
    : reporting_origin(),
      conversion_data(0ULL) {}

Conversion::Conversion(
    const ::scoped_refptr<const ::blink::SecurityOrigin>& reporting_origin_in,
    uint64_t conversion_data_in)
    : reporting_origin(std::move(reporting_origin_in)),
      conversion_data(std::move(conversion_data_in)) {}

Conversion::~Conversion() = default;

void Conversion::AsValueInto(base::trace_event::TracedValue* value) const {
  value->SetString("reporting_origin", base::trace_event::ValueToString(this->reporting_origin, "<value of type const ::scoped_refptr<const ::blink::SecurityOrigin>&>"));
  value->SetString("conversion_data", base::NumberToString(this->conversion_data));
}

bool Conversion::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
const char ConversionHost::Name_[] = "blink.mojom.ConversionHost";

ConversionHostProxy::ConversionHostProxy(mojo::MessageReceiverWithResponder* receiver)
    : receiver_(receiver) {
}

void ConversionHostProxy::RegisterConversion(
    ConversionPtr in_conversion) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "blink::mojom::ConversionHost::RegisterConversion", "input_parameters",
    [&](){
      auto value = std::make_unique<base::trace_event::TracedValue>();
      base::trace_event::TracedValue* raw_value = value.get();
      if (in_conversion.is_null()) {
        raw_value->SetString("conversion", "nullptr");
      } else {
        raw_value->BeginDictionary("conversion");
        in_conversion->AsValueInto(raw_value);
        raw_value->EndDictionary();
      }
      return value;
    }());
#endif
  const bool kExpectsResponse = false;
  const bool kIsSync = false;
  
  const uint32_t kFlags =
      ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
      ((kIsSync) ? mojo::Message::kFlagIsSync : 0);
  
  mojo::Message message(
      internal::kConversionHost_RegisterConversion_Name, kFlags, 0, 0, nullptr);
  auto* buffer = message.payload_buffer();
  ::blink::mojom::internal::ConversionHost_RegisterConversion_Params_Data::BufferWriter
      params;
  mojo::internal::SerializationContext serialization_context;
  params.Allocate(buffer);
  typename decltype(params->conversion)::BaseType::BufferWriter
      conversion_writer;
  mojo::internal::Serialize<::blink::mojom::ConversionDataView>(
      in_conversion, buffer, &conversion_writer, &serialization_context);
  params->conversion.Set(
      conversion_writer.is_null() ? nullptr : conversion_writer.data());
  MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
      params->conversion.is_null(),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null conversion in ConversionHost.RegisterConversion request");
  message.AttachHandlesFromSerializationContext(
      &serialization_context);

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(ConversionHost::Name_);
  message.set_method_name("RegisterConversion");
#endif
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ignore_result(receiver_->Accept(&message));
}

// static
bool ConversionHostStubDispatch::Accept(
    ConversionHost* impl,
    mojo::Message* message) {
  mojo::internal::MessageDispatchContext dispatch_context(message);
  mojo::internal::SerializationContext serialization_context;
  serialization_context.TakeHandlesFromMessage(message);
  switch (message->header()->name) {
    case internal::kConversionHost_RegisterConversion_Name: {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      TRACE_EVENT1(
          "mojom",
          "(Impl)blink::mojom::ConversionHost::RegisterConversion",
          "message", message->name());
#endif
      static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr(
              "(Impl)blink::mojom::ConversionHost::RegisterConversion");
      base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash);

      DCHECK(message->is_serialized());
      internal::ConversionHost_RegisterConversion_Params_Data* params =
          reinterpret_cast<internal::ConversionHost_RegisterConversion_Params_Data*>(
              message->mutable_payload());
      
      bool success = true;
      ConversionPtr p_conversion{};
      ConversionHost_RegisterConversion_ParamsDataView input_data_view(params, &serialization_context);
      
      if (success && !input_data_view.ReadConversion(&p_conversion))
        success = false;
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            ConversionHost::Name_, 0, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->RegisterConversion(
std::move(p_conversion));
      return true;
    }
  }
  return false;
}

// static
bool ConversionHostStubDispatch::AcceptWithResponder(
    ConversionHost* impl,
    mojo::Message* message,
    std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
  mojo::internal::MessageDispatchContext dispatch_context(message);
  mojo::internal::SerializationContext serialization_context;
  serialization_context.TakeHandlesFromMessage(message);
  const bool message_is_sync = message->has_flag(mojo::Message::kFlagIsSync);
  const uint64_t request_id = message->request_id();
  ALLOW_UNUSED_LOCAL(message_is_sync);
  ALLOW_UNUSED_LOCAL(request_id);
  switch (message->header()->name) {
    case internal::kConversionHost_RegisterConversion_Name: {
      break;
    }
  }
  return false;
}


static const mojo::internal::GenericValidationInfo kConversionHostValidationInfo[] = {
    {&internal::ConversionHost_RegisterConversion_Params_Data::Validate,
     nullptr /* no response */},
};

bool ConversionHostRequestValidator::Accept(mojo::Message* message) {
  const char* name = ::blink::mojom::blink::ConversionHost::Name_;
  return mojo::internal::ValidateRequestGenericPacked(message, name, kConversionHostValidationInfo);
}

}  // namespace blink
}  // namespace mojom
}  // namespace blink

namespace mojo {


// static
bool StructTraits<::blink::mojom::blink::Conversion::DataView, ::blink::mojom::blink::ConversionPtr>::Read(
    ::blink::mojom::blink::Conversion::DataView input,
    ::blink::mojom::blink::ConversionPtr* output) {
  bool success = true;
  ::blink::mojom::blink::ConversionPtr result(::blink::mojom::blink::Conversion::New());
  
      if (success && !input.ReadReportingOrigin(&result->reporting_origin))
        success = false;
      if (success)
        result->conversion_data = input.conversion_data();
  *output = std::move(result);
  return success;
}

}  // namespace mojo

#if defined(__clang__)
#pragma clang diagnostic pop
#endif