1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef IPC_IPC_MESSAGE_ATTACHMENT_H_ 6 #define IPC_IPC_MESSAGE_ATTACHMENT_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "base/pickle.h" 10 #include "build/build_config.h" 11 #include "ipc/ipc_message_support_export.h" 12 #include "mojo/public/cpp/system/handle.h" 13 14 namespace IPC { 15 16 // Auxiliary data sent with |Message|. This can be a platform file descriptor 17 // or a mojo |MessagePipe|. |GetType()| returns the type of the subclass. 18 class IPC_MESSAGE_SUPPORT_EXPORT MessageAttachment 19 : public base::Pickle::Attachment { 20 public: 21 enum class Type { 22 MOJO_HANDLE, 23 PLATFORM_FILE, 24 WIN_HANDLE, 25 MACH_PORT, 26 FUCHSIA_HANDLE, 27 }; 28 29 static scoped_refptr<MessageAttachment> CreateFromMojoHandle( 30 mojo::ScopedHandle handle, 31 Type type); 32 33 MessageAttachment(const MessageAttachment&) = delete; 34 MessageAttachment& operator=(const MessageAttachment&) = delete; 35 36 virtual Type GetType() const = 0; 37 38 mojo::ScopedHandle TakeMojoHandle(); 39 40 protected: 41 friend class base::RefCountedThreadSafe<MessageAttachment>; 42 MessageAttachment(); 43 ~MessageAttachment() override; 44 }; 45 46 } // namespace IPC 47 48 #endif // IPC_IPC_MESSAGE_ATTACHMENT_H_ 49