ipc_message_attachment.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2015 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 IPC_IPC_MESSAGE_ATTACHMENT_H_
  5. #define IPC_IPC_MESSAGE_ATTACHMENT_H_
  6. #include "base/memory/ref_counted.h"
  7. #include "base/pickle.h"
  8. #include "build/build_config.h"
  9. #include "ipc/ipc_message_support_export.h"
  10. #include "mojo/public/cpp/system/handle.h"
  11. namespace IPC {
  12. // Auxiliary data sent with |Message|. This can be a platform file descriptor
  13. // or a mojo |MessagePipe|. |GetType()| returns the type of the subclass.
  14. class IPC_MESSAGE_SUPPORT_EXPORT MessageAttachment
  15. : public base::Pickle::Attachment {
  16. public:
  17. enum class Type {
  18. MOJO_HANDLE,
  19. PLATFORM_FILE,
  20. WIN_HANDLE,
  21. MACH_PORT,
  22. FUCHSIA_HANDLE,
  23. };
  24. static scoped_refptr<MessageAttachment> CreateFromMojoHandle(
  25. mojo::ScopedHandle handle,
  26. Type type);
  27. MessageAttachment(const MessageAttachment&) = delete;
  28. MessageAttachment& operator=(const MessageAttachment&) = delete;
  29. virtual Type GetType() const = 0;
  30. mojo::ScopedHandle TakeMojoHandle();
  31. protected:
  32. friend class base::RefCountedThreadSafe<MessageAttachment>;
  33. MessageAttachment();
  34. ~MessageAttachment() override;
  35. };
  36. } // namespace IPC
  37. #endif // IPC_IPC_MESSAGE_ATTACHMENT_H_