| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef IPC_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ | 5 #ifndef IPC_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ |
| 6 #define IPC_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ | 6 #define IPC_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ |
| 7 | 7 |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "ipc/ipc_export.h" | 11 #include "ipc/ipc_export.h" |
| 12 #include "ipc/ipc_message_attachment.h" | 12 #include "ipc/ipc_message_attachment.h" |
| 13 #include "mojo/public/cpp/system/handle.h" | 13 #include "mojo/public/cpp/system/handle.h" |
| 14 | 14 |
| 15 namespace IPC { | 15 namespace IPC { |
| 16 | 16 |
| 17 namespace internal { | 17 namespace internal { |
| 18 | 18 |
| 19 // A MessageAttachment that holds a MojoHandle. | 19 // A MessageAttachment that holds a MojoHandle. |
| 20 // * On the sending side, every Mojo handle is a MessagePipe. This is because | 20 // This can hold any type of transferrable Mojo handle (i.e. message pipe, data |
| 21 // any platform files are wrapped by PlatformFileAttachment. | 21 // pipe, etc), but the receiver is expected to know what type of handle to |
| 22 // * On the receiving side, the handle can be either MessagePipe or wrapped | 22 // expect. |
| 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 { | 23 class IPC_MOJO_EXPORT MojoHandleAttachment : public MessageAttachment { |
| 27 public: | 24 public: |
| 28 explicit MojoHandleAttachment(mojo::ScopedHandle handle); | 25 explicit MojoHandleAttachment(mojo::ScopedHandle handle); |
| 29 | 26 |
| 30 Type GetType() const override; | 27 Type GetType() const override; |
| 31 | 28 |
| 32 #if defined(OS_POSIX) | 29 #if defined(OS_POSIX) |
| 33 // Returns wrapped file if it wraps a file, or | 30 // Should not be called. |
| 34 // an invalid fd otherwise. The ownership of handle | |
| 35 // is passed to the caller. | |
| 36 base::PlatformFile TakePlatformFile() override; | 31 base::PlatformFile TakePlatformFile() override; |
| 37 #endif // OS_POSIX | 32 #endif // OS_POSIX |
| 38 | 33 |
| 39 // Returns the owning handle transferring the ownership. | 34 // Returns the owning handle transferring the ownership. |
| 40 mojo::ScopedHandle TakeHandle(); | 35 mojo::ScopedHandle TakeHandle(); |
| 41 | 36 |
| 42 private: | 37 private: |
| 43 ~MojoHandleAttachment() override; | 38 ~MojoHandleAttachment() override; |
| 44 mojo::ScopedHandle handle_; | 39 mojo::ScopedHandle handle_; |
| 45 | 40 |
| 46 DISALLOW_COPY_AND_ASSIGN(MojoHandleAttachment); | 41 DISALLOW_COPY_AND_ASSIGN(MojoHandleAttachment); |
| 47 }; | 42 }; |
| 48 | 43 |
| 49 } // namespace internal | 44 } // namespace internal |
| 50 } // namespace IPC | 45 } // namespace IPC |
| 51 | 46 |
| 52 #endif // IPC_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ | 47 #endif // IPC_MOJO_IPC_MOJO_HANDLE_ATTACHMENT_H_ |
| OLD | NEW |