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