transmissible_platform_handle.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_TRANSMISSIBLE_PLATFORM_HANDLE_H_
  5. #define MOJO_CORE_IPCZ_DRIVER_TRANSMISSIBLE_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 to hold a PlatformHandle which the platform's Channel
  12. // implementation can transmit as-is, out-of-band from message data.
  13. //
  14. // TransmissiblePlatformHandle is the only type of driver object that can be
  15. // emitted by the driver's Serialize(), and it's the only kind accepted by its
  16. // Transmit().
  17. //
  18. // Note that this is never used on Windows, where handles are inlined as message
  19. // data during serialization.
  20. class MOJO_SYSTEM_IMPL_EXPORT TransmissiblePlatformHandle
  21. : public Object<TransmissiblePlatformHandle> {
  22. public:
  23. TransmissiblePlatformHandle();
  24. explicit TransmissiblePlatformHandle(PlatformHandle handle);
  25. PlatformHandle& handle() { return handle_; }
  26. PlatformHandle TakeHandle() { return std::move(handle_); }
  27. static constexpr Type object_type() { return kTransmissiblePlatformHandle; }
  28. // Object:
  29. void Close() override;
  30. bool IsSerializable() const override;
  31. bool GetSerializedDimensions(Transport& transmitter,
  32. size_t& num_bytes,
  33. size_t& num_handles) override;
  34. bool Serialize(Transport& transmitter,
  35. base::span<uint8_t> data,
  36. base::span<PlatformHandle> handles) override;
  37. static scoped_refptr<TransmissiblePlatformHandle> Deserialize(
  38. base::span<const uint8_t> data,
  39. base::span<PlatformHandle> handles);
  40. private:
  41. ~TransmissiblePlatformHandle() override;
  42. PlatformHandle handle_;
  43. };
  44. } // namespace mojo::core::ipcz_driver
  45. #endif // MOJO_CORE_IPCZ_DRIVER_TRANSMISSIBLE_PLATFORM_HANDLE_H_