dom/storage/SessionStorageObserver.cpp
author Jan de Mooij <jdemooij@mozilla.com>
Wed, 13 Feb 2019 06:41:44 +0000
changeset 516733 8c306186cbd7672259b3a730471cfcbe44a9b0d0
parent 515429 04eecadabb485bd398c6c37e258ba47b946e7982
permissions -rw-r--r--
Bug 1526588 - Fix some issues with js::GetFirstGlobalInCompartment and XPCWrappedNativeScope::UpdateWeakPointersInAllScopesAfterGC. r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D19493

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=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/. */

#include "SessionStorageObserver.h"

namespace mozilla {
namespace dom {

namespace {

SessionStorageObserver* gSessionStorageObserver = nullptr;

}  // namespace

SessionStorageObserver::SessionStorageObserver() : mActor(nullptr) {
  AssertIsOnOwningThread();
  MOZ_ASSERT(NextGenLocalStorageEnabled());

  MOZ_ASSERT(!gSessionStorageObserver);
  gSessionStorageObserver = this;
}

SessionStorageObserver::~SessionStorageObserver() {
  AssertIsOnOwningThread();

  if (mActor) {
    mActor->SendDeleteMeInternal();
    MOZ_ASSERT(!mActor, "SendDeleteMeInternal should have cleared!");
  }

  MOZ_ASSERT(gSessionStorageObserver);
  gSessionStorageObserver = nullptr;
}

// static
SessionStorageObserver* SessionStorageObserver::Get() {
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(NextGenLocalStorageEnabled());

  return gSessionStorageObserver;
}

void SessionStorageObserver::SetActor(SessionStorageObserverChild* aActor) {
  AssertIsOnOwningThread();
  MOZ_ASSERT(aActor);
  MOZ_ASSERT(!mActor);

  mActor = aActor;
}

}  // namespace dom
}  // namespace mozilla