// services/metrics/public/mojom/ukm_interface.mojom.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 "services/metrics/public/mojom/ukm_interface.mojom.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 "services/metrics/public/mojom/ukm_interface.mojom-params-data.h"
#include "services/metrics/public/mojom/ukm_interface.mojom-shared-message-ids.h"

#include "services/metrics/public/mojom/ukm_interface.mojom-import-headers.h"


#ifndef SERVICES_METRICS_PUBLIC_MOJOM_UKM_INTERFACE_MOJOM_JUMBO_H_
#define SERVICES_METRICS_PUBLIC_MOJOM_UKM_INTERFACE_MOJOM_JUMBO_H_
#endif
namespace ukm {
namespace mojom {
UkmEntry::UkmEntry()
    : source_id(),
      event_hash(),
      metrics() {}

UkmEntry::UkmEntry(
    int64_t source_id_in,
    uint64_t event_hash_in,
    const base::flat_map<uint64_t, int64_t>& metrics_in)
    : source_id(std::move(source_id_in)),
      event_hash(std::move(event_hash_in)),
      metrics(std::move(metrics_in)) {}

UkmEntry::~UkmEntry() = default;

void UkmEntry::AsValueInto(base::trace_event::TracedValue* value) const {
  value->SetString("source_id", base::NumberToString(this->source_id));
  value->SetString("event_hash", base::NumberToString(this->event_hash));
  value->BeginDictionary("metrics");
  for (const auto& item0 : this->metrics) {
    value->SetStringWithCopiedName(base::trace_event::ValueToString(item0.first, "<value of type uint64_t>"), base::NumberToString(item0.second));
  }
  value->EndDictionary();
}

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

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

void UkmRecorderInterfaceProxy::AddEntry(
    UkmEntryPtr in_entry) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "ukm::mojom::UkmRecorderInterface::AddEntry", "input_parameters",
    [&](){
      auto value = std::make_unique<base::trace_event::TracedValue>();
      base::trace_event::TracedValue* raw_value = value.get();
      if (in_entry.is_null()) {
        raw_value->SetString("entry", "nullptr");
      } else {
        raw_value->BeginDictionary("entry");
        in_entry->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::kUkmRecorderInterface_AddEntry_Name, kFlags, 0, 0, nullptr);
  auto* buffer = message.payload_buffer();
  ::ukm::mojom::internal::UkmRecorderInterface_AddEntry_Params_Data::BufferWriter
      params;
  mojo::internal::SerializationContext serialization_context;
  params.Allocate(buffer);
  typename decltype(params->entry)::BaseType::BufferWriter
      entry_writer;
  mojo::internal::Serialize<::ukm::mojom::UkmEntryDataView>(
      in_entry, buffer, &entry_writer, &serialization_context);
  params->entry.Set(
      entry_writer.is_null() ? nullptr : entry_writer.data());
  MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
      params->entry.is_null(),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null entry in UkmRecorderInterface.AddEntry request");
  message.AttachHandlesFromSerializationContext(
      &serialization_context);

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(UkmRecorderInterface::Name_);
  message.set_method_name("AddEntry");
#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));
}

void UkmRecorderInterfaceProxy::UpdateSourceURL(
    int64_t in_source_id, const std::string& in_url) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "ukm::mojom::UkmRecorderInterface::UpdateSourceURL", "input_parameters",
    [&](){
      auto value = std::make_unique<base::trace_event::TracedValue>();
      base::trace_event::TracedValue* raw_value = value.get();
      raw_value->SetString("source_id", base::NumberToString(in_source_id));
      raw_value->SetString("url", in_url);
      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::kUkmRecorderInterface_UpdateSourceURL_Name, kFlags, 0, 0, nullptr);
  auto* buffer = message.payload_buffer();
  ::ukm::mojom::internal::UkmRecorderInterface_UpdateSourceURL_Params_Data::BufferWriter
      params;
  mojo::internal::SerializationContext serialization_context;
  params.Allocate(buffer);
  params->source_id = in_source_id;
  typename decltype(params->url)::BaseType::BufferWriter
      url_writer;
  mojo::internal::Serialize<mojo::StringDataView>(
      in_url, buffer, &url_writer, &serialization_context);
  params->url.Set(
      url_writer.is_null() ? nullptr : url_writer.data());
  MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
      params->url.is_null(),
      mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
      "null url in UkmRecorderInterface.UpdateSourceURL request");
  message.AttachHandlesFromSerializationContext(
      &serialization_context);

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(UkmRecorderInterface::Name_);
  message.set_method_name("UpdateSourceURL");
#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 UkmRecorderInterfaceStubDispatch::Accept(
    UkmRecorderInterface* 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::kUkmRecorderInterface_AddEntry_Name: {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      TRACE_EVENT1(
          "mojom",
          "(Impl)ukm::mojom::UkmRecorderInterface::AddEntry",
          "message", message->name());
#endif
      static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr(
              "(Impl)ukm::mojom::UkmRecorderInterface::AddEntry");
      base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash);

      DCHECK(message->is_serialized());
      internal::UkmRecorderInterface_AddEntry_Params_Data* params =
          reinterpret_cast<internal::UkmRecorderInterface_AddEntry_Params_Data*>(
              message->mutable_payload());
      
      bool success = true;
      UkmEntryPtr p_entry{};
      UkmRecorderInterface_AddEntry_ParamsDataView input_data_view(params, &serialization_context);
      
      if (success && !input_data_view.ReadEntry(&p_entry))
        success = false;
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            UkmRecorderInterface::Name_, 0, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->AddEntry(
std::move(p_entry));
      return true;
    }
    case internal::kUkmRecorderInterface_UpdateSourceURL_Name: {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      TRACE_EVENT1(
          "mojom",
          "(Impl)ukm::mojom::UkmRecorderInterface::UpdateSourceURL",
          "message", message->name());
#endif
      static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr(
              "(Impl)ukm::mojom::UkmRecorderInterface::UpdateSourceURL");
      base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash);

      DCHECK(message->is_serialized());
      internal::UkmRecorderInterface_UpdateSourceURL_Params_Data* params =
          reinterpret_cast<internal::UkmRecorderInterface_UpdateSourceURL_Params_Data*>(
              message->mutable_payload());
      
      bool success = true;
      int64_t p_source_id{};
      std::string p_url{};
      UkmRecorderInterface_UpdateSourceURL_ParamsDataView input_data_view(params, &serialization_context);
      
      if (success)
        p_source_id = input_data_view.source_id();
      if (success && !input_data_view.ReadUrl(&p_url))
        success = false;
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            UkmRecorderInterface::Name_, 1, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->UpdateSourceURL(
std::move(p_source_id), 
std::move(p_url));
      return true;
    }
  }
  return false;
}

// static
bool UkmRecorderInterfaceStubDispatch::AcceptWithResponder(
    UkmRecorderInterface* 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::kUkmRecorderInterface_AddEntry_Name: {
      break;
    }
    case internal::kUkmRecorderInterface_UpdateSourceURL_Name: {
      break;
    }
  }
  return false;
}


static const std::pair<uint32_t, mojo::internal::GenericValidationInfo> kUkmRecorderInterfaceValidationInfo[] = {
    {internal::kUkmRecorderInterface_AddEntry_Name,
     {&internal::UkmRecorderInterface_AddEntry_Params_Data::Validate,
      nullptr /* no response */}},
    {internal::kUkmRecorderInterface_UpdateSourceURL_Name,
     {&internal::UkmRecorderInterface_UpdateSourceURL_Params_Data::Validate,
      nullptr /* no response */}},
};

bool UkmRecorderInterfaceRequestValidator::Accept(mojo::Message* message) {
  const char* name = ::ukm::mojom::UkmRecorderInterface::Name_;
  return mojo::internal::ValidateRequestGeneric(message, name, kUkmRecorderInterfaceValidationInfo);
}

}  // namespace mojom
}  // namespace ukm

namespace mojo {


// static
bool StructTraits<::ukm::mojom::UkmEntry::DataView, ::ukm::mojom::UkmEntryPtr>::Read(
    ::ukm::mojom::UkmEntry::DataView input,
    ::ukm::mojom::UkmEntryPtr* output) {
  bool success = true;
  ::ukm::mojom::UkmEntryPtr result(::ukm::mojom::UkmEntry::New());
  
      if (success)
        result->source_id = input.source_id();
      if (success)
        result->event_hash = input.event_hash();
      if (success && !input.ReadMetrics(&result->metrics))
        success = false;
  *output = std::move(result);
  return success;
}

}  // namespace mojo

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