tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

InputStreamUtils.h (2046B)


      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/. */
      6 
      7 #ifndef mozilla_ipc_InputStreamUtils_h
      8 #define mozilla_ipc_InputStreamUtils_h
      9 
     10 #include "mozilla/ipc/InputStreamParams.h"
     11 #include "nsCOMPtr.h"
     12 #include "nsIInputStream.h"
     13 #include "nsTArray.h"
     14 
     15 namespace mozilla {
     16 namespace ipc {
     17 
     18 class FileDescriptor;
     19 
     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);
     27 
     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);
     38 
     39  // When a stream wants to serialize itself as a DataPipe, it uses this method.
     40  static void SerializeInputStreamAsPipe(nsIInputStream* aInputStream,
     41                                         InputStreamParams& aParams);
     42 
     43  static already_AddRefed<nsIInputStream> DeserializeInputStream(
     44      const InputStreamParams& aParams);
     45 };
     46 
     47 }  // namespace ipc
     48 }  // namespace mozilla
     49 
     50 #endif  // mozilla_ipc_InputStreamUtils_h