xref: /aosp_15_r20/external/cronet/ipc/ipc_mojo_handle_attachment.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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_MOJO_HANDLE_ATTACHMENT_H_
6 #define IPC_IPC_MOJO_HANDLE_ATTACHMENT_H_
7 
8 #include "build/build_config.h"
9 #include "ipc/ipc_message_attachment.h"
10 #include "ipc/ipc_message_support_export.h"
11 #include "mojo/public/cpp/system/handle.h"
12 
13 namespace IPC {
14 
15 namespace internal {
16 
17 // A MessageAttachment that holds a MojoHandle.
18 // This can hold any type of transferrable Mojo handle (i.e. message pipe, data
19 // pipe, etc), but the receiver is expected to know what type of handle to
20 // expect.
21 class IPC_MESSAGE_SUPPORT_EXPORT MojoHandleAttachment
22     : public MessageAttachment {
23  public:
24   explicit MojoHandleAttachment(mojo::ScopedHandle handle);
25 
26   MojoHandleAttachment(const MojoHandleAttachment&) = delete;
27   MojoHandleAttachment& operator=(const MojoHandleAttachment&) = delete;
28 
29   Type GetType() const override;
30 
31   // Returns the owning handle transferring the ownership.
32   mojo::ScopedHandle TakeHandle();
33 
34  private:
35   ~MojoHandleAttachment() override;
36   mojo::ScopedHandle handle_;
37 };
38 
39 }  // namespace internal
40 }  // namespace IPC
41 
42 #endif  // IPC_IPC_MOJO_HANDLE_ATTACHMENT_H_
43