blob: 4331c932d6dbf4a709ddc0fc483165d07d7f1205 [file] [log] [blame]
// chromeos/services/machine_learning/public/mojom/model.mojom-blink.cc is auto generated by mojom_bindings_generator.py, do not edit
// Copyright 2013 The Chromium Authors. All rights reserved.
// 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 "chromeos/services/machine_learning/public/mojom/model.mojom-blink.h"
#include <math.h>
#include <stdint.h>
#include <utility>
#include "base/debug/alias.h"
#include "base/hash/md5_constexpr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/typed_macros.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/send_message_helper.h"
#include "mojo/public/cpp/bindings/lib/proxy_to_responder.h"
#include "mojo/public/cpp/bindings/lib/serialization_util.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/interfaces/bindings/interface_control_messages.mojom.h"
#include "third_party/perfetto/include/perfetto/tracing/traced_value.h"
#include "chromeos/services/machine_learning/public/mojom/model.mojom-params-data.h"
#include "chromeos/services/machine_learning/public/mojom/model.mojom-shared-message-ids.h"
#include "chromeos/services/machine_learning/public/mojom/model.mojom-blink-import-headers.h"
#include "chromeos/services/machine_learning/public/mojom/model.mojom-blink-test-utils.h"
#include "mojo/public/cpp/bindings/lib/wtf_serialization.h"
#ifndef CHROMEOS_SERVICES_MACHINE_LEARNING_PUBLIC_MOJOM_MODEL_MOJOM_BLINK_JUMBO_H_
#define CHROMEOS_SERVICES_MACHINE_LEARNING_PUBLIC_MOJOM_MODEL_MOJOM_BLINK_JUMBO_H_
#endif
namespace chromeos {
namespace machine_learning {
namespace mojom {
namespace blink {
GraphExecutorOptions::GraphExecutorOptions()
: use_nnapi(false),
use_gpu(false),
gpu_delegate_api(GpuDelegateApi::OPENGL) {}
GraphExecutorOptions::GraphExecutorOptions(
bool use_nnapi_in)
: use_nnapi(std::move(use_nnapi_in)),
use_gpu(false),
gpu_delegate_api(GpuDelegateApi::OPENGL) {}
GraphExecutorOptions::GraphExecutorOptions(
bool use_nnapi_in,
bool use_gpu_in)
: use_nnapi(std::move(use_nnapi_in)),
use_gpu(std::move(use_gpu_in)),
gpu_delegate_api(GpuDelegateApi::OPENGL) {}
GraphExecutorOptions::GraphExecutorOptions(
bool use_nnapi_in,
bool use_gpu_in,
GpuDelegateApi gpu_delegate_api_in)
: use_nnapi(std::move(use_nnapi_in)),
use_gpu(std::move(use_gpu_in)),
gpu_delegate_api(std::move(gpu_delegate_api_in)) {}
GraphExecutorOptions::~GraphExecutorOptions() = default;
size_t GraphExecutorOptions::Hash(size_t seed) const {
seed = mojo::internal::WTFHash(seed, this->use_nnapi);
seed = mojo::internal::WTFHash(seed, this->use_gpu);
seed = mojo::internal::WTFHash(seed, this->gpu_delegate_api);
return seed;
}
void GraphExecutorOptions::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"use_nnapi"), this->use_nnapi,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type bool>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"use_gpu"), this->use_gpu,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type bool>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"gpu_delegate_api"), this->gpu_delegate_api,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type GpuDelegateApi>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool GraphExecutorOptions::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
BuiltinModelSpec::BuiltinModelSpec()
: id() {}
BuiltinModelSpec::BuiltinModelSpec(
BuiltinModelId id_in)
: id(std::move(id_in)) {}
BuiltinModelSpec::~BuiltinModelSpec() = default;
size_t BuiltinModelSpec::Hash(size_t seed) const {
seed = mojo::internal::WTFHash(seed, this->id);
return seed;
}
void BuiltinModelSpec::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"id"), this->id,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type BuiltinModelId>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool BuiltinModelSpec::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
FlatBufferModelSpec::FlatBufferModelSpec()
: model_string(),
inputs(),
outputs(),
metrics_model_name() {}
FlatBufferModelSpec::FlatBufferModelSpec(
const WTF::String& model_string_in,
const WTF::HashMap<WTF::String, int32_t>& inputs_in,
const WTF::HashMap<WTF::String, int32_t>& outputs_in,
const WTF::String& metrics_model_name_in)
: model_string(std::move(model_string_in)),
inputs(std::move(inputs_in)),
outputs(std::move(outputs_in)),
metrics_model_name(std::move(metrics_model_name_in)) {}
FlatBufferModelSpec::~FlatBufferModelSpec() = default;
void FlatBufferModelSpec::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"model_string"), this->model_string,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const WTF::String&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"inputs"), this->inputs,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const WTF::HashMap<WTF::String, int32_t>&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"outputs"), this->outputs,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const WTF::HashMap<WTF::String, int32_t>&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"metrics_model_name"), this->metrics_model_name,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const WTF::String&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool FlatBufferModelSpec::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
const char Model::Name_[] = "chromeos.machine_learning.mojom.Model";
std::pair<uint32_t, const void*> Model::MessageToMethodInfo_(mojo::Message& message) {
switch (message.name()) {
case internal::kModel_REMOVED_0_Name: {
constexpr uint32_t value = base::MD5Hash32Constexpr(
"(Impl)chromeos::machine_learning::mojom::Model::REMOVED_0");
#if BUILDFLAG(IS_FUCHSIA)
return std::make_pair(value, nullptr);
#else
return std::make_pair(value, reinterpret_cast<const void*>(&Model::REMOVED_0_Sym::IPCSymbol));
#endif // BUILDFLAG(IS_FUCHSIA)
}
case internal::kModel_CreateGraphExecutor_Name: {
constexpr uint32_t value = base::MD5Hash32Constexpr(
"(Impl)chromeos::machine_learning::mojom::Model::CreateGraphExecutor");
#if BUILDFLAG(IS_FUCHSIA)
return std::make_pair(value, nullptr);
#else
return std::make_pair(value, reinterpret_cast<const void*>(&Model::CreateGraphExecutor_Sym::IPCSymbol));
#endif // BUILDFLAG(IS_FUCHSIA)
}
}
return std::make_pair(0, nullptr);
}
const char* Model::MessageToMethodName_(mojo::Message& message) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
bool is_response = message.has_flag(mojo::Message::kFlagIsResponse);
if (!is_response) {
switch (message.name()) {
case internal::kModel_REMOVED_0_Name:
return "Receive chromeos::machine_learning::mojom::Model::REMOVED_0";
case internal::kModel_CreateGraphExecutor_Name:
return "Receive chromeos::machine_learning::mojom::Model::CreateGraphExecutor";
}
} else {
switch (message.name()) {
case internal::kModel_REMOVED_0_Name:
return "Receive reply chromeos::machine_learning::mojom::Model::REMOVED_0";
case internal::kModel_CreateGraphExecutor_Name:
return "Receive reply chromeos::machine_learning::mojom::Model::CreateGraphExecutor";
}
}
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)
void Model::REMOVED_0_Sym::IPCSymbol() {
// This method's address is used for indetifiying the mojo method name after
// symblozation. So each IPCSymbol should have a unique address.
NO_CODE_FOLDING();
}
void Model::CreateGraphExecutor_Sym::IPCSymbol() {
// This method's address is used for indetifiying the mojo method name after
// symblozation. So each IPCSymbol should have a unique address.
NO_CODE_FOLDING();
}
# endif // !BUILDFLAG(IS_FUCHSIA)
class Model_REMOVED_0_ForwardToCallback
: public mojo::MessageReceiver {
public:
Model_REMOVED_0_ForwardToCallback(
Model::REMOVED_0Callback callback
) : callback_(std::move(callback)) {
}
Model_REMOVED_0_ForwardToCallback(const Model_REMOVED_0_ForwardToCallback&) = delete;
Model_REMOVED_0_ForwardToCallback& operator=(const Model_REMOVED_0_ForwardToCallback&) = delete;
bool Accept(mojo::Message* message) override;
private:
Model::REMOVED_0Callback callback_;
};
class Model_CreateGraphExecutor_ForwardToCallback
: public mojo::MessageReceiver {
public:
Model_CreateGraphExecutor_ForwardToCallback(
Model::CreateGraphExecutorCallback callback
) : callback_(std::move(callback)) {
}
Model_CreateGraphExecutor_ForwardToCallback(const Model_CreateGraphExecutor_ForwardToCallback&) = delete;
Model_CreateGraphExecutor_ForwardToCallback& operator=(const Model_CreateGraphExecutor_ForwardToCallback&) = delete;
bool Accept(mojo::Message* message) override;
private:
Model::CreateGraphExecutorCallback callback_;
};
ModelProxy::ModelProxy(mojo::MessageReceiverWithResponder* receiver)
: receiver_(receiver) {
}
void ModelProxy::REMOVED_0(
::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor> in_receiver, REMOVED_0Callback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send chromeos::machine_learning::mojom::Model::REMOVED_0", "input_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("receiver"), in_receiver,
"<value of type ::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor>>");
});
#endif
const bool kExpectsResponse = true;
const bool kIsSync = false;
const bool kAllowInterrupt = true;
const uint32_t kFlags =
((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
((kIsSync) ? mojo::Message::kFlagIsSync : 0) |
((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt);
mojo::Message message(
internal::kModel_REMOVED_0_Name, kFlags, 0, 0, nullptr);
mojo::internal::MessageFragment<
::chromeos::machine_learning::mojom::internal::Model_REMOVED_0_Params_Data> params(
message);
params.Allocate();
mojo::internal::Serialize<mojo::InterfaceRequestDataView<::chromeos::machine_learning::mojom::GraphExecutorInterfaceBase>>(
in_receiver, &params->receiver, &params.message());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
!mojo::internal::IsHandleOrInterfaceValid(params->receiver),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
"invalid receiver in Model.REMOVED_0 request");
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(Model::Name_);
message.set_method_name("REMOVED_0");
#endif
std::unique_ptr<mojo::MessageReceiver> responder(
new Model_REMOVED_0_ForwardToCallback(
std::move(callback)));
::mojo::internal::SendMessage(*receiver_, message, std::move(responder));
}
void ModelProxy::CreateGraphExecutor(
GraphExecutorOptionsPtr in_options, ::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor> in_receiver, CreateGraphExecutorCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send chromeos::machine_learning::mojom::Model::CreateGraphExecutor", "input_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("options"), in_options,
"<value of type GraphExecutorOptionsPtr>");
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("receiver"), in_receiver,
"<value of type ::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor>>");
});
#endif
const bool kExpectsResponse = true;
const bool kIsSync = false;
const bool kAllowInterrupt = true;
const uint32_t kFlags =
((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) |
((kIsSync) ? mojo::Message::kFlagIsSync : 0) |
((kAllowInterrupt) ? 0 : mojo::Message::kFlagNoInterrupt);
mojo::Message message(
internal::kModel_CreateGraphExecutor_Name, kFlags, 0, 0, nullptr);
mojo::internal::MessageFragment<
::chromeos::machine_learning::mojom::internal::Model_CreateGraphExecutor_Params_Data> params(
message);
params.Allocate();
mojo::internal::MessageFragment<
typename decltype(params->options)::BaseType> options_fragment(
params.message());
mojo::internal::Serialize<::chromeos::machine_learning::mojom::GraphExecutorOptionsDataView>(
in_options, options_fragment);
params->options.Set(
options_fragment.is_null() ? nullptr : options_fragment.data());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
params->options.is_null(),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null options in Model.CreateGraphExecutor request");
mojo::internal::Serialize<mojo::InterfaceRequestDataView<::chromeos::machine_learning::mojom::GraphExecutorInterfaceBase>>(
in_receiver, &params->receiver, &params.message());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
!mojo::internal::IsHandleOrInterfaceValid(params->receiver),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
"invalid receiver in Model.CreateGraphExecutor request");
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(Model::Name_);
message.set_method_name("CreateGraphExecutor");
#endif
std::unique_ptr<mojo::MessageReceiver> responder(
new Model_CreateGraphExecutor_ForwardToCallback(
std::move(callback)));
::mojo::internal::SendMessage(*receiver_, message, std::move(responder));
}
class Model_REMOVED_0_ProxyToResponder : public ::mojo::internal::ProxyToResponder {
public:
static Model::REMOVED_0Callback CreateCallback(
::mojo::Message& message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
std::unique_ptr<Model_REMOVED_0_ProxyToResponder> proxy(
new Model_REMOVED_0_ProxyToResponder(
message, std::move(responder)));
return base::BindOnce(&Model_REMOVED_0_ProxyToResponder::Run,
std::move(proxy));
}
~Model_REMOVED_0_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.
responder_->IsConnectedAsync(base::BindOnce(&OnIsConnectedComplete));
}
#endif
}
private:
Model_REMOVED_0_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)
<< "Model::REMOVED_0Callback 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(
CreateGraphExecutorResult in_result);
};
bool Model_REMOVED_0_ForwardToCallback::Accept(
mojo::Message* message) {
DCHECK(message->is_serialized());
internal::Model_REMOVED_0_ResponseParams_Data* params =
reinterpret_cast<
internal::Model_REMOVED_0_ResponseParams_Data*>(
message->mutable_payload());
bool success = true;
CreateGraphExecutorResult p_result{};
Model_REMOVED_0_ResponseParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadResult(&p_result))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
Model::Name_, 0, true);
return false;
}
if (!callback_.is_null())
std::move(callback_).Run(
std::move(p_result));
return true;
}
void Model_REMOVED_0_ProxyToResponder::Run(
CreateGraphExecutorResult in_result) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send reply chromeos::machine_learning::mojom::Model::REMOVED_0", "async_response_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("result"), in_result,
"<value of type CreateGraphExecutorResult>");
});
#endif
const uint32_t kFlags = mojo::Message::kFlagIsResponse |
((is_sync_) ? mojo::Message::kFlagIsSync : 0) |
((true) ? 0 : mojo::Message::kFlagNoInterrupt);
mojo::Message message(
internal::kModel_REMOVED_0_Name, kFlags, 0, 0, nullptr);
mojo::internal::MessageFragment<
::chromeos::machine_learning::mojom::internal::Model_REMOVED_0_ResponseParams_Data> params(
message);
params.Allocate();
mojo::internal::Serialize<::chromeos::machine_learning::mojom::CreateGraphExecutorResult>(
in_result, &params->result);
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(Model::Name_);
message.set_method_name("REMOVED_0");
#endif
message.set_request_id(request_id_);
message.set_trace_nonce(trace_nonce_);
::mojo::internal::SendMessage(*responder_, message);
// SendMessage fails silently if the responder connection is closed,
// or if the message is malformed.
//
// TODO(darin): If Accept() returns false due to a malformed message, that
// may be good reason to close the connection. However, we don't have a
// way to do that from here. We should add a way.
responder_ = nullptr;
}
class Model_CreateGraphExecutor_ProxyToResponder : public ::mojo::internal::ProxyToResponder {
public:
static Model::CreateGraphExecutorCallback CreateCallback(
::mojo::Message& message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
std::unique_ptr<Model_CreateGraphExecutor_ProxyToResponder> proxy(
new Model_CreateGraphExecutor_ProxyToResponder(
message, std::move(responder)));
return base::BindOnce(&Model_CreateGraphExecutor_ProxyToResponder::Run,
std::move(proxy));
}
~Model_CreateGraphExecutor_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.
responder_->IsConnectedAsync(base::BindOnce(&OnIsConnectedComplete));
}
#endif
}
private:
Model_CreateGraphExecutor_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)
<< "Model::CreateGraphExecutorCallback 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(
CreateGraphExecutorResult in_result);
};
bool Model_CreateGraphExecutor_ForwardToCallback::Accept(
mojo::Message* message) {
DCHECK(message->is_serialized());
internal::Model_CreateGraphExecutor_ResponseParams_Data* params =
reinterpret_cast<
internal::Model_CreateGraphExecutor_ResponseParams_Data*>(
message->mutable_payload());
bool success = true;
CreateGraphExecutorResult p_result{};
Model_CreateGraphExecutor_ResponseParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadResult(&p_result))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
Model::Name_, 1, true);
return false;
}
if (!callback_.is_null())
std::move(callback_).Run(
std::move(p_result));
return true;
}
void Model_CreateGraphExecutor_ProxyToResponder::Run(
CreateGraphExecutorResult in_result) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send reply chromeos::machine_learning::mojom::Model::CreateGraphExecutor", "async_response_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("result"), in_result,
"<value of type CreateGraphExecutorResult>");
});
#endif
const uint32_t kFlags = mojo::Message::kFlagIsResponse |
((is_sync_) ? mojo::Message::kFlagIsSync : 0) |
((true) ? 0 : mojo::Message::kFlagNoInterrupt);
mojo::Message message(
internal::kModel_CreateGraphExecutor_Name, kFlags, 0, 0, nullptr);
mojo::internal::MessageFragment<
::chromeos::machine_learning::mojom::internal::Model_CreateGraphExecutor_ResponseParams_Data> params(
message);
params.Allocate();
mojo::internal::Serialize<::chromeos::machine_learning::mojom::CreateGraphExecutorResult>(
in_result, &params->result);
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(Model::Name_);
message.set_method_name("CreateGraphExecutor");
#endif
message.set_request_id(request_id_);
message.set_trace_nonce(trace_nonce_);
::mojo::internal::SendMessage(*responder_, message);
// SendMessage 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 ModelStubDispatch::Accept(
Model* impl,
mojo::Message* message) {
switch (message->header()->name) {
case internal::kModel_REMOVED_0_Name: {
break;
}
case internal::kModel_CreateGraphExecutor_Name: {
break;
}
}
return false;
}
// static
bool ModelStubDispatch::AcceptWithResponder(
Model* 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 (message->header()->name) {
case internal::kModel_REMOVED_0_Name: {
internal::Model_REMOVED_0_Params_Data* params =
reinterpret_cast<
internal::Model_REMOVED_0_Params_Data*>(
message->mutable_payload());
bool success = true;
::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor> p_receiver{};
Model_REMOVED_0_ParamsDataView input_data_view(params, message);
if (success) {
p_receiver =
input_data_view.TakeReceiver<decltype(p_receiver)>();
}
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
Model::Name_, 0, false);
return false;
}
Model::REMOVED_0Callback callback =
Model_REMOVED_0_ProxyToResponder::CreateCallback(
*message, std::move(responder));
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->REMOVED_0(
std::move(p_receiver), std::move(callback));
return true;
}
case internal::kModel_CreateGraphExecutor_Name: {
internal::Model_CreateGraphExecutor_Params_Data* params =
reinterpret_cast<
internal::Model_CreateGraphExecutor_Params_Data*>(
message->mutable_payload());
bool success = true;
GraphExecutorOptionsPtr p_options{};
::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor> p_receiver{};
Model_CreateGraphExecutor_ParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadOptions(&p_options))
success = false;
if (success) {
p_receiver =
input_data_view.TakeReceiver<decltype(p_receiver)>();
}
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
Model::Name_, 1, false);
return false;
}
Model::CreateGraphExecutorCallback callback =
Model_CreateGraphExecutor_ProxyToResponder::CreateCallback(
*message, std::move(responder));
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->CreateGraphExecutor(
std::move(p_options),
std::move(p_receiver), std::move(callback));
return true;
}
}
return false;
}
static const mojo::internal::GenericValidationInfo kModelValidationInfo[] = {
{&internal::Model_REMOVED_0_Params_Data::Validate,
&internal::Model_REMOVED_0_ResponseParams_Data::Validate},
{&internal::Model_CreateGraphExecutor_Params_Data::Validate,
&internal::Model_CreateGraphExecutor_ResponseParams_Data::Validate},
};
bool ModelRequestValidator::Accept(mojo::Message* message) {
const char* name = ::chromeos::machine_learning::mojom::blink::Model::Name_;
return mojo::internal::ValidateRequestGenericPacked(message, name, kModelValidationInfo);
}
bool ModelResponseValidator::Accept(mojo::Message* message) {
const char* name = ::chromeos::machine_learning::mojom::blink::Model::Name_;
return mojo::internal::ValidateResponseGenericPacked(message, name, kModelValidationInfo);
}
} // namespace blink
} // namespace mojom
} // namespace machine_learning
} // namespace chromeos
namespace mojo {
// static
bool StructTraits<::chromeos::machine_learning::mojom::blink::GraphExecutorOptions::DataView, ::chromeos::machine_learning::mojom::blink::GraphExecutorOptionsPtr>::Read(
::chromeos::machine_learning::mojom::blink::GraphExecutorOptions::DataView input,
::chromeos::machine_learning::mojom::blink::GraphExecutorOptionsPtr* output) {
bool success = true;
::chromeos::machine_learning::mojom::blink::GraphExecutorOptionsPtr result(::chromeos::machine_learning::mojom::blink::GraphExecutorOptions::New());
if (success)
result->use_nnapi = input.use_nnapi();
if (success)
result->use_gpu = input.use_gpu();
if (success && !input.ReadGpuDelegateApi(&result->gpu_delegate_api))
success = false;
*output = std::move(result);
return success;
}
// static
bool StructTraits<::chromeos::machine_learning::mojom::blink::BuiltinModelSpec::DataView, ::chromeos::machine_learning::mojom::blink::BuiltinModelSpecPtr>::Read(
::chromeos::machine_learning::mojom::blink::BuiltinModelSpec::DataView input,
::chromeos::machine_learning::mojom::blink::BuiltinModelSpecPtr* output) {
bool success = true;
::chromeos::machine_learning::mojom::blink::BuiltinModelSpecPtr result(::chromeos::machine_learning::mojom::blink::BuiltinModelSpec::New());
if (success && !input.ReadId(&result->id))
success = false;
*output = std::move(result);
return success;
}
// static
bool StructTraits<::chromeos::machine_learning::mojom::blink::FlatBufferModelSpec::DataView, ::chromeos::machine_learning::mojom::blink::FlatBufferModelSpecPtr>::Read(
::chromeos::machine_learning::mojom::blink::FlatBufferModelSpec::DataView input,
::chromeos::machine_learning::mojom::blink::FlatBufferModelSpecPtr* output) {
bool success = true;
::chromeos::machine_learning::mojom::blink::FlatBufferModelSpecPtr result(::chromeos::machine_learning::mojom::blink::FlatBufferModelSpec::New());
if (success && !input.ReadModelString(&result->model_string))
success = false;
if (success && !input.ReadInputs(&result->inputs))
success = false;
if (success && !input.ReadOutputs(&result->outputs))
success = false;
if (success && !input.ReadMetricsModelName(&result->metrics_model_name))
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 chromeos {
namespace machine_learning {
namespace mojom {
namespace blink {
void ModelInterceptorForTesting::REMOVED_0(::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor> receiver, REMOVED_0Callback callback) {
GetForwardingInterface()->REMOVED_0(std::move(receiver), std::move(callback));
}
void ModelInterceptorForTesting::CreateGraphExecutor(GraphExecutorOptionsPtr options, ::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor> receiver, CreateGraphExecutorCallback callback) {
GetForwardingInterface()->CreateGraphExecutor(std::move(options), std::move(receiver), std::move(callback));
}
ModelAsyncWaiter::ModelAsyncWaiter(
Model* proxy) : proxy_(proxy) {}
ModelAsyncWaiter::~ModelAsyncWaiter() = default;
void ModelAsyncWaiter::REMOVED_0(
::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor> receiver, CreateGraphExecutorResult* out_result) {
base::RunLoop loop;
proxy_->REMOVED_0(std::move(receiver),
base::BindOnce(
[](base::RunLoop* loop,
CreateGraphExecutorResult* out_result
,
CreateGraphExecutorResult result) {*out_result = std::move(result);
loop->Quit();
},
&loop,
out_result));
loop.Run();
}
void ModelAsyncWaiter::CreateGraphExecutor(
GraphExecutorOptionsPtr options, ::mojo::PendingReceiver<::chromeos::machine_learning::mojom::blink::GraphExecutor> receiver, CreateGraphExecutorResult* out_result) {
base::RunLoop loop;
proxy_->CreateGraphExecutor(std::move(options),std::move(receiver),
base::BindOnce(
[](base::RunLoop* loop,
CreateGraphExecutorResult* out_result
,
CreateGraphExecutorResult result) {*out_result = std::move(result);
loop->Quit();
},
&loop,
out_result));
loop.Run();
}
} // namespace blink
} // namespace mojom
} // namespace machine_learning
} // namespace chromeos
#if defined(__clang__)
#pragma clang diagnostic pop
#endif