// third_party/blink/public/mojom/frame/agent_cluster_key.mojom-blink.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/frame/agent_cluster_key.mojom-blink.h"
#include <stdint.h>
#include <utility>
#include "base/notreached.h"
#include "mojo/public/cpp/bindings/lib/default_construct_tag_internal.h"
#include "mojo/public/cpp/bindings/lib/serialization.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 "third_party/perfetto/include/perfetto/tracing/traced_value.h"

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

#include "third_party/blink/public/mojom/frame/agent_cluster_key.mojom-blink-import-headers.h"
#include "third_party/blink/public/mojom/frame/agent_cluster_key.mojom-blink-test-utils.h"
#include "mojo/public/cpp/bindings/lib/wtf_serialization.h"


namespace blink::mojom::blink {
CrossOriginIsolationKey::CrossOriginIsolationKey()
    : common_origin(),
      mode() {}

CrossOriginIsolationKey::CrossOriginIsolationKey(
    const ::scoped_refptr<const ::blink::SecurityOrigin>& common_origin_in,
    CrossOriginIsolationMode mode_in)
    : common_origin(std::move(common_origin_in)),
      mode(std::move(mode_in)) {}

CrossOriginIsolationKey::~CrossOriginIsolationKey() = default;

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

bool CrossOriginIsolationKey::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
OriginKeyedAgentClusterKey::OriginKeyedAgentClusterKey()
    : origin(),
      isolation_key() {}

OriginKeyedAgentClusterKey::OriginKeyedAgentClusterKey(
    const ::scoped_refptr<const ::blink::SecurityOrigin>& origin_in,
    CrossOriginIsolationKeyPtr isolation_key_in)
    : origin(std::move(origin_in)),
      isolation_key(std::move(isolation_key_in)) {}

OriginKeyedAgentClusterKey::~OriginKeyedAgentClusterKey() = default;

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

bool OriginKeyedAgentClusterKey::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context);
}
AgentClusterKeyPtr
AgentClusterKey::NewSiteKey(
    const ::blink::KURL& value) {
  return AgentClusterKeyPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kSiteKey)>,
      std::move(value));
}

AgentClusterKeyPtr
AgentClusterKey::NewOriginKey(
    OriginKeyedAgentClusterKeyPtr value) {
  return AgentClusterKeyPtr(
      std::in_place,
      std::in_place_index<static_cast<size_t>(Tag::kOriginKey)>,
      std::move(value));
}

AgentClusterKey::AgentClusterKey(
    std::in_place_index_t<static_cast<size_t>(Tag::kSiteKey)>,
    const ::blink::KURL& value)
    : tag_(Tag::kSiteKey),
      data_(std::in_place_index<static_cast<size_t>(Tag::kSiteKey)>,
            std::move(value)) {}

AgentClusterKey::AgentClusterKey(
    std::in_place_index_t<static_cast<size_t>(Tag::kOriginKey)>,
    OriginKeyedAgentClusterKeyPtr value)
    : tag_(Tag::kOriginKey),
      data_(std::in_place_index<static_cast<size_t>(Tag::kOriginKey)>,
            std::move(value)) {}
AgentClusterKey::~AgentClusterKey() {
  DestroyActive();
}

void AgentClusterKey::set_site_key(const ::blink::KURL& site_key) {
  if (tag_ == Tag::kSiteKey) {
    data_.site_key = std::move(site_key);
  } else {
    DestroyActive();
    tag_ = Tag::kSiteKey;
    new (&data_.site_key) ::blink::KURL(
        std::move(site_key));
  }
}

void AgentClusterKey::set_origin_key(OriginKeyedAgentClusterKeyPtr origin_key) {
  if (tag_ == Tag::kOriginKey) {
    data_.origin_key = std::move(origin_key);
  } else {
    DestroyActive();
    tag_ = Tag::kOriginKey;
    new (&data_.origin_key) OriginKeyedAgentClusterKeyPtr(
        std::move(origin_key));
  }
}


AgentClusterKey::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kSiteKey)>,
    const ::blink::KURL& value)
    : site_key(std::move(value)) {}

AgentClusterKey::Union_::Union_(
    std::in_place_index_t<static_cast<size_t>(Tag::kOriginKey)>,
    OriginKeyedAgentClusterKeyPtr value)
    : origin_key(std::move(value)) {}

void AgentClusterKey::DestroyActive() {
  switch (tag_) {

    case Tag::kSiteKey:
      std::destroy_at(&data_.site_key);
      break;
    case Tag::kOriginKey:
      std::destroy_at(&data_.origin_key);
      break;
  }
}

bool AgentClusterKey::Validate(
    const void* data,
    mojo::internal::ValidationContext* validation_context) {
  return Data_::Validate(data, validation_context, false);
}


}  // blink::mojom::blink


namespace mojo {


// static
bool StructTraits<::blink::mojom::blink::CrossOriginIsolationKey::DataView, ::blink::mojom::blink::CrossOriginIsolationKeyPtr>::Read(
    ::blink::mojom::blink::CrossOriginIsolationKey::DataView input,
    ::blink::mojom::blink::CrossOriginIsolationKeyPtr* output) {
  bool success = true;
  ::blink::mojom::blink::CrossOriginIsolationKeyPtr result(::blink::mojom::blink::CrossOriginIsolationKey::New());
  
      if (success && !input.ReadCommonOrigin(&result->common_origin))
        success = false;
      if (success && !input.ReadMode(&result->mode))
        success = false;
  *output = std::move(result);
  return success;
}


// static
bool StructTraits<::blink::mojom::blink::OriginKeyedAgentClusterKey::DataView, ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr>::Read(
    ::blink::mojom::blink::OriginKeyedAgentClusterKey::DataView input,
    ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr* output) {
  bool success = true;
  ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr result(::blink::mojom::blink::OriginKeyedAgentClusterKey::New());
  
      if (success && !input.ReadOrigin(&result->origin))
        success = false;
      if (success && !input.ReadIsolationKey(&result->isolation_key))
        success = false;
  *output = std::move(result);
  return success;
}

// static
bool UnionTraits<::blink::mojom::blink::AgentClusterKey::DataView, ::blink::mojom::blink::AgentClusterKeyPtr>::Read(
    ::blink::mojom::blink::AgentClusterKey::DataView input,
    ::blink::mojom::blink::AgentClusterKeyPtr* output) {
  using UnionType = ::blink::mojom::blink::AgentClusterKey;
  using Tag = UnionType::Tag;

  switch (input.tag()) {
    case Tag::kSiteKey: {
      ::blink::KURL result_site_key{};
      if (!input.ReadSiteKey(&result_site_key))
        return false;

      *output = UnionType::NewSiteKey(
          std::move(result_site_key));
      break;
    }
    case Tag::kOriginKey: {
      ::blink::mojom::blink::OriginKeyedAgentClusterKeyPtr result_origin_key{};
      if (!input.ReadOriginKey(&result_origin_key))
        return false;

      *output = UnionType::NewOriginKey(
          std::move(result_origin_key));
      break;
    }
    default:

      return false;
  }
  return true;
}

}  // 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::blink {




}  // blink::mojom::blink


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