blob: 6cbe72903731ef37e889be2b5b90f48dcb4026bd [file] [log] [blame]
// chromeos/services/machine_learning/public/mojom/web_platform_handwriting.mojom.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/web_platform_handwriting.mojom.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/web_platform_handwriting.mojom-params-data.h"
#include "chromeos/services/machine_learning/public/mojom/web_platform_handwriting.mojom-shared-message-ids.h"
#include "chromeos/services/machine_learning/public/mojom/web_platform_handwriting.mojom-import-headers.h"
#include "chromeos/services/machine_learning/public/mojom/web_platform_handwriting.mojom-test-utils.h"
#ifndef CHROMEOS_SERVICES_MACHINE_LEARNING_PUBLIC_MOJOM_WEB_PLATFORM_HANDWRITING_MOJOM_JUMBO_H_
#define CHROMEOS_SERVICES_MACHINE_LEARNING_PUBLIC_MOJOM_WEB_PLATFORM_HANDWRITING_MOJOM_JUMBO_H_
#endif
namespace chromeos {
namespace machine_learning {
namespace web_platform {
namespace mojom {
HandwritingPoint::HandwritingPoint()
: location(),
t() {}
HandwritingPoint::HandwritingPoint(
const ::gfx::PointF& location_in,
absl::optional<::base::TimeDelta> t_in)
: location(std::move(location_in)),
t(std::move(t_in)) {}
HandwritingPoint::~HandwritingPoint() = default;
void HandwritingPoint::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"location"), this->location,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const ::gfx::PointF&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"t"), this->t,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type absl::optional<::base::TimeDelta>>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool HandwritingPoint::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
HandwritingStroke::HandwritingStroke()
: points() {}
HandwritingStroke::HandwritingStroke(
std::vector<HandwritingPointPtr> points_in)
: points(std::move(points_in)) {}
HandwritingStroke::~HandwritingStroke() = default;
void HandwritingStroke::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"points"), this->points,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type std::vector<HandwritingPointPtr>>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool HandwritingStroke::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
HandwritingDrawingSegment::HandwritingDrawingSegment()
: stroke_index(),
begin_point_index(),
end_point_index() {}
HandwritingDrawingSegment::HandwritingDrawingSegment(
uint32_t stroke_index_in,
uint32_t begin_point_index_in,
uint32_t end_point_index_in)
: stroke_index(std::move(stroke_index_in)),
begin_point_index(std::move(begin_point_index_in)),
end_point_index(std::move(end_point_index_in)) {}
HandwritingDrawingSegment::~HandwritingDrawingSegment() = default;
size_t HandwritingDrawingSegment::Hash(size_t seed) const {
seed = mojo::internal::Hash(seed, this->stroke_index);
seed = mojo::internal::Hash(seed, this->begin_point_index);
seed = mojo::internal::Hash(seed, this->end_point_index);
return seed;
}
void HandwritingDrawingSegment::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"stroke_index"), this->stroke_index,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type uint32_t>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"begin_point_index"), this->begin_point_index,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type uint32_t>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"end_point_index"), this->end_point_index,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type uint32_t>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool HandwritingDrawingSegment::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
HandwritingSegment::HandwritingSegment()
: grapheme(),
begin_index(),
end_index(),
drawing_segments() {}
HandwritingSegment::HandwritingSegment(
const std::string& grapheme_in,
uint32_t begin_index_in,
uint32_t end_index_in,
std::vector<HandwritingDrawingSegmentPtr> drawing_segments_in)
: grapheme(std::move(grapheme_in)),
begin_index(std::move(begin_index_in)),
end_index(std::move(end_index_in)),
drawing_segments(std::move(drawing_segments_in)) {}
HandwritingSegment::~HandwritingSegment() = default;
void HandwritingSegment::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"grapheme"), this->grapheme,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const std::string&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"begin_index"), this->begin_index,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type uint32_t>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"end_index"), this->end_index,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type uint32_t>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"drawing_segments"), this->drawing_segments,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type std::vector<HandwritingDrawingSegmentPtr>>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool HandwritingSegment::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
HandwritingPrediction::HandwritingPrediction()
: text(),
segmentation_result() {}
HandwritingPrediction::HandwritingPrediction(
const std::string& text_in,
std::vector<HandwritingSegmentPtr> segmentation_result_in)
: text(std::move(text_in)),
segmentation_result(std::move(segmentation_result_in)) {}
HandwritingPrediction::~HandwritingPrediction() = default;
void HandwritingPrediction::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"text"), this->text,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const std::string&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"segmentation_result"), this->segmentation_result,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type std::vector<HandwritingSegmentPtr>>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool HandwritingPrediction::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
HandwritingHints::HandwritingHints()
: recognition_type(),
input_type(),
deprecated_text_context(),
alternatives(),
text_context() {}
HandwritingHints::HandwritingHints(
const std::string& recognition_type_in,
const std::string& input_type_in,
const std::string& deprecated_text_context_in,
uint32_t alternatives_in)
: recognition_type(std::move(recognition_type_in)),
input_type(std::move(input_type_in)),
deprecated_text_context(std::move(deprecated_text_context_in)),
alternatives(std::move(alternatives_in)),
text_context() {}
HandwritingHints::HandwritingHints(
const std::string& recognition_type_in,
const std::string& input_type_in,
const std::string& deprecated_text_context_in,
uint32_t alternatives_in,
const absl::optional<std::string>& text_context_in)
: recognition_type(std::move(recognition_type_in)),
input_type(std::move(input_type_in)),
deprecated_text_context(std::move(deprecated_text_context_in)),
alternatives(std::move(alternatives_in)),
text_context(std::move(text_context_in)) {}
HandwritingHints::~HandwritingHints() = default;
void HandwritingHints::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"recognition_type"), this->recognition_type,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const std::string&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"input_type"), this->input_type,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const std::string&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"deprecated_text_context"), this->deprecated_text_context,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const std::string&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"alternatives"), this->alternatives,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type uint32_t>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"text_context"), this->text_context,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const absl::optional<std::string>&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool HandwritingHints::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
HandwritingModelConstraint::HandwritingModelConstraint()
: languages() {}
HandwritingModelConstraint::HandwritingModelConstraint(
std::vector<std::string> languages_in)
: languages(std::move(languages_in)) {}
HandwritingModelConstraint::~HandwritingModelConstraint() = default;
void HandwritingModelConstraint::WriteIntoTrace(
perfetto::TracedValue traced_context) const {
[[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem(
"languages"), this->languages,
#if BUILDFLAG(MOJO_TRACE_ENABLED)
"<value of type const std::vector<std::string>&>"
#else
"<value>"
#endif // BUILDFLAG(MOJO_TRACE_ENABLED)
);
}
bool HandwritingModelConstraint::Validate(
const void* data,
mojo::internal::ValidationContext* validation_context) {
return Data_::Validate(data, validation_context);
}
const char HandwritingRecognizer::Name_[] = "chromeos.machine_learning.web_platform.mojom.HandwritingRecognizer";
std::pair<uint32_t, const void*> HandwritingRecognizer::MessageToMethodInfo_(mojo::Message& message) {
switch (message.name()) {
case internal::kHandwritingRecognizer_GetPrediction_Name: {
constexpr uint32_t value = base::MD5Hash32Constexpr(
"(Impl)chromeos::machine_learning::web_platform::mojom::HandwritingRecognizer::GetPrediction");
#if BUILDFLAG(IS_FUCHSIA)
return std::make_pair(value, nullptr);
#else
return std::make_pair(value, reinterpret_cast<const void*>(&HandwritingRecognizer::GetPrediction_Sym::IPCSymbol));
#endif // BUILDFLAG(IS_FUCHSIA)
}
}
return std::make_pair(0, nullptr);
}
const char* HandwritingRecognizer::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::kHandwritingRecognizer_GetPrediction_Name:
return "Receive chromeos::machine_learning::web_platform::mojom::HandwritingRecognizer::GetPrediction";
}
} else {
switch (message.name()) {
case internal::kHandwritingRecognizer_GetPrediction_Name:
return "Receive reply chromeos::machine_learning::web_platform::mojom::HandwritingRecognizer::GetPrediction";
}
}
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 HandwritingRecognizer::GetPrediction_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 HandwritingRecognizer_GetPrediction_ForwardToCallback
: public mojo::MessageReceiver {
public:
HandwritingRecognizer_GetPrediction_ForwardToCallback(
HandwritingRecognizer::GetPredictionCallback callback
) : callback_(std::move(callback)) {
}
HandwritingRecognizer_GetPrediction_ForwardToCallback(const HandwritingRecognizer_GetPrediction_ForwardToCallback&) = delete;
HandwritingRecognizer_GetPrediction_ForwardToCallback& operator=(const HandwritingRecognizer_GetPrediction_ForwardToCallback&) = delete;
bool Accept(mojo::Message* message) override;
private:
HandwritingRecognizer::GetPredictionCallback callback_;
};
HandwritingRecognizerProxy::HandwritingRecognizerProxy(mojo::MessageReceiverWithResponder* receiver)
: receiver_(receiver) {
}
void HandwritingRecognizerProxy::GetPrediction(
std::vector<HandwritingStrokePtr> in_strokes, HandwritingHintsPtr in_hints, GetPredictionCallback callback) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send chromeos::machine_learning::web_platform::mojom::HandwritingRecognizer::GetPrediction", "input_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("strokes"), in_strokes,
"<value of type std::vector<HandwritingStrokePtr>>");
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("hints"), in_hints,
"<value of type HandwritingHintsPtr>");
});
#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::kHandwritingRecognizer_GetPrediction_Name, kFlags, 0, 0, nullptr);
mojo::internal::MessageFragment<
::chromeos::machine_learning::web_platform::mojom::internal::HandwritingRecognizer_GetPrediction_Params_Data> params(
message);
params.Allocate();
mojo::internal::MessageFragment<
typename decltype(params->strokes)::BaseType>
strokes_fragment(params.message());
const mojo::internal::ContainerValidateParams strokes_validate_params(
0, false, nullptr);
mojo::internal::Serialize<mojo::ArrayDataView<::chromeos::machine_learning::web_platform::mojom::HandwritingStrokeDataView>>(
in_strokes, strokes_fragment, &strokes_validate_params);
params->strokes.Set(
strokes_fragment.is_null() ? nullptr : strokes_fragment.data());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
params->strokes.is_null(),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null strokes in HandwritingRecognizer.GetPrediction request");
mojo::internal::MessageFragment<
typename decltype(params->hints)::BaseType> hints_fragment(
params.message());
mojo::internal::Serialize<::chromeos::machine_learning::web_platform::mojom::HandwritingHintsDataView>(
in_hints, hints_fragment);
params->hints.Set(
hints_fragment.is_null() ? nullptr : hints_fragment.data());
MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
params->hints.is_null(),
mojo::internal::VALIDATION_ERROR_UNEXPECTED_NULL_POINTER,
"null hints in HandwritingRecognizer.GetPrediction request");
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(HandwritingRecognizer::Name_);
message.set_method_name("GetPrediction");
#endif
std::unique_ptr<mojo::MessageReceiver> responder(
new HandwritingRecognizer_GetPrediction_ForwardToCallback(
std::move(callback)));
::mojo::internal::SendMessage(*receiver_, message, std::move(responder));
}
class HandwritingRecognizer_GetPrediction_ProxyToResponder : public ::mojo::internal::ProxyToResponder {
public:
static HandwritingRecognizer::GetPredictionCallback CreateCallback(
::mojo::Message& message,
std::unique_ptr<mojo::MessageReceiverWithStatus> responder) {
std::unique_ptr<HandwritingRecognizer_GetPrediction_ProxyToResponder> proxy(
new HandwritingRecognizer_GetPrediction_ProxyToResponder(
message, std::move(responder)));
return base::BindOnce(&HandwritingRecognizer_GetPrediction_ProxyToResponder::Run,
std::move(proxy));
}
~HandwritingRecognizer_GetPrediction_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:
HandwritingRecognizer_GetPrediction_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)
<< "HandwritingRecognizer::GetPredictionCallback 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(
absl::optional<std::vector<HandwritingPredictionPtr>> in_prediction);
};
bool HandwritingRecognizer_GetPrediction_ForwardToCallback::Accept(
mojo::Message* message) {
DCHECK(message->is_serialized());
internal::HandwritingRecognizer_GetPrediction_ResponseParams_Data* params =
reinterpret_cast<
internal::HandwritingRecognizer_GetPrediction_ResponseParams_Data*>(
message->mutable_payload());
bool success = true;
absl::optional<std::vector<HandwritingPredictionPtr>> p_prediction{};
HandwritingRecognizer_GetPrediction_ResponseParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadPrediction(&p_prediction))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
HandwritingRecognizer::Name_, 0, true);
return false;
}
if (!callback_.is_null())
std::move(callback_).Run(
std::move(p_prediction));
return true;
}
void HandwritingRecognizer_GetPrediction_ProxyToResponder::Run(
absl::optional<std::vector<HandwritingPredictionPtr>> in_prediction) {
#if BUILDFLAG(MOJO_TRACE_ENABLED)
TRACE_EVENT1(
"mojom", "Send reply chromeos::machine_learning::web_platform::mojom::HandwritingRecognizer::GetPrediction", "async_response_parameters",
[&](perfetto::TracedValue context){
auto dict = std::move(context).WriteDictionary();
perfetto::WriteIntoTracedValueWithFallback(
dict.AddItem("prediction"), in_prediction,
"<value of type absl::optional<std::vector<HandwritingPredictionPtr>>>");
});
#endif
const uint32_t kFlags = mojo::Message::kFlagIsResponse |
((is_sync_) ? mojo::Message::kFlagIsSync : 0) |
((true) ? 0 : mojo::Message::kFlagNoInterrupt);
mojo::Message message(
internal::kHandwritingRecognizer_GetPrediction_Name, kFlags, 0, 0, nullptr);
mojo::internal::MessageFragment<
::chromeos::machine_learning::web_platform::mojom::internal::HandwritingRecognizer_GetPrediction_ResponseParams_Data> params(
message);
params.Allocate();
mojo::internal::MessageFragment<
typename decltype(params->prediction)::BaseType>
prediction_fragment(params.message());
const mojo::internal::ContainerValidateParams prediction_validate_params(
0, false, nullptr);
mojo::internal::Serialize<mojo::ArrayDataView<::chromeos::machine_learning::web_platform::mojom::HandwritingPredictionDataView>>(
in_prediction, prediction_fragment, &prediction_validate_params);
params->prediction.Set(
prediction_fragment.is_null() ? nullptr : prediction_fragment.data());
#if defined(ENABLE_IPC_FUZZER)
message.set_interface_name(HandwritingRecognizer::Name_);
message.set_method_name("GetPrediction");
#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 HandwritingRecognizerStubDispatch::Accept(
HandwritingRecognizer* impl,
mojo::Message* message) {
switch (message->header()->name) {
case internal::kHandwritingRecognizer_GetPrediction_Name: {
break;
}
}
return false;
}
// static
bool HandwritingRecognizerStubDispatch::AcceptWithResponder(
HandwritingRecognizer* 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::kHandwritingRecognizer_GetPrediction_Name: {
internal::HandwritingRecognizer_GetPrediction_Params_Data* params =
reinterpret_cast<
internal::HandwritingRecognizer_GetPrediction_Params_Data*>(
message->mutable_payload());
bool success = true;
std::vector<HandwritingStrokePtr> p_strokes{};
HandwritingHintsPtr p_hints{};
HandwritingRecognizer_GetPrediction_ParamsDataView input_data_view(params, message);
if (success && !input_data_view.ReadStrokes(&p_strokes))
success = false;
if (success && !input_data_view.ReadHints(&p_hints))
success = false;
if (!success) {
ReportValidationErrorForMessage(
message,
mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED,
HandwritingRecognizer::Name_, 0, false);
return false;
}
HandwritingRecognizer::GetPredictionCallback callback =
HandwritingRecognizer_GetPrediction_ProxyToResponder::CreateCallback(
*message, std::move(responder));
// A null |impl| means no implementation was bound.
DCHECK(impl);
impl->GetPrediction(
std::move(p_strokes),
std::move(p_hints), std::move(callback));
return true;
}
}
return false;
}
static const mojo::internal::GenericValidationInfo kHandwritingRecognizerValidationInfo[] = {
{&internal::HandwritingRecognizer_GetPrediction_Params_Data::Validate,
&internal::HandwritingRecognizer_GetPrediction_ResponseParams_Data::Validate},
};
bool HandwritingRecognizerRequestValidator::Accept(mojo::Message* message) {
const char* name = ::chromeos::machine_learning::web_platform::mojom::HandwritingRecognizer::Name_;
return mojo::internal::ValidateRequestGenericPacked(message, name, kHandwritingRecognizerValidationInfo);
}
bool HandwritingRecognizerResponseValidator::Accept(mojo::Message* message) {
const char* name = ::chromeos::machine_learning::web_platform::mojom::HandwritingRecognizer::Name_;
return mojo::internal::ValidateResponseGenericPacked(message, name, kHandwritingRecognizerValidationInfo);
}
} // namespace mojom
} // namespace web_platform
} // namespace machine_learning
} // namespace chromeos
namespace mojo {
// static
bool StructTraits<::chromeos::machine_learning::web_platform::mojom::HandwritingPoint::DataView, ::chromeos::machine_learning::web_platform::mojom::HandwritingPointPtr>::Read(
::chromeos::machine_learning::web_platform::mojom::HandwritingPoint::DataView input,
::chromeos::machine_learning::web_platform::mojom::HandwritingPointPtr* output) {
bool success = true;
::chromeos::machine_learning::web_platform::mojom::HandwritingPointPtr result(::chromeos::machine_learning::web_platform::mojom::HandwritingPoint::New());
if (success && !input.ReadLocation(&result->location))
success = false;
if (success && !input.ReadT(&result->t))
success = false;
*output = std::move(result);
return success;
}
// static
bool StructTraits<::chromeos::machine_learning::web_platform::mojom::HandwritingStroke::DataView, ::chromeos::machine_learning::web_platform::mojom::HandwritingStrokePtr>::Read(
::chromeos::machine_learning::web_platform::mojom::HandwritingStroke::DataView input,
::chromeos::machine_learning::web_platform::mojom::HandwritingStrokePtr* output) {
bool success = true;
::chromeos::machine_learning::web_platform::mojom::HandwritingStrokePtr result(::chromeos::machine_learning::web_platform::mojom::HandwritingStroke::New());
if (success && !input.ReadPoints(&result->points))
success = false;
*output = std::move(result);
return success;
}
// static
bool StructTraits<::chromeos::machine_learning::web_platform::mojom::HandwritingDrawingSegment::DataView, ::chromeos::machine_learning::web_platform::mojom::HandwritingDrawingSegmentPtr>::Read(
::chromeos::machine_learning::web_platform::mojom::HandwritingDrawingSegment::DataView input,
::chromeos::machine_learning::web_platform::mojom::HandwritingDrawingSegmentPtr* output) {
bool success = true;
::chromeos::machine_learning::web_platform::mojom::HandwritingDrawingSegmentPtr result(::chromeos::machine_learning::web_platform::mojom::HandwritingDrawingSegment::New());
if (success)
result->stroke_index = input.stroke_index();
if (success)
result->begin_point_index = input.begin_point_index();
if (success)
result->end_point_index = input.end_point_index();
*output = std::move(result);
return success;
}
// static
bool StructTraits<::chromeos::machine_learning::web_platform::mojom::HandwritingSegment::DataView, ::chromeos::machine_learning::web_platform::mojom::HandwritingSegmentPtr>::Read(
::chromeos::machine_learning::web_platform::mojom::HandwritingSegment::DataView input,
::chromeos::machine_learning::web_platform::mojom::HandwritingSegmentPtr* output) {
bool success = true;
::chromeos::machine_learning::web_platform::mojom::HandwritingSegmentPtr result(::chromeos::machine_learning::web_platform::mojom::HandwritingSegment::New());
if (success && !input.ReadGrapheme(&result->grapheme))
success = false;
if (success)
result->begin_index = input.begin_index();
if (success)
result->end_index = input.end_index();
if (success && !input.ReadDrawingSegments(&result->drawing_segments))
success = false;
*output = std::move(result);
return success;
}
// static
bool StructTraits<::chromeos::machine_learning::web_platform::mojom::HandwritingPrediction::DataView, ::chromeos::machine_learning::web_platform::mojom::HandwritingPredictionPtr>::Read(
::chromeos::machine_learning::web_platform::mojom::HandwritingPrediction::DataView input,
::chromeos::machine_learning::web_platform::mojom::HandwritingPredictionPtr* output) {
bool success = true;
::chromeos::machine_learning::web_platform::mojom::HandwritingPredictionPtr result(::chromeos::machine_learning::web_platform::mojom::HandwritingPrediction::New());
if (success && !input.ReadText(&result->text))
success = false;
if (success && !input.ReadSegmentationResult(&result->segmentation_result))
success = false;
*output = std::move(result);
return success;
}
// static
bool StructTraits<::chromeos::machine_learning::web_platform::mojom::HandwritingHints::DataView, ::chromeos::machine_learning::web_platform::mojom::HandwritingHintsPtr>::Read(
::chromeos::machine_learning::web_platform::mojom::HandwritingHints::DataView input,
::chromeos::machine_learning::web_platform::mojom::HandwritingHintsPtr* output) {
bool success = true;
::chromeos::machine_learning::web_platform::mojom::HandwritingHintsPtr result(::chromeos::machine_learning::web_platform::mojom::HandwritingHints::New());
if (success && !input.ReadRecognitionType(&result->recognition_type))
success = false;
if (success && !input.ReadInputType(&result->input_type))
success = false;
if (success && !input.ReadDeprecatedTextContext(&result->deprecated_text_context))
success = false;
if (success)
result->alternatives = input.alternatives();
if (success && !input.ReadTextContext(&result->text_context))
success = false;
*output = std::move(result);
return success;
}
// static
bool StructTraits<::chromeos::machine_learning::web_platform::mojom::HandwritingModelConstraint::DataView, ::chromeos::machine_learning::web_platform::mojom::HandwritingModelConstraintPtr>::Read(
::chromeos::machine_learning::web_platform::mojom::HandwritingModelConstraint::DataView input,
::chromeos::machine_learning::web_platform::mojom::HandwritingModelConstraintPtr* output) {
bool success = true;
::chromeos::machine_learning::web_platform::mojom::HandwritingModelConstraintPtr result(::chromeos::machine_learning::web_platform::mojom::HandwritingModelConstraint::New());
if (success && !input.ReadLanguages(&result->languages))
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 web_platform {
namespace mojom {
void HandwritingRecognizerInterceptorForTesting::GetPrediction(std::vector<HandwritingStrokePtr> strokes, HandwritingHintsPtr hints, GetPredictionCallback callback) {
GetForwardingInterface()->GetPrediction(std::move(strokes), std::move(hints), std::move(callback));
}
HandwritingRecognizerAsyncWaiter::HandwritingRecognizerAsyncWaiter(
HandwritingRecognizer* proxy) : proxy_(proxy) {}
HandwritingRecognizerAsyncWaiter::~HandwritingRecognizerAsyncWaiter() = default;
void HandwritingRecognizerAsyncWaiter::GetPrediction(
std::vector<HandwritingStrokePtr> strokes, HandwritingHintsPtr hints, absl::optional<std::vector<HandwritingPredictionPtr>>* out_prediction) {
base::RunLoop loop;
proxy_->GetPrediction(std::move(strokes),std::move(hints),
base::BindOnce(
[](base::RunLoop* loop,
absl::optional<std::vector<HandwritingPredictionPtr>>* out_prediction
,
absl::optional<std::vector<HandwritingPredictionPtr>> prediction) {*out_prediction = std::move(prediction);
loop->Quit();
},
&loop,
out_prediction));
loop.Run();
}
} // namespace mojom
} // namespace web_platform
} // namespace machine_learning
} // namespace chromeos
#if defined(__clang__)
#pragma clang diagnostic pop
#endif