summaryrefslogtreecommitdiffstats
path: root/dom/localstorage/LSObserver.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/localstorage/LSObserver.h
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/localstorage/LSObserver.h')
-rw-r--r--dom/localstorage/LSObserver.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/dom/localstorage/LSObserver.h b/dom/localstorage/LSObserver.h
new file mode 100644
index 0000000000..55107bc6c4
--- /dev/null
+++ b/dom/localstorage/LSObserver.h
@@ -0,0 +1,68 @@
+/* -*- 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_dom_localstorage_LSObserver_h
+#define mozilla_dom_localstorage_LSObserver_h
+
+#include "mozilla/Assertions.h"
+#include "nsISupports.h"
+#include "nsString.h"
+
+namespace mozilla::dom {
+
+class LSObserverChild;
+
+/**
+ * Effectively just a refcounted life-cycle management wrapper around
+ * LSObserverChild which exists to receive "storage" event information from
+ * other processes. (Same-process events are handled within the process, see
+ * `LSObject::OnChange`.)
+ *
+ * ## Lifecycle ##
+ * - Created by LSObject::EnsureObserver via synchronous LSRequest idiom
+ * whenever the first window's origin adds a "storage" event. Placed in the
+ * gLSObservers LSObserverHashtable for subsequent LSObject's via
+ * LSObserver::Get lookup.
+ * - The LSObserverChild directly handles "Observe" messages, shunting them
+ * directly to Storage::NotifyChange which does all the legwork of notifying
+ * windows about "storage" events.
+ * - Destroyed when refcount goes to zero due to all owning LSObjects being
+ * destroyed or having their `LSObject::DropObserver` methods invoked due to
+ * the last "storage" event listener being removed from the owning window.
+ */
+class LSObserver final {
+ friend class LSObject;
+
+ LSObserverChild* mActor;
+
+ const nsCString mOrigin;
+
+ public:
+ static LSObserver* Get(const nsACString& aOrigin);
+
+ NS_INLINE_DECL_REFCOUNTING(LSObserver)
+
+ void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(LSObserver); }
+
+ void SetActor(LSObserverChild* aActor);
+
+ void ClearActor() {
+ AssertIsOnOwningThread();
+ MOZ_ASSERT(mActor);
+
+ mActor = nullptr;
+ }
+
+ private:
+ // Only created by LSObject.
+ explicit LSObserver(const nsACString& aOrigin);
+
+ ~LSObserver();
+};
+
+} // namespace mozilla::dom
+
+#endif // mozilla_dom_localstorage_LSObserver_h