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

// Copyright 2013 The Chromium Authors
// 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/document_metadata/document_metadata.mojom.h"
#include <math.h>
#include <stdint.h>
#include <utility>
#include "base/debug/alias.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/typed_macros.h"
#include "mojo/public/cpp/bindings/lib/default_construct_tag_internal.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/proxy_to_responder.h"
#include "mojo/public/cpp/bindings/lib/send_message_helper.h"
#include "mojo/public/cpp/bindings/lib/serialization.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_errors.h"
#include "mojo/public/cpp/bindings/mojo_buildflags.h"
#include "mojo/public/cpp/bindings/urgent_message_scope.h"
#include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

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

#include "third_party/blink/public/mojom/document_metadata/document_metadata.mojom-import-headers.h"
#include "third_party/blink/public/mojom/document_metadata/document_metadata.mojom-test-utils.h"


namespace blink::mojom {
WebPage::WebPage()
    : url(),
      title(),
      entities() {}

WebPage::WebPage(
    const ::GURL& url_in,
    const std::string& title_in,
    std::vector<::schema_org::mojom::EntityPtr> entities_in)
    : url(std::move(url_in)),
      title(std::move(title_in)),
      entities(std::move(entities_in)) {}

WebPage::~WebPage() = default;

void WebPage::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "url"), this->url,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const ::GURL&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "title"), this->title,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::string&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "entities"), this->entities,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::vector<::schema_org::mojom::EntityPtr>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool WebPage::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
ProductClassificationResult::ProductClassificationResult()
    : allowed_keyword_found(),
      blocked_keyword_found() {}

ProductClassificationResult::ProductClassificationResult(
    bool allowed_keyword_found_in,
    bool blocked_keyword_found_in)
    : allowed_keyword_found(std::move(allowed_keyword_found_in)),
      blocked_keyword_found(std::move(blocked_keyword_found_in)) {}

ProductClassificationResult::~ProductClassificationResult() = default;
size_t ProductClassificationResult::Hash(size_t seed) const {
  seed = mojo::internal::Hash(seed, this->allowed_keyword_found);
  seed = mojo::internal::Hash(seed, this->blocked_keyword_found);
  return seed;
}

void ProductClassificationResult::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "allowed_keyword_found"), this->allowed_keyword_found,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type bool>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "blocked_keyword_found"), this->blocked_keyword_found,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type bool>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool ProductClassificationResult::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
// The declaration includes the definition on other builds.

DocumentMetadata::IPCStableHashFunction DocumentMetadata::MessageToMethodInfo_(mojo::Message& message) {
#if !BUILDFLAG(IS_FUCHSIA)
  switch (static_cast<messages::DocumentMetadata>(message.name())) {
    case messages::DocumentMetadata::kGetEntities: {
      return &DocumentMetadata::GetEntities_Sym::IPCStableHash;
    }
    case messages::DocumentMetadata::kClassifyProductDetails: {
      return &DocumentMetadata::ClassifyProductDetails_Sym::IPCStableHash;
    }
  }
#endif  // !BUILDFLAG(IS_FUCHSIA)
  return nullptr;
}


const char* DocumentMetadata::MessageToMethodName_(mojo::Message& message) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  bool is_response = message.has_flag(mojo::Message::kFlagIsResponse);
  if (!is_response) {
    switch (static_cast<messages::DocumentMetadata>(message.name())) {
      case messages::DocumentMetadata::kGetEntities:
            return "Receive blink::mojom::DocumentMetadata::GetEntities";
      case messages::DocumentMetadata::kClassifyProductDetails:
            return "Receive blink::mojom::DocumentMetadata::ClassifyProductDetails";
    }
  } else {
    switch (static_cast<messages::DocumentMetadata>(message.name())) {
      case messages::DocumentMetadata::kGetEntities:
            return "Receive reply blink::mojom::DocumentMetadata::GetEntities";
      case messages::DocumentMetadata::kClassifyProductDetails:
            return "Receive reply blink::mojom::DocumentMetadata::ClassifyProductDetails";
    }
  }
  return "Receive unknown mojo message";
#else
  bool is_response = message.has_flag(mojo::Message::kFlagIsResponse);
  if (is_response) {
    return "Receive mojo reply";
  } else {
    return "Receive mojo message";
  }
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
}

#if !BUILDFLAG(IS_FUCHSIA)
uint32_t DocumentMetadata::GetEntities_Sym::IPCStableHash() {
  // This method's address is used for identifying the mojo method name after
  // symbolization. So each IPCStableHash should have a unique address.
  // We cannot use NO_CODE_FOLDING() here - it relies on the uniqueness of
  // __LINE__ value, which is not unique across different mojo modules.
  // The code below is very similar to NO_CODE_FOLDING, but it uses a unique
  // hash instead of __LINE__.
  static constexpr uint32_t kHash = 0x84786853;  // IPCStableHash for blink::mojom::DocumentMetadata::GetEntities
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
uint32_t DocumentMetadata::ClassifyProductDetails_Sym::IPCStableHash() {
  // This method's address is used for identifying the mojo method name after
  // symbolization. So each IPCStableHash should have a unique address.
  // We cannot use NO_CODE_FOLDING() here - it relies on the uniqueness of
  // __LINE__ value, which is not unique across different mojo modules.
  // The code below is very similar to NO_CODE_FOLDING, but it uses a unique
  // hash instead of __LINE__.
  static constexpr uint32_t kHash = 0x0882f543;  // IPCStableHash for blink::mojom::DocumentMetadata::ClassifyProductDetails
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
# endif // !BUILDFLAG(IS_FUCHSIA)

class DocumentMetadata_GetEntities_ForwardToCallback
    : public mojo::MessageReceiver {
 public:
  DocumentMetadata_GetEntities_ForwardToCallback(
      DocumentMetadata::GetEntitiesCallback callback
      ) : callback_(std::move(callback)) {
  }

  DocumentMetadata_GetEntities_ForwardToCallback(const DocumentMetadata_GetEntities_ForwardToCallback&) = delete;
  DocumentMetadata_GetEntities_ForwardToCallback& operator=(const DocumentMetadata_GetEntities_ForwardToCallback&) = delete;

  bool Accept(mojo::Message* message) override;
 private:
  DocumentMetadata::GetEntitiesCallback callback_;
};

class DocumentMetadata_ClassifyProductDetails_ForwardToCallback
    : public mojo::MessageReceiver {
 public:
  DocumentMetadata_ClassifyProductDetails_ForwardToCallback(
      DocumentMetadata::ClassifyProductDetailsCallback callback
      ) : callback_(std::move(callback)) {
  }

  DocumentMetadata_ClassifyProductDetails_ForwardToCallback(const DocumentMetadata_ClassifyProductDetails_ForwardToCallback&) = delete;
  DocumentMetadata_ClassifyProductDetails_ForwardToCallback& operator=(const DocumentMetadata_ClassifyProductDetails_ForwardToCallback&) = delete;

  bool Accept(mojo::Message* message) override;
 private:
  DocumentMetadata::ClassifyProductDetailsCallback callback_;
};

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

void DocumentMetadataProxy::GetEntities(
    GetEntitiesCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT0("mojom", "Send blink::mojom::DocumentMetadata::GetEntities");
#endif

  const bool kExpectsResponse = true;
  const bool kIsSync = false;
  const bool kAllowInterrupt = true;
  const bool is_urgent = false;

  const uint32_t kFlags =
      ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
      ((kIsSync) ? mojo::Message::kFlagIsSync : 0) |
      ((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt) |
      ((is_urgent) ? mojo::Message::kFlagIsUrgent : 0);

  const size_t estimated_payload_size =
    0;
  mojo::Message message(
      std::to_underlying(messages::DocumentMetadata::kGetEntities), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::blink::mojom::internal::DocumentMetadata_GetEntities_Params_Data> params(
          message);
  params.Allocate();

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(DocumentMetadata::Name_);
  message.set_method_name("GetEntities");
#endif
  std::unique_ptr<mojo::MessageReceiver> responder(
      new DocumentMetadata_GetEntities_ForwardToCallback(
          std::move(callback)));
  ::mojo::internal::SendMojoMessage(*receiver_, message, std::move(responder));
}

void DocumentMetadataProxy::ClassifyProductDetails(
    const std::vector<std::string>& in_allowed_keywords, const std::vector<std::string>& in_blocked_keywords, ClassifyProductDetailsCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send blink::mojom::DocumentMetadata::ClassifyProductDetails", "input_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("allowed_keywords"), in_allowed_keywords,
                        "<value of type const std::vector<std::string>&>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("blocked_keywords"), in_blocked_keywords,
                        "<value of type const std::vector<std::string>&>");
   });
#endif

  const bool kExpectsResponse = true;
  const bool kIsSync = false;
  const bool kAllowInterrupt = true;
  const bool is_urgent = false;

  const uint32_t kFlags =
      ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
      ((kIsSync) ? mojo::Message::kFlagIsSync : 0) |
      ((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt) |
      ((is_urgent) ? mojo::Message::kFlagIsUrgent : 0);

  const size_t estimated_payload_size =
    0;
  mojo::Message message(
      std::to_underlying(messages::DocumentMetadata::kClassifyProductDetails), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::blink::mojom::internal::DocumentMetadata_ClassifyProductDetails_Params_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->allowed_keywords)::BaseType>
      allowed_keywords_fragment(params.message());
  constexpr const mojo::internal::ContainerValidateParams& allowed_keywords_validate_params =
      mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>();
  
  mojo::internal::Serialize<mojo::ArrayDataView<mojo::StringDataView>>(
    in_allowed_keywords,
    allowed_keywords_fragment,
    &allowed_keywords_validate_params);

  params->allowed_keywords.Set(
      allowed_keywords_fragment.is_null() ? nullptr : allowed_keywords_fragment.data());

  
  MOJO_INTERNAL_CHECK_SERIALIZATION(
    mojo::internal::SendValidation::kDefault,
    !(params->allowed_keywords.is_null()),
    mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
    "null allowed_keywords in DocumentMetadata.ClassifyProductDetails request");
  mojo::internal::MessageFragment<
      typename decltype(params->blocked_keywords)::BaseType>
      blocked_keywords_fragment(params.message());
  constexpr const mojo::internal::ContainerValidateParams& blocked_keywords_validate_params =
      mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>();
  
  mojo::internal::Serialize<mojo::ArrayDataView<mojo::StringDataView>>(
    in_blocked_keywords,
    blocked_keywords_fragment,
    &blocked_keywords_validate_params);

  params->blocked_keywords.Set(
      blocked_keywords_fragment.is_null() ? nullptr : blocked_keywords_fragment.data());

  
  MOJO_INTERNAL_CHECK_SERIALIZATION(
    mojo::internal::SendValidation::kDefault,
    !(params->blocked_keywords.is_null()),
    mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
    "null blocked_keywords in DocumentMetadata.ClassifyProductDetails request");

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(DocumentMetadata::Name_);
  message.set_method_name("ClassifyProductDetails");
#endif
  std::unique_ptr<mojo::MessageReceiver> responder(
      new DocumentMetadata_ClassifyProductDetails_ForwardToCallback(
          std::move(callback)));
  ::mojo::internal::SendMojoMessage(*receiver_, message, std::move(responder));
}
class DocumentMetadata_GetEntities_ProxyToResponder : public ::mojo::internal::ProxyToResponder {
 public:
  static DocumentMetadata::GetEntitiesCallback CreateCallback(
      ::mojo::Message& message,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
    std::unique_ptr<DocumentMetadata_GetEntities_ProxyToResponder> proxy(
        new DocumentMetadata_GetEntities_ProxyToResponder(
            message, std::move(responder)));
    return base::BindOnce(&DocumentMetadata_GetEntities_ProxyToResponder::Run,
                          std::move(proxy));
  }

  ~DocumentMetadata_GetEntities_ProxyToResponder() {
#if DCHECK_IS_ON()
    if (responder_) {
      // If we're being destroyed without being run, we want to ensure the
      // binding endpoint has been closed. This checks for that asynchronously.
      // We pass a bound generated callback to handle the response so that any
      // resulting DCHECK stack will have useful interface type information.
      // Instantiate a ScopedFizzleBlockShutdownTasks to allow this request to
      // fizzle if this happens after shutdown and the endpoint is bound to a
      // BLOCK_SHUTDOWN sequence.
      base::ThreadPoolInstance::ScopedFizzleBlockShutdownTasks fizzler;
      responder_->IsConnectedAsync(base::BindOnce(&OnIsConnectedComplete));
    }
#endif
  }

 private:
  DocumentMetadata_GetEntities_ProxyToResponder(
      ::mojo::Message& message,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder)
      : ::mojo::internal::ProxyToResponder(message, std::move(responder)) {
  }

#if DCHECK_IS_ON()
  static void OnIsConnectedComplete(bool connected) {
    DCHECK(!connected)
        << "DocumentMetadata::GetEntitiesCallback was destroyed without "
        << "first either being run or its corresponding binding being closed. "
        << "It is an error to drop response callbacks which still correspond "
        << "to an open interface pipe.";
  }
#endif

  void Run(
      WebPagePtr in_page);
};

bool DocumentMetadata_GetEntities_ForwardToCallback::Accept(
    mojo::Message* message) {
  DCHECK(message->is_serialized());
  internal::DocumentMetadata_GetEntities_ResponseParams_Data* params =
      reinterpret_cast<
          internal::DocumentMetadata_GetEntities_ResponseParams_Data*>(
              message->mutable_payload());
  

  // Validation for DocumentMetadata.0
  bool success = true;
  WebPagePtr p_page{};
  DocumentMetadata_GetEntities_ResponseParamsDataView input_data_view(params, message);
  
  if (success && !input_data_view.ReadPage(&p_page))
    success = false;
  if (!success) {
    ReportValidationErrorForMessage(
        message,
        mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
        DocumentMetadata::Name_, 0, true);
    return false;
  }
  if (!callback_.is_null()) {
    std::move(callback_).Run(
std::move(p_page));
  }
  return true;
}

void DocumentMetadata_GetEntities_ProxyToResponder::Run(
    WebPagePtr in_page) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send reply blink::mojom::DocumentMetadata::GetEntities", "async_response_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("page"), in_page,
                        "<value of type WebPagePtr>");
   });
#endif

  const uint32_t kFlags = mojo::Message::kFlagIsResponse |
      ((is_sync_) ? mojo::Message::kFlagIsSync : 0) |
      ((true) ? 0 : mojo::Message::kFlagNoInterrupt) |
      ((false) ? mojo::Message::kFlagIsUrgent : 0);

  const size_t estimated_payload_size =
    0;
  mojo::Message message(
      std::to_underlying(messages::DocumentMetadata::kGetEntities), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::blink::mojom::internal::DocumentMetadata_GetEntities_ResponseParams_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->page)::BaseType> page_fragment(
          params.message());
  
  mojo::internal::Serialize<::blink::mojom::WebPageDataView>(
    in_page,
    page_fragment);

  params->page.Set(
      page_fragment.is_null() ? nullptr : page_fragment.data());

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(DocumentMetadata::Name_);
  message.set_method_name("GetEntities");
#endif

  message.set_request_id(request_id_);
  message.set_trace_nonce(trace_nonce_);
  ::mojo::internal::SendMojoMessage(*responder_, message);
  // SendMojoMessage() fails silently if the responder connection is closed,
  // or if the message is malformed.
  //
  // TODO(darin): If Accept() returns false due to a malformed message, that
  // may be good reason to close the connection. However, we don't have a
  // way to do that from here. We should add a way.
  responder_ = nullptr;
}
class DocumentMetadata_ClassifyProductDetails_ProxyToResponder : public ::mojo::internal::ProxyToResponder {
 public:
  static DocumentMetadata::ClassifyProductDetailsCallback CreateCallback(
      ::mojo::Message& message,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
    std::unique_ptr<DocumentMetadata_ClassifyProductDetails_ProxyToResponder> proxy(
        new DocumentMetadata_ClassifyProductDetails_ProxyToResponder(
            message, std::move(responder)));
    return base::BindOnce(&DocumentMetadata_ClassifyProductDetails_ProxyToResponder::Run,
                          std::move(proxy));
  }

  ~DocumentMetadata_ClassifyProductDetails_ProxyToResponder() {
#if DCHECK_IS_ON()
    if (responder_) {
      // If we're being destroyed without being run, we want to ensure the
      // binding endpoint has been closed. This checks for that asynchronously.
      // We pass a bound generated callback to handle the response so that any
      // resulting DCHECK stack will have useful interface type information.
      // Instantiate a ScopedFizzleBlockShutdownTasks to allow this request to
      // fizzle if this happens after shutdown and the endpoint is bound to a
      // BLOCK_SHUTDOWN sequence.
      base::ThreadPoolInstance::ScopedFizzleBlockShutdownTasks fizzler;
      responder_->IsConnectedAsync(base::BindOnce(&OnIsConnectedComplete));
    }
#endif
  }

 private:
  DocumentMetadata_ClassifyProductDetails_ProxyToResponder(
      ::mojo::Message& message,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder)
      : ::mojo::internal::ProxyToResponder(message, std::move(responder)) {
  }

#if DCHECK_IS_ON()
  static void OnIsConnectedComplete(bool connected) {
    DCHECK(!connected)
        << "DocumentMetadata::ClassifyProductDetailsCallback was destroyed without "
        << "first either being run or its corresponding binding being closed. "
        << "It is an error to drop response callbacks which still correspond "
        << "to an open interface pipe.";
  }
#endif

  void Run(
      ProductClassificationResultPtr in_result);
};

bool DocumentMetadata_ClassifyProductDetails_ForwardToCallback::Accept(
    mojo::Message* message) {
  DCHECK(message->is_serialized());
  internal::DocumentMetadata_ClassifyProductDetails_ResponseParams_Data* params =
      reinterpret_cast<
          internal::DocumentMetadata_ClassifyProductDetails_ResponseParams_Data*>(
              message->mutable_payload());
  

  // Validation for DocumentMetadata.1
  bool success = true;
  ProductClassificationResultPtr p_result{};
  DocumentMetadata_ClassifyProductDetails_ResponseParamsDataView input_data_view(params, message);
  
  if (success && !input_data_view.ReadResult(&p_result))
    success = false;
  if (!success) {
    ReportValidationErrorForMessage(
        message,
        mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
        DocumentMetadata::Name_, 1, true);
    return false;
  }
  if (!callback_.is_null()) {
    std::move(callback_).Run(
std::move(p_result));
  }
  return true;
}

void DocumentMetadata_ClassifyProductDetails_ProxyToResponder::Run(
    ProductClassificationResultPtr in_result) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send reply blink::mojom::DocumentMetadata::ClassifyProductDetails", "async_response_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("result"), in_result,
                        "<value of type ProductClassificationResultPtr>");
   });
#endif

  const uint32_t kFlags = mojo::Message::kFlagIsResponse |
      ((is_sync_) ? mojo::Message::kFlagIsSync : 0) |
      ((true) ? 0 : mojo::Message::kFlagNoInterrupt) |
      ((false) ? mojo::Message::kFlagIsUrgent : 0);

  const size_t estimated_payload_size =
    0;
  mojo::Message message(
      std::to_underlying(messages::DocumentMetadata::kClassifyProductDetails), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::blink::mojom::internal::DocumentMetadata_ClassifyProductDetails_ResponseParams_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->result)::BaseType> result_fragment(
          params.message());
  
  mojo::internal::Serialize<::blink::mojom::ProductClassificationResultDataView>(
    in_result,
    result_fragment);

  params->result.Set(
      result_fragment.is_null() ? nullptr : result_fragment.data());

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(DocumentMetadata::Name_);
  message.set_method_name("ClassifyProductDetails");
#endif

  message.set_request_id(request_id_);
  message.set_trace_nonce(trace_nonce_);
  ::mojo::internal::SendMojoMessage(*responder_, message);
  // SendMojoMessage() fails silently if the responder connection is closed,
  // or if the message is malformed.
  //
  // TODO(darin): If Accept() returns false due to a malformed message, that
  // may be good reason to close the connection. However, we don't have a
  // way to do that from here. We should add a way.
  responder_ = nullptr;
}

// static
bool DocumentMetadataStubDispatch::Accept(
    DocumentMetadata* impl,
    mojo::Message* message) {
  switch (static_cast<messages::DocumentMetadata>(message->header()->name)) {
    case messages::DocumentMetadata::kGetEntities: {
      break;
    }
    case messages::DocumentMetadata::kClassifyProductDetails: {
      break;
    }
  }
  return false;
}

// static
bool DocumentMetadataStubDispatch::AcceptWithResponder(
    DocumentMetadata* impl,
    mojo::Message* message,
    std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
  [[maybe_unused]] const bool message_is_sync =
      message->has_flag(mojo::Message::kFlagIsSync);
  [[maybe_unused]] const uint64_t request_id = message->request_id();
  switch (static_cast<messages::DocumentMetadata>(message->header()->name)) {
    case messages::DocumentMetadata::kGetEntities: {
      internal::DocumentMetadata_GetEntities_Params_Data* params =
          reinterpret_cast<
              internal::DocumentMetadata_GetEntities_Params_Data*>(
                  message->mutable_payload());
      

      // Validation for DocumentMetadata.0
      bool success = true;
      DocumentMetadata_GetEntities_ParamsDataView input_data_view(params, message);
      
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            DocumentMetadata::Name_, 0, false);
        return false;
      }
      auto callback =
          DocumentMetadata_GetEntities_ProxyToResponder::CreateCallback(
              *message, std::move(responder));
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->GetEntities(std::move(callback));
      return true;
    }
    case messages::DocumentMetadata::kClassifyProductDetails: {
      internal::DocumentMetadata_ClassifyProductDetails_Params_Data* params =
          reinterpret_cast<
              internal::DocumentMetadata_ClassifyProductDetails_Params_Data*>(
                  message->mutable_payload());
      

      // Validation for DocumentMetadata.1
      bool success = true;
      std::vector<std::string> p_allowed_keywords{};
      std::vector<std::string> p_blocked_keywords{};
      DocumentMetadata_ClassifyProductDetails_ParamsDataView input_data_view(params, message);
      
      if (success && !input_data_view.ReadAllowedKeywords(&p_allowed_keywords))
        success = false;
      if (success && !input_data_view.ReadBlockedKeywords(&p_blocked_keywords))
        success = false;
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            DocumentMetadata::Name_, 1, false);
        return false;
      }
      auto callback =
          DocumentMetadata_ClassifyProductDetails_ProxyToResponder::CreateCallback(
              *message, std::move(responder));
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->ClassifyProductDetails(        
        std::move(p_allowed_keywords), 
        std::move(p_blocked_keywords), std::move(callback));
      return true;
    }
  }
  return false;
}
namespace {
}  // namespace
static const mojo::internal::GenericValidationInfo kDocumentMetadataValidationInfo[] = {
    { &internal::DocumentMetadata_GetEntities_Params_Data::Validate,
     &internal::DocumentMetadata_GetEntities_ResponseParams_Data::Validate},
    { &internal::DocumentMetadata_ClassifyProductDetails_Params_Data::Validate,
     &internal::DocumentMetadata_ClassifyProductDetails_ResponseParams_Data::Validate},
};

bool DocumentMetadataRequestValidator::Accept(mojo::Message* message) {
  return mojo::internal::ValidateRequestGenericPacked(
    message,
    ::blink::mojom::DocumentMetadata::Name_,
    kDocumentMetadataValidationInfo);
}

bool DocumentMetadataResponseValidator::Accept(mojo::Message* message) {
  return mojo::internal::ValidateResponseGenericPacked(
    message,
    ::blink::mojom::DocumentMetadata::Name_,
    kDocumentMetadataValidationInfo);
}


}  // blink::mojom


namespace mojo {


// static
bool StructTraits<::blink::mojom::WebPage::DataView, ::blink::mojom::WebPagePtr>::Read(
    ::blink::mojom::WebPage::DataView input,
    ::blink::mojom::WebPagePtr* output) {
  bool success = true;
  ::blink::mojom::WebPagePtr result(::blink::mojom::WebPage::New());
  
      if (success && !input.ReadUrl(&result->url))
        success = false;
      if (success && !input.ReadTitle(&result->title))
        success = false;
      if (success && !input.ReadEntities(&result->entities))
        success = false;
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::blink::mojom::ProductClassificationResult::DataView, ::blink::mojom::ProductClassificationResultPtr>::Read(
    ::blink::mojom::ProductClassificationResult::DataView input,
    ::blink::mojom::ProductClassificationResultPtr* output) {
  bool success = true;
  ::blink::mojom::ProductClassificationResultPtr result(::blink::mojom::ProductClassificationResult::New());
  
      if (success)
        result->allowed_keyword_found = input.allowed_keyword_found();
      if (success)
        result->blocked_keyword_found = input.blocked_keyword_found();
  *output = std::move(result);
  return success;
}

}  // namespace mojo


// Symbols declared in the -test-utils.h header are defined here instead of a
// separate .cc file to save compile time.


namespace blink::mojom {


void DocumentMetadataInterceptorForTesting::GetEntities(GetEntitiesCallback callback) {
  GetForwardingInterface()->GetEntities(std::move(callback));
}
void DocumentMetadataInterceptorForTesting::ClassifyProductDetails(const std::vector<std::string>& allowed_keywords, const std::vector<std::string>& blocked_keywords, ClassifyProductDetailsCallback callback) {
  GetForwardingInterface()->ClassifyProductDetails(
    std::move(allowed_keywords)
    , 
    std::move(blocked_keywords)
    , std::move(callback));
}
DocumentMetadataAsyncWaiter::DocumentMetadataAsyncWaiter(
    DocumentMetadata* proxy) : proxy_(proxy) {}

DocumentMetadataAsyncWaiter::~DocumentMetadataAsyncWaiter() = default;


void DocumentMetadataAsyncWaiter::GetEntities(
    WebPagePtr* out_page) {
  base::RunLoop loop;
  proxy_->GetEntities(
      base::BindOnce(
          [](base::RunLoop* loop,
             WebPagePtr* out_page
,
             WebPagePtr page) {*out_page = std::move(page);
            loop->Quit();
          },
          &loop,
          out_page));
  loop.Run();
}

WebPagePtr DocumentMetadataAsyncWaiter::GetEntities(
    ) {
  WebPagePtr async_wait_result;
  GetEntities(&async_wait_result);
  return async_wait_result;
}

void DocumentMetadataAsyncWaiter::ClassifyProductDetails(
    const std::vector<std::string>& allowed_keywords, const std::vector<std::string>& blocked_keywords, ProductClassificationResultPtr* out_result) {
  base::RunLoop loop;
  proxy_->ClassifyProductDetails(
      std::move(allowed_keywords),
      std::move(blocked_keywords),
      base::BindOnce(
          [](base::RunLoop* loop,
             ProductClassificationResultPtr* out_result
,
             ProductClassificationResultPtr result) {*out_result = std::move(result);
            loop->Quit();
          },
          &loop,
          out_result));
  loop.Run();
}

ProductClassificationResultPtr DocumentMetadataAsyncWaiter::ClassifyProductDetails(
    const std::vector<std::string>& allowed_keywords, const std::vector<std::string>& blocked_keywords) {
  ProductClassificationResultPtr async_wait_result;
  ClassifyProductDetails(std::move(allowed_keywords),std::move(blocked_keywords),&async_wait_result);
  return async_wait_result;
}






}  // blink::mojom


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