// components/optimization_guide/public/mojom/model_broker_debug.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 "components/optimization_guide/public/mojom/model_broker_debug.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 "components/optimization_guide/public/mojom/model_broker_debug.mojom-params-data.h"
#include "components/optimization_guide/public/mojom/model_broker_debug.mojom-shared-message-ids.h"

#include "components/optimization_guide/public/mojom/model_broker_debug.mojom-import-headers.h"
#include "components/optimization_guide/public/mojom/model_broker_debug.mojom-test-utils.h"


namespace optimization_guide::mojom {
BrokerPropertyInfo::BrokerPropertyInfo()
    : description(),
      value() {}

BrokerPropertyInfo::BrokerPropertyInfo(
    const std::string& description_in,
    const std::string& value_in)
    : description(std::move(description_in)),
      value(std::move(value_in)) {}

BrokerPropertyInfo::~BrokerPropertyInfo() = default;
size_t BrokerPropertyInfo::Hash(size_t seed) const {
  seed = mojo::internal::Hash(seed, this->description);
  seed = mojo::internal::Hash(seed, this->value);
  return seed;
}

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

bool BrokerPropertyInfo::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
BrokerAssetInfo::BrokerAssetInfo()
    : name(),
      version(),
      state(),
      error(),
      bytes_downloaded(),
      bytes_total() {}

BrokerAssetInfo::BrokerAssetInfo(
    const std::string& name_in,
    const std::optional<std::string>& version_in,
    BrokerAssetState state_in,
    const std::optional<std::string>& error_in,
    uint64_t bytes_downloaded_in,
    uint64_t bytes_total_in)
    : name(std::move(name_in)),
      version(std::move(version_in)),
      state(std::move(state_in)),
      error(std::move(error_in)),
      bytes_downloaded(std::move(bytes_downloaded_in)),
      bytes_total(std::move(bytes_total_in)) {}

BrokerAssetInfo::~BrokerAssetInfo() = default;

void BrokerAssetInfo::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "name"), this->name,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::string&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "version"), this->version,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::optional<std::string>&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "state"), this->state,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type BrokerAssetState>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "error"), this->error,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::optional<std::string>&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "bytes_downloaded"), this->bytes_downloaded,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type uint64_t>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "bytes_total"), this->bytes_total,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type uint64_t>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool BrokerAssetInfo::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
BrokerUseCaseInfo::BrokerUseCaseInfo()
    : name(),
      assets_requested(),
      unavailable_reason() {}

BrokerUseCaseInfo::BrokerUseCaseInfo(
    const std::string& name_in,
    bool assets_requested_in,
    std::optional<::optimization_guide::mojom::ModelUnavailableReason> unavailable_reason_in)
    : name(std::move(name_in)),
      assets_requested(std::move(assets_requested_in)),
      unavailable_reason(std::move(unavailable_reason_in)) {}

BrokerUseCaseInfo::~BrokerUseCaseInfo() = default;

void BrokerUseCaseInfo::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "name"), this->name,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::string&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "assets_requested"), this->assets_requested,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type bool>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "unavailable_reason"), this->unavailable_reason,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::optional<::optimization_guide::mojom::ModelUnavailableReason>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool BrokerUseCaseInfo::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
BrokerModelInfo::BrokerModelInfo()
    : name(),
      folder_size(),
      weights_path(),
      backend_type() {}

BrokerModelInfo::BrokerModelInfo(
    const std::string& name_in,
    uint64_t folder_size_in,
    const std::string& weights_path_in,
    const std::string& backend_type_in)
    : name(std::move(name_in)),
      folder_size(std::move(folder_size_in)),
      weights_path(std::move(weights_path_in)),
      backend_type(std::move(backend_type_in)) {}

BrokerModelInfo::~BrokerModelInfo() = default;
size_t BrokerModelInfo::Hash(size_t seed) const {
  seed = mojo::internal::Hash(seed, this->name);
  seed = mojo::internal::Hash(seed, this->folder_size);
  seed = mojo::internal::Hash(seed, this->weights_path);
  seed = mojo::internal::Hash(seed, this->backend_type);
  return seed;
}

void BrokerModelInfo::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "name"), this->name,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::string&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "folder_size"), this->folder_size,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type uint64_t>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "weights_path"), this->weights_path,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::string&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "backend_type"), this->backend_type,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::string&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

bool BrokerModelInfo::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
BrokerStateInfo::BrokerStateInfo()
    : properties(),
      assets(),
      use_cases(),
      models(),
      model_crash_count(),
      max_model_crash_count(),
      is_asset_manager_initialized() {}

BrokerStateInfo::BrokerStateInfo(
    std::vector<BrokerPropertyInfoPtr> properties_in,
    std::vector<BrokerAssetInfoPtr> assets_in,
    std::vector<BrokerUseCaseInfoPtr> use_cases_in,
    std::vector<BrokerModelInfoPtr> models_in,
    std::optional<int32_t> model_crash_count_in,
    std::optional<int32_t> max_model_crash_count_in,
    bool is_asset_manager_initialized_in)
    : properties(std::move(properties_in)),
      assets(std::move(assets_in)),
      use_cases(std::move(use_cases_in)),
      models(std::move(models_in)),
      model_crash_count(std::move(model_crash_count_in)),
      max_model_crash_count(std::move(max_model_crash_count_in)),
      is_asset_manager_initialized(std::move(is_asset_manager_initialized_in)) {}

BrokerStateInfo::~BrokerStateInfo() = default;

void BrokerStateInfo::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "properties"), this->properties,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::vector<BrokerPropertyInfoPtr>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "assets"), this->assets,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::vector<BrokerAssetInfoPtr>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "use_cases"), this->use_cases,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::vector<BrokerUseCaseInfoPtr>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "models"), this->models,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::vector<BrokerModelInfoPtr>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "model_crash_count"), this->model_crash_count,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::optional<int32_t>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "max_model_crash_count"), this->max_model_crash_count,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type std::optional<int32_t>>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "is_asset_manager_initialized"), this->is_asset_manager_initialized,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type bool>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

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

ModelBrokerDebugObserver::IPCStableHashFunction ModelBrokerDebugObserver::MessageToMethodInfo_(mojo::Message& message) {
#if !BUILDFLAG(IS_FUCHSIA)
  switch (static_cast<messages::ModelBrokerDebugObserver>(message.name())) {
    case messages::ModelBrokerDebugObserver::kOnBrokerStateChanged: {
      return &ModelBrokerDebugObserver::OnBrokerStateChanged_Sym::IPCStableHash;
    }
  }
#endif  // !BUILDFLAG(IS_FUCHSIA)
  return nullptr;
}


const char* ModelBrokerDebugObserver::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::ModelBrokerDebugObserver>(message.name())) {
      case messages::ModelBrokerDebugObserver::kOnBrokerStateChanged:
            return "Receive optimization_guide::mojom::ModelBrokerDebugObserver::OnBrokerStateChanged";
    }
  } else {
    switch (static_cast<messages::ModelBrokerDebugObserver>(message.name())) {
      case messages::ModelBrokerDebugObserver::kOnBrokerStateChanged:
            return "Receive reply optimization_guide::mojom::ModelBrokerDebugObserver::OnBrokerStateChanged";
    }
  }
  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 ModelBrokerDebugObserver::OnBrokerStateChanged_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 = 0xff60363f;  // IPCStableHash for optimization_guide::mojom::ModelBrokerDebugObserver::OnBrokerStateChanged
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
# endif // !BUILDFLAG(IS_FUCHSIA)

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

void ModelBrokerDebugObserverProxy::OnBrokerStateChanged(
    ) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT0("mojom", "Send optimization_guide::mojom::ModelBrokerDebugObserver::OnBrokerStateChanged");
#endif

  const bool kExpectsResponse = false;
  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::ModelBrokerDebugObserver::kOnBrokerStateChanged), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::optimization_guide::mojom::internal::ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data> params(
          message);
  params.Allocate();

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(ModelBrokerDebugObserver::Name_);
  message.set_method_name("OnBrokerStateChanged");
#endif
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ::mojo::internal::SendMojoMessage(*receiver_, message);
}

// static
bool ModelBrokerDebugObserverStubDispatch::Accept(
    ModelBrokerDebugObserver* impl,
    mojo::Message* message) {
  switch (static_cast<messages::ModelBrokerDebugObserver>(message->header()->name)) {
    case messages::ModelBrokerDebugObserver::kOnBrokerStateChanged: {
      DCHECK(message->is_serialized());
      internal::ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data* params =
          reinterpret_cast<internal::ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data*>(
              message->mutable_payload());
      

      // Validation for ModelBrokerDebugObserver.0
      bool success = true;
      ModelBrokerDebugObserver_OnBrokerStateChanged_ParamsDataView input_data_view(params, message);
      
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            ModelBrokerDebugObserver::Name_, 0, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->OnBrokerStateChanged(        );
      return true;
    }
  }
  return false;
}

// static
bool ModelBrokerDebugObserverStubDispatch::AcceptWithResponder(
    ModelBrokerDebugObserver* 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::ModelBrokerDebugObserver>(message->header()->name)) {
    case messages::ModelBrokerDebugObserver::kOnBrokerStateChanged: {
      break;
    }
  }
  return false;
}
namespace {
}  // namespace
static const mojo::internal::GenericValidationInfo kModelBrokerDebugObserverValidationInfo[] = {
    { &internal::ModelBrokerDebugObserver_OnBrokerStateChanged_Params_Data::Validate,
     nullptr /* no response */},
};

bool ModelBrokerDebugObserverRequestValidator::Accept(mojo::Message* message) {
  return mojo::internal::ValidateRequestGenericPacked(
    message,
    ::optimization_guide::mojom::ModelBrokerDebugObserver::Name_,
    kModelBrokerDebugObserverValidationInfo);
}

// The declaration includes the definition on other builds.

ModelBrokerDebug::IPCStableHashFunction ModelBrokerDebug::MessageToMethodInfo_(mojo::Message& message) {
#if !BUILDFLAG(IS_FUCHSIA)
  switch (static_cast<messages::ModelBrokerDebug>(message.name())) {
    case messages::ModelBrokerDebug::kGetStateInfo: {
      return &ModelBrokerDebug::GetStateInfo_Sym::IPCStableHash;
    }
    case messages::ModelBrokerDebug::kSetUseCaseRequested: {
      return &ModelBrokerDebug::SetUseCaseRequested_Sym::IPCStableHash;
    }
    case messages::ModelBrokerDebug::kUninstallModels: {
      return &ModelBrokerDebug::UninstallModels_Sym::IPCStableHash;
    }
    case messages::ModelBrokerDebug::kResetModelCrashCount: {
      return &ModelBrokerDebug::ResetModelCrashCount_Sym::IPCStableHash;
    }
    case messages::ModelBrokerDebug::kAddObserver: {
      return &ModelBrokerDebug::AddObserver_Sym::IPCStableHash;
    }
    case messages::ModelBrokerDebug::kAddAssetDownloadObserver: {
      return &ModelBrokerDebug::AddAssetDownloadObserver_Sym::IPCStableHash;
    }
  }
#endif  // !BUILDFLAG(IS_FUCHSIA)
  return nullptr;
}


const char* ModelBrokerDebug::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::ModelBrokerDebug>(message.name())) {
      case messages::ModelBrokerDebug::kGetStateInfo:
            return "Receive optimization_guide::mojom::ModelBrokerDebug::GetStateInfo";
      case messages::ModelBrokerDebug::kSetUseCaseRequested:
            return "Receive optimization_guide::mojom::ModelBrokerDebug::SetUseCaseRequested";
      case messages::ModelBrokerDebug::kUninstallModels:
            return "Receive optimization_guide::mojom::ModelBrokerDebug::UninstallModels";
      case messages::ModelBrokerDebug::kResetModelCrashCount:
            return "Receive optimization_guide::mojom::ModelBrokerDebug::ResetModelCrashCount";
      case messages::ModelBrokerDebug::kAddObserver:
            return "Receive optimization_guide::mojom::ModelBrokerDebug::AddObserver";
      case messages::ModelBrokerDebug::kAddAssetDownloadObserver:
            return "Receive optimization_guide::mojom::ModelBrokerDebug::AddAssetDownloadObserver";
    }
  } else {
    switch (static_cast<messages::ModelBrokerDebug>(message.name())) {
      case messages::ModelBrokerDebug::kGetStateInfo:
            return "Receive reply optimization_guide::mojom::ModelBrokerDebug::GetStateInfo";
      case messages::ModelBrokerDebug::kSetUseCaseRequested:
            return "Receive reply optimization_guide::mojom::ModelBrokerDebug::SetUseCaseRequested";
      case messages::ModelBrokerDebug::kUninstallModels:
            return "Receive reply optimization_guide::mojom::ModelBrokerDebug::UninstallModels";
      case messages::ModelBrokerDebug::kResetModelCrashCount:
            return "Receive reply optimization_guide::mojom::ModelBrokerDebug::ResetModelCrashCount";
      case messages::ModelBrokerDebug::kAddObserver:
            return "Receive reply optimization_guide::mojom::ModelBrokerDebug::AddObserver";
      case messages::ModelBrokerDebug::kAddAssetDownloadObserver:
            return "Receive reply optimization_guide::mojom::ModelBrokerDebug::AddAssetDownloadObserver";
    }
  }
  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 ModelBrokerDebug::GetStateInfo_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 = 0xc3f5f2df;  // IPCStableHash for optimization_guide::mojom::ModelBrokerDebug::GetStateInfo
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
uint32_t ModelBrokerDebug::SetUseCaseRequested_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 = 0x97bd8ea0;  // IPCStableHash for optimization_guide::mojom::ModelBrokerDebug::SetUseCaseRequested
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
uint32_t ModelBrokerDebug::UninstallModels_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 = 0x924f4d41;  // IPCStableHash for optimization_guide::mojom::ModelBrokerDebug::UninstallModels
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
uint32_t ModelBrokerDebug::ResetModelCrashCount_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 = 0x454cb869;  // IPCStableHash for optimization_guide::mojom::ModelBrokerDebug::ResetModelCrashCount
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
uint32_t ModelBrokerDebug::AddObserver_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 = 0x31cb47d6;  // IPCStableHash for optimization_guide::mojom::ModelBrokerDebug::AddObserver
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
uint32_t ModelBrokerDebug::AddAssetDownloadObserver_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 = 0xf4cf26e8;  // IPCStableHash for optimization_guide::mojom::ModelBrokerDebug::AddAssetDownloadObserver
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
# endif // !BUILDFLAG(IS_FUCHSIA)

class ModelBrokerDebug_GetStateInfo_ForwardToCallback
    : public mojo::MessageReceiver {
 public:
  ModelBrokerDebug_GetStateInfo_ForwardToCallback(
      ModelBrokerDebug::GetStateInfoCallback callback
      ) : callback_(std::move(callback)) {
  }

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

  bool Accept(mojo::Message* message) override;
 private:
  ModelBrokerDebug::GetStateInfoCallback callback_;
};

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

void ModelBrokerDebugProxy::GetStateInfo(
    GetStateInfoCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT0("mojom", "Send optimization_guide::mojom::ModelBrokerDebug::GetStateInfo");
#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::ModelBrokerDebug::kGetStateInfo), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::optimization_guide::mojom::internal::ModelBrokerDebug_GetStateInfo_Params_Data> params(
          message);
  params.Allocate();

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

void ModelBrokerDebugProxy::SetUseCaseRequested(
    const std::string& in_use_case, bool in_requested) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send optimization_guide::mojom::ModelBrokerDebug::SetUseCaseRequested", "input_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("use_case"), in_use_case,
                        "<value of type const std::string&>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("requested"), in_requested,
                        "<value of type bool>");
   });
#endif

  const bool kExpectsResponse = false;
  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::ModelBrokerDebug::kSetUseCaseRequested), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::optimization_guide::mojom::internal::ModelBrokerDebug_SetUseCaseRequested_Params_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->use_case)::BaseType> use_case_fragment(
          params.message());
  
  mojo::internal::Serialize<mojo::StringDataView>(
    in_use_case,
    use_case_fragment);

  params->use_case.Set(
      use_case_fragment.is_null() ? nullptr : use_case_fragment.data());

  
  MOJO_INTERNAL_CHECK_SERIALIZATION(
    mojo::internal::SendValidation::kDefault,
    !(params->use_case.is_null()),
    mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
    "null use_case in ModelBrokerDebug.SetUseCaseRequested request");

  params->requested = in_requested;

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(ModelBrokerDebug::Name_);
  message.set_method_name("SetUseCaseRequested");
#endif
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ::mojo::internal::SendMojoMessage(*receiver_, message);
}

void ModelBrokerDebugProxy::UninstallModels(
    ) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT0("mojom", "Send optimization_guide::mojom::ModelBrokerDebug::UninstallModels");
#endif

  const bool kExpectsResponse = false;
  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::ModelBrokerDebug::kUninstallModels), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::optimization_guide::mojom::internal::ModelBrokerDebug_UninstallModels_Params_Data> params(
          message);
  params.Allocate();

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(ModelBrokerDebug::Name_);
  message.set_method_name("UninstallModels");
#endif
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ::mojo::internal::SendMojoMessage(*receiver_, message);
}

void ModelBrokerDebugProxy::ResetModelCrashCount(
    ) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT0("mojom", "Send optimization_guide::mojom::ModelBrokerDebug::ResetModelCrashCount");
#endif

  const bool kExpectsResponse = false;
  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::ModelBrokerDebug::kResetModelCrashCount), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::optimization_guide::mojom::internal::ModelBrokerDebug_ResetModelCrashCount_Params_Data> params(
          message);
  params.Allocate();

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(ModelBrokerDebug::Name_);
  message.set_method_name("ResetModelCrashCount");
#endif
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ::mojo::internal::SendMojoMessage(*receiver_, message);
}

void ModelBrokerDebugProxy::AddObserver(
    ::mojo::PendingRemote<ModelBrokerDebugObserver> in_observer) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send optimization_guide::mojom::ModelBrokerDebug::AddObserver", "input_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("observer"), in_observer,
                        "<value of type ::mojo::PendingRemote<ModelBrokerDebugObserver>>");
   });
#endif

  const bool kExpectsResponse = false;
  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::ModelBrokerDebug::kAddObserver), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::optimization_guide::mojom::internal::ModelBrokerDebug_AddObserver_Params_Data> params(
          message);
  params.Allocate();

  
  mojo::internal::Serialize<mojo::InterfacePtrDataView<::optimization_guide::mojom::ModelBrokerDebugObserverInterfaceBase>>(
    in_observer,
    &params->observer,
    &params.message());

  
  MOJO_INTERNAL_CHECK_SERIALIZATION(
    mojo::internal::SendValidation::kDefault,
    !(!mojo::internal::IsHandleOrInterfaceValid(params->observer)),
    mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
    "invalid observer in ModelBrokerDebug.AddObserver request");

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(ModelBrokerDebug::Name_);
  message.set_method_name("AddObserver");
#endif
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ::mojo::internal::SendMojoMessage(*receiver_, message);
}

void ModelBrokerDebugProxy::AddAssetDownloadObserver(
    const std::string& in_asset_name, ::mojo::PendingRemote<::on_device_model::mojom::DownloadObserver> in_observer) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send optimization_guide::mojom::ModelBrokerDebug::AddAssetDownloadObserver", "input_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("asset_name"), in_asset_name,
                        "<value of type const std::string&>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("observer"), in_observer,
                        "<value of type ::mojo::PendingRemote<::on_device_model::mojom::DownloadObserver>>");
   });
#endif

  const bool kExpectsResponse = false;
  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::ModelBrokerDebug::kAddAssetDownloadObserver), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::optimization_guide::mojom::internal::ModelBrokerDebug_AddAssetDownloadObserver_Params_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->asset_name)::BaseType> asset_name_fragment(
          params.message());
  
  mojo::internal::Serialize<mojo::StringDataView>(
    in_asset_name,
    asset_name_fragment);

  params->asset_name.Set(
      asset_name_fragment.is_null() ? nullptr : asset_name_fragment.data());

  
  MOJO_INTERNAL_CHECK_SERIALIZATION(
    mojo::internal::SendValidation::kDefault,
    !(params->asset_name.is_null()),
    mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
    "null asset_name in ModelBrokerDebug.AddAssetDownloadObserver request");

  
  mojo::internal::Serialize<mojo::InterfacePtrDataView<::on_device_model::mojom::DownloadObserverInterfaceBase>>(
    in_observer,
    &params->observer,
    &params.message());

  
  MOJO_INTERNAL_CHECK_SERIALIZATION(
    mojo::internal::SendValidation::kDefault,
    !(!mojo::internal::IsHandleOrInterfaceValid(params->observer)),
    mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
    "invalid observer in ModelBrokerDebug.AddAssetDownloadObserver request");

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(ModelBrokerDebug::Name_);
  message.set_method_name("AddAssetDownloadObserver");
#endif
  // This return value may be ignored as false implies the Connector has
  // encountered an error, which will be visible through other means.
  ::mojo::internal::SendMojoMessage(*receiver_, message);
}
class ModelBrokerDebug_GetStateInfo_ProxyToResponder : public ::mojo::internal::ProxyToResponder {
 public:
  static ModelBrokerDebug::GetStateInfoCallback CreateCallback(
      ::mojo::Message& message,
      std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
    std::unique_ptr<ModelBrokerDebug_GetStateInfo_ProxyToResponder> proxy(
        new ModelBrokerDebug_GetStateInfo_ProxyToResponder(
            message, std::move(responder)));
    return base::BindOnce(&ModelBrokerDebug_GetStateInfo_ProxyToResponder::Run,
                          std::move(proxy));
  }

  ~ModelBrokerDebug_GetStateInfo_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:
  ModelBrokerDebug_GetStateInfo_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)
        << "ModelBrokerDebug::GetStateInfoCallback 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(
      BrokerStateInfoPtr in_state);
};

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

  // Validation for ModelBrokerDebug.0
  bool success = true;
  BrokerStateInfoPtr p_state{};
  ModelBrokerDebug_GetStateInfo_ResponseParamsDataView input_data_view(params, message);
  
  if (success && !input_data_view.ReadState(&p_state))
    success = false;
  if (!success) {
    ReportValidationErrorForMessage(
        message,
        mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
        ModelBrokerDebug::Name_, 0, true);
    return false;
  }
  if (!callback_.is_null()) {
    std::move(callback_).Run(
std::move(p_state));
  }
  return true;
}

void ModelBrokerDebug_GetStateInfo_ProxyToResponder::Run(
    BrokerStateInfoPtr in_state) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send reply optimization_guide::mojom::ModelBrokerDebug::GetStateInfo", "async_response_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("state"), in_state,
                        "<value of type BrokerStateInfoPtr>");
   });
#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::ModelBrokerDebug::kGetStateInfo), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::optimization_guide::mojom::internal::ModelBrokerDebug_GetStateInfo_ResponseParams_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->state)::BaseType> state_fragment(
          params.message());
  
  mojo::internal::Serialize<::optimization_guide::mojom::BrokerStateInfoDataView>(
    in_state,
    state_fragment);

  params->state.Set(
      state_fragment.is_null() ? nullptr : state_fragment.data());

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

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(ModelBrokerDebug::Name_);
  message.set_method_name("GetStateInfo");
#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 ModelBrokerDebugStubDispatch::Accept(
    ModelBrokerDebug* impl,
    mojo::Message* message) {
  switch (static_cast<messages::ModelBrokerDebug>(message->header()->name)) {
    case messages::ModelBrokerDebug::kGetStateInfo: {
      break;
    }
    case messages::ModelBrokerDebug::kSetUseCaseRequested: {
      DCHECK(message->is_serialized());
      internal::ModelBrokerDebug_SetUseCaseRequested_Params_Data* params =
          reinterpret_cast<internal::ModelBrokerDebug_SetUseCaseRequested_Params_Data*>(
              message->mutable_payload());
      

      // Validation for ModelBrokerDebug.1
      bool success = true;
      std::string p_use_case{};
      bool p_requested{};
      ModelBrokerDebug_SetUseCaseRequested_ParamsDataView input_data_view(params, message);
      
      if (success && !input_data_view.ReadUseCase(&p_use_case))
        success = false;
      if (success)
        p_requested = input_data_view.requested();
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            ModelBrokerDebug::Name_, 1, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->SetUseCaseRequested(        
        std::move(p_use_case), 
        std::move(p_requested));
      return true;
    }
    case messages::ModelBrokerDebug::kUninstallModels: {
      DCHECK(message->is_serialized());
      internal::ModelBrokerDebug_UninstallModels_Params_Data* params =
          reinterpret_cast<internal::ModelBrokerDebug_UninstallModels_Params_Data*>(
              message->mutable_payload());
      

      // Validation for ModelBrokerDebug.2
      bool success = true;
      ModelBrokerDebug_UninstallModels_ParamsDataView input_data_view(params, message);
      
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            ModelBrokerDebug::Name_, 2, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->UninstallModels(        );
      return true;
    }
    case messages::ModelBrokerDebug::kResetModelCrashCount: {
      DCHECK(message->is_serialized());
      internal::ModelBrokerDebug_ResetModelCrashCount_Params_Data* params =
          reinterpret_cast<internal::ModelBrokerDebug_ResetModelCrashCount_Params_Data*>(
              message->mutable_payload());
      

      // Validation for ModelBrokerDebug.3
      bool success = true;
      ModelBrokerDebug_ResetModelCrashCount_ParamsDataView input_data_view(params, message);
      
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            ModelBrokerDebug::Name_, 3, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->ResetModelCrashCount(        );
      return true;
    }
    case messages::ModelBrokerDebug::kAddObserver: {
      DCHECK(message->is_serialized());
      internal::ModelBrokerDebug_AddObserver_Params_Data* params =
          reinterpret_cast<internal::ModelBrokerDebug_AddObserver_Params_Data*>(
              message->mutable_payload());
      

      // Validation for ModelBrokerDebug.4
      bool success = true;
      ::mojo::PendingRemote<ModelBrokerDebugObserver> p_observer{};
      ModelBrokerDebug_AddObserver_ParamsDataView input_data_view(params, message);
      
      if (success) {
        p_observer =
            input_data_view.TakeObserver<decltype(p_observer)>();
      }
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            ModelBrokerDebug::Name_, 4, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->AddObserver(        
        std::move(p_observer));
      return true;
    }
    case messages::ModelBrokerDebug::kAddAssetDownloadObserver: {
      DCHECK(message->is_serialized());
      internal::ModelBrokerDebug_AddAssetDownloadObserver_Params_Data* params =
          reinterpret_cast<internal::ModelBrokerDebug_AddAssetDownloadObserver_Params_Data*>(
              message->mutable_payload());
      

      // Validation for ModelBrokerDebug.5
      bool success = true;
      std::string p_asset_name{};
      ::mojo::PendingRemote<::on_device_model::mojom::DownloadObserver> p_observer{};
      ModelBrokerDebug_AddAssetDownloadObserver_ParamsDataView input_data_view(params, message);
      
      if (success && !input_data_view.ReadAssetName(&p_asset_name))
        success = false;
      if (success) {
        p_observer =
            input_data_view.TakeObserver<decltype(p_observer)>();
      }
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            ModelBrokerDebug::Name_, 5, false);
        return false;
      }
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->AddAssetDownloadObserver(        
        std::move(p_asset_name), 
        std::move(p_observer));
      return true;
    }
  }
  return false;
}

// static
bool ModelBrokerDebugStubDispatch::AcceptWithResponder(
    ModelBrokerDebug* 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::ModelBrokerDebug>(message->header()->name)) {
    case messages::ModelBrokerDebug::kGetStateInfo: {
      internal::ModelBrokerDebug_GetStateInfo_Params_Data* params =
          reinterpret_cast<
              internal::ModelBrokerDebug_GetStateInfo_Params_Data*>(
                  message->mutable_payload());
      

      // Validation for ModelBrokerDebug.0
      bool success = true;
      ModelBrokerDebug_GetStateInfo_ParamsDataView input_data_view(params, message);
      
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            ModelBrokerDebug::Name_, 0, false);
        return false;
      }
      auto callback =
          ModelBrokerDebug_GetStateInfo_ProxyToResponder::CreateCallback(
              *message, std::move(responder));
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->GetStateInfo(std::move(callback));
      return true;
    }
    case messages::ModelBrokerDebug::kSetUseCaseRequested: {
      break;
    }
    case messages::ModelBrokerDebug::kUninstallModels: {
      break;
    }
    case messages::ModelBrokerDebug::kResetModelCrashCount: {
      break;
    }
    case messages::ModelBrokerDebug::kAddObserver: {
      break;
    }
    case messages::ModelBrokerDebug::kAddAssetDownloadObserver: {
      break;
    }
  }
  return false;
}
namespace {
}  // namespace
static const mojo::internal::GenericValidationInfo kModelBrokerDebugValidationInfo[] = {
    { &internal::ModelBrokerDebug_GetStateInfo_Params_Data::Validate,
     &internal::ModelBrokerDebug_GetStateInfo_ResponseParams_Data::Validate},
    { &internal::ModelBrokerDebug_SetUseCaseRequested_Params_Data::Validate,
     nullptr /* no response */},
    { &internal::ModelBrokerDebug_UninstallModels_Params_Data::Validate,
     nullptr /* no response */},
    { &internal::ModelBrokerDebug_ResetModelCrashCount_Params_Data::Validate,
     nullptr /* no response */},
    { &internal::ModelBrokerDebug_AddObserver_Params_Data::Validate,
     nullptr /* no response */},
    { &internal::ModelBrokerDebug_AddAssetDownloadObserver_Params_Data::Validate,
     nullptr /* no response */},
};

bool ModelBrokerDebugRequestValidator::Accept(mojo::Message* message) {
  return mojo::internal::ValidateRequestGenericPacked(
    message,
    ::optimization_guide::mojom::ModelBrokerDebug::Name_,
    kModelBrokerDebugValidationInfo);
}

bool ModelBrokerDebugResponseValidator::Accept(mojo::Message* message) {
  return mojo::internal::ValidateResponseGenericPacked(
    message,
    ::optimization_guide::mojom::ModelBrokerDebug::Name_,
    kModelBrokerDebugValidationInfo);
}


}  // optimization_guide::mojom


namespace mojo {


// static
bool StructTraits<::optimization_guide::mojom::BrokerPropertyInfo::DataView, ::optimization_guide::mojom::BrokerPropertyInfoPtr>::Read(
    ::optimization_guide::mojom::BrokerPropertyInfo::DataView input,
    ::optimization_guide::mojom::BrokerPropertyInfoPtr* output) {
  bool success = true;
  ::optimization_guide::mojom::BrokerPropertyInfoPtr result(::optimization_guide::mojom::BrokerPropertyInfo::New());
  
      if (success && !input.ReadDescription(&result->description))
        success = false;
      if (success && !input.ReadValue(&result->value))
        success = false;
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::optimization_guide::mojom::BrokerAssetInfo::DataView, ::optimization_guide::mojom::BrokerAssetInfoPtr>::Read(
    ::optimization_guide::mojom::BrokerAssetInfo::DataView input,
    ::optimization_guide::mojom::BrokerAssetInfoPtr* output) {
  bool success = true;
  ::optimization_guide::mojom::BrokerAssetInfoPtr result(::optimization_guide::mojom::BrokerAssetInfo::New());
  
      if (success && !input.ReadName(&result->name))
        success = false;
      if (success && !input.ReadVersion(&result->version))
        success = false;
      if (success && !input.ReadState(&result->state))
        success = false;
      if (success && !input.ReadError(&result->error))
        success = false;
      if (success)
        result->bytes_downloaded = input.bytes_downloaded();
      if (success)
        result->bytes_total = input.bytes_total();
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::optimization_guide::mojom::BrokerUseCaseInfo::DataView, ::optimization_guide::mojom::BrokerUseCaseInfoPtr>::Read(
    ::optimization_guide::mojom::BrokerUseCaseInfo::DataView input,
    ::optimization_guide::mojom::BrokerUseCaseInfoPtr* output) {
  bool success = true;
  ::optimization_guide::mojom::BrokerUseCaseInfoPtr result(::optimization_guide::mojom::BrokerUseCaseInfo::New());
  
      if (success && !input.ReadName(&result->name))
        success = false;
      if (success)
        result->assets_requested = input.assets_requested();
      if (success && !input.ReadUnavailableReason(&result->unavailable_reason)) {
        success = false;
      }
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::optimization_guide::mojom::BrokerModelInfo::DataView, ::optimization_guide::mojom::BrokerModelInfoPtr>::Read(
    ::optimization_guide::mojom::BrokerModelInfo::DataView input,
    ::optimization_guide::mojom::BrokerModelInfoPtr* output) {
  bool success = true;
  ::optimization_guide::mojom::BrokerModelInfoPtr result(::optimization_guide::mojom::BrokerModelInfo::New());
  
      if (success && !input.ReadName(&result->name))
        success = false;
      if (success)
        result->folder_size = input.folder_size();
      if (success && !input.ReadWeightsPath(&result->weights_path))
        success = false;
      if (success && !input.ReadBackendType(&result->backend_type))
        success = false;
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::optimization_guide::mojom::BrokerStateInfo::DataView, ::optimization_guide::mojom::BrokerStateInfoPtr>::Read(
    ::optimization_guide::mojom::BrokerStateInfo::DataView input,
    ::optimization_guide::mojom::BrokerStateInfoPtr* output) {
  bool success = true;
  ::optimization_guide::mojom::BrokerStateInfoPtr result(::optimization_guide::mojom::BrokerStateInfo::New());
  
      if (success && !input.ReadProperties(&result->properties))
        success = false;
      if (success && !input.ReadAssets(&result->assets))
        success = false;
      if (success && !input.ReadUseCases(&result->use_cases))
        success = false;
      if (success && !input.ReadModels(&result->models))
        success = false;
      if (success) {
        result->model_crash_count = input.model_crash_count();
      }
      if (success) {
        result->max_model_crash_count = input.max_model_crash_count();
      }
      if (success)
        result->is_asset_manager_initialized = input.is_asset_manager_initialized();
  *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 optimization_guide::mojom {


void ModelBrokerDebugObserverInterceptorForTesting::OnBrokerStateChanged() {
  GetForwardingInterface()->OnBrokerStateChanged();
}
ModelBrokerDebugObserverAsyncWaiter::ModelBrokerDebugObserverAsyncWaiter(
    ModelBrokerDebugObserver* proxy) : proxy_(proxy) {}

ModelBrokerDebugObserverAsyncWaiter::~ModelBrokerDebugObserverAsyncWaiter() = default;





void ModelBrokerDebugInterceptorForTesting::GetStateInfo(GetStateInfoCallback callback) {
  GetForwardingInterface()->GetStateInfo(std::move(callback));
}
void ModelBrokerDebugInterceptorForTesting::SetUseCaseRequested(const std::string& use_case, bool requested) {
  GetForwardingInterface()->SetUseCaseRequested(
    std::move(use_case)
    , 
    std::move(requested)
    );
}
void ModelBrokerDebugInterceptorForTesting::UninstallModels() {
  GetForwardingInterface()->UninstallModels();
}
void ModelBrokerDebugInterceptorForTesting::ResetModelCrashCount() {
  GetForwardingInterface()->ResetModelCrashCount();
}
void ModelBrokerDebugInterceptorForTesting::AddObserver(::mojo::PendingRemote<ModelBrokerDebugObserver> observer) {
  GetForwardingInterface()->AddObserver(
    std::move(observer)
    );
}
void ModelBrokerDebugInterceptorForTesting::AddAssetDownloadObserver(const std::string& asset_name, ::mojo::PendingRemote<::on_device_model::mojom::DownloadObserver> observer) {
  GetForwardingInterface()->AddAssetDownloadObserver(
    std::move(asset_name)
    , 
    std::move(observer)
    );
}
ModelBrokerDebugAsyncWaiter::ModelBrokerDebugAsyncWaiter(
    ModelBrokerDebug* proxy) : proxy_(proxy) {}

ModelBrokerDebugAsyncWaiter::~ModelBrokerDebugAsyncWaiter() = default;


void ModelBrokerDebugAsyncWaiter::GetStateInfo(
    BrokerStateInfoPtr* out_state) {
  base::RunLoop loop;
  proxy_->GetStateInfo(
      base::BindOnce(
          [](base::RunLoop* loop,
             BrokerStateInfoPtr* out_state
,
             BrokerStateInfoPtr state) {*out_state = std::move(state);
            loop->Quit();
          },
          &loop,
          out_state));
  loop.Run();
}

BrokerStateInfoPtr ModelBrokerDebugAsyncWaiter::GetStateInfo(
    ) {
  BrokerStateInfoPtr async_wait_result;
  GetStateInfo(&async_wait_result);
  return async_wait_result;
}






}  // optimization_guide::mojom


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