1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_ipc_InputStreamUtils_h
8 #define mozilla_ipc_InputStreamUtils_h
10 #include "mozilla/ipc/InputStreamParams.h"
12 #include "nsIInputStream.h"
19 class PFileDescriptorSetChild
;
20 class PFileDescriptorSetParent
;
21 class PChildToParentStreamChild
;
22 class PParentToChildStreamParent
;
24 // Provide two interfaces for sending PParentToChildStream and
25 // PFileDescriptorSet constructor messages.
26 class ParentToChildStreamActorManager
{
28 virtual PParentToChildStreamParent
* SendPParentToChildStreamConstructor(
29 PParentToChildStreamParent
* aActor
) = 0;
30 virtual PFileDescriptorSetParent
* SendPFileDescriptorSetConstructor(
31 const FileDescriptor
& aFD
) = 0;
34 class ChildToParentStreamActorManager
{
36 virtual PChildToParentStreamChild
* SendPChildToParentStreamConstructor(
37 PChildToParentStreamChild
* aActor
) = 0;
38 virtual PFileDescriptorSetChild
* SendPFileDescriptorSetConstructor(
39 const FileDescriptor
& aFD
) = 0;
42 // If you want to serialize an inputStream, please use AutoIPCStream.
43 class InputStreamHelper
{
45 // These 2 methods allow to serialize an inputStream into InputStreamParams.
46 // The manager is needed in case a stream needs to serialize itself as
48 // The stream serializes itself fully only if the resulting IPC message will
49 // be smaller than |aMaxSize|. Otherwise, the stream serializes itself as
50 // IPCRemoteStream, and, its content will be sent to the other side of the IPC
51 // pipe in chunks. This sending can start immediatelly or at the first read
52 // based on the value of |aDelayedStart|. The IPC message size is returned
54 static void SerializeInputStream(nsIInputStream
* aInputStream
,
55 InputStreamParams
& aParams
,
56 nsTArray
<FileDescriptor
>& aFileDescriptors
,
57 bool aDelayedStart
, uint32_t aMaxSize
,
59 ParentToChildStreamActorManager
* aManager
);
61 static void SerializeInputStream(nsIInputStream
* aInputStream
,
62 InputStreamParams
& aParams
,
63 nsTArray
<FileDescriptor
>& aFileDescriptors
,
64 bool aDelayedStart
, uint32_t aMaxSize
,
66 ChildToParentStreamActorManager
* aManager
);
68 // When a stream wants to serialize itself as IPCRemoteStream, it uses one of
70 static void SerializeInputStreamAsPipe(
71 nsIInputStream
* aInputStream
, InputStreamParams
& aParams
,
72 bool aDelayedStart
, ParentToChildStreamActorManager
* aManager
);
74 static void SerializeInputStreamAsPipe(
75 nsIInputStream
* aInputStream
, InputStreamParams
& aParams
,
76 bool aDelayedStart
, ChildToParentStreamActorManager
* aManager
);
78 // After the sending of the inputStream into the IPC pipe, some of the
79 // InputStreamParams data struct needs to be activated (IPCRemoteStream).
80 // These 2 methods do that.
81 static void PostSerializationActivation(InputStreamParams
& aParams
,
85 static void PostSerializationActivation(Maybe
<InputStreamParams
>& aParams
,
89 static already_AddRefed
<nsIInputStream
> DeserializeInputStream(
90 const InputStreamParams
& aParams
,
91 const nsTArray
<FileDescriptor
>& aFileDescriptors
);
95 } // namespace mozilla
97 #endif // mozilla_ipc_InputStreamUtils_h