// media/mojo/mojom/mediadrm_support.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 "media/mojo/mojom/mediadrm_support.mojom-blink.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 "media/mojo/mojom/mediadrm_support.mojom-params-data.h"
#include "media/mojo/mojom/mediadrm_support.mojom-shared-message-ids.h"

#include "media/mojo/mojom/mediadrm_support.mojom-blink-import-headers.h"
#include "media/mojo/mojom/mediadrm_support.mojom-blink-test-utils.h"
#include "mojo/public/cpp/bindings/lib/wtf_serialization.h"


namespace media::mojom::blink {
MediaDrmSupportResult::MediaDrmSupportResult()
    : key_system_supports_video_mp4(),
      key_system_supports_video_webm(),
      key_system_version() {}

MediaDrmSupportResult::MediaDrmSupportResult(
    bool key_system_supports_video_mp4_in,
    bool key_system_supports_video_webm_in,
    const std::optional<::base::Version>& key_system_version_in)
    : key_system_supports_video_mp4(std::move(key_system_supports_video_mp4_in)),
      key_system_supports_video_webm(std::move(key_system_supports_video_webm_in)),
      key_system_version(std::move(key_system_version_in)) {}

MediaDrmSupportResult::~MediaDrmSupportResult() = default;

void MediaDrmSupportResult::WriteIntoTrace(
    perfetto::TracedValue traced_context) const {
  [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "key_system_supports_video_mp4"), this->key_system_supports_video_mp4,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type bool>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "key_system_supports_video_webm"), this->key_system_supports_video_webm,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type bool>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
  perfetto::WriteIntoTracedValueWithFallback(
    dict.AddItem(
      "key_system_version"), this->key_system_version,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
      "<value of type const std::optional<::base::Version>&>"
#else
      "<value>"
#endif  // BUILDFLAG(MOJO_TRACE_ENABLED)
    );
}

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

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


const char* MediaDrmSupport::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::MediaDrmSupport>(message.name())) {
      case messages::MediaDrmSupport::kIsKeySystemSupported:
            return "Receive media::mojom::MediaDrmSupport::IsKeySystemSupported";
    }
  } else {
    switch (static_cast<messages::MediaDrmSupport>(message.name())) {
      case messages::MediaDrmSupport::kIsKeySystemSupported:
            return "Receive reply media::mojom::MediaDrmSupport::IsKeySystemSupported";
    }
  }
  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 MediaDrmSupport::IsKeySystemSupported_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 = 0x8588934a;  // IPCStableHash for media::mojom::MediaDrmSupport::IsKeySystemSupported
  const uint32_t hash = kHash;
  base::debug::Alias(&hash);
  return hash;
}
# endif // !BUILDFLAG(IS_FUCHSIA)

class MediaDrmSupport_IsKeySystemSupported_ForwardToCallback
    : public mojo::MessageReceiver {
 public:
  MediaDrmSupport_IsKeySystemSupported_ForwardToCallback(
      MediaDrmSupport::IsKeySystemSupportedCallback callback
      ) : callback_(std::move(callback)) {
  }

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

  bool Accept(mojo::Message* message) override;
 private:
  MediaDrmSupport::IsKeySystemSupportedCallback callback_;
};

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

void MediaDrmSupportProxy::IsKeySystemSupported(
    const ::blink::String& in_key_system, bool in_is_secure, IsKeySystemSupportedCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send media::mojom::MediaDrmSupport::IsKeySystemSupported", "input_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("key_system"), in_key_system,
                        "<value of type const ::blink::String&>");
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("is_secure"), in_is_secure,
                        "<value of type bool>");
   });
#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::MediaDrmSupport::kIsKeySystemSupported), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::media::mojom::internal::MediaDrmSupport_IsKeySystemSupported_Params_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->key_system)::BaseType> key_system_fragment(
          params.message());
  
  mojo::internal::Serialize<mojo::StringDataView>(
    in_key_system,
    key_system_fragment);

  params->key_system.Set(
      key_system_fragment.is_null() ? nullptr : key_system_fragment.data());

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

  params->is_secure = in_is_secure;

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

  ~MediaDrmSupport_IsKeySystemSupported_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:
  MediaDrmSupport_IsKeySystemSupported_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)
        << "MediaDrmSupport::IsKeySystemSupportedCallback 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(
      MediaDrmSupportResultPtr in_key_system_supports);
};

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

  // Validation for MediaDrmSupport.0
  bool success = true;
  MediaDrmSupportResultPtr p_key_system_supports{};
  MediaDrmSupport_IsKeySystemSupported_ResponseParamsDataView input_data_view(params, message);
  
  if (success && !input_data_view.ReadKeySystemSupports(&p_key_system_supports))
    success = false;
  if (!success) {
    ReportValidationErrorForMessage(
        message,
        mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
        MediaDrmSupport::Name_, 0, true);
    return false;
  }
  if (!callback_.is_null()) {
    std::move(callback_).Run(
std::move(p_key_system_supports));
  }
  return true;
}

void MediaDrmSupport_IsKeySystemSupported_ProxyToResponder::Run(
    MediaDrmSupportResultPtr in_key_system_supports) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
  TRACE_EVENT1(
    "mojom", "Send reply media::mojom::MediaDrmSupport::IsKeySystemSupported", "async_response_parameters",
    [&](perfetto::TracedValue context){
      auto dict = std::move(context).WriteDictionary();
      perfetto::WriteIntoTracedValueWithFallback(
           dict.AddItem("key_system_supports"), in_key_system_supports,
                        "<value of type MediaDrmSupportResultPtr>");
   });
#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::MediaDrmSupport::kIsKeySystemSupported), kFlags, estimated_payload_size);
  mojo::internal::MessageFragment<
      ::media::mojom::internal::MediaDrmSupport_IsKeySystemSupported_ResponseParams_Data> params(
          message);
  params.Allocate();
  mojo::internal::MessageFragment<
      typename decltype(params->key_system_supports)::BaseType> key_system_supports_fragment(
          params.message());
  
  mojo::internal::Serialize<::media::mojom::MediaDrmSupportResultDataView>(
    in_key_system_supports,
    key_system_supports_fragment);

  params->key_system_supports.Set(
      key_system_supports_fragment.is_null() ? nullptr : key_system_supports_fragment.data());

#if defined(ENABLE_IPC_FUZZER)
  message.set_interface_name(MediaDrmSupport::Name_);
  message.set_method_name("IsKeySystemSupported");
#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 MediaDrmSupportStubDispatch::Accept(
    MediaDrmSupport* impl,
    mojo::Message* message) {
  switch (static_cast<messages::MediaDrmSupport>(message->header()->name)) {
    case messages::MediaDrmSupport::kIsKeySystemSupported: {
      break;
    }
  }
  return false;
}

// static
bool MediaDrmSupportStubDispatch::AcceptWithResponder(
    MediaDrmSupport* 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::MediaDrmSupport>(message->header()->name)) {
    case messages::MediaDrmSupport::kIsKeySystemSupported: {
      internal::MediaDrmSupport_IsKeySystemSupported_Params_Data* params =
          reinterpret_cast<
              internal::MediaDrmSupport_IsKeySystemSupported_Params_Data*>(
                  message->mutable_payload());
      

      // Validation for MediaDrmSupport.0
      bool success = true;
      ::blink::String p_key_system{};
      bool p_is_secure{};
      MediaDrmSupport_IsKeySystemSupported_ParamsDataView input_data_view(params, message);
      
      if (success && !input_data_view.ReadKeySystem(&p_key_system))
        success = false;
      if (success)
        p_is_secure = input_data_view.is_secure();
      if (!success) {
        ReportValidationErrorForMessage(
            message,
            mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
            MediaDrmSupport::Name_, 0, false);
        return false;
      }
      auto callback =
          MediaDrmSupport_IsKeySystemSupported_ProxyToResponder::CreateCallback(
              *message, std::move(responder));
      // A null |impl| means no implementation was bound.
      DCHECK(impl);
      impl->IsKeySystemSupported(        
        std::move(p_key_system), 
        std::move(p_is_secure), std::move(callback));
      return true;
    }
  }
  return false;
}
namespace {
}  // namespace
static const mojo::internal::GenericValidationInfo kMediaDrmSupportValidationInfo[] = {
    { &internal::MediaDrmSupport_IsKeySystemSupported_Params_Data::Validate,
     &internal::MediaDrmSupport_IsKeySystemSupported_ResponseParams_Data::Validate},
};

bool MediaDrmSupportRequestValidator::Accept(mojo::Message* message) {
  return mojo::internal::ValidateRequestGenericPacked(
    message,
    ::media::mojom::blink::MediaDrmSupport::Name_,
    kMediaDrmSupportValidationInfo);
}

bool MediaDrmSupportResponseValidator::Accept(mojo::Message* message) {
  return mojo::internal::ValidateResponseGenericPacked(
    message,
    ::media::mojom::blink::MediaDrmSupport::Name_,
    kMediaDrmSupportValidationInfo);
}


}  // media::mojom::blink


namespace mojo {


// static
bool StructTraits<::media::mojom::blink::MediaDrmSupportResult::DataView, ::media::mojom::blink::MediaDrmSupportResultPtr>::Read(
    ::media::mojom::blink::MediaDrmSupportResult::DataView input,
    ::media::mojom::blink::MediaDrmSupportResultPtr* output) {
  bool success = true;
  ::media::mojom::blink::MediaDrmSupportResultPtr result(::media::mojom::blink::MediaDrmSupportResult::New());
  
      if (success)
        result->key_system_supports_video_mp4 = input.key_system_supports_video_mp4();
      if (success)
        result->key_system_supports_video_webm = input.key_system_supports_video_webm();
      if (success && !input.ReadKeySystemVersion(&result->key_system_version))
        success = false;
  *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 media::mojom::blink {


void MediaDrmSupportInterceptorForTesting::IsKeySystemSupported(const ::blink::String& key_system, bool is_secure, IsKeySystemSupportedCallback callback) {
  GetForwardingInterface()->IsKeySystemSupported(
    std::move(key_system)
    , 
    std::move(is_secure)
    , std::move(callback));
}
MediaDrmSupportAsyncWaiter::MediaDrmSupportAsyncWaiter(
    MediaDrmSupport* proxy) : proxy_(proxy) {}

MediaDrmSupportAsyncWaiter::~MediaDrmSupportAsyncWaiter() = default;


void MediaDrmSupportAsyncWaiter::IsKeySystemSupported(
    const ::blink::String& key_system, bool is_secure, MediaDrmSupportResultPtr* out_key_system_supports) {
  base::RunLoop loop;
  proxy_->IsKeySystemSupported(
      std::move(key_system),
      std::move(is_secure),
      base::BindOnce(
          [](base::RunLoop* loop,
             MediaDrmSupportResultPtr* out_key_system_supports
,
             MediaDrmSupportResultPtr key_system_supports) {*out_key_system_supports = std::move(key_system_supports);
            loop->Quit();
          },
          &loop,
          out_key_system_supports));
  loop.Run();
}

MediaDrmSupportResultPtr MediaDrmSupportAsyncWaiter::IsKeySystemSupported(
    const ::blink::String& key_system, bool is_secure) {
  MediaDrmSupportResultPtr async_wait_result;
  IsKeySystemSupported(std::move(key_system),std::move(is_secure),&async_wait_result);
  return async_wait_result;
}






}  // media::mojom::blink


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