michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 et : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "PluginIdentifierChild.h" michael@0: #include "PluginModuleChild.h" michael@0: michael@0: namespace mozilla { michael@0: namespace plugins { michael@0: michael@0: void michael@0: PluginIdentifierChild::MakePermanent() michael@0: { michael@0: if (mCanonicalIdentifier) { michael@0: NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, michael@0: "Canonical identifiers should always be permanent."); michael@0: return; // nothing to do michael@0: } michael@0: michael@0: if (!mHashed) { michael@0: NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?"); michael@0: michael@0: PluginIdentifierChild* c = GetCanonical(); michael@0: if (c) { michael@0: NS_ASSERTION(c != this, "How did I get in the hash?"); michael@0: mCanonicalIdentifier = c; michael@0: NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, michael@0: "Canonical identifiers should always be permanent."); michael@0: return; michael@0: } michael@0: michael@0: Hash(); michael@0: mHashed = true; michael@0: return; michael@0: } michael@0: michael@0: if (mTemporaryRefs) { michael@0: SendRetain(); michael@0: mTemporaryRefs = 0; michael@0: } michael@0: } michael@0: michael@0: void michael@0: PluginIdentifierChild::StartTemporary() michael@0: { michael@0: if (mCanonicalIdentifier) { michael@0: NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, michael@0: "Canonical identifiers should always be permanent."); michael@0: return; // nothing to do michael@0: } michael@0: michael@0: if (!mHashed) { michael@0: NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?"); michael@0: michael@0: PluginIdentifierChild* c = GetCanonical(); michael@0: if (c) { michael@0: NS_ASSERTION(c != this, "How did I get in the hash?"); michael@0: mCanonicalIdentifier = c; michael@0: NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, michael@0: "Canonical identifiers should always be permanent."); michael@0: return; michael@0: } michael@0: michael@0: Hash(); michael@0: mHashed = true; michael@0: mTemporaryRefs = 1; michael@0: return; michael@0: } michael@0: michael@0: if (mTemporaryRefs) michael@0: ++mTemporaryRefs; michael@0: } michael@0: michael@0: void michael@0: PluginIdentifierChild::FinishTemporary() michael@0: { michael@0: if (mCanonicalIdentifier) michael@0: return; michael@0: michael@0: NS_ASSERTION(mHashed, "Finishing unhashed identifier?"); michael@0: if (!mTemporaryRefs) michael@0: return; michael@0: michael@0: --mTemporaryRefs; michael@0: if (mTemporaryRefs) michael@0: return; michael@0: michael@0: Unhash(); michael@0: mHashed = false; michael@0: } michael@0: michael@0: PluginIdentifierChild* michael@0: PluginIdentifierChildString::GetCanonical() michael@0: { michael@0: PluginModuleChild* module = static_cast(Manager()); michael@0: return module->mStringIdentifiers.Get(mString); michael@0: } michael@0: michael@0: void michael@0: PluginIdentifierChildString::Hash() michael@0: { michael@0: PluginModuleChild* module = static_cast(Manager()); michael@0: NS_ASSERTION(module->mStringIdentifiers.Get(mString) == nullptr, "Replacing Hash?"); michael@0: module->mStringIdentifiers.Put(mString, this); michael@0: } michael@0: michael@0: void michael@0: PluginIdentifierChildString::Unhash() michael@0: { michael@0: PluginModuleChild* module = static_cast(Manager()); michael@0: NS_ASSERTION(module->mStringIdentifiers.Get(mString) == this, "Incorrect identifier hash?"); michael@0: module->mStringIdentifiers.Remove(mString); michael@0: } michael@0: michael@0: PluginIdentifierChild* michael@0: PluginIdentifierChildInt::GetCanonical() michael@0: { michael@0: PluginModuleChild* module = static_cast(Manager()); michael@0: return module->mIntIdentifiers.Get(mInt); michael@0: } michael@0: michael@0: void michael@0: PluginIdentifierChildInt::Hash() michael@0: { michael@0: PluginModuleChild* module = static_cast(Manager()); michael@0: NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == nullptr, "Replacing Hash?"); michael@0: module->mIntIdentifiers.Put(mInt, this); michael@0: } michael@0: michael@0: void michael@0: PluginIdentifierChildInt::Unhash() michael@0: { michael@0: PluginModuleChild* module = static_cast(Manager()); michael@0: NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == this, "Incorrect identifier hash?"); michael@0: module->mIntIdentifiers.Remove(mInt); michael@0: } michael@0: michael@0: } // namespace mozilla::plugins michael@0: } // namespace mozilla