Bug 1908670 - Home and newtab topic personalization needs region controls r=home...
[gecko.git] / ipc / glue / InputStreamUtils.h
blob27a65b02e20ca0c3bfbc823a144b1b7c09a57f1f
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"
11 #include "nsCOMPtr.h"
12 #include "nsIInputStream.h"
13 #include "nsTArray.h"
15 namespace mozilla {
16 namespace ipc {
18 class FileDescriptor;
20 // If you want to serialize an inputStream, please use SerializeIPCStream or
21 // nsIInputStream directly.
22 class InputStreamHelper {
23 public:
24 static void SerializedComplexity(nsIInputStream* aInputStream,
25 uint32_t aMaxSize, uint32_t* aSizeUsed,
26 uint32_t* aPipes, uint32_t* aTransferables);
28 // These 2 methods allow to serialize an inputStream into InputStreamParams.
29 // The manager is needed in case a stream needs to serialize itself as
30 // IPCRemoteStream.
31 // The stream serializes itself fully only if the resulting IPC message will
32 // be smaller than |aMaxSize|. Otherwise, the stream serializes itself as a
33 // DataPipe, and, its content will be sent to the other side of the IPC pipe
34 // in chunks. The IPC message size is returned into |aSizeUsed|.
35 static void SerializeInputStream(nsIInputStream* aInputStream,
36 InputStreamParams& aParams,
37 uint32_t aMaxSize, uint32_t* aSizeUsed);
39 // When a stream wants to serialize itself as a DataPipe, it uses this method.
40 static void SerializeInputStreamAsPipe(nsIInputStream* aInputStream,
41 InputStreamParams& aParams);
43 static already_AddRefed<nsIInputStream> DeserializeInputStream(
44 const InputStreamParams& aParams);
47 } // namespace ipc
48 } // namespace mozilla
50 #endif // mozilla_ipc_InputStreamUtils_h