SessionStorageObserver.h (1881B)
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_dom_SessionStorageObserver_h 8 #define mozilla_dom_SessionStorageObserver_h 9 10 #include "nsISupportsImpl.h" 11 12 namespace mozilla::dom { 13 14 class SessionStorageObserverChild; 15 16 /** 17 * Effectively just a refcounted life-cycle management wrapper around 18 * SessionStorageObserverChild which exists to receive chrome observer 19 * notifications from the main process. 20 * 21 * ## Lifecycle ## 22 * - Created by SessionStorageManager::SessionStorageManager. Placed in the 23 * gSessionStorageObserver variable for subsequent SessionStorageManager's via 24 * SessionStorageObserver::Get lookup. 25 * - The SessionStorageObserverChild directly handles "Observe" messages, 26 * shunting them directly to StorageObserver::Notify which distributes them to 27 * individual observer sinks. 28 * - Destroyed when refcount goes to zero due to all owning 29 * SessionStorageManager being destroyed. 30 */ 31 class SessionStorageObserver final { 32 friend class SessionStorageManager; 33 34 SessionStorageObserverChild* mActor; 35 36 public: 37 static SessionStorageObserver* Get(); 38 39 NS_INLINE_DECL_REFCOUNTING(SessionStorageObserver) 40 41 void AssertIsOnOwningThread() const { 42 NS_ASSERT_OWNINGTHREAD(SessionStorageObserver); 43 } 44 45 void SetActor(SessionStorageObserverChild* aActor); 46 47 void ClearActor() { 48 AssertIsOnOwningThread(); 49 MOZ_ASSERT(mActor); 50 51 mActor = nullptr; 52 } 53 54 private: 55 // Only created by SessionStorageManager. 56 SessionStorageObserver(); 57 58 ~SessionStorageObserver(); 59 }; 60 61 } // namespace mozilla::dom 62 63 #endif // mozilla_dom_SessionStorageObserver_h