| // 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/interfaces/wake_lock.mojom.h" |
| |
| #include <math.h> |
| #include <stdint.h> |
| #include <utility> |
| |
| #include "base/logging.h" |
| #include "base/run_loop.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/interfaces/wake_lock.mojom-shared-message-ids.h" |
| namespace device { |
| namespace mojom { |
| const char WakeLock::Name_[] = "device::mojom::WakeLock"; |
| |
| class WakeLock_ChangeType_ForwardToCallback |
| : public mojo::MessageReceiver { |
| public: |
| WakeLock_ChangeType_ForwardToCallback( |
| WakeLock::ChangeTypeCallback callback |
| ) : callback_(std::move(callback)) { |
| } |
| bool Accept(mojo::Message* message) override; |
| private: |
| WakeLock::ChangeTypeCallback callback_; |
| DISALLOW_COPY_AND_ASSIGN(WakeLock_ChangeType_ForwardToCallback); |
| }; |
| |
| class WakeLock_HasWakeLockForTests_ForwardToCallback |
| : public mojo::MessageReceiver { |
| public: |
| WakeLock_HasWakeLockForTests_ForwardToCallback( |
| WakeLock::HasWakeLockForTestsCallback callback |
| ) : callback_(std::move(callback)) { |
| } |
| bool Accept(mojo::Message* message) override; |
| private: |
| WakeLock::HasWakeLockForTestsCallback callback_; |
| DISALLOW_COPY_AND_ASSIGN(WakeLock_HasWakeLockForTests_ForwardToCallback); |
| }; |
| |
| WakeLockProxy::WakeLockProxy(mojo::MessageReceiverWithResponder* receiver) |
| : receiver_(receiver) { |
| } |
| |
| void WakeLockProxy::RequestWakeLock( |
| ) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "device::mojom::WakeLock::RequestWakeLock"); |
| #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::kWakeLock_RequestWakeLock_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::WakeLock_RequestWakeLock_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| // 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 WakeLockProxy::CancelWakeLock( |
| ) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "device::mojom::WakeLock::CancelWakeLock"); |
| #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::kWakeLock_CancelWakeLock_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::WakeLock_CancelWakeLock_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| // 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 WakeLockProxy::AddClient( |
| WakeLockRequest in_wake_lock) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "device::mojom::WakeLock::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::kWakeLock_AddClient_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::WakeLock_AddClient_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| mojo::internal::Serialize<::device::mojom::WakeLockRequestDataView>( |
| in_wake_lock, ¶ms->wake_lock, &serialization_context); |
| MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( |
| !mojo::internal::IsHandleOrInterfaceValid(params->wake_lock), |
| mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, |
| "invalid wake_lock in WakeLock.AddClient request"); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| // 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 WakeLockProxy::ChangeType( |
| WakeLockType in_type, ChangeTypeCallback callback) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "device::mojom::WakeLock::ChangeType"); |
| #endif |
| const bool kExpectsResponse = true; |
| const bool kIsSync = false; |
| |
| const uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0); |
| |
| mojo::Message message( |
| internal::kWakeLock_ChangeType_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::WakeLock_ChangeType_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| mojo::internal::Serialize<::device::mojom::WakeLockType>( |
| in_type, ¶ms->type); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| std::unique_ptr<mojo::MessageReceiver> responder( |
| new WakeLock_ChangeType_ForwardToCallback( |
| std::move(callback))); |
| ignore_result(receiver_->AcceptWithResponder(&message, std::move(responder))); |
| } |
| |
| void WakeLockProxy::HasWakeLockForTests( |
| HasWakeLockForTestsCallback callback) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT0("mojom", "device::mojom::WakeLock::HasWakeLockForTests"); |
| #endif |
| const bool kExpectsResponse = true; |
| const bool kIsSync = false; |
| |
| const uint32_t kFlags = |
| ((kExpectsResponse) ? mojo::Message::kFlagExpectsResponse : 0) | |
| ((kIsSync) ? mojo::Message::kFlagIsSync : 0); |
| |
| mojo::Message message( |
| internal::kWakeLock_HasWakeLockForTests_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::WakeLock_HasWakeLockForTests_Params_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| std::unique_ptr<mojo::MessageReceiver> responder( |
| new WakeLock_HasWakeLockForTests_ForwardToCallback( |
| std::move(callback))); |
| ignore_result(receiver_->AcceptWithResponder(&message, std::move(responder))); |
| } |
| class WakeLock_ChangeType_ProxyToResponder { |
| public: |
| static WakeLock::ChangeTypeCallback CreateCallback( |
| uint64_t request_id, |
| bool is_sync, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| std::unique_ptr<WakeLock_ChangeType_ProxyToResponder> proxy( |
| new WakeLock_ChangeType_ProxyToResponder( |
| request_id, is_sync, std::move(responder))); |
| return base::Bind(&WakeLock_ChangeType_ProxyToResponder::Run, |
| base::Passed(&proxy)); |
| } |
| |
| ~WakeLock_ChangeType_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 |
| // If the Callback was dropped then deleting the responder will close |
| // the pipe so the calling application knows to stop waiting for a reply. |
| responder_ = nullptr; |
| } |
| |
| private: |
| WakeLock_ChangeType_ProxyToResponder( |
| uint64_t request_id, |
| bool is_sync, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) |
| : request_id_(request_id), |
| is_sync_(is_sync), |
| responder_(std::move(responder)) { |
| } |
| |
| #if DCHECK_IS_ON() |
| static void OnIsConnectedComplete(bool connected) { |
| DCHECK(!connected) |
| << "WakeLock::ChangeTypeCallback 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( |
| bool in_result); |
| |
| uint64_t request_id_; |
| bool is_sync_; |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder_; |
| |
| DISALLOW_COPY_AND_ASSIGN(WakeLock_ChangeType_ProxyToResponder); |
| }; |
| |
| bool WakeLock_ChangeType_ForwardToCallback::Accept( |
| mojo::Message* message) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "device::mojom::WakeLock::ChangeTypeCallback", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext dispatch_context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::WakeLock_ChangeType_ResponseParams_Data* params = |
| reinterpret_cast< |
| internal::WakeLock_ChangeType_ResponseParams_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| bool p_result{}; |
| WakeLock_ChangeType_ResponseParamsDataView input_data_view(params, &serialization_context); |
| |
| p_result = input_data_view.result(); |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "WakeLock::ChangeType response deserializer"); |
| return false; |
| } |
| if (!callback_.is_null()) |
| std::move(callback_).Run( |
| std::move(p_result)); |
| return true; |
| } |
| |
| void WakeLock_ChangeType_ProxyToResponder::Run( |
| bool in_result) { |
| |
| const uint32_t kFlags = mojo::Message::kFlagIsResponse | |
| ((is_sync_) ? mojo::Message::kFlagIsSync : 0); |
| |
| mojo::Message message( |
| internal::kWakeLock_ChangeType_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::WakeLock_ChangeType_ResponseParams_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| params->result = in_result; |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::ChangeTypeCallback", |
| "message", message.name()); |
| #endif |
| message.set_request_id(request_id_); |
| ignore_result(responder_->Accept(&message)); |
| // TODO(darin): Accept() returning false indicates a malformed message, and |
| // 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 WakeLock_HasWakeLockForTests_ProxyToResponder { |
| public: |
| static WakeLock::HasWakeLockForTestsCallback CreateCallback( |
| uint64_t request_id, |
| bool is_sync, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| std::unique_ptr<WakeLock_HasWakeLockForTests_ProxyToResponder> proxy( |
| new WakeLock_HasWakeLockForTests_ProxyToResponder( |
| request_id, is_sync, std::move(responder))); |
| return base::Bind(&WakeLock_HasWakeLockForTests_ProxyToResponder::Run, |
| base::Passed(&proxy)); |
| } |
| |
| ~WakeLock_HasWakeLockForTests_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 |
| // If the Callback was dropped then deleting the responder will close |
| // the pipe so the calling application knows to stop waiting for a reply. |
| responder_ = nullptr; |
| } |
| |
| private: |
| WakeLock_HasWakeLockForTests_ProxyToResponder( |
| uint64_t request_id, |
| bool is_sync, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) |
| : request_id_(request_id), |
| is_sync_(is_sync), |
| responder_(std::move(responder)) { |
| } |
| |
| #if DCHECK_IS_ON() |
| static void OnIsConnectedComplete(bool connected) { |
| DCHECK(!connected) |
| << "WakeLock::HasWakeLockForTestsCallback 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( |
| bool in_result); |
| |
| uint64_t request_id_; |
| bool is_sync_; |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder_; |
| |
| DISALLOW_COPY_AND_ASSIGN(WakeLock_HasWakeLockForTests_ProxyToResponder); |
| }; |
| |
| bool WakeLock_HasWakeLockForTests_ForwardToCallback::Accept( |
| mojo::Message* message) { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "device::mojom::WakeLock::HasWakeLockForTestsCallback", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext dispatch_context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::WakeLock_HasWakeLockForTests_ResponseParams_Data* params = |
| reinterpret_cast< |
| internal::WakeLock_HasWakeLockForTests_ResponseParams_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| bool p_result{}; |
| WakeLock_HasWakeLockForTests_ResponseParamsDataView input_data_view(params, &serialization_context); |
| |
| p_result = input_data_view.result(); |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "WakeLock::HasWakeLockForTests response deserializer"); |
| return false; |
| } |
| if (!callback_.is_null()) |
| std::move(callback_).Run( |
| std::move(p_result)); |
| return true; |
| } |
| |
| void WakeLock_HasWakeLockForTests_ProxyToResponder::Run( |
| bool in_result) { |
| |
| const uint32_t kFlags = mojo::Message::kFlagIsResponse | |
| ((is_sync_) ? mojo::Message::kFlagIsSync : 0); |
| |
| mojo::Message message( |
| internal::kWakeLock_HasWakeLockForTests_Name, kFlags, 0, 0, nullptr); |
| auto* buffer = message.payload_buffer(); |
| ::device::mojom::internal::WakeLock_HasWakeLockForTests_ResponseParams_Data::BufferWriter |
| params; |
| mojo::internal::SerializationContext serialization_context; |
| params.Allocate(buffer); |
| params->result = in_result; |
| message.AttachHandlesFromSerializationContext( |
| &serialization_context); |
| |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::HasWakeLockForTestsCallback", |
| "message", message.name()); |
| #endif |
| message.set_request_id(request_id_); |
| ignore_result(responder_->Accept(&message)); |
| // TODO(darin): Accept() returning false indicates a malformed message, and |
| // 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 WakeLockStubDispatch::Accept( |
| WakeLock* impl, |
| mojo::Message* message) { |
| switch (message->header()->name) { |
| case internal::kWakeLock_RequestWakeLock_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::RequestWakeLock", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::WakeLock_RequestWakeLock_Params_Data* params = |
| reinterpret_cast<internal::WakeLock_RequestWakeLock_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| WakeLock_RequestWakeLock_ParamsDataView input_data_view(params, &serialization_context); |
| |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "WakeLock::RequestWakeLock deserializer"); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| assert(impl); |
| impl->RequestWakeLock(); |
| return true; |
| } |
| case internal::kWakeLock_CancelWakeLock_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::CancelWakeLock", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::WakeLock_CancelWakeLock_Params_Data* params = |
| reinterpret_cast<internal::WakeLock_CancelWakeLock_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| WakeLock_CancelWakeLock_ParamsDataView input_data_view(params, &serialization_context); |
| |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "WakeLock::CancelWakeLock deserializer"); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| assert(impl); |
| impl->CancelWakeLock(); |
| return true; |
| } |
| case internal::kWakeLock_AddClient_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::AddClient", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext context(message); |
| |
| DCHECK(message->is_serialized()); |
| internal::WakeLock_AddClient_Params_Data* params = |
| reinterpret_cast<internal::WakeLock_AddClient_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| WakeLockRequest p_wake_lock{}; |
| WakeLock_AddClient_ParamsDataView input_data_view(params, &serialization_context); |
| |
| p_wake_lock = |
| input_data_view.TakeWakeLock<decltype(p_wake_lock)>(); |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "WakeLock::AddClient deserializer"); |
| return false; |
| } |
| // A null |impl| means no implementation was bound. |
| assert(impl); |
| impl->AddClient( |
| std::move(p_wake_lock)); |
| return true; |
| } |
| case internal::kWakeLock_ChangeType_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::ChangeType", |
| "message", message->name()); |
| #endif |
| break; |
| } |
| case internal::kWakeLock_HasWakeLockForTests_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::HasWakeLockForTests", |
| "message", message->name()); |
| #endif |
| break; |
| } |
| } |
| return false; |
| } |
| |
| // static |
| bool WakeLockStubDispatch::AcceptWithResponder( |
| WakeLock* impl, |
| mojo::Message* message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) { |
| switch (message->header()->name) { |
| case internal::kWakeLock_RequestWakeLock_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::RequestWakeLock", |
| "message", message->name()); |
| #endif |
| break; |
| } |
| case internal::kWakeLock_CancelWakeLock_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::CancelWakeLock", |
| "message", message->name()); |
| #endif |
| break; |
| } |
| case internal::kWakeLock_AddClient_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::AddClient", |
| "message", message->name()); |
| #endif |
| break; |
| } |
| case internal::kWakeLock_ChangeType_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::ChangeType", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext context(message); |
| |
| internal::WakeLock_ChangeType_Params_Data* params = |
| reinterpret_cast< |
| internal::WakeLock_ChangeType_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| WakeLockType p_type{}; |
| WakeLock_ChangeType_ParamsDataView input_data_view(params, &serialization_context); |
| |
| if (!input_data_view.ReadType(&p_type)) |
| success = false; |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "WakeLock::ChangeType deserializer"); |
| return false; |
| } |
| WakeLock::ChangeTypeCallback callback = |
| WakeLock_ChangeType_ProxyToResponder::CreateCallback( |
| message->request_id(), |
| message->has_flag(mojo::Message::kFlagIsSync), |
| std::move(responder)); |
| // A null |impl| means no implementation was bound. |
| assert(impl); |
| impl->ChangeType( |
| std::move(p_type), std::move(callback)); |
| return true; |
| } |
| case internal::kWakeLock_HasWakeLockForTests_Name: { |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| TRACE_EVENT1("mojom", "(Impl)device::mojom::WakeLock::HasWakeLockForTests", |
| "message", message->name()); |
| #endif |
| mojo::internal::MessageDispatchContext context(message); |
| |
| internal::WakeLock_HasWakeLockForTests_Params_Data* params = |
| reinterpret_cast< |
| internal::WakeLock_HasWakeLockForTests_Params_Data*>( |
| message->mutable_payload()); |
| |
| mojo::internal::SerializationContext serialization_context; |
| serialization_context.TakeHandlesFromMessage(message); |
| bool success = true; |
| WakeLock_HasWakeLockForTests_ParamsDataView input_data_view(params, &serialization_context); |
| |
| if (!success) { |
| ReportValidationErrorForMessage( |
| message, |
| mojo::internal::VALIDATION_ERROR_DESERIALIZATION_FAILED, |
| "WakeLock::HasWakeLockForTests deserializer"); |
| return false; |
| } |
| WakeLock::HasWakeLockForTestsCallback callback = |
| WakeLock_HasWakeLockForTests_ProxyToResponder::CreateCallback( |
| message->request_id(), |
| message->has_flag(mojo::Message::kFlagIsSync), |
| std::move(responder)); |
| // A null |impl| means no implementation was bound. |
| assert(impl); |
| impl->HasWakeLockForTests(std::move(callback)); |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| bool WakeLockRequestValidator::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, |
| "WakeLock RequestValidator"); |
| |
| switch (message->header()->name) { |
| case internal::kWakeLock_RequestWakeLock_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::WakeLock_RequestWakeLock_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kWakeLock_CancelWakeLock_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::WakeLock_CancelWakeLock_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kWakeLock_AddClient_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestWithoutResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::WakeLock_AddClient_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kWakeLock_ChangeType_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestExpectingResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::WakeLock_ChangeType_Params_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kWakeLock_HasWakeLockForTests_Name: { |
| if (!mojo::internal::ValidateMessageIsRequestExpectingResponse( |
| message, &validation_context)) { |
| return false; |
| } |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::WakeLock_HasWakeLockForTests_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; |
| } |
| |
| bool WakeLockResponseValidator::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, |
| "WakeLock ResponseValidator"); |
| |
| if (!mojo::internal::ValidateMessageIsResponse(message, &validation_context)) |
| return false; |
| switch (message->header()->name) { |
| case internal::kWakeLock_ChangeType_Name: { |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::WakeLock_ChangeType_ResponseParams_Data>( |
| message, &validation_context)) { |
| return false; |
| } |
| return true; |
| } |
| case internal::kWakeLock_HasWakeLockForTests_Name: { |
| if (!mojo::internal::ValidateMessagePayload< |
| internal::WakeLock_HasWakeLockForTests_ResponseParams_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; |
| } |
| void WakeLockInterceptorForTesting::RequestWakeLock() { |
| GetForwardingInterface()->RequestWakeLock(); |
| } |
| void WakeLockInterceptorForTesting::CancelWakeLock() { |
| GetForwardingInterface()->CancelWakeLock(); |
| } |
| void WakeLockInterceptorForTesting::AddClient(WakeLockRequest wake_lock) { |
| GetForwardingInterface()->AddClient(std::move(wake_lock)); |
| } |
| void WakeLockInterceptorForTesting::ChangeType(WakeLockType type, ChangeTypeCallback callback) { |
| GetForwardingInterface()->ChangeType(std::move(type), std::move(callback)); |
| } |
| void WakeLockInterceptorForTesting::HasWakeLockForTests(HasWakeLockForTestsCallback callback) { |
| GetForwardingInterface()->HasWakeLockForTests(std::move(callback)); |
| } |
| WakeLockAsyncWaiter::WakeLockAsyncWaiter( |
| WakeLock* proxy) : proxy_(proxy) {} |
| |
| WakeLockAsyncWaiter::~WakeLockAsyncWaiter() = default; |
| |
| void WakeLockAsyncWaiter::ChangeType( |
| WakeLockType type, bool* out_result) { |
| base::RunLoop loop; |
| proxy_->ChangeType(std::move(type), |
| base::Bind( |
| [](base::RunLoop* loop, |
| bool* out_result |
| , |
| bool result) {*out_result = std::move(result); |
| loop->Quit(); |
| }, |
| &loop, |
| out_result)); |
| loop.Run(); |
| } |
| void WakeLockAsyncWaiter::HasWakeLockForTests( |
| bool* out_result) { |
| base::RunLoop loop; |
| proxy_->HasWakeLockForTests( |
| base::Bind( |
| [](base::RunLoop* loop, |
| bool* out_result |
| , |
| bool result) {*out_result = std::move(result); |
| loop->Quit(); |
| }, |
| &loop, |
| out_result)); |
| loop.Run(); |
| } |
| |
| } // namespace mojom |
| } // namespace device |
| |
| namespace mojo { |
| |
| } // namespace mojo |
| |
| #if defined(__clang__) |
| #pragma clang diagnostic pop |
| #elif defined(_MSC_VER) |
| #pragma warning(pop) |
| #endif |