wrapped_platform_handle.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MOJO_CORE_IPCZ_DRIVER_WRAPPED_PLATFORM_HANDLE_H_
  5. #define MOJO_CORE_IPCZ_DRIVER_WRAPPED_PLATFORM_HANDLE_H_
  6. #include <utility>
  7. #include "mojo/core/ipcz_driver/object.h"
  8. #include "mojo/core/system_impl_export.h"
  9. #include "mojo/public/cpp/platform/platform_handle.h"
  10. namespace mojo::core::ipcz_driver {
  11. // Driver object which wraps a single PlatformHandle. PlatformHandles wrapped by
  12. // this object may not be immediately transmissible by the platform's Channel
  13. // implementation, but they can be serialized into a something that is.
  14. class MOJO_SYSTEM_IMPL_EXPORT WrappedPlatformHandle
  15. : public Object<WrappedPlatformHandle> {
  16. public:
  17. WrappedPlatformHandle();
  18. explicit WrappedPlatformHandle(PlatformHandle handle);
  19. PlatformHandle& handle() { return handle_; }
  20. PlatformHandle TakeHandle() { return std::move(handle_); }
  21. static constexpr Type object_type() { return kWrappedPlatformHandle; }
  22. // Object:
  23. void Close() override;
  24. bool IsSerializable() const override;
  25. bool GetSerializedDimensions(Transport& transmitter,
  26. size_t& num_bytes,
  27. size_t& num_handles) override;
  28. bool Serialize(Transport& transmitter,
  29. base::span<uint8_t> data,
  30. base::span<PlatformHandle> handles) override;
  31. static scoped_refptr<WrappedPlatformHandle> Deserialize(
  32. base::span<const uint8_t> data,
  33. base::span<PlatformHandle> handles);
  34. private:
  35. ~WrappedPlatformHandle() override;
  36. PlatformHandle handle_;
  37. };
  38. } // namespace mojo::core::ipcz_driver
  39. #endif // MOJO_CORE_IPCZ_DRIVER_WRAPPED_PLATFORM_HANDLE_H_