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