summaryrefslogtreecommitdiffstats
path: root/media/cdm
diff options
context:
space:
mode:
authorjrummell <jrummell@chromium.org>2015-07-06 16:36:01 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-06 23:36:32 +0000
commit78fc986c325af191a8fe2ca121bbd93b6835d45e (patch)
tree7fadcd016bae5e8ba74d1d8b5397aa78171c5bcd /media/cdm
parenta8ff58440771425da799936e663b9c52b99d1157 (diff)
downloadchromium_src-78fc986c325af191a8fe2ca121bbd93b6835d45e.zip
chromium_src-78fc986c325af191a8fe2ca121bbd93b6835d45e.tar.gz
chromium_src-78fc986c325af191a8fe2ca121bbd93b6835d45e.tar.bz2
Lock while using key to prevent Update() from changing it
Since decrypting content happens on the media thread while changing keys happen on the main thread, change the locking when using the keys to prevent accessing a key while it is being updated. BUG=506749 TEST=EME layout tests pass Review URL: https://codereview.chromium.org/1210033005 Cr-Commit-Position: refs/heads/master@{#337517}
Diffstat (limited to 'media/cdm')
-rw-r--r--media/cdm/aes_decryptor.cc9
-rw-r--r--media/cdm/aes_decryptor.h2
2 files changed, 6 insertions, 5 deletions
diff --git a/media/cdm/aes_decryptor.cc b/media/cdm/aes_decryptor.cc
index 6bc7121..8c110fa 100644
--- a/media/cdm/aes_decryptor.cc
+++ b/media/cdm/aes_decryptor.cc
@@ -472,7 +472,8 @@ void AesDecryptor::Decrypt(StreamType stream_type,
encrypted->data_size());
} else {
const std::string& key_id = encrypted->decrypt_config()->key_id();
- DecryptionKey* key = GetKey(key_id);
+ base::AutoLock auto_lock(key_map_lock_);
+ DecryptionKey* key = GetKey_Locked(key_id);
if (!key) {
DVLOG(1) << "Could not find a matching key for the given key ID.";
decrypt_cb.Run(kNoKey, NULL);
@@ -555,9 +556,9 @@ bool AesDecryptor::AddDecryptionKey(const std::string& session_id,
return true;
}
-AesDecryptor::DecryptionKey* AesDecryptor::GetKey(
+AesDecryptor::DecryptionKey* AesDecryptor::GetKey_Locked(
const std::string& key_id) const {
- base::AutoLock auto_lock(key_map_lock_);
+ key_map_lock_.AssertAcquired();
KeyIdToSessionKeysMap::const_iterator key_id_found = key_map_.find(key_id);
if (key_id_found == key_map_.end())
return NULL;
@@ -580,7 +581,7 @@ void AesDecryptor::DeleteKeysForSession(const std::string& session_id) {
base::AutoLock auto_lock(key_map_lock_);
// Remove all keys associated with |session_id|. Since the data is
- // optimized for access in GetKey(), we need to look at each entry in
+ // optimized for access in GetKey_Locked(), we need to look at each entry in
// |key_map_|.
KeyIdToSessionKeysMap::iterator it = key_map_.begin();
while (it != key_map_.end()) {
diff --git a/media/cdm/aes_decryptor.h b/media/cdm/aes_decryptor.h
index 278be95..e254026 100644
--- a/media/cdm/aes_decryptor.h
+++ b/media/cdm/aes_decryptor.h
@@ -124,7 +124,7 @@ class MEDIA_EXPORT AesDecryptor : public MediaKeys,
// Gets a DecryptionKey associated with |key_id|. The AesDecryptor still owns
// the key. Returns NULL if no key is associated with |key_id|.
- DecryptionKey* GetKey(const std::string& key_id) const;
+ DecryptionKey* GetKey_Locked(const std::string& key_id) const;
// Determines if |key_id| is already specified for |session_id|.
bool HasKey(const std::string& session_id, const std::string& key_id);