| // 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. |
| |
| #ifndef SERVICES_DEVICE_PUBLIC_INTERFACES_WAKE_LOCK_CONTEXT_MOJOM_H_ |
| #define SERVICES_DEVICE_PUBLIC_INTERFACES_WAKE_LOCK_CONTEXT_MOJOM_H_ |
| |
| #include <stdint.h> |
| |
| #include <limits> |
| #include <type_traits> |
| #include <utility> |
| |
| #include "base/callback.h" |
| #include "base/macros.h" |
| #include "base/optional.h" |
| |
| #include "mojo/public/cpp/bindings/mojo_features.h" |
| #if BUILDFLAG(MOJO_TRACE_ENABLED) |
| #include "base/trace_event/trace_event.h" |
| #endif |
| #include "mojo/public/cpp/bindings/clone_traits.h" |
| #include "mojo/public/cpp/bindings/equals_traits.h" |
| #include "mojo/public/cpp/bindings/lib/serialization.h" |
| #include "mojo/public/cpp/bindings/struct_ptr.h" |
| #include "mojo/public/cpp/bindings/struct_traits.h" |
| #include "mojo/public/cpp/bindings/union_traits.h" |
| #include "services/device/public/interfaces/wake_lock_context.mojom-shared.h" |
| #include "services/device/public/interfaces/wake_lock.mojom.h" |
| #include <string> |
| #include <vector> |
| |
| #include "mojo/public/cpp/bindings/associated_interface_ptr.h" |
| #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
| #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| #include "mojo/public/cpp/bindings/interface_ptr.h" |
| #include "mojo/public/cpp/bindings/interface_request.h" |
| #include "mojo/public/cpp/bindings/lib/control_message_handler.h" |
| #include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h" |
| #include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" |
| |
| |
| #include "mojo/public/cpp/bindings/lib/native_enum_serialization.h" |
| #include "mojo/public/cpp/bindings/lib/native_struct_serialization.h" |
| |
| |
| namespace device { |
| namespace mojom { |
| class WakeLockContext; |
| using WakeLockContextPtr = mojo::InterfacePtr<WakeLockContext>; |
| using WakeLockContextPtrInfo = mojo::InterfacePtrInfo<WakeLockContext>; |
| using ThreadSafeWakeLockContextPtr = |
| mojo::ThreadSafeInterfacePtr<WakeLockContext>; |
| using WakeLockContextRequest = mojo::InterfaceRequest<WakeLockContext>; |
| using WakeLockContextAssociatedPtr = |
| mojo::AssociatedInterfacePtr<WakeLockContext>; |
| using ThreadSafeWakeLockContextAssociatedPtr = |
| mojo::ThreadSafeAssociatedInterfacePtr<WakeLockContext>; |
| using WakeLockContextAssociatedPtrInfo = |
| mojo::AssociatedInterfacePtrInfo<WakeLockContext>; |
| using WakeLockContextAssociatedRequest = |
| mojo::AssociatedInterfaceRequest<WakeLockContext>; |
| |
| |
| class WakeLockContextProxy; |
| |
| template <typename ImplRefTraits> |
| class WakeLockContextStub; |
| |
| class WakeLockContextRequestValidator; |
| |
| class WakeLockContext |
| : public WakeLockContextInterfaceBase { |
| public: |
| static const char Name_[]; |
| static constexpr uint32_t Version_ = 0; |
| static constexpr bool PassesAssociatedKinds_ = false; |
| static constexpr bool HasSyncMethods_ = false; |
| |
| using Proxy_ = WakeLockContextProxy; |
| |
| template <typename ImplRefTraits> |
| using Stub_ = WakeLockContextStub<ImplRefTraits>; |
| |
| using RequestValidator_ = WakeLockContextRequestValidator; |
| using ResponseValidator_ = mojo::PassThroughFilter; |
| enum MethodMinVersions : uint32_t { |
| kGetWakeLockMinVersion = 0, |
| }; |
| virtual ~WakeLockContext() {} |
| |
| virtual void GetWakeLock(::device::mojom::WakeLockType type, ::device::mojom::WakeLockReason reason, const std::string& description, ::device::mojom::WakeLockRequest wake_lock) = 0; |
| }; |
| class WakeLockContextInterceptorForTesting : public WakeLockContext { |
| virtual WakeLockContext* GetForwardingInterface() = 0; |
| void GetWakeLock(::device::mojom::WakeLockType type, ::device::mojom::WakeLockReason reason, const std::string& description, ::device::mojom::WakeLockRequest wake_lock) override; |
| }; |
| class WakeLockContextAsyncWaiter { |
| public: |
| explicit WakeLockContextAsyncWaiter(WakeLockContext* proxy); |
| ~WakeLockContextAsyncWaiter(); |
| |
| private: |
| WakeLockContext* const proxy_; |
| |
| DISALLOW_COPY_AND_ASSIGN(WakeLockContextAsyncWaiter); |
| }; |
| |
| class WakeLockContextProxy |
| : public WakeLockContext { |
| public: |
| explicit WakeLockContextProxy(mojo::MessageReceiverWithResponder* receiver); |
| void GetWakeLock(::device::mojom::WakeLockType type, ::device::mojom::WakeLockReason reason, const std::string& description, ::device::mojom::WakeLockRequest wake_lock) final; |
| |
| private: |
| mojo::MessageReceiverWithResponder* receiver_; |
| }; |
| class WakeLockContextStubDispatch { |
| public: |
| static bool Accept(WakeLockContext* impl, mojo::Message* message); |
| static bool AcceptWithResponder( |
| WakeLockContext* impl, |
| mojo::Message* message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder); |
| }; |
| |
| template <typename ImplRefTraits = |
| mojo::RawPtrImplRefTraits<WakeLockContext>> |
| class WakeLockContextStub |
| : public mojo::MessageReceiverWithResponderStatus { |
| public: |
| using ImplPointerType = typename ImplRefTraits::PointerType; |
| |
| WakeLockContextStub() {} |
| ~WakeLockContextStub() override {} |
| |
| void set_sink(ImplPointerType sink) { sink_ = std::move(sink); } |
| ImplPointerType& sink() { return sink_; } |
| |
| bool Accept(mojo::Message* message) override { |
| if (ImplRefTraits::IsNull(sink_)) |
| return false; |
| return WakeLockContextStubDispatch::Accept( |
| ImplRefTraits::GetRawPointer(&sink_), message); |
| } |
| |
| bool AcceptWithResponder( |
| mojo::Message* message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) override { |
| if (ImplRefTraits::IsNull(sink_)) |
| return false; |
| return WakeLockContextStubDispatch::AcceptWithResponder( |
| ImplRefTraits::GetRawPointer(&sink_), message, std::move(responder)); |
| } |
| |
| private: |
| ImplPointerType sink_; |
| }; |
| class WakeLockContextRequestValidator : public mojo::MessageReceiver { |
| public: |
| bool Accept(mojo::Message* message) override; |
| }; |
| |
| |
| |
| |
| |
| } // namespace mojom |
| } // namespace device |
| |
| namespace mojo { |
| |
| } // namespace mojo |
| |
| #endif // SERVICES_DEVICE_PUBLIC_INTERFACES_WAKE_LOCK_CONTEXT_MOJOM_H_ |