| // 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" |
| #elif defined(_MSC_VER) |
| #pragma warning(push) |
| #pragma warning(disable:4056) |
| #pragma warning(disable:4065) |
| #pragma warning(disable:4756) |
| #endif |
| |
| #include "services/device/public/mojom/power_monitor.mojom-blink.h" |
| |
| #include <math.h> |
| #include <stdint.h> |
| #include <utility> |
| |
| #include "base/hash/md5_constexpr.h" |
| #include "base/logging.h" |
| #include "base/run_loop.h" |
| #include "base/task/common/task_annotator.h" |
| #include "mojo/public/cpp/bindings/lib/message_internal.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_context.h" |
| #include "mojo/public/cpp/bindings/lib/validation_errors.h" |
| #include "mojo/public/interfaces/bindings/interface_control_messages.mojom.h" |
| |
| #include "services/device/public/mojom/power_monitor.mojom-params-data.h" |
| #include "services/device/public/mojom/power_monitor.mojom-shared-message-ids.h" |
| |
| #include "services/device/public/mojom/power_monitor.mojom-blink-import-headers.h" |
| #include "mojo/public/cpp/bindings/lib/wtf_serialization.h" |
| |
| |
| #ifndef SERVICES_DEVICE_PUBLIC_MOJOM_POWER_MONITOR_MOJOM_BLINK_JUMBO_H_ |
| #define SERVICES_DEVICE_PUBLIC_MOJOM_POWER_MONITOR_MOJOM_BLINK_JUMBO_H_ |
| #endif |
| namespace device { |
| namespace mojom { |
| namespace blink { |
| const char PowerMonitor::Name_[] = "device.mojom.PowerMonitor"; |
| |
| PowerMonitorProxy::PowerMonitorProxy(mojo::MessageReceiverWithResponder* receiver) |
| : receiver_(receiver) { |
| } |
| |
| void PowerMonitorProxy::AddClient( |
| PowerMonitorClientPtr in_client) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "<class 'jinja2::utils::Namespace'>::PowerMonitor::AddClient"); |
| #endif |
| const bool kExpectsResponse = false; |
| const bool kIsSync = false; |
| |
| const uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0); |
| |
| mojo::Message message( |
| internal::kPowerMonitor_AddClient_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::PowerMonitor_AddClient_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| mojo::internal::Serialize<::device::mojom::PowerMonitorClientPtrDataView>( |
| in_client, ¶ms->client, &serialization_context); |
| MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| !mojo::internal::IsHandleOrInterfaceValid(params->client), |
| mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, |
| "invalid client in PowerMonitor.AddClient request"); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(PowerMonitor::Name_); |
| message.set_method_name("AddClient"); |
| #endif |
| // This return value may be ignored as false implies the Connector has |
| // encountered an error, which will be visible through other means. |
| ignore_result(receiver_->Accept(&message)); |
| } |
| |
| // static |
| bool PowerMonitorStubDispatch::Accept( |
| PowerMonitor* impl, |
| mojo::Message* message) { |
| switch (message->header()->name) { |
| case internal::kPowerMonitor_AddClient_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", |
| "(Impl)<class 'jinja2::utils::Namespace'>::PowerMonitor::AddClient", |
| "message", message->name()); |
| #endif |
| static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr( |
| "(Impl)<class 'jinja2::utils::Namespace'>::PowerMonitor::AddClient"); |
| base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash); |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::PowerMonitor_AddClient_Params_Data* params = |
| reinterpret_cast<internal::PowerMonitor_AddClient_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| PowerMonitorClientPtr p_client{}; |
| PowerMonitor_AddClient_ParamsDataView input_data_view(params, &serialization_context); |
| |
| p_client = |
| input_data_view.TakeClient<decltype(p_client)>(); |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| PowerMonitor::Name_, 0, false); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->AddClient( |
| std::move(p_client)); |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| // static |
| bool PowerMonitorStubDispatch::AcceptWithResponder( |
| PowerMonitor* impl, |
| mojo::Message* message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| switch (message->header()->name) { |
| case internal::kPowerMonitor_AddClient_Name: { |
| break; |
| } |
| } |
| return false; |
| } |
| |
| bool PowerMonitorRequestValidator::Accept(mojo::Message* message) { |
| if (!message->is_serialized() || |
| mojo::internal::ControlMessageHandler::IsControlMessage(message)) { |
| return true; |
| } |
| |
| mojo::internal::ValidationContext validation_context( |
| message->payload(), message->payload_num_bytes(), |
| message->handles()->size(), message->payload_num_interface_ids(), message, |
| "PowerMonitor RequestValidator"); |
| |
| switch (message->header()->name) { |
| case internal::kPowerMonitor_AddClient_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::PowerMonitor_AddClient_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| default: |
| break; |
| } |
| |
| // Unrecognized message. |
| ReportValidationError( |
| &validation_context, |
| mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); |
| return false; |
| } |
| |
| const char PowerMonitorClient::Name_[] = "device.mojom.PowerMonitorClient"; |
| |
| PowerMonitorClientProxy::PowerMonitorClientProxy(mojo::MessageReceiverWithResponder* receiver) |
| : receiver_(receiver) { |
| } |
| |
| void PowerMonitorClientProxy::PowerStateChange( |
| bool in_on_battery_power) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "<class 'jinja2::utils::Namespace'>::PowerMonitorClient::PowerStateChange"); |
| #endif |
| const bool kExpectsResponse = false; |
| const bool kIsSync = false; |
| |
| const uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0); |
| |
| mojo::Message message( |
| internal::kPowerMonitorClient_PowerStateChange_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::PowerMonitorClient_PowerStateChange_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| params->on_battery_power = in_on_battery_power; |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(PowerMonitorClient::Name_); |
| message.set_method_name("PowerStateChange"); |
| #endif |
| // This return value may be ignored as false implies the Connector has |
| // encountered an error, which will be visible through other means. |
| ignore_result(receiver_->Accept(&message)); |
| } |
| |
| void PowerMonitorClientProxy::Suspend( |
| ) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "<class 'jinja2::utils::Namespace'>::PowerMonitorClient::Suspend"); |
| #endif |
| const bool kExpectsResponse = false; |
| const bool kIsSync = false; |
| |
| const uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0); |
| |
| mojo::Message message( |
| internal::kPowerMonitorClient_Suspend_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::PowerMonitorClient_Suspend_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(PowerMonitorClient::Name_); |
| message.set_method_name("Suspend"); |
| #endif |
| // This return value may be ignored as false implies the Connector has |
| // encountered an error, which will be visible through other means. |
| ignore_result(receiver_->Accept(&message)); |
| } |
| |
| void PowerMonitorClientProxy::Resume( |
| ) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "<class 'jinja2::utils::Namespace'>::PowerMonitorClient::Resume"); |
| #endif |
| const bool kExpectsResponse = false; |
| const bool kIsSync = false; |
| |
| const uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0); |
| |
| mojo::Message message( |
| internal::kPowerMonitorClient_Resume_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::PowerMonitorClient_Resume_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| |
| #if defined(ENABLE_IPC_FUZZER) |
| message.set_interface_name(PowerMonitorClient::Name_); |
| message.set_method_name("Resume"); |
| #endif |
| // This return value may be ignored as false implies the Connector has |
| // encountered an error, which will be visible through other means. |
| ignore_result(receiver_->Accept(&message)); |
| } |
| |
| // static |
| bool PowerMonitorClientStubDispatch::Accept( |
| PowerMonitorClient* impl, |
| mojo::Message* message) { |
| switch (message->header()->name) { |
| case internal::kPowerMonitorClient_PowerStateChange_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", |
| "(Impl)<class 'jinja2::utils::Namespace'>::PowerMonitorClient::PowerStateChange", |
| "message", message->name()); |
| #endif |
| static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr( |
| "(Impl)<class 'jinja2::utils::Namespace'>::PowerMonitorClient::PowerStateChange"); |
| base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash); |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::PowerMonitorClient_PowerStateChange_Params_Data* params = |
| reinterpret_cast<internal::PowerMonitorClient_PowerStateChange_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| bool p_on_battery_power{}; |
| PowerMonitorClient_PowerStateChange_ParamsDataView input_data_view(params, &serialization_context); |
| |
| p_on_battery_power = input_data_view.on_battery_power(); |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| PowerMonitorClient::Name_, 0, false); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->PowerStateChange( |
| std::move(p_on_battery_power)); |
| return true; |
| } |
| case internal::kPowerMonitorClient_Suspend_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", |
| "(Impl)<class 'jinja2::utils::Namespace'>::PowerMonitorClient::Suspend", |
| "message", message->name()); |
| #endif |
| static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr( |
| "(Impl)<class 'jinja2::utils::Namespace'>::PowerMonitorClient::Suspend"); |
| base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash); |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::PowerMonitorClient_Suspend_Params_Data* params = |
| reinterpret_cast<internal::PowerMonitorClient_Suspend_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| PowerMonitorClient_Suspend_ParamsDataView input_data_view(params, &serialization_context); |
| |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| PowerMonitorClient::Name_, 1, false); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->Suspend(); |
| return true; |
| } |
| case internal::kPowerMonitorClient_Resume_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1( |
| "mojom", |
| "(Impl)<class 'jinja2::utils::Namespace'>::PowerMonitorClient::Resume", |
| "message", message->name()); |
| #endif |
| static constexpr uint32_t kMessageHash = base::MD5Hash32Constexpr( |
| "(Impl)<class 'jinja2::utils::Namespace'>::PowerMonitorClient::Resume"); |
| base::TaskAnnotator::ScopedSetIpcHash scoped_ipc_hash(kMessageHash); |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::PowerMonitorClient_Resume_Params_Data* params = |
| reinterpret_cast<internal::PowerMonitorClient_Resume_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| PowerMonitorClient_Resume_ParamsDataView input_data_view(params, &serialization_context); |
| |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| PowerMonitorClient::Name_, 2, false); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| DCHECK(impl); |
| impl->Resume(); |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| // static |
| bool PowerMonitorClientStubDispatch::AcceptWithResponder( |
| PowerMonitorClient* impl, |
| mojo::Message* message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| switch (message->header()->name) { |
| case internal::kPowerMonitorClient_PowerStateChange_Name: { |
| break; |
| } |
| case internal::kPowerMonitorClient_Suspend_Name: { |
| break; |
| } |
| case internal::kPowerMonitorClient_Resume_Name: { |
| break; |
| } |
| } |
| return false; |
| } |
| |
| bool PowerMonitorClientRequestValidator::Accept(mojo::Message* message) { |
| if (!message->is_serialized() || |
| mojo::internal::ControlMessageHandler::IsControlMessage(message)) { |
| return true; |
| } |
| |
| mojo::internal::ValidationContext validation_context( |
| message->payload(), message->payload_num_bytes(), |
| message->handles()->size(), message->payload_num_interface_ids(), message, |
| "PowerMonitorClient RequestValidator"); |
| |
| switch (message->header()->name) { |
| case internal::kPowerMonitorClient_PowerStateChange_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::PowerMonitorClient_PowerStateChange_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kPowerMonitorClient_Suspend_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::PowerMonitorClient_Suspend_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kPowerMonitorClient_Resume_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::PowerMonitorClient_Resume_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| default: |
| break; |
| } |
| |
| // Unrecognized message. |
| ReportValidationError( |
| &validation_context, |
| mojo::internal::VALIDATION_ERROR_MESSAGE_HEADER_UNKNOWN_METHOD); |
| return false; |
| } |
| |
| } // namespace blink |
| } // namespace mojom |
| } // namespace device |
| |
| namespace mojo { |
| |
| } // namespace mojo |
| |
| #if defined(__clang__) |
| #pragma clang diagnostic pop |
| #elif defined(_MSC_VER) |
| #pragma warning(pop) |
| #endif |