| // 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 COMPONENTS_CHROME_CLEANER_PUBLIC_INTERFACES_CHROME_PROMPT_MOJOM_H_ |
| #define COMPONENTS_CHROME_CLEANER_PUBLIC_INTERFACES_CHROME_PROMPT_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/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/clone_traits.h" |
| #include "mojo/public/cpp/bindings/equals_traits.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/lib/control_message_proxy.h" |
| #include "mojo/public/cpp/bindings/lib/serialization.h" |
| #include "mojo/public/cpp/bindings/native_struct.h" |
| #include "mojo/public/cpp/bindings/raw_ptr_impl_ref_traits.h" |
| #include "mojo/public/cpp/bindings/struct_ptr.h" |
| #include "mojo/public/cpp/bindings/struct_traits.h" |
| #include "mojo/public/cpp/bindings/thread_safe_interface_ptr.h" |
| #include "mojo/public/cpp/bindings/union_traits.h" |
| #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom-shared.h" |
| #include "mojo/common/file_path.mojom.h" |
| #include <string> |
| #include <vector> |
| |
| |
| namespace chrome_cleaner { |
| namespace mojom { |
| class ChromePrompt; |
| using ChromePromptPtr = mojo::InterfacePtr<ChromePrompt>; |
| using ChromePromptPtrInfo = mojo::InterfacePtrInfo<ChromePrompt>; |
| using ThreadSafeChromePromptPtr = |
| mojo::ThreadSafeInterfacePtr<ChromePrompt>; |
| using ChromePromptRequest = mojo::InterfaceRequest<ChromePrompt>; |
| using ChromePromptAssociatedPtr = |
| mojo::AssociatedInterfacePtr<ChromePrompt>; |
| using ThreadSafeChromePromptAssociatedPtr = |
| mojo::ThreadSafeAssociatedInterfacePtr<ChromePrompt>; |
| using ChromePromptAssociatedPtrInfo = |
| mojo::AssociatedInterfacePtrInfo<ChromePrompt>; |
| using ChromePromptAssociatedRequest = |
| mojo::AssociatedInterfaceRequest<ChromePrompt>; |
| |
| class ObservedBehaviours; |
| using ObservedBehavioursPtr = mojo::InlinedStructPtr<ObservedBehaviours>; |
| |
| class UwS; |
| using UwSPtr = mojo::StructPtr<UwS>; |
| |
| |
| class ChromePromptProxy; |
| |
| template <typename ImplRefTraits> |
| class ChromePromptStub; |
| |
| class ChromePromptRequestValidator; |
| class ChromePromptResponseValidator; |
| |
| class ChromePrompt |
| : public ChromePromptInterfaceBase { |
| public: |
| static const char Name_[]; |
| static constexpr uint32_t Version_ = 0; |
| static constexpr bool PassesAssociatedKinds_ = false; |
| static constexpr bool HasSyncMethods_ = false; |
| |
| using Proxy_ = ChromePromptProxy; |
| |
| template <typename ImplRefTraits> |
| using Stub_ = ChromePromptStub<ImplRefTraits>; |
| |
| using RequestValidator_ = ChromePromptRequestValidator; |
| using ResponseValidator_ = ChromePromptResponseValidator; |
| enum MethodMinVersions : uint32_t { |
| kPromptUserMinVersion = 0, |
| }; |
| virtual ~ChromePrompt() {} |
| |
| |
| using PromptUserCallback = base::Callback<void(PromptAcceptance)>; |
| virtual void PromptUser(std::vector<UwSPtr> removable_uws_found, ElevationStatus elevation_status, const PromptUserCallback& callback) = 0; |
| }; |
| |
| class ChromePromptProxy |
| : public ChromePrompt { |
| public: |
| explicit ChromePromptProxy(mojo::MessageReceiverWithResponder* receiver); |
| void PromptUser(std::vector<UwSPtr> removable_uws_found, ElevationStatus elevation_status, const PromptUserCallback& callback) override; |
| |
| private: |
| mojo::MessageReceiverWithResponder* receiver_; |
| }; |
| class ChromePromptStubDispatch { |
| public: |
| static bool Accept(ChromePrompt* impl, mojo::Message* message); |
| static bool AcceptWithResponder( |
| ChromePrompt* impl, |
| mojo::Message* message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder); |
| }; |
| |
| template <typename ImplRefTraits = |
| mojo::RawPtrImplRefTraits<ChromePrompt>> |
| class ChromePromptStub |
| : public NON_EXPORTED_BASE(mojo::MessageReceiverWithResponderStatus) { |
| public: |
| using ImplPointerType = typename ImplRefTraits::PointerType; |
| |
| ChromePromptStub() {} |
| ~ChromePromptStub() 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 ChromePromptStubDispatch::Accept( |
| ImplRefTraits::GetRawPointer(&sink_), message); |
| } |
| |
| bool AcceptWithResponder( |
| mojo::Message* message, |
| std::unique_ptr<mojo::MessageReceiverWithStatus> responder) override { |
| if (ImplRefTraits::IsNull(sink_)) |
| return false; |
| return ChromePromptStubDispatch::AcceptWithResponder( |
| ImplRefTraits::GetRawPointer(&sink_), message, std::move(responder)); |
| } |
| |
| private: |
| ImplPointerType sink_; |
| }; |
| class ChromePromptRequestValidator : public NON_EXPORTED_BASE(mojo::MessageReceiver) { |
| public: |
| bool Accept(mojo::Message* message) override; |
| }; |
| class ChromePromptResponseValidator : public NON_EXPORTED_BASE(mojo::MessageReceiver) { |
| public: |
| bool Accept(mojo::Message* message) override; |
| }; |
| |
| |
| class ObservedBehaviours { |
| public: |
| using DataView = ObservedBehavioursDataView; |
| using Data_ = internal::ObservedBehaviours_Data; |
| |
| template <typename... Args> |
| static ObservedBehavioursPtr New(Args&&... args) { |
| return ObservedBehavioursPtr( |
| base::in_place, |
| std::forward<Args>(args)...); |
| } |
| |
| template <typename U> |
| static ObservedBehavioursPtr From(const U& u) { |
| return mojo::TypeConverter<ObservedBehavioursPtr, U>::Convert(u); |
| } |
| |
| template <typename U> |
| U To() const { |
| return mojo::TypeConverter<U, ObservedBehaviours>::Convert(*this); |
| } |
| |
| |
| ObservedBehaviours(); |
| |
| ObservedBehaviours( |
| bool ad_injector, |
| bool settings_hijacker, |
| bool extensions_injector, |
| bool dropper); |
| |
| ~ObservedBehaviours(); |
| |
| // Clone() is a template so it is only instantiated if it is used. Thus, the |
| // bindings generator does not need to know whether Clone() or copy |
| // constructor/assignment are available for members. |
| template <typename StructPtrType = ObservedBehavioursPtr> |
| ObservedBehavioursPtr Clone() const; |
| |
| // Equals() is a template so it is only instantiated if it is used. Thus, the |
| // bindings generator does not need to know whether Equals() or == operator |
| // are available for members. |
| template <typename T, |
| typename std::enable_if<std::is_same< |
| T, ObservedBehaviours>::value>::type* = nullptr> |
| bool Equals(const T& other) const; |
| size_t Hash(size_t seed) const; |
| |
| template <typename UserType> |
| static std::vector<uint8_t> Serialize(UserType* input) { |
| return mojo::internal::StructSerializeImpl< |
| ObservedBehaviours::DataView, std::vector<uint8_t>>(input); |
| } |
| |
| template <typename UserType> |
| static bool Deserialize(const std::vector<uint8_t>& input, |
| UserType* output) { |
| return mojo::internal::StructDeserializeImpl< |
| ObservedBehaviours::DataView, std::vector<uint8_t>>( |
| input, output, Validate); |
| } |
| |
| bool ad_injector; |
| bool settings_hijacker; |
| bool extensions_injector; |
| bool dropper; |
| |
| private: |
| static bool Validate(const void* data, |
| mojo::internal::ValidationContext* validation_context); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| class UwS { |
| public: |
| using DataView = UwSDataView; |
| using Data_ = internal::UwS_Data; |
| |
| template <typename... Args> |
| static UwSPtr New(Args&&... args) { |
| return UwSPtr( |
| base::in_place, |
| std::forward<Args>(args)...); |
| } |
| |
| template <typename U> |
| static UwSPtr From(const U& u) { |
| return mojo::TypeConverter<UwSPtr, U>::Convert(u); |
| } |
| |
| template <typename U> |
| U To() const { |
| return mojo::TypeConverter<U, UwS>::Convert(*this); |
| } |
| |
| |
| UwS(); |
| |
| UwS( |
| int32_t id, |
| const std::string& name, |
| ObservedBehavioursPtr observed_behaviours, |
| const std::vector<base::FilePath>& files_to_delete); |
| |
| ~UwS(); |
| |
| // Clone() is a template so it is only instantiated if it is used. Thus, the |
| // bindings generator does not need to know whether Clone() or copy |
| // constructor/assignment are available for members. |
| template <typename StructPtrType = UwSPtr> |
| UwSPtr Clone() const; |
| |
| // Equals() is a template so it is only instantiated if it is used. Thus, the |
| // bindings generator does not need to know whether Equals() or == operator |
| // are available for members. |
| template <typename T, |
| typename std::enable_if<std::is_same< |
| T, UwS>::value>::type* = nullptr> |
| bool Equals(const T& other) const; |
| |
| template <typename UserType> |
| static std::vector<uint8_t> Serialize(UserType* input) { |
| return mojo::internal::StructSerializeImpl< |
| UwS::DataView, std::vector<uint8_t>>(input); |
| } |
| |
| template <typename UserType> |
| static bool Deserialize(const std::vector<uint8_t>& input, |
| UserType* output) { |
| return mojo::internal::StructDeserializeImpl< |
| UwS::DataView, std::vector<uint8_t>>( |
| input, output, Validate); |
| } |
| |
| int32_t id; |
| std::string name; |
| ObservedBehavioursPtr observed_behaviours; |
| std::vector<base::FilePath> files_to_delete; |
| |
| private: |
| static bool Validate(const void* data, |
| mojo::internal::ValidationContext* validation_context); |
| DISALLOW_COPY_AND_ASSIGN(UwS); |
| }; |
| |
| |
| template <typename StructPtrType> |
| ObservedBehavioursPtr ObservedBehaviours::Clone() const { |
| return New( |
| mojo::Clone(ad_injector), |
| mojo::Clone(settings_hijacker), |
| mojo::Clone(extensions_injector), |
| mojo::Clone(dropper) |
| ); |
| } |
| |
| template <typename T, |
| typename std::enable_if<std::is_same< |
| T, ObservedBehaviours>::value>::type*> |
| bool ObservedBehaviours::Equals(const T& other) const { |
| if (!mojo::Equals(this->ad_injector, other.ad_injector)) |
| return false; |
| if (!mojo::Equals(this->settings_hijacker, other.settings_hijacker)) |
| return false; |
| if (!mojo::Equals(this->extensions_injector, other.extensions_injector)) |
| return false; |
| if (!mojo::Equals(this->dropper, other.dropper)) |
| return false; |
| return true; |
| } |
| template <typename StructPtrType> |
| UwSPtr UwS::Clone() const { |
| return New( |
| mojo::Clone(id), |
| mojo::Clone(name), |
| mojo::Clone(observed_behaviours), |
| mojo::Clone(files_to_delete) |
| ); |
| } |
| |
| template <typename T, |
| typename std::enable_if<std::is_same< |
| T, UwS>::value>::type*> |
| bool UwS::Equals(const T& other) const { |
| if (!mojo::Equals(this->id, other.id)) |
| return false; |
| if (!mojo::Equals(this->name, other.name)) |
| return false; |
| if (!mojo::Equals(this->observed_behaviours, other.observed_behaviours)) |
| return false; |
| if (!mojo::Equals(this->files_to_delete, other.files_to_delete)) |
| return false; |
| return true; |
| } |
| |
| |
| } // namespace mojom |
| } // namespace chrome_cleaner |
| |
| namespace mojo { |
| |
| |
| template <> |
| struct StructTraits<::chrome_cleaner::mojom::ObservedBehaviours::DataView, |
| ::chrome_cleaner::mojom::ObservedBehavioursPtr> { |
| static bool IsNull(const ::chrome_cleaner::mojom::ObservedBehavioursPtr& input) { return !input; } |
| static void SetToNull(::chrome_cleaner::mojom::ObservedBehavioursPtr* output) { output->reset(); } |
| |
| static decltype(::chrome_cleaner::mojom::ObservedBehaviours::ad_injector) ad_injector( |
| const ::chrome_cleaner::mojom::ObservedBehavioursPtr& input) { |
| return input->ad_injector; |
| } |
| |
| static decltype(::chrome_cleaner::mojom::ObservedBehaviours::settings_hijacker) settings_hijacker( |
| const ::chrome_cleaner::mojom::ObservedBehavioursPtr& input) { |
| return input->settings_hijacker; |
| } |
| |
| static decltype(::chrome_cleaner::mojom::ObservedBehaviours::extensions_injector) extensions_injector( |
| const ::chrome_cleaner::mojom::ObservedBehavioursPtr& input) { |
| return input->extensions_injector; |
| } |
| |
| static decltype(::chrome_cleaner::mojom::ObservedBehaviours::dropper) dropper( |
| const ::chrome_cleaner::mojom::ObservedBehavioursPtr& input) { |
| return input->dropper; |
| } |
| |
| static bool Read(::chrome_cleaner::mojom::ObservedBehaviours::DataView input, ::chrome_cleaner::mojom::ObservedBehavioursPtr* output); |
| }; |
| |
| |
| template <> |
| struct StructTraits<::chrome_cleaner::mojom::UwS::DataView, |
| ::chrome_cleaner::mojom::UwSPtr> { |
| static bool IsNull(const ::chrome_cleaner::mojom::UwSPtr& input) { return !input; } |
| static void SetToNull(::chrome_cleaner::mojom::UwSPtr* output) { output->reset(); } |
| |
| static decltype(::chrome_cleaner::mojom::UwS::id) id( |
| const ::chrome_cleaner::mojom::UwSPtr& input) { |
| return input->id; |
| } |
| |
| static const decltype(::chrome_cleaner::mojom::UwS::name)& name( |
| const ::chrome_cleaner::mojom::UwSPtr& input) { |
| return input->name; |
| } |
| |
| static const decltype(::chrome_cleaner::mojom::UwS::observed_behaviours)& observed_behaviours( |
| const ::chrome_cleaner::mojom::UwSPtr& input) { |
| return input->observed_behaviours; |
| } |
| |
| static const decltype(::chrome_cleaner::mojom::UwS::files_to_delete)& files_to_delete( |
| const ::chrome_cleaner::mojom::UwSPtr& input) { |
| return input->files_to_delete; |
| } |
| |
| static bool Read(::chrome_cleaner::mojom::UwS::DataView input, ::chrome_cleaner::mojom::UwSPtr* output); |
| }; |
| |
| } // namespace mojo |
| |
| #endif // COMPONENTS_CHROME_CLEANER_PUBLIC_INTERFACES_CHROME_PROMPT_MOJOM_H_ |