From 67369e80dde57209c6406b94a8ea621e5168b993 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Fri, 19 Dec 2014 09:55:00 +1300 Subject: [PATCH] Bug 1109457 - Use Contains instead of std.find to detect whether we have keys in gmp-clearkey, and don't overwrite old decryptors when we get a new key. r=edwin. --- .../gmp-clearkey/0.1/ClearKeyDecryptionManager.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/media/gmp-clearkey/0.1/ClearKeyDecryptionManager.cpp b/media/gmp-clearkey/0.1/ClearKeyDecryptionManager.cpp index 001f60ca2b81..fb665c62d186 100644 --- a/media/gmp-clearkey/0.1/ClearKeyDecryptionManager.cpp +++ b/media/gmp-clearkey/0.1/ClearKeyDecryptionManager.cpp @@ -145,10 +145,9 @@ ClearKeyDecryptionManager::CreateSession(uint32_t aPromiseId, const vector& sessionKeys = session->GetKeyIds(); vector neededKeys; for (auto it = sessionKeys.begin(); it != sessionKeys.end(); it++) { - if (mDecryptors.find(*it) == mDecryptors.end()) { + if (!Contains(mDecryptors, *it)) { // Need to request this key ID from the client. neededKeys.push_back(*it); - mDecryptors[*it] = nullptr; } else { // We already have a key for this key ID. Mark as usable. mCallback->KeyIdUsable(sessionId.c_str(), sessionId.length(), @@ -272,7 +271,7 @@ ClearKeyDecryptionManager::UpdateSession(uint32_t aPromiseId, for (auto it = keyPairs.begin(); it != keyPairs.end(); it++) { KeyId& keyId = it->mKeyId; - if (mDecryptors.find(keyId) != mDecryptors.end()) { + if (!Contains(mDecryptors, keyId)) { mDecryptors[keyId] = new ClearKeyDecryptor(mCallback, it->mKey); mCallback->KeyIdUsable(aSessionId, aSessionIdLength, &keyId[0], keyId.size()); @@ -349,8 +348,7 @@ ClearKeyDecryptionManager::ClearInMemorySessionData(ClearKeySession* aSession) const vector& keyIds = aSession->GetKeyIds(); for (auto it = keyIds.begin(); it != keyIds.end(); it++) { - MOZ_ASSERT(mDecryptors.find(*it) != mDecryptors.end()); - + MOZ_ASSERT(Contains(mDecryptors, *it)); if (!mDecryptors[*it]->Release()) { mDecryptors.erase(*it); mCallback->KeyIdNotUsable(aSession->Id().c_str(), aSession->Id().size(), @@ -420,8 +418,7 @@ ClearKeyDecryptionManager::Decrypt(GMPBuffer* aBuffer, CK_LOGD("ClearKeyDecryptionManager::Decrypt"); KeyId keyId(aMetadata->KeyId(), aMetadata->KeyId() + aMetadata->KeyIdSize()); - auto itr = mDecryptors.find(keyId); - if (itr == mDecryptors.end() || !(itr->second)) { + if (!Contains(mDecryptors, keyId)) { CK_LOGD("ClearKeyDecryptionManager::Decrypt GMPNoKeyErr"); mCallback->Decrypted(aBuffer, GMPNoKeyErr); return; @@ -438,10 +435,12 @@ ClearKeyDecryptionManager::DecryptingComplete() for (auto it = mSessions.begin(); it != mSessions.end(); it++) { delete it->second; } + mSessions.clear(); for (auto it = mDecryptors.begin(); it != mDecryptors.end(); it++) { delete it->second; } + mDecryptors.clear(); Release(); }