Make Properties::Init() Take Action Only Once
(This is a merge of http://go/wvgerrit/70383) Up until now, implementations of Properties::Init() have had to handle potentially being called multiple times, at any point during runtime. In practice, this has meant little for the actual implementations, and all of them have committed the error of blowing away mutated property state if the method is re-run at the wrong time. This patch makes the platform implementations a private function, Properties::InitOnce(), which Properties::Init() ensures will never be called more than once per run. Bug: 112046733 Test: CE CDM Unit Tests Test: Android Unit Tests Change-Id: If33f5e37abfad5d26da8380b4bc25fc018450970
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "cdm_client_property_set.h"
|
||||
@@ -30,11 +31,14 @@ typedef std::map<CdmSessionId, CdmClientPropertySet*>
|
||||
// Setter methods are provided but their only planned use is for testing.
|
||||
class Properties {
|
||||
public:
|
||||
// Called at least once before any properties are used. Depending on the
|
||||
// platform, this function may be called multiple times. It is called each
|
||||
// time a CdmEngine is created, and when running unit tests it is called in
|
||||
// many tests' SetUp function.
|
||||
static void Init();
|
||||
static void Init() {
|
||||
std::unique_lock<std::mutex> lock(init_mutex_);
|
||||
|
||||
if (!is_initialized_) {
|
||||
InitOnce();
|
||||
is_initialized_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool oem_crypto_use_secure_buffers() {
|
||||
return oem_crypto_use_secure_buffers_;
|
||||
@@ -108,6 +112,11 @@ class Properties {
|
||||
#endif
|
||||
|
||||
private:
|
||||
// Called at least once before any properties are used.
|
||||
static void InitOnce();
|
||||
|
||||
static std::mutex init_mutex_;
|
||||
static bool is_initialized_;
|
||||
static bool oem_crypto_use_secure_buffers_;
|
||||
static bool oem_crypto_use_fifo_;
|
||||
static bool oem_crypto_use_userspace_buffers_;
|
||||
|
||||
@@ -11,6 +11,8 @@ const char* kSecurityLevelDirs[] = {"L1/", "L3/"};
|
||||
} // namespace
|
||||
|
||||
namespace wvcdm {
|
||||
std::mutex Properties::init_mutex_;
|
||||
bool Properties::is_initialized_ = false;
|
||||
bool Properties::oem_crypto_use_secure_buffers_;
|
||||
bool Properties::oem_crypto_use_fifo_;
|
||||
bool Properties::oem_crypto_use_userspace_buffers_;
|
||||
|
||||
@@ -45,7 +45,7 @@ bool GetAndroidProperty(const char* key, std::string* value) {
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
void Properties::Init() {
|
||||
void Properties::InitOnce() {
|
||||
oem_crypto_use_secure_buffers_ = kPropertyOemCryptoUseSecureBuffers;
|
||||
oem_crypto_use_fifo_ = kPropertyOemCryptoUseFifo;
|
||||
oem_crypto_use_userspace_buffers_ = kPropertyOemCryptoUseUserSpaceBuffers;
|
||||
|
||||
Reference in New Issue
Block a user