Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / localstorage / LSObserver.h
blob55107bc6c47439a8a389bd9883420e91e15507b7
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_dom_localstorage_LSObserver_h
8 #define mozilla_dom_localstorage_LSObserver_h
10 #include "mozilla/Assertions.h"
11 #include "nsISupports.h"
12 #include "nsString.h"
14 namespace mozilla::dom {
16 class LSObserverChild;
18 /**
19 * Effectively just a refcounted life-cycle management wrapper around
20 * LSObserverChild which exists to receive "storage" event information from
21 * other processes. (Same-process events are handled within the process, see
22 * `LSObject::OnChange`.)
24 * ## Lifecycle ##
25 * - Created by LSObject::EnsureObserver via synchronous LSRequest idiom
26 * whenever the first window's origin adds a "storage" event. Placed in the
27 * gLSObservers LSObserverHashtable for subsequent LSObject's via
28 * LSObserver::Get lookup.
29 * - The LSObserverChild directly handles "Observe" messages, shunting them
30 * directly to Storage::NotifyChange which does all the legwork of notifying
31 * windows about "storage" events.
32 * - Destroyed when refcount goes to zero due to all owning LSObjects being
33 * destroyed or having their `LSObject::DropObserver` methods invoked due to
34 * the last "storage" event listener being removed from the owning window.
36 class LSObserver final {
37 friend class LSObject;
39 LSObserverChild* mActor;
41 const nsCString mOrigin;
43 public:
44 static LSObserver* Get(const nsACString& aOrigin);
46 NS_INLINE_DECL_REFCOUNTING(LSObserver)
48 void AssertIsOnOwningThread() const { NS_ASSERT_OWNINGTHREAD(LSObserver); }
50 void SetActor(LSObserverChild* aActor);
52 void ClearActor() {
53 AssertIsOnOwningThread();
54 MOZ_ASSERT(mActor);
56 mActor = nullptr;
59 private:
60 // Only created by LSObject.
61 explicit LSObserver(const nsACString& aOrigin);
63 ~LSObserver();
66 } // namespace mozilla::dom
68 #endif // mozilla_dom_localstorage_LSObserver_h