summaryrefslogtreecommitdiffstats
path: root/ipc/glue/IPCStreamDestination.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /ipc/glue/IPCStreamDestination.h
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--ipc/glue/IPCStreamDestination.h95
1 files changed, 95 insertions, 0 deletions
diff --git a/ipc/glue/IPCStreamDestination.h b/ipc/glue/IPCStreamDestination.h
new file mode 100644
index 0000000000..8bd0cb3f87
--- /dev/null
+++ b/ipc/glue/IPCStreamDestination.h
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_ipc_IPCStreamDestination_h
+#define mozilla_ipc_IPCStreamDestination_h
+
+#include "mozilla/AlreadyAddRefed.h"
+#include "nsIRunnable.h"
+#include "nsIThread.h"
+
+class nsIInputStream;
+class nsIAsyncInputStream;
+class nsIAsyncOutputStream;
+
+namespace mozilla {
+
+namespace wr {
+struct ByteBuffer;
+} // namespace wr
+
+namespace ipc {
+
+class PChildToParentStreamParent;
+class PParentToChildStreamChild;
+
+// On the destination side, you must simply call TakeReader() upon receiving a
+// reference to the IPCStream{Child,Parent} actor. You do not need to maintain
+// a reference to the actor itself.
+class IPCStreamDestination {
+ public:
+ static IPCStreamDestination* Cast(PChildToParentStreamParent* aActor);
+
+ static IPCStreamDestination* Cast(PParentToChildStreamChild* aActor);
+
+ void SetDelayedStart(bool aDelayedStart);
+
+ void SetLength(int64_t aLength);
+
+ already_AddRefed<nsIInputStream> TakeReader();
+
+ bool IsOnOwningThread() const;
+
+ void DispatchRunnable(already_AddRefed<nsIRunnable>&& aRunnable);
+
+ protected:
+ IPCStreamDestination();
+ virtual ~IPCStreamDestination();
+
+ nsresult Initialize();
+
+ // The implementation of the actor should call these methods.
+
+ void ActorDestroyed();
+
+ void BufferReceived(const wr::ByteBuffer& aBuffer);
+
+ void CloseReceived(nsresult aRv);
+
+#ifdef DEBUG
+ bool HasDelayedStart() const { return mDelayedStart; }
+#endif
+
+ // These methods will be implemented by the actor.
+
+ virtual void StartReading() = 0;
+
+ virtual void RequestClose(nsresult aRv) = 0;
+
+ virtual void TerminateDestination() = 0;
+
+ private:
+ nsCOMPtr<nsIAsyncInputStream> mReader;
+ nsCOMPtr<nsIAsyncOutputStream> mWriter;
+
+ // This is created by TakeReader() if we need to delay the reading of data.
+ // We keep a reference to the stream in order to inform it when the actor goes
+ // away. If that happens, the reading of data will not be possible anymore.
+ class DelayedStartInputStream;
+ RefPtr<DelayedStartInputStream> mDelayedStartInputStream;
+
+ nsCOMPtr<nsIThread> mOwningThread;
+ bool mDelayedStart;
+
+#ifdef MOZ_DEBUG
+ bool mLengthSet;
+#endif
+};
+
+} // namespace ipc
+} // namespace mozilla
+
+#endif // mozilla_ipc_IPCStreamDestination_h