| // mojo/public/interfaces/bindings/tests/test_wtf_types.mojom.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 "mojo/public/interfaces/bindings/tests/test_wtf_types.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/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/features.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_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/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 "mojo/public/interfaces/bindings/tests/test_wtf_types.mojom-params-data.h" |
| #include "mojo/public/interfaces/bindings/tests/test_wtf_types.mojom-shared-message-ids.h" |
| |
| #include "mojo/public/interfaces/bindings/tests/test_wtf_types.mojom-import-headers.h" |
| #include "mojo/public/interfaces/bindings/tests/test_wtf_types.mojom-test-utils.h" |
| |
| |
| namespace mojo::test { |
| TestWTFCodeGeneration::TestWTFCodeGeneration() |
| : str(), |
| nullable_str(), |
| strs(), |
| nullable_strs(), |
| arrays(), |
| bools(), |
| handles(), |
| str_map(), |
| array_map(), |
| handle_map(), |
| str_maps() {} |
| |
| TestWTFCodeGeneration::TestWTFCodeGeneration( |
| const std::string& str_in, |
| const std::optional<std::string>& nullable_str_in, |
| std::vector<std::string> strs_in, |
| std::vector<std::optional<std::string>> nullable_strs_in, |
| std::vector<std::vector<int32_t>> arrays_in, |
| std::vector<bool> bools_in, |
| std::vector<::mojo::ScopedMessagePipeHandle> handles_in, |
| const base::flat_map<std::string, std::optional<std::string>>& str_map_in, |
| const base::flat_map<int32_t, std::vector<int32_t>>& array_map_in, |
| base::flat_map<int32_t, ::mojo::ScopedMessagePipeHandle> handle_map_in, |
| std::vector<base::flat_map<std::string, std::optional<std::string>>> str_maps_in) |
| : str(std::move(str_in)), |
| nullable_str(std::move(nullable_str_in)), |
| strs(std::move(strs_in)), |
| nullable_strs(std::move(nullable_strs_in)), |
| arrays(std::move(arrays_in)), |
| bools(std::move(bools_in)), |
| handles(std::move(handles_in)), |
| str_map(std::move(str_map_in)), |
| array_map(std::move(array_map_in)), |
| handle_map(std::move(handle_map_in)), |
| str_maps(std::move(str_maps_in)) {} |
| |
| TestWTFCodeGeneration::~TestWTFCodeGeneration() = default; |
| |
| void TestWTFCodeGeneration::WriteIntoTrace( |
| perfetto::TracedValue traced_context) const { |
| [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "str"), this->str, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const std::string&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "nullable_str"), this->nullable_str, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const std::optional<std::string>&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "strs"), this->strs, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const std::vector<std::string>&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "nullable_strs"), this->nullable_strs, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const std::vector<std::optional<std::string>>&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "arrays"), this->arrays, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const std::vector<std::vector<int32_t>>&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "bools"), this->bools, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const std::vector<bool>&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "handles"), this->handles, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type std::vector<::mojo::ScopedMessagePipeHandle>>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "str_map"), this->str_map, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const base::flat_map<std::string, std::optional<std::string>>&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "array_map"), this->array_map, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const base::flat_map<int32_t, std::vector<int32_t>>&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "handle_map"), this->handle_map, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type base::flat_map<int32_t, ::mojo::ScopedMessagePipeHandle>>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "str_maps"), this->str_maps, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const std::vector<base::flat_map<std::string, std::optional<std::string>>>&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| } |
| |
| bool TestWTFCodeGeneration::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| return Data_::Validate(data, validation_context); |
| } |
| TestWTFStruct::TestWTFStruct() |
| : str(), |
| integer() {} |
| |
| TestWTFStruct::TestWTFStruct( |
| const std::string& str_in, |
| int32_t integer_in) |
| : str(std::move(str_in)), |
| integer(std::move(integer_in)) {} |
| |
| TestWTFStruct::~TestWTFStruct() = default; |
| size_t TestWTFStruct::Hash(size_t seed) const { |
| seed = mojo::internal::Hash(seed, this->str); |
| seed = mojo::internal::Hash(seed, this->integer); |
| return seed; |
| } |
| |
| void TestWTFStruct::WriteIntoTrace( |
| perfetto::TracedValue traced_context) const { |
| [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "str"), this->str, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type const std::string&>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "integer"), this->integer, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type int32_t>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| } |
| |
| bool TestWTFStruct::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| return Data_::Validate(data, validation_context); |
| } |
| TestWTFStructWrapper::TestWTFStructWrapper() |
| : nested_struct(), |
| array_struct(), |
| map_struct() {} |
| |
| TestWTFStructWrapper::TestWTFStructWrapper( |
| TestWTFStructPtr nested_struct_in, |
| std::vector<TestWTFStructPtr> array_struct_in, |
| base::flat_map<TestWTFStructPtr, TestWTFStructPtr> map_struct_in) |
| : nested_struct(std::move(nested_struct_in)), |
| array_struct(std::move(array_struct_in)), |
| map_struct(std::move(map_struct_in)) {} |
| |
| TestWTFStructWrapper::~TestWTFStructWrapper() = default; |
| |
| void TestWTFStructWrapper::WriteIntoTrace( |
| perfetto::TracedValue traced_context) const { |
| [[maybe_unused]] auto dict = std::move(traced_context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "nested_struct"), this->nested_struct, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type TestWTFStructPtr>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "array_struct"), this->array_struct, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type std::vector<TestWTFStructPtr>>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem( |
| "map_struct"), this->map_struct, |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| "<value of type base::flat_map<TestWTFStructPtr, TestWTFStructPtr>>" |
| #else |
| "<value>" |
| #endif // BUILDFLAG(MOJO_TRACE_ENABLED) |
| ); |
| } |
| |
| bool TestWTFStructWrapper::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| return Data_::Validate(data, validation_context); |
| } |
| TestWTFCodeGeneration2::TestWTFCodeGeneration2() : tag_(Tag::kStr) { |
| data_.str = new std::string; |
| } |
| |
| TestWTFCodeGeneration2::~TestWTFCodeGeneration2() { |
| DestroyActive(); |
| } |
| |
| |
| void TestWTFCodeGeneration2::set_str( |
| const std::string& str) { |
| if (tag_ == Tag::kStr) { |
| *(data_.str) = std::move(str); |
| } else { |
| DestroyActive(); |
| tag_ = Tag::kStr; |
| data_.str = new std::string( |
| std::move(str)); |
| } |
| } |
| void TestWTFCodeGeneration2::set_strs( |
| std::vector<std::string> strs) { |
| if (tag_ == Tag::kStrs) { |
| *(data_.strs) = std::move(strs); |
| } else { |
| DestroyActive(); |
| tag_ = Tag::kStrs; |
| data_.strs = new std::vector<std::string>( |
| std::move(strs)); |
| } |
| } |
| void TestWTFCodeGeneration2::set_str_map( |
| const base::flat_map<std::string, std::optional<std::string>>& str_map) { |
| if (tag_ == Tag::kStrMap) { |
| *(data_.str_map) = std::move(str_map); |
| } else { |
| DestroyActive(); |
| tag_ = Tag::kStrMap; |
| data_.str_map = new base::flat_map<std::string, std::optional<std::string>>( |
| std::move(str_map)); |
| } |
| } |
| |
| void TestWTFCodeGeneration2::DestroyActive() { |
| switch (tag_) { |
| |
| case Tag::kStr: |
| |
| delete data_.str; |
| break; |
| case Tag::kStrs: |
| |
| delete data_.strs; |
| break; |
| case Tag::kStrMap: |
| |
| delete data_.str_map; |
| break; |
| } |
| } |
| |
| bool TestWTFCodeGeneration2::Validate( |
| const void* data, |
| mojo::internal::ValidationContext* validation_context) { |
| return Data_::Validate(data, validation_context, false); |
| } |
| const char TestWTF::Name_[] = "mojo.test.TestWTF"; |
| |
| TestWTF::IPCStableHashFunction TestWTF::MessageToMethodInfo_(mojo::Message& message) { |
| #if !BUILDFLAG(IS_FUCHSIA) |
| switch (static_cast<messages::TestWTF>(message.name())) { |
| case messages::TestWTF::kEchoString: { |
| return &TestWTF::EchoString_Sym::IPCStableHash; |
| } |
| case messages::TestWTF::kEchoStringArray: { |
| return &TestWTF::EchoStringArray_Sym::IPCStableHash; |
| } |
| case messages::TestWTF::kEchoStringMap: { |
| return &TestWTF::EchoStringMap_Sym::IPCStableHash; |
| } |
| } |
| #endif // !BUILDFLAG(IS_FUCHSIA) |
| return nullptr; |
| } |
| |
| |
| const char* TestWTF::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::TestWTF>(message.name())) { |
| case messages::TestWTF::kEchoString: |
| return "Receive mojo::test::TestWTF::EchoString"; |
| case messages::TestWTF::kEchoStringArray: |
| return "Receive mojo::test::TestWTF::EchoStringArray"; |
| case messages::TestWTF::kEchoStringMap: |
| return "Receive mojo::test::TestWTF::EchoStringMap"; |
| } |
| } else { |
| switch (static_cast<messages::TestWTF>(message.name())) { |
| case messages::TestWTF::kEchoString: |
| return "Receive reply mojo::test::TestWTF::EchoString"; |
| case messages::TestWTF::kEchoStringArray: |
| return "Receive reply mojo::test::TestWTF::EchoStringArray"; |
| case messages::TestWTF::kEchoStringMap: |
| return "Receive reply mojo::test::TestWTF::EchoStringMap"; |
| } |
| } |
| 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 TestWTF::EchoString_Sym::IPCStableHash() { |
| // This method's address is used for indetifiying 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 accross different mojo modules. |
| // The code below is very similar to NO_CODE_FOLDING, but it uses a unique |
| // hash instead of __LINE__. |
| constexpr uint32_t kHash = base::MD5Hash32Constexpr( |
| "(Impl)mojo::test::TestWTF::EchoString"); |
| const uint32_t hash = kHash; |
| base::debug::Alias(&hash); |
| return hash; |
| } |
| uint32_t TestWTF::EchoStringArray_Sym::IPCStableHash() { |
| // This method's address is used for indetifiying 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 accross different mojo modules. |
| // The code below is very similar to NO_CODE_FOLDING, but it uses a unique |
| // hash instead of __LINE__. |
| constexpr uint32_t kHash = base::MD5Hash32Constexpr( |
| "(Impl)mojo::test::TestWTF::EchoStringArray"); |
| const uint32_t hash = kHash; |
| base::debug::Alias(&hash); |
| return hash; |
| } |
| uint32_t TestWTF::EchoStringMap_Sym::IPCStableHash() { |
| // This method's address is used for indetifiying 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 accross different mojo modules. |
| // The code below is very similar to NO_CODE_FOLDING, but it uses a unique |
| // hash instead of __LINE__. |
| constexpr uint32_t kHash = base::MD5Hash32Constexpr( |
| "(Impl)mojo::test::TestWTF::EchoStringMap"); |
| const uint32_t hash = kHash; |
| base::debug::Alias(&hash); |
| return hash; |
| } |
| # endif // !BUILDFLAG(IS_FUCHSIA) |
| |
| class TestWTF_EchoString_ForwardToCallback |
| : public mojo::MessageReceiver { |
| public: |
| TestWTF_EchoString_ForwardToCallback( |
| TestWTF::EchoStringCallback callback |
| ) : callback_(std::move(callback)) { |
| } |
| |
| TestWTF_EchoString_ForwardToCallback(const TestWTF_EchoString_ForwardToCallback&) = delete; |
| TestWTF_EchoString_ForwardToCallback& operator=(const TestWTF_EchoString_ForwardToCallback&) = delete; |
| |
| bool Accept(mojo::Message* message) override; |
| private: |
| TestWTF::EchoStringCallback callback_; |
| }; |
| |
| class TestWTF_EchoStringArray_ForwardToCallback |
| : public mojo::MessageReceiver { |
| public: |
| TestWTF_EchoStringArray_ForwardToCallback( |
| TestWTF::EchoStringArrayCallback callback |
| ) : callback_(std::move(callback)) { |
| } |
| |
| TestWTF_EchoStringArray_ForwardToCallback(const TestWTF_EchoStringArray_ForwardToCallback&) = delete; |
| TestWTF_EchoStringArray_ForwardToCallback& operator=(const TestWTF_EchoStringArray_ForwardToCallback&) = delete; |
| |
| bool Accept(mojo::Message* message) override; |
| private: |
| TestWTF::EchoStringArrayCallback callback_; |
| }; |
| |
| class TestWTF_EchoStringMap_ForwardToCallback |
| : public mojo::MessageReceiver { |
| public: |
| TestWTF_EchoStringMap_ForwardToCallback( |
| TestWTF::EchoStringMapCallback callback |
| ) : callback_(std::move(callback)) { |
| } |
| |
| TestWTF_EchoStringMap_ForwardToCallback(const TestWTF_EchoStringMap_ForwardToCallback&) = delete; |
| TestWTF_EchoStringMap_ForwardToCallback& operator=(const TestWTF_EchoStringMap_ForwardToCallback&) = delete; |
| |
| bool Accept(mojo::Message* message) override; |
| private: |
| TestWTF::EchoStringMapCallback callback_; |
| }; |
| |
| TestWTFProxy::TestWTFProxy(mojo::MessageReceiverWithResponder* receiver) |
| : receiver_(receiver) { |
| } |
| |
| void TestWTFProxy::EchoString( |
| const std::optional<std::string>& in_str, EchoStringCallback callback) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", "Send mojo::test::TestWTF::EchoString", "input_parameters", |
| [&](perfetto::TracedValue context){ |
| auto dict = std::move(context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem("str"), in_str, |
| "<value of type const std::optional<std::string>&>"); |
| }); |
| #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( |
| base::to_underlying(messages::TestWTF::kEchoString), kFlags, estimated_payload_size); |
| mojo::internal::MessageFragment< |
| ::mojo::test::internal::TestWTF_EchoString_Params_Data> params( |
| message); |
| params.Allocate(); |
| mojo::internal::MessageFragment< |
| typename decltype(params->str)::BaseType> str_fragment( |
| params.message()); |
| mojo::internal::Serialize<mojo::StringDataView>( |
| in_str, str_fragment); |
| params->str.Set( |
| str_fragment.is_null() ? nullptr : str_fragment.data()); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(TestWTF::Name_); |
| message.set_method_name("EchoString"); |
| #endif |
| std::unique_ptr<mojo::MessageReceiver> responder( |
| new TestWTF_EchoString_ForwardToCallback( |
| std::move(callback))); |
| ::mojo::internal::SendMojoMessage(*receiver_, message, std::move(responder)); |
| } |
| |
| void TestWTFProxy::EchoStringArray( |
| const std::optional<std::vector<std::optional<std::string>>>& in_arr, EchoStringArrayCallback callback) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", "Send mojo::test::TestWTF::EchoStringArray", "input_parameters", |
| [&](perfetto::TracedValue context){ |
| auto dict = std::move(context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem("arr"), in_arr, |
| "<value of type const std::optional<std::vector<std::optional<std::string>>>&>"); |
| }); |
| #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( |
| base::to_underlying(messages::TestWTF::kEchoStringArray), kFlags, estimated_payload_size); |
| mojo::internal::MessageFragment< |
| ::mojo::test::internal::TestWTF_EchoStringArray_Params_Data> params( |
| message); |
| params.Allocate(); |
| mojo::internal::MessageFragment< |
| typename decltype(params->arr)::BaseType> |
| arr_fragment(params.message()); |
| constexpr const mojo::internal::ContainerValidateParams& arr_validate_params = |
| mojo::internal::GetArrayValidator<0, true, &mojo::internal::GetArrayValidator<0, false, nullptr>()>(); |
| mojo::internal::Serialize<mojo::ArrayDataView<mojo::StringDataView>>( |
| in_arr, arr_fragment, &arr_validate_params); |
| params->arr.Set( |
| arr_fragment.is_null() ? nullptr : arr_fragment.data()); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(TestWTF::Name_); |
| message.set_method_name("EchoStringArray"); |
| #endif |
| std::unique_ptr<mojo::MessageReceiver> responder( |
| new TestWTF_EchoStringArray_ForwardToCallback( |
| std::move(callback))); |
| ::mojo::internal::SendMojoMessage(*receiver_, message, std::move(responder)); |
| } |
| |
| void TestWTFProxy::EchoStringMap( |
| const std::optional<base::flat_map<std::string, std::optional<std::string>>>& in_str_map, EchoStringMapCallback callback) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", "Send mojo::test::TestWTF::EchoStringMap", "input_parameters", |
| [&](perfetto::TracedValue context){ |
| auto dict = std::move(context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem("str_map"), in_str_map, |
| "<value of type const std::optional<base::flat_map<std::string, std::optional<std::string>>>&>"); |
| }); |
| #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( |
| base::to_underlying(messages::TestWTF::kEchoStringMap), kFlags, estimated_payload_size); |
| mojo::internal::MessageFragment< |
| ::mojo::test::internal::TestWTF_EchoStringMap_Params_Data> params( |
| message); |
| params.Allocate(); |
| mojo::internal::MessageFragment< |
| typename decltype(params->str_map)::BaseType> |
| str_map_fragment(params.message()); |
| constexpr const mojo::internal::ContainerValidateParams& str_map_validate_params = |
| mojo::internal::GetMapValidator<*&mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>(), *&mojo::internal::GetArrayValidator<0, true, &mojo::internal::GetArrayValidator<0, false, nullptr>()>()>(); |
| mojo::internal::Serialize<mojo::MapDataView<mojo::StringDataView, mojo::StringDataView>>( |
| in_str_map, str_map_fragment, &str_map_validate_params); |
| params->str_map.Set( |
| str_map_fragment.is_null() ? nullptr : str_map_fragment.data()); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(TestWTF::Name_); |
| message.set_method_name("EchoStringMap"); |
| #endif |
| std::unique_ptr<mojo::MessageReceiver> responder( |
| new TestWTF_EchoStringMap_ForwardToCallback( |
| std::move(callback))); |
| ::mojo::internal::SendMojoMessage(*receiver_, message, std::move(responder)); |
| } |
| class TestWTF_EchoString_ProxyToResponder : public ::mojo::internal::ProxyToResponder { |
| public: |
| static TestWTF::EchoStringCallback CreateCallback( |
| ::mojo::Message& message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| std::unique_ptr<TestWTF_EchoString_ProxyToResponder> proxy( |
| new TestWTF_EchoString_ProxyToResponder( |
| message, std::move(responder))); |
| return base::BindOnce(&TestWTF_EchoString_ProxyToResponder::Run, |
| std::move(proxy)); |
| } |
| |
| ~TestWTF_EchoString_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: |
| TestWTF_EchoString_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) |
| << "TestWTF::EchoStringCallback 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( |
| const std::optional<std::string>& in_str); |
| }; |
| |
| bool TestWTF_EchoString_ForwardToCallback::Accept( |
| mojo::Message* message) { |
| DCHECK(message->is_serialized()); |
| internal::TestWTF_EchoString_ResponseParams_Data* params = |
| reinterpret_cast< |
| internal::TestWTF_EchoString_ResponseParams_Data*>( |
| message->mutable_payload()); |
| |
| |
| // Validation for TestWTF.0 |
| bool success = true; |
| std::optional<std::string> p_str{}; |
| TestWTF_EchoString_ResponseParamsDataView input_data_view(params, message); |
| |
| if (success && !input_data_view.ReadStr(&p_str)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| TestWTF::Name_, 0, true); |
| return false; |
| } |
| if (!callback_.is_null()) |
| std::move(callback_).Run( |
| std::move(p_str)); |
| return true; |
| } |
| |
| void TestWTF_EchoString_ProxyToResponder::Run( |
| const std::optional<std::string>& in_str) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", "Send reply mojo::test::TestWTF::EchoString", "async_response_parameters", |
| [&](perfetto::TracedValue context){ |
| auto dict = std::move(context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem("str"), in_str, |
| "<value of type const std::optional<std::string>&>"); |
| }); |
| #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( |
| base::to_underlying(messages::TestWTF::kEchoString), kFlags, estimated_payload_size); |
| mojo::internal::MessageFragment< |
| ::mojo::test::internal::TestWTF_EchoString_ResponseParams_Data> params( |
| message); |
| params.Allocate(); |
| mojo::internal::MessageFragment< |
| typename decltype(params->str)::BaseType> str_fragment( |
| params.message()); |
| mojo::internal::Serialize<mojo::StringDataView>( |
| in_str, str_fragment); |
| params->str.Set( |
| str_fragment.is_null() ? nullptr : str_fragment.data()); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(TestWTF::Name_); |
| message.set_method_name("EchoString"); |
| #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; |
| } |
| class TestWTF_EchoStringArray_ProxyToResponder : public ::mojo::internal::ProxyToResponder { |
| public: |
| static TestWTF::EchoStringArrayCallback CreateCallback( |
| ::mojo::Message& message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| std::unique_ptr<TestWTF_EchoStringArray_ProxyToResponder> proxy( |
| new TestWTF_EchoStringArray_ProxyToResponder( |
| message, std::move(responder))); |
| return base::BindOnce(&TestWTF_EchoStringArray_ProxyToResponder::Run, |
| std::move(proxy)); |
| } |
| |
| ~TestWTF_EchoStringArray_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: |
| TestWTF_EchoStringArray_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) |
| << "TestWTF::EchoStringArrayCallback 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( |
| const std::optional<std::vector<std::optional<std::string>>>& in_arr); |
| }; |
| |
| bool TestWTF_EchoStringArray_ForwardToCallback::Accept( |
| mojo::Message* message) { |
| DCHECK(message->is_serialized()); |
| internal::TestWTF_EchoStringArray_ResponseParams_Data* params = |
| reinterpret_cast< |
| internal::TestWTF_EchoStringArray_ResponseParams_Data*>( |
| message->mutable_payload()); |
| |
| |
| // Validation for TestWTF.1 |
| bool success = true; |
| std::optional<std::vector<std::optional<std::string>>> p_arr{}; |
| TestWTF_EchoStringArray_ResponseParamsDataView input_data_view(params, message); |
| |
| if (success && !input_data_view.ReadArr(&p_arr)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| TestWTF::Name_, 1, true); |
| return false; |
| } |
| if (!callback_.is_null()) |
| std::move(callback_).Run( |
| std::move(p_arr)); |
| return true; |
| } |
| |
| void TestWTF_EchoStringArray_ProxyToResponder::Run( |
| const std::optional<std::vector<std::optional<std::string>>>& in_arr) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", "Send reply mojo::test::TestWTF::EchoStringArray", "async_response_parameters", |
| [&](perfetto::TracedValue context){ |
| auto dict = std::move(context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem("arr"), in_arr, |
| "<value of type const std::optional<std::vector<std::optional<std::string>>>&>"); |
| }); |
| #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( |
| base::to_underlying(messages::TestWTF::kEchoStringArray), kFlags, estimated_payload_size); |
| mojo::internal::MessageFragment< |
| ::mojo::test::internal::TestWTF_EchoStringArray_ResponseParams_Data> params( |
| message); |
| params.Allocate(); |
| mojo::internal::MessageFragment< |
| typename decltype(params->arr)::BaseType> |
| arr_fragment(params.message()); |
| constexpr const mojo::internal::ContainerValidateParams& arr_validate_params = |
| mojo::internal::GetArrayValidator<0, true, &mojo::internal::GetArrayValidator<0, false, nullptr>()>(); |
| mojo::internal::Serialize<mojo::ArrayDataView<mojo::StringDataView>>( |
| in_arr, arr_fragment, &arr_validate_params); |
| params->arr.Set( |
| arr_fragment.is_null() ? nullptr : arr_fragment.data()); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(TestWTF::Name_); |
| message.set_method_name("EchoStringArray"); |
| #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; |
| } |
| class TestWTF_EchoStringMap_ProxyToResponder : public ::mojo::internal::ProxyToResponder { |
| public: |
| static TestWTF::EchoStringMapCallback CreateCallback( |
| ::mojo::Message& message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| std::unique_ptr<TestWTF_EchoStringMap_ProxyToResponder> proxy( |
| new TestWTF_EchoStringMap_ProxyToResponder( |
| message, std::move(responder))); |
| return base::BindOnce(&TestWTF_EchoStringMap_ProxyToResponder::Run, |
| std::move(proxy)); |
| } |
| |
| ~TestWTF_EchoStringMap_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: |
| TestWTF_EchoStringMap_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) |
| << "TestWTF::EchoStringMapCallback 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( |
| const std::optional<base::flat_map<std::string, std::optional<std::string>>>& in_str_map); |
| }; |
| |
| bool TestWTF_EchoStringMap_ForwardToCallback::Accept( |
| mojo::Message* message) { |
| DCHECK(message->is_serialized()); |
| internal::TestWTF_EchoStringMap_ResponseParams_Data* params = |
| reinterpret_cast< |
| internal::TestWTF_EchoStringMap_ResponseParams_Data*>( |
| message->mutable_payload()); |
| |
| |
| // Validation for TestWTF.2 |
| bool success = true; |
| std::optional<base::flat_map<std::string, std::optional<std::string>>> p_str_map{}; |
| TestWTF_EchoStringMap_ResponseParamsDataView input_data_view(params, message); |
| |
| if (success && !input_data_view.ReadStrMap(&p_str_map)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| TestWTF::Name_, 2, true); |
| return false; |
| } |
| if (!callback_.is_null()) |
| std::move(callback_).Run( |
| std::move(p_str_map)); |
| return true; |
| } |
| |
| void TestWTF_EchoStringMap_ProxyToResponder::Run( |
| const std::optional<base::flat_map<std::string, std::optional<std::string>>>& in_str_map) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", "Send reply mojo::test::TestWTF::EchoStringMap", "async_response_parameters", |
| [&](perfetto::TracedValue context){ |
| auto dict = std::move(context).WriteDictionary(); |
| perfetto::WriteIntoTracedValueWithFallback( |
| dict.AddItem("str_map"), in_str_map, |
| "<value of type const std::optional<base::flat_map<std::string, std::optional<std::string>>>&>"); |
| }); |
| #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( |
| base::to_underlying(messages::TestWTF::kEchoStringMap), kFlags, estimated_payload_size); |
| mojo::internal::MessageFragment< |
| ::mojo::test::internal::TestWTF_EchoStringMap_ResponseParams_Data> params( |
| message); |
| params.Allocate(); |
| mojo::internal::MessageFragment< |
| typename decltype(params->str_map)::BaseType> |
| str_map_fragment(params.message()); |
| constexpr const mojo::internal::ContainerValidateParams& str_map_validate_params = |
| mojo::internal::GetMapValidator<*&mojo::internal::GetArrayValidator<0, false, &mojo::internal::GetArrayValidator<0, false, nullptr>()>(), *&mojo::internal::GetArrayValidator<0, true, &mojo::internal::GetArrayValidator<0, false, nullptr>()>()>(); |
| mojo::internal::Serialize<mojo::MapDataView<mojo::StringDataView, mojo::StringDataView>>( |
| in_str_map, str_map_fragment, &str_map_validate_params); |
| params->str_map.Set( |
| str_map_fragment.is_null() ? nullptr : str_map_fragment.data()); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(TestWTF::Name_); |
| message.set_method_name("EchoStringMap"); |
| #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 TestWTFStubDispatch::Accept( |
| TestWTF* impl, |
| mojo::Message* message) { |
| switch (static_cast<messages::TestWTF>(message->header()->name)) { |
| case messages::TestWTF::kEchoString: { |
| break; |
| } |
| case messages::TestWTF::kEchoStringArray: { |
| break; |
| } |
| case messages::TestWTF::kEchoStringMap: { |
| break; |
| } |
| } |
| return false; |
| } |
| |
| // static |
| bool TestWTFStubDispatch::AcceptWithResponder( |
| TestWTF* 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::TestWTF>(message->header()->name)) { |
| case messages::TestWTF::kEchoString: { |
| internal::TestWTF_EchoString_Params_Data* params = |
| reinterpret_cast< |
| internal::TestWTF_EchoString_Params_Data*>( |
| message->mutable_payload()); |
| |
| |
| // Validation for TestWTF.0 |
| bool success = true; |
| std::optional<std::string> p_str{}; |
| TestWTF_EchoString_ParamsDataView input_data_view(params, message); |
| |
| if (success && !input_data_view.ReadStr(&p_str)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| TestWTF::Name_, 0, false); |
| return false; |
| } |
| TestWTF::EchoStringCallback callback = |
| TestWTF_EchoString_ProxyToResponder::CreateCallback( |
| *message, std::move(responder)); |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->EchoString( |
| std::move(p_str), std::move(callback)); |
| return true; |
| } |
| case messages::TestWTF::kEchoStringArray: { |
| internal::TestWTF_EchoStringArray_Params_Data* params = |
| reinterpret_cast< |
| internal::TestWTF_EchoStringArray_Params_Data*>( |
| message->mutable_payload()); |
| |
| |
| // Validation for TestWTF.1 |
| bool success = true; |
| std::optional<std::vector<std::optional<std::string>>> p_arr{}; |
| TestWTF_EchoStringArray_ParamsDataView input_data_view(params, message); |
| |
| if (success && !input_data_view.ReadArr(&p_arr)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| TestWTF::Name_, 1, false); |
| return false; |
| } |
| TestWTF::EchoStringArrayCallback callback = |
| TestWTF_EchoStringArray_ProxyToResponder::CreateCallback( |
| *message, std::move(responder)); |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->EchoStringArray( |
| std::move(p_arr), std::move(callback)); |
| return true; |
| } |
| case messages::TestWTF::kEchoStringMap: { |
| internal::TestWTF_EchoStringMap_Params_Data* params = |
| reinterpret_cast< |
| internal::TestWTF_EchoStringMap_Params_Data*>( |
| message->mutable_payload()); |
| |
| |
| // Validation for TestWTF.2 |
| bool success = true; |
| std::optional<base::flat_map<std::string, std::optional<std::string>>> p_str_map{}; |
| TestWTF_EchoStringMap_ParamsDataView input_data_view(params, message); |
| |
| if (success && !input_data_view.ReadStrMap(&p_str_map)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| TestWTF::Name_, 2, false); |
| return false; |
| } |
| TestWTF::EchoStringMapCallback callback = |
| TestWTF_EchoStringMap_ProxyToResponder::CreateCallback( |
| *message, std::move(responder)); |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->EchoStringMap( |
| std::move(p_str_map), std::move(callback)); |
| return true; |
| } |
| } |
| return false; |
| } |
| namespace { |
| } // namespace |
| static const mojo::internal::GenericValidationInfo kTestWTFValidationInfo[] = { |
| { &internal::TestWTF_EchoString_Params_Data::Validate, |
| &internal::TestWTF_EchoString_ResponseParams_Data::Validate}, |
| { &internal::TestWTF_EchoStringArray_Params_Data::Validate, |
| &internal::TestWTF_EchoStringArray_ResponseParams_Data::Validate}, |
| { &internal::TestWTF_EchoStringMap_Params_Data::Validate, |
| &internal::TestWTF_EchoStringMap_ResponseParams_Data::Validate}, |
| }; |
| |
| bool TestWTFRequestValidator::Accept(mojo::Message* message) { |
| const char* name = ::mojo::test::TestWTF::Name_; |
| return mojo::internal::ValidateRequestGenericPacked(message, name, kTestWTFValidationInfo); |
| } |
| |
| bool TestWTFResponseValidator::Accept(mojo::Message* message) { |
| const char* name = ::mojo::test::TestWTF::Name_; |
| return mojo::internal::ValidateResponseGenericPacked(message, name, kTestWTFValidationInfo); |
| } |
| |
| |
| } // mojo::test |
| |
| |
| namespace mojo { |
| |
| |
| // static |
| bool StructTraits<::mojo::test::TestWTFCodeGeneration::DataView, ::mojo::test::TestWTFCodeGenerationPtr>::Read( |
| ::mojo::test::TestWTFCodeGeneration::DataView input, |
| ::mojo::test::TestWTFCodeGenerationPtr* output) { |
| bool success = true; |
| ::mojo::test::TestWTFCodeGenerationPtr result(::mojo::test::TestWTFCodeGeneration::New()); |
| |
| if (success && !input.ReadStr(&result->str)) |
| success = false; |
| if (success && !input.ReadNullableStr(&result->nullable_str)) |
| success = false; |
| if (success && !input.ReadStrs(&result->strs)) |
| success = false; |
| if (success && !input.ReadNullableStrs(&result->nullable_strs)) |
| success = false; |
| if (success && !input.ReadArrays(&result->arrays)) |
| success = false; |
| if (success && !input.ReadBools(&result->bools)) |
| success = false; |
| if (success && !input.ReadHandles(&result->handles)) |
| success = false; |
| if (success && !input.ReadStrMap(&result->str_map)) |
| success = false; |
| if (success && !input.ReadArrayMap(&result->array_map)) |
| success = false; |
| if (success && !input.ReadHandleMap(&result->handle_map)) |
| success = false; |
| if (success && !input.ReadStrMaps(&result->str_maps)) |
| success = false; |
| *output = std::move(result); |
| return success; |
| } |
| |
| |
| // static |
| bool StructTraits<::mojo::test::TestWTFStruct::DataView, ::mojo::test::TestWTFStructPtr>::Read( |
| ::mojo::test::TestWTFStruct::DataView input, |
| ::mojo::test::TestWTFStructPtr* output) { |
| bool success = true; |
| ::mojo::test::TestWTFStructPtr result(::mojo::test::TestWTFStruct::New()); |
| |
| if (success && !input.ReadStr(&result->str)) |
| success = false; |
| if (success) |
| result->integer = input.integer(); |
| *output = std::move(result); |
| return success; |
| } |
| |
| |
| // static |
| bool StructTraits<::mojo::test::TestWTFStructWrapper::DataView, ::mojo::test::TestWTFStructWrapperPtr>::Read( |
| ::mojo::test::TestWTFStructWrapper::DataView input, |
| ::mojo::test::TestWTFStructWrapperPtr* output) { |
| bool success = true; |
| ::mojo::test::TestWTFStructWrapperPtr result(::mojo::test::TestWTFStructWrapper::New()); |
| |
| if (success && !input.ReadNestedStruct(&result->nested_struct)) |
| success = false; |
| if (success && !input.ReadArrayStruct(&result->array_struct)) |
| success = false; |
| if (success && !input.ReadMapStruct(&result->map_struct)) |
| success = false; |
| *output = std::move(result); |
| return success; |
| } |
| |
| // static |
| bool UnionTraits<::mojo::test::TestWTFCodeGeneration2::DataView, ::mojo::test::TestWTFCodeGeneration2Ptr>::Read( |
| ::mojo::test::TestWTFCodeGeneration2::DataView input, |
| ::mojo::test::TestWTFCodeGeneration2Ptr* output) { |
| using UnionType = ::mojo::test::TestWTFCodeGeneration2; |
| using Tag = UnionType::Tag; |
| |
| switch (input.tag()) { |
| case Tag::kStr: { |
| std::string result_str; |
| if (!input.ReadStr(&result_str)) |
| return false; |
| |
| *output = UnionType::NewStr( |
| std::move(result_str)); |
| break; |
| } |
| case Tag::kStrs: { |
| std::vector<std::string> result_strs; |
| if (!input.ReadStrs(&result_strs)) |
| return false; |
| |
| *output = UnionType::NewStrs( |
| std::move(result_strs)); |
| break; |
| } |
| case Tag::kStrMap: { |
| base::flat_map<std::string, std::optional<std::string>> result_str_map; |
| if (!input.ReadStrMap(&result_str_map)) |
| return false; |
| |
| *output = UnionType::NewStrMap( |
| std::move(result_str_map)); |
| 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 mojo::test { |
| |
| |
| void TestWTFInterceptorForTesting::EchoString(const std::optional<std::string>& str, EchoStringCallback callback) { |
| GetForwardingInterface()->EchoString( |
| std::move(str) |
| , std::move(callback)); |
| } |
| void TestWTFInterceptorForTesting::EchoStringArray(const std::optional<std::vector<std::optional<std::string>>>& arr, EchoStringArrayCallback callback) { |
| GetForwardingInterface()->EchoStringArray( |
| std::move(arr) |
| , std::move(callback)); |
| } |
| void TestWTFInterceptorForTesting::EchoStringMap(const std::optional<base::flat_map<std::string, std::optional<std::string>>>& str_map, EchoStringMapCallback callback) { |
| GetForwardingInterface()->EchoStringMap( |
| std::move(str_map) |
| , std::move(callback)); |
| } |
| TestWTFAsyncWaiter::TestWTFAsyncWaiter( |
| TestWTF* proxy) : proxy_(proxy) {} |
| |
| TestWTFAsyncWaiter::~TestWTFAsyncWaiter() = default; |
| |
| void TestWTFAsyncWaiter::EchoString( |
| const std::optional<std::string>& str, std::optional<std::string>* out_str) { |
| base::RunLoop loop; |
| proxy_->EchoString( |
| std::move(str), |
| base::BindOnce( |
| [](base::RunLoop* loop, |
| std::optional<std::string>* out_str |
| , |
| const std::optional<std::string>& str) {*out_str = std::move(str); |
| loop->Quit(); |
| }, |
| &loop, |
| out_str)); |
| loop.Run(); |
| } |
| |
| std::optional<std::string> TestWTFAsyncWaiter::EchoString( |
| const std::optional<std::string>& str) { |
| std::optional<std::string> async_wait_result; |
| EchoString(std::move(str),&async_wait_result); |
| return async_wait_result; |
| } |
| |
| void TestWTFAsyncWaiter::EchoStringArray( |
| const std::optional<std::vector<std::optional<std::string>>>& arr, std::optional<std::vector<std::optional<std::string>>>* out_arr) { |
| base::RunLoop loop; |
| proxy_->EchoStringArray( |
| std::move(arr), |
| base::BindOnce( |
| [](base::RunLoop* loop, |
| std::optional<std::vector<std::optional<std::string>>>* out_arr |
| , |
| const std::optional<std::vector<std::optional<std::string>>>& arr) {*out_arr = std::move(arr); |
| loop->Quit(); |
| }, |
| &loop, |
| out_arr)); |
| loop.Run(); |
| } |
| |
| std::optional<std::vector<std::optional<std::string>>> TestWTFAsyncWaiter::EchoStringArray( |
| const std::optional<std::vector<std::optional<std::string>>>& arr) { |
| std::optional<std::vector<std::optional<std::string>>> async_wait_result; |
| EchoStringArray(std::move(arr),&async_wait_result); |
| return async_wait_result; |
| } |
| |
| void TestWTFAsyncWaiter::EchoStringMap( |
| const std::optional<base::flat_map<std::string, std::optional<std::string>>>& str_map, std::optional<base::flat_map<std::string, std::optional<std::string>>>* out_str_map) { |
| base::RunLoop loop; |
| proxy_->EchoStringMap( |
| std::move(str_map), |
| base::BindOnce( |
| [](base::RunLoop* loop, |
| std::optional<base::flat_map<std::string, std::optional<std::string>>>* out_str_map |
| , |
| const std::optional<base::flat_map<std::string, std::optional<std::string>>>& str_map) {*out_str_map = std::move(str_map); |
| loop->Quit(); |
| }, |
| &loop, |
| out_str_map)); |
| loop.Run(); |
| } |
| |
| std::optional<base::flat_map<std::string, std::optional<std::string>>> TestWTFAsyncWaiter::EchoStringMap( |
| const std::optional<base::flat_map<std::string, std::optional<std::string>>>& str_map) { |
| std::optional<base::flat_map<std::string, std::optional<std::string>>> async_wait_result; |
| EchoStringMap(std::move(str_map),&async_wait_result); |
| return async_wait_result; |
| } |
| |
| |
| |
| |
| |
| |
| } // mojo::test |
| |
| |
| #if defined(__clang__) |
| #pragma clang diagnostic pop |
| #endif |