morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 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 | |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 8 | #include "base/files/file.h" |
| 9 | #include "base/macros.h" |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 10 | #include "base/memory/ref_counted.h" |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 11 | #include "base/pickle.h" |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame] | 12 | #include "build/build_config.h" |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 13 | #include "ipc/ipc_export.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. |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 19 | class IPC_EXPORT MessageAttachment : public base::Pickle::Attachment { |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 20 | public: |
| 21 | enum Type { |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 22 | TYPE_PLATFORM_FILE, // The instance is |PlatformFileAttachment|. |
| 23 | TYPE_MOJO_HANDLE, // The instance is |MojoHandleAttachment|. |
| 24 | TYPE_BROKERABLE_ATTACHMENT, // The instance is |BrokerableAttachment|. |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | virtual Type GetType() const = 0; |
morrita | 81b17e0 | 2015-02-06 00:58:30 | [diff] [blame] | 28 | |
| 29 | #if defined(OS_POSIX) |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 30 | virtual base::PlatformFile TakePlatformFile() = 0; |
morrita | 81b17e0 | 2015-02-06 00:58:30 | [diff] [blame] | 31 | #endif // OS_POSIX |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 32 | |
| 33 | protected: |
erikchen | fa70536 | 2015-10-30 23:16:29 | [diff] [blame] | 34 | friend class base::RefCountedThreadSafe<MessageAttachment>; |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 35 | MessageAttachment(); |
rockot | 502c94f | 2016-02-03 20:20:16 | [diff] [blame] | 36 | ~MessageAttachment() override; |
morrita | 1aa788c | 2015-01-31 05:45:42 | [diff] [blame] | 37 | |
| 38 | DISALLOW_COPY_AND_ASSIGN(MessageAttachment); |
morrita | 98b7aaa | 2015-01-26 22:42:54 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | } // namespace IPC |
| 42 | |
| 43 | #endif // IPC_IPC_MESSAGE_ATTACHMENT_H_ |