Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=2 et : |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "PluginIdentifierChild.h" |
michael@0 | 8 | #include "PluginModuleChild.h" |
michael@0 | 9 | |
michael@0 | 10 | namespace mozilla { |
michael@0 | 11 | namespace plugins { |
michael@0 | 12 | |
michael@0 | 13 | void |
michael@0 | 14 | PluginIdentifierChild::MakePermanent() |
michael@0 | 15 | { |
michael@0 | 16 | if (mCanonicalIdentifier) { |
michael@0 | 17 | NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, |
michael@0 | 18 | "Canonical identifiers should always be permanent."); |
michael@0 | 19 | return; // nothing to do |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | if (!mHashed) { |
michael@0 | 23 | NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?"); |
michael@0 | 24 | |
michael@0 | 25 | PluginIdentifierChild* c = GetCanonical(); |
michael@0 | 26 | if (c) { |
michael@0 | 27 | NS_ASSERTION(c != this, "How did I get in the hash?"); |
michael@0 | 28 | mCanonicalIdentifier = c; |
michael@0 | 29 | NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, |
michael@0 | 30 | "Canonical identifiers should always be permanent."); |
michael@0 | 31 | return; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | Hash(); |
michael@0 | 35 | mHashed = true; |
michael@0 | 36 | return; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | if (mTemporaryRefs) { |
michael@0 | 40 | SendRetain(); |
michael@0 | 41 | mTemporaryRefs = 0; |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | void |
michael@0 | 46 | PluginIdentifierChild::StartTemporary() |
michael@0 | 47 | { |
michael@0 | 48 | if (mCanonicalIdentifier) { |
michael@0 | 49 | NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, |
michael@0 | 50 | "Canonical identifiers should always be permanent."); |
michael@0 | 51 | return; // nothing to do |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | if (!mHashed) { |
michael@0 | 55 | NS_ASSERTION(mTemporaryRefs == 0, "Not hashed, but temporary refs?"); |
michael@0 | 56 | |
michael@0 | 57 | PluginIdentifierChild* c = GetCanonical(); |
michael@0 | 58 | if (c) { |
michael@0 | 59 | NS_ASSERTION(c != this, "How did I get in the hash?"); |
michael@0 | 60 | mCanonicalIdentifier = c; |
michael@0 | 61 | NS_ASSERTION(mCanonicalIdentifier->mHashed && mCanonicalIdentifier->mTemporaryRefs == 0, |
michael@0 | 62 | "Canonical identifiers should always be permanent."); |
michael@0 | 63 | return; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | Hash(); |
michael@0 | 67 | mHashed = true; |
michael@0 | 68 | mTemporaryRefs = 1; |
michael@0 | 69 | return; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | if (mTemporaryRefs) |
michael@0 | 73 | ++mTemporaryRefs; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | void |
michael@0 | 77 | PluginIdentifierChild::FinishTemporary() |
michael@0 | 78 | { |
michael@0 | 79 | if (mCanonicalIdentifier) |
michael@0 | 80 | return; |
michael@0 | 81 | |
michael@0 | 82 | NS_ASSERTION(mHashed, "Finishing unhashed identifier?"); |
michael@0 | 83 | if (!mTemporaryRefs) |
michael@0 | 84 | return; |
michael@0 | 85 | |
michael@0 | 86 | --mTemporaryRefs; |
michael@0 | 87 | if (mTemporaryRefs) |
michael@0 | 88 | return; |
michael@0 | 89 | |
michael@0 | 90 | Unhash(); |
michael@0 | 91 | mHashed = false; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | PluginIdentifierChild* |
michael@0 | 95 | PluginIdentifierChildString::GetCanonical() |
michael@0 | 96 | { |
michael@0 | 97 | PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
michael@0 | 98 | return module->mStringIdentifiers.Get(mString); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | void |
michael@0 | 102 | PluginIdentifierChildString::Hash() |
michael@0 | 103 | { |
michael@0 | 104 | PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
michael@0 | 105 | NS_ASSERTION(module->mStringIdentifiers.Get(mString) == nullptr, "Replacing Hash?"); |
michael@0 | 106 | module->mStringIdentifiers.Put(mString, this); |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | void |
michael@0 | 110 | PluginIdentifierChildString::Unhash() |
michael@0 | 111 | { |
michael@0 | 112 | PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
michael@0 | 113 | NS_ASSERTION(module->mStringIdentifiers.Get(mString) == this, "Incorrect identifier hash?"); |
michael@0 | 114 | module->mStringIdentifiers.Remove(mString); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | PluginIdentifierChild* |
michael@0 | 118 | PluginIdentifierChildInt::GetCanonical() |
michael@0 | 119 | { |
michael@0 | 120 | PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
michael@0 | 121 | return module->mIntIdentifiers.Get(mInt); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | void |
michael@0 | 125 | PluginIdentifierChildInt::Hash() |
michael@0 | 126 | { |
michael@0 | 127 | PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
michael@0 | 128 | NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == nullptr, "Replacing Hash?"); |
michael@0 | 129 | module->mIntIdentifiers.Put(mInt, this); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | void |
michael@0 | 133 | PluginIdentifierChildInt::Unhash() |
michael@0 | 134 | { |
michael@0 | 135 | PluginModuleChild* module = static_cast<PluginModuleChild*>(Manager()); |
michael@0 | 136 | NS_ASSERTION(module->mIntIdentifiers.Get(mInt) == this, "Incorrect identifier hash?"); |
michael@0 | 137 | module->mIntIdentifiers.Remove(mInt); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | } // namespace mozilla::plugins |
michael@0 | 141 | } // namespace mozilla |