Commit 08d41ac5 authored by John Rummell's avatar John Rummell Committed by Commit Bot

Add GUARDED_BY annotations to //media/cdm.

Adding the annotation makes it clear which fields are protected by
base::Lock, and enables compile-time analysis to verify this.

BUG=893739,887645
TEST=compiles

Change-Id: I1b8cdd720fe4c30ed800d73bc117a33780593214
Reviewed-on: https://chromium-review.googlesource.com/c/1274832Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Commit-Queue: John Rummell <jrummell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598987}
parent 5dd3f933
......@@ -16,6 +16,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "media/base/cdm_context.h"
#include "media/base/cdm_key_information.h"
#include "media/base/cdm_promise.h"
......@@ -164,7 +165,8 @@ class MEDIA_EXPORT AesDecryptor : public ContentDecryptionModule,
// 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_Locked(const std::string& key_id) const;
DecryptionKey* GetKey_Locked(const std::string& key_id) const
EXCLUSIVE_LOCKS_REQUIRED(key_map_lock_);
// Determines if |key_id| is already specified for |session_id|.
bool HasKey(const std::string& session_id, const std::string& key_id);
......@@ -184,8 +186,8 @@ class MEDIA_EXPORT AesDecryptor : public ContentDecryptionModule,
// Since only Decrypt() is called off the renderer thread, we only need to
// protect |key_map_|, the only member variable that is shared between
// Decrypt() and other methods.
KeyIdToSessionKeysMap key_map_; // Protected by |key_map_lock_|.
mutable base::Lock key_map_lock_; // Protects the |key_map_|.
mutable base::Lock key_map_lock_;
KeyIdToSessionKeysMap key_map_ GUARDED_BY(key_map_lock_);
// Keeps track of current open sessions and their type. Although publicly
// AesDecryptor only supports temporary sessions, ClearKeyPersistentSessionCdm
......@@ -193,12 +195,11 @@ class MEDIA_EXPORT AesDecryptor : public ContentDecryptionModule,
// CdmSessionType for each session.
std::map<std::string, CdmSessionType> open_sessions_;
NewKeyCB new_audio_key_cb_;
NewKeyCB new_video_key_cb_;
// Protect |new_audio_key_cb_| and |new_video_key_cb_| as they are set on the
// main thread but called on the media thread.
mutable base::Lock new_key_cb_lock_;
NewKeyCB new_audio_key_cb_ GUARDED_BY(new_key_cb_lock_);
NewKeyCB new_video_key_cb_ GUARDED_BY(new_key_cb_lock_);
DISALLOW_COPY_AND_ASSIGN(AesDecryptor);
};
......
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "media/base/media_export.h"
#include "media/cdm/cdm_manager_export.h"
......@@ -40,7 +41,8 @@ class CDM_MANAGER_EXPORT CdmManager {
private:
base::Lock lock_;
std::map<int, scoped_refptr<ContentDecryptionModule>> cdm_map_;
std::map<int, scoped_refptr<ContentDecryptionModule>> cdm_map_
GUARDED_BY(lock_);
DISALLOW_COPY_AND_ASSIGN(CdmManager);
};
......
......@@ -10,6 +10,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "media/base/media_export.h"
#include "media/base/player_tracker.h"
......@@ -42,11 +43,9 @@ class MEDIA_EXPORT PlayerTrackerImpl : public PlayerTracker {
base::Closure cdm_unset_cb;
};
// Lock used to serialize access to other data members.
base::Lock lock_;
int next_registration_id_;
std::map<int, PlayerCallbacks> player_callbacks_map_;
int next_registration_id_ GUARDED_BY(lock_);
std::map<int, PlayerCallbacks> player_callbacks_map_ GUARDED_BY(lock_);
DISALLOW_COPY_AND_ASSIGN(PlayerTrackerImpl);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment