SessionStorageObserver.cpp (1432B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "SessionStorageObserver.h" 8 9 #include "StorageIPC.h" 10 #include "mozilla/dom/LocalStorageCommon.h" 11 12 namespace mozilla::dom { 13 14 namespace { 15 16 SessionStorageObserver* gSessionStorageObserver = nullptr; 17 18 } // namespace 19 20 SessionStorageObserver::SessionStorageObserver() : mActor(nullptr) { 21 AssertIsOnOwningThread(); 22 MOZ_ASSERT(NextGenLocalStorageEnabled()); 23 24 MOZ_ASSERT(!gSessionStorageObserver); 25 gSessionStorageObserver = this; 26 } 27 28 SessionStorageObserver::~SessionStorageObserver() { 29 AssertIsOnOwningThread(); 30 31 if (mActor) { 32 mActor->SendDeleteMeInternal(); 33 MOZ_ASSERT(!mActor, "SendDeleteMeInternal should have cleared!"); 34 } 35 36 MOZ_ASSERT(gSessionStorageObserver); 37 gSessionStorageObserver = nullptr; 38 } 39 40 // static 41 SessionStorageObserver* SessionStorageObserver::Get() { 42 MOZ_ASSERT(NS_IsMainThread()); 43 MOZ_ASSERT(NextGenLocalStorageEnabled()); 44 45 return gSessionStorageObserver; 46 } 47 48 void SessionStorageObserver::SetActor(SessionStorageObserverChild* aActor) { 49 AssertIsOnOwningThread(); 50 MOZ_ASSERT(aActor); 51 MOZ_ASSERT(!mActor); 52 53 mActor = aActor; 54 } 55 56 } // namespace mozilla::dom