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

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

#include "third_party/blink/public/mojom/subapps/sub_apps_service.mojom-shared.h"
#include <ostream>
#include <utility>
#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/bindings/lib/validate_params.h"
#include "mojo/public/cpp/bindings/lib/validation_errors.h"
#include "mojo/public/cpp/bindings/lib/validation_util.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"

#include "third_party/blink/public/mojom/subapps/sub_apps_service.mojom-params-data.h"
namespace blink {
namespace mojom {

NOINLINE static const char* SubAppsServiceResultCodeToStringHelper(SubAppsServiceResultCode value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case SubAppsServiceResultCode::kWrongContext:
      return "kWrongContext";
    case SubAppsServiceResultCode::kUserDeclined:
      return "kUserDeclined";
    case SubAppsServiceResultCode::kTotalLimitExceeded:
      return "kTotalLimitExceeded";
    case SubAppsServiceResultCode::kPerPromptLimitExceeded:
      return "kPerPromptLimitExceeded";
    case SubAppsServiceResultCode::kWebAppsNotUserInstallable:
      return "kWebAppsNotUserInstallable";
    case SubAppsServiceResultCode::kGenericError:
      return "kGenericError";
    default:
      return nullptr;
  }
}

std::string SubAppsServiceResultCodeToString(SubAppsServiceResultCode value) {
  const char *str = SubAppsServiceResultCodeToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown SubAppsServiceResultCode value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, SubAppsServiceResultCode value) {
  return os << SubAppsServiceResultCodeToString(value);
}

NOINLINE static const char* SubAppsServiceAddResultTypeToStringHelper(SubAppsServiceAddResultType value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case SubAppsServiceAddResultType::kSuccess:
      return "kSuccess";
    case SubAppsServiceAddResultType::kScopeOverlap:
      return "kScopeOverlap";
    case SubAppsServiceAddResultType::kRecursiveInstall:
      return "kRecursiveInstall";
    case SubAppsServiceAddResultType::kInvalidManifest:
      return "kInvalidManifest";
    case SubAppsServiceAddResultType::kAlreadyInstalled:
      return "kAlreadyInstalled";
    case SubAppsServiceAddResultType::kGenericError:
      return "kGenericError";
    default:
      return nullptr;
  }
}

std::string SubAppsServiceAddResultTypeToString(SubAppsServiceAddResultType value) {
  const char *str = SubAppsServiceAddResultTypeToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown SubAppsServiceAddResultType value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, SubAppsServiceAddResultType value) {
  return os << SubAppsServiceAddResultTypeToString(value);
}

NOINLINE static const char* SubAppsServiceRemoveResultTypeToStringHelper(SubAppsServiceRemoveResultType value) {
  // Defined in a helper function to ensure that Clang generates a lookup table.
  switch(value) {
    case SubAppsServiceRemoveResultType::kSuccess:
      return "kSuccess";
    case SubAppsServiceRemoveResultType::kNotFound:
      return "kNotFound";
    case SubAppsServiceRemoveResultType::kGenericError:
      return "kGenericError";
    default:
      return nullptr;
  }
}

std::string SubAppsServiceRemoveResultTypeToString(SubAppsServiceRemoveResultType value) {
  const char *str = SubAppsServiceRemoveResultTypeToStringHelper(value);
  if (!str) {
    return base::StringPrintf("Unknown SubAppsServiceRemoveResultType value: %i", static_cast<int32_t>(value));
  }
  return str;
}

std::ostream& operator<<(std::ostream& os, SubAppsServiceRemoveResultType value) {
  return os << SubAppsServiceRemoveResultTypeToString(value);
}

namespace internal {
// static
bool SubAppsService_Add_ResponseParam_Result_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context,
    bool inlined) {
  if (!data) {
    DCHECK(!inlined);
    return true;
  }

  // If it is inlined, the alignment is already enforced by its enclosing
  // object. We don't have to validate that.
  DCHECK(!inlined || mojo::internal::IsAligned(data));

  if (!inlined &&
      !mojo::internal::ValidateNonInlinedUnionHeaderAndClaimMemory(
          data, validation_context)) {
    return false;
  }

  const SubAppsService_Add_ResponseParam_Result_Data* object = static_cast<const SubAppsService_Add_ResponseParam_Result_Data*>(data);

  if (inlined && object->is_null())
    return true;

  switch (object->tag) {

    case SubAppsService_Add_ResponseParam_Result_Tag::kSuccess: {

      if (!mojo::internal::ValidatePointerNonNullable(
              object->data.f_success, 1, validation_context)) {
        return false;
      }
      constexpr const mojo::internal::ContainerValidateParams& success_validate_params =
          mojo::internal::GetArrayValidator<0, false, nullptr>();
      if (!mojo::internal::ValidateContainer(object->data.f_success, validation_context,
                                             &success_validate_params)) {
        return false;
      }
      return true;
    }
    case SubAppsService_Add_ResponseParam_Result_Tag::kFailure: {


      if (!::blink::mojom::internal::SubAppsServiceResultCode_Data
            ::Validate(object->data.f_failure, validation_context))
        return false;
      return true;
    }
    default: {

      ReportValidationError(
          validation_context,
          mojo::internal::VALIDATION_ERROR_UNKNOWN_UNION_TAG,
          "unknown tag in SubAppsService_Add_ResponseParam_Result");
      return false;
    }
  }
}
// static
bool SubAppsService_List_ResponseParam_Result_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context,
    bool inlined) {
  if (!data) {
    DCHECK(!inlined);
    return true;
  }

  // If it is inlined, the alignment is already enforced by its enclosing
  // object. We don't have to validate that.
  DCHECK(!inlined || mojo::internal::IsAligned(data));

  if (!inlined &&
      !mojo::internal::ValidateNonInlinedUnionHeaderAndClaimMemory(
          data, validation_context)) {
    return false;
  }

  const SubAppsService_List_ResponseParam_Result_Data* object = static_cast<const SubAppsService_List_ResponseParam_Result_Data*>(data);

  if (inlined && object->is_null())
    return true;

  switch (object->tag) {

    case SubAppsService_List_ResponseParam_Result_Tag::kSuccess: {

      if (!mojo::internal::ValidatePointerNonNullable(
              object->data.f_success, 1, validation_context)) {
        return false;
      }
      constexpr const mojo::internal::ContainerValidateParams& success_validate_params =
          mojo::internal::GetArrayValidator<0, false, nullptr>();
      if (!mojo::internal::ValidateContainer(object->data.f_success, validation_context,
                                             &success_validate_params)) {
        return false;
      }
      return true;
    }
    case SubAppsService_List_ResponseParam_Result_Tag::kFailure: {


      if (!::blink::mojom::internal::SubAppsServiceResultCode_Data
            ::Validate(object->data.f_failure, validation_context))
        return false;
      return true;
    }
    default: {

      ReportValidationError(
          validation_context,
          mojo::internal::VALIDATION_ERROR_UNKNOWN_UNION_TAG,
          "unknown tag in SubAppsService_List_ResponseParam_Result");
      return false;
    }
  }
}
// static
bool SubAppsService_Remove_ResponseParam_Result_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context,
    bool inlined) {
  if (!data) {
    DCHECK(!inlined);
    return true;
  }

  // If it is inlined, the alignment is already enforced by its enclosing
  // object. We don't have to validate that.
  DCHECK(!inlined || mojo::internal::IsAligned(data));

  if (!inlined &&
      !mojo::internal::ValidateNonInlinedUnionHeaderAndClaimMemory(
          data, validation_context)) {
    return false;
  }

  const SubAppsService_Remove_ResponseParam_Result_Data* object = static_cast<const SubAppsService_Remove_ResponseParam_Result_Data*>(data);

  if (inlined && object->is_null())
    return true;

  switch (object->tag) {

    case SubAppsService_Remove_ResponseParam_Result_Tag::kSuccess: {

      if (!mojo::internal::ValidatePointerNonNullable(
              object->data.f_success, 1, validation_context)) {
        return false;
      }
      constexpr const mojo::internal::ContainerValidateParams& success_validate_params =
          mojo::internal::GetArrayValidator<0, false, nullptr>();
      if (!mojo::internal::ValidateContainer(object->data.f_success, validation_context,
                                             &success_validate_params)) {
        return false;
      }
      return true;
    }
    case SubAppsService_Remove_ResponseParam_Result_Tag::kFailure: {


      if (!::blink::mojom::internal::SubAppsServiceResultCode_Data
            ::Validate(object->data.f_failure, validation_context))
        return false;
      return true;
    }
    default: {

      ReportValidationError(
          validation_context,
          mojo::internal::VALIDATION_ERROR_UNKNOWN_UNION_TAG,
          "unknown tag in SubAppsService_Remove_ResponseParam_Result");
      return false;
    }
  }
}


// static
bool SubAppsServiceAddResult_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 32, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsServiceAddResult_Data* object =
      static_cast<const SubAppsServiceAddResult_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->install_path, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& install_path_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->install_path, validation_context,
                                         &install_path_validate_params)) {
    return false;
  }

  constexpr const mojo::internal::ContainerValidateParams& manifest_id_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->manifest_id, validation_context,
                                         &manifest_id_validate_params)) {
    return false;
  }


  if (!::blink::mojom::internal::SubAppsServiceAddResultType_Data
        ::Validate(object->result_type, validation_context))
    return false;

  return true;
}

SubAppsServiceAddResult_Data::SubAppsServiceAddResult_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SubAppsServiceListResultEntry_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsServiceListResultEntry_Data* object =
      static_cast<const SubAppsServiceListResultEntry_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->manifest_id, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& manifest_id_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->manifest_id, validation_context,
                                         &manifest_id_validate_params)) {
    return false;
  }

  if (!mojo::internal::ValidatePointerNonNullable(
          object->app_name, 2, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& app_name_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->app_name, validation_context,
                                         &app_name_validate_params)) {
    return false;
  }

  return true;
}

SubAppsServiceListResultEntry_Data::SubAppsServiceListResultEntry_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SubAppsServiceRemoveResult_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsServiceRemoveResult_Data* object =
      static_cast<const SubAppsServiceRemoveResult_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->manifest_id, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& manifest_id_validate_params =
      mojo::internal::GetArrayValidator<0, false, nullptr>();
  if (!mojo::internal::ValidateContainer(object->manifest_id, validation_context,
                                         &manifest_id_validate_params)) {
    return false;
  }


  if (!::blink::mojom::internal::SubAppsServiceRemoveResultType_Data
        ::Validate(object->result_type, validation_context))
    return false;

  return true;
}

SubAppsServiceRemoveResult_Data::SubAppsServiceRemoveResult_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SubAppsService_Add_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 16, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsService_Add_Params_Data* object =
      static_cast<const SubAppsService_Add_Params_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->install_paths, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& install_paths_validate_params =
      mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>();
  if (!mojo::internal::ValidateContainer(object->install_paths, validation_context,
                                         &install_paths_validate_params)) {
    return false;
  }

  return true;
}

SubAppsService_Add_Params_Data::SubAppsService_Add_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SubAppsService_Add_ResponseParams_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsService_Add_ResponseParams_Data* object =
      static_cast<const SubAppsService_Add_ResponseParams_Data*>(data);

  if (!mojo::internal::ValidateInlinedUnionNonNullable(
          object->result, 1, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateInlinedUnion(object->result, validation_context))
    return false;

  return true;
}

SubAppsService_Add_ResponseParams_Data::SubAppsService_Add_ResponseParams_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SubAppsService_List_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 8, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsService_List_Params_Data* object =
      static_cast<const SubAppsService_List_Params_Data*>(data);

  return true;
}

SubAppsService_List_Params_Data::SubAppsService_List_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SubAppsService_List_ResponseParams_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsService_List_ResponseParams_Data* object =
      static_cast<const SubAppsService_List_ResponseParams_Data*>(data);

  if (!mojo::internal::ValidateInlinedUnionNonNullable(
          object->result, 1, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateInlinedUnion(object->result, validation_context))
    return false;

  return true;
}

SubAppsService_List_ResponseParams_Data::SubAppsService_List_ResponseParams_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SubAppsService_Remove_Params_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 16, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsService_Remove_Params_Data* object =
      static_cast<const SubAppsService_Remove_Params_Data*>(data);

  if (!mojo::internal::ValidatePointerNonNullable(
          object->manifest_ids, 1, validation_context)) {
    return false;
  }
  constexpr const mojo::internal::ContainerValidateParams& manifest_ids_validate_params =
      mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>();
  if (!mojo::internal::ValidateContainer(object->manifest_ids, validation_context,
                                         &manifest_ids_validate_params)) {
    return false;
  }

  return true;
}

SubAppsService_Remove_Params_Data::SubAppsService_Remove_Params_Data()
    : header_({sizeof(*this), 0}) {}


// static
bool SubAppsService_Remove_ResponseParams_Data::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  if (!data)
    return true;
  if (!ValidateUnversionedStructHeaderAndSizeAndClaimMemory(
          data, 24, validation_context)) {
    return false;
  }

  // NOTE: The memory backing |object| may be smaller than |sizeof(*object)| if
  // the message comes from an older version.
  [[maybe_unused]] const SubAppsService_Remove_ResponseParams_Data* object =
      static_cast<const SubAppsService_Remove_ResponseParams_Data*>(data);

  if (!mojo::internal::ValidateInlinedUnionNonNullable(
          object->result, 1, validation_context)) {
    return false;
  }
  if (!mojo::internal::ValidateInlinedUnion(object->result, validation_context))
    return false;

  return true;
}

SubAppsService_Remove_ResponseParams_Data::SubAppsService_Remove_ResponseParams_Data()
    : header_({sizeof(*this), 0}) {}

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

namespace perfetto {

// static
void TraceFormatTraits<::blink::mojom::SubAppsServiceResultCode>::WriteIntoTrace(
   perfetto::TracedValue context, ::blink::mojom::SubAppsServiceResultCode value) {
  return std::move(context).WriteString(::blink::mojom::SubAppsServiceResultCodeToString(value));
}

} // namespace perfetto

namespace perfetto {

// static
void TraceFormatTraits<::blink::mojom::SubAppsServiceAddResultType>::WriteIntoTrace(
   perfetto::TracedValue context, ::blink::mojom::SubAppsServiceAddResultType value) {
  return std::move(context).WriteString(::blink::mojom::SubAppsServiceAddResultTypeToString(value));
}

} // namespace perfetto

namespace perfetto {

// static
void TraceFormatTraits<::blink::mojom::SubAppsServiceRemoveResultType>::WriteIntoTrace(
   perfetto::TracedValue context, ::blink::mojom::SubAppsServiceRemoveResultType value) {
  return std::move(context).WriteString(::blink::mojom::SubAppsServiceRemoveResultTypeToString(value));
}

} // namespace perfetto