object.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include "mojo/core/ipcz_driver/object.h"
  5. #include "base/check_op.h"
  6. #include "mojo/core/ipcz_api.h"
  7. namespace mojo::core::ipcz_driver {
  8. ObjectBase::ObjectBase(Type type) : type_(type) {}
  9. ObjectBase::~ObjectBase() = default;
  10. void ObjectBase::Close() {}
  11. bool ObjectBase::IsSerializable() const {
  12. return false;
  13. }
  14. bool ObjectBase::GetSerializedDimensions(Transport& transmitter,
  15. size_t& num_bytes,
  16. size_t& num_handles) {
  17. return false;
  18. }
  19. bool ObjectBase::Serialize(Transport& transmitter,
  20. base::span<uint8_t> data,
  21. base::span<PlatformHandle> handles) {
  22. return false;
  23. }
  24. // static
  25. IpczHandle ObjectBase::Box(scoped_refptr<ObjectBase> object) {
  26. IpczDriverHandle handle = ReleaseAsHandle(std::move(object));
  27. IpczHandle box;
  28. const IpczResult result =
  29. GetIpczAPI().Box(GetIpczNode(), handle, IPCZ_NO_FLAGS, nullptr, &box);
  30. CHECK_EQ(result, IPCZ_RESULT_OK);
  31. return box;
  32. }
  33. // static
  34. IpczDriverHandle ObjectBase::PeekBox(IpczHandle box) {
  35. IpczDriverHandle handle = IPCZ_INVALID_DRIVER_HANDLE;
  36. GetIpczAPI().Unbox(box, IPCZ_UNBOX_PEEK, nullptr, &handle);
  37. return handle;
  38. }
  39. // static
  40. scoped_refptr<ObjectBase> ObjectBase::Unbox(IpczHandle box) {
  41. IpczDriverHandle handle = IPCZ_INVALID_DRIVER_HANDLE;
  42. GetIpczAPI().Unbox(box, IPCZ_NO_FLAGS, nullptr, &handle);
  43. return TakeFromHandle(handle);
  44. }
  45. } // namespace mojo::core::ipcz_driver