xref: /aosp_15_r20/external/libchrome/ipc/ipc_mojo_handle_attachment.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef IPC_IPC_MOJO_HANDLE_ATTACHMENT_H_
6*635a8641SAndroid Build Coastguard Worker #define IPC_IPC_MOJO_HANDLE_ATTACHMENT_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include "base/files/file.h"
9*635a8641SAndroid Build Coastguard Worker #include "base/macros.h"
10*635a8641SAndroid Build Coastguard Worker #include "build/build_config.h"
11*635a8641SAndroid Build Coastguard Worker #include "ipc/ipc_message_attachment.h"
12*635a8641SAndroid Build Coastguard Worker #include "ipc/ipc_message_support_export.h"
13*635a8641SAndroid Build Coastguard Worker #include "mojo/public/cpp/system/handle.h"
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker namespace IPC {
16*635a8641SAndroid Build Coastguard Worker 
17*635a8641SAndroid Build Coastguard Worker namespace internal {
18*635a8641SAndroid Build Coastguard Worker 
19*635a8641SAndroid Build Coastguard Worker // A MessageAttachment that holds a MojoHandle.
20*635a8641SAndroid Build Coastguard Worker // This can hold any type of transferrable Mojo handle (i.e. message pipe, data
21*635a8641SAndroid Build Coastguard Worker // pipe, etc), but the receiver is expected to know what type of handle to
22*635a8641SAndroid Build Coastguard Worker // expect.
23*635a8641SAndroid Build Coastguard Worker class IPC_MESSAGE_SUPPORT_EXPORT MojoHandleAttachment
24*635a8641SAndroid Build Coastguard Worker     : public MessageAttachment {
25*635a8641SAndroid Build Coastguard Worker  public:
26*635a8641SAndroid Build Coastguard Worker   explicit MojoHandleAttachment(mojo::ScopedHandle handle);
27*635a8641SAndroid Build Coastguard Worker 
28*635a8641SAndroid Build Coastguard Worker   Type GetType() const override;
29*635a8641SAndroid Build Coastguard Worker 
30*635a8641SAndroid Build Coastguard Worker   // Returns the owning handle transferring the ownership.
31*635a8641SAndroid Build Coastguard Worker   mojo::ScopedHandle TakeHandle();
32*635a8641SAndroid Build Coastguard Worker 
33*635a8641SAndroid Build Coastguard Worker  private:
34*635a8641SAndroid Build Coastguard Worker   ~MojoHandleAttachment() override;
35*635a8641SAndroid Build Coastguard Worker   mojo::ScopedHandle handle_;
36*635a8641SAndroid Build Coastguard Worker 
37*635a8641SAndroid Build Coastguard Worker   DISALLOW_COPY_AND_ASSIGN(MojoHandleAttachment);
38*635a8641SAndroid Build Coastguard Worker };
39*635a8641SAndroid Build Coastguard Worker 
40*635a8641SAndroid Build Coastguard Worker }  // namespace internal
41*635a8641SAndroid Build Coastguard Worker }  // namespace IPC
42*635a8641SAndroid Build Coastguard Worker 
43*635a8641SAndroid Build Coastguard Worker #endif  // IPC_IPC_MOJO_HANDLE_ATTACHMENT_H_
44