morrita | 81b17e0 | 2015-02-06 00:58:30 | [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_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ |
| 6 | #define IPC_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ |
| 7 | |
| 8 | #include "base/files/file.h" |
avi | 246998d8 | 2015-12-22 02:39:04 | [diff] [blame^] | 9 | #include "base/macros.h" |
| 10 | #include "build/build_config.h" |
morrita | 81b17e0 | 2015-02-06 00:58:30 | [diff] [blame] | 11 | #include "ipc/ipc_export.h" |
| 12 | #include "ipc/ipc_message_attachment.h" |
rockot | 85dce086 | 2015-11-13 01:33:59 | [diff] [blame] | 13 | #include "mojo/public/cpp/system/handle.h" |
morrita | 81b17e0 | 2015-02-06 00:58:30 | [diff] [blame] | 14 | |
| 15 | namespace IPC { |
| 16 | |
| 17 | namespace internal { |
| 18 | |
| 19 | // A MessageAttachment that holds a MojoHandle. |
| 20 | // * On the sending side, every Mojo handle is a MessagePipe. This is because |
| 21 | // any platform files are wrapped by PlatformFileAttachment. |
| 22 | // * On the receiving side, the handle can be either MessagePipe or wrapped |
| 23 | // platform file: All files, not only MessagePipes are wrapped as a |
| 24 | // MojoHandle. The message deserializer should know which type of the object |
| 25 | // the handle wraps. |
| 26 | class IPC_MOJO_EXPORT MojoHandleAttachment : public MessageAttachment { |
| 27 | public: |
| 28 | explicit MojoHandleAttachment(mojo::ScopedHandle handle); |
| 29 | |
| 30 | Type GetType() const override; |
| 31 | |
| 32 | #if defined(OS_POSIX) |
| 33 | // Returns wrapped file if it wraps a file, or |
| 34 | // an invalid fd otherwise. The ownership of handle |
| 35 | // is passed to the caller. |
| 36 | base::PlatformFile TakePlatformFile() override; |
| 37 | #endif // OS_POSIX |
| 38 | |
| 39 | // Returns the owning handle transferring the ownership. |
| 40 | mojo::ScopedHandle TakeHandle(); |
| 41 | |
| 42 | private: |
| 43 | ~MojoHandleAttachment() override; |
| 44 | mojo::ScopedHandle handle_; |
| 45 | |
| 46 | DISALLOW_COPY_AND_ASSIGN(MojoHandleAttachment); |
| 47 | }; |
| 48 | |
| 49 | } // namespace internal |
| 50 | } // namespace IPC |
| 51 | |
| 52 | #endif // IPC_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ |