Merge "Added mutex for reserved_license_ids_." into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
da1e3c5de2
@@ -5,6 +5,7 @@
|
|||||||
#ifndef WVCDM_CORE_DEVICE_FILES_H_
|
#ifndef WVCDM_CORE_DEVICE_FILES_H_
|
||||||
#define WVCDM_CORE_DEVICE_FILES_H_
|
#define WVCDM_CORE_DEVICE_FILES_H_
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -369,6 +370,7 @@ class DeviceFiles {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static std::set<std::string> reserved_license_ids_;
|
static std::set<std::string> reserved_license_ids_;
|
||||||
|
static std::mutex reserved_license_ids_mutex_;
|
||||||
|
|
||||||
wvutil::FileSystem* file_system_;
|
wvutil::FileSystem* file_system_;
|
||||||
CdmSecurityLevel security_level_;
|
CdmSecurityLevel security_level_;
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ using video_widevine_client::sdk::
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace wvcdm {
|
namespace wvcdm {
|
||||||
|
using UniqueLock = std::unique_lock<std::mutex>;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const char kEmptyFileName[] = "";
|
const char kEmptyFileName[] = "";
|
||||||
const char kFalse[] = "false";
|
const char kFalse[] = "false";
|
||||||
@@ -364,6 +366,7 @@ const char* DeviceFiles::ResponseTypeToString(ResponseType type) {
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
std::set<std::string> DeviceFiles::reserved_license_ids_;
|
std::set<std::string> DeviceFiles::reserved_license_ids_;
|
||||||
|
std::mutex DeviceFiles::reserved_license_ids_mutex_;
|
||||||
|
|
||||||
DeviceFiles::DeviceFiles(wvutil::FileSystem* file_system)
|
DeviceFiles::DeviceFiles(wvutil::FileSystem* file_system)
|
||||||
: file_system_(file_system),
|
: file_system_(file_system),
|
||||||
@@ -847,6 +850,7 @@ bool DeviceFiles::StoreLicense(const CdmLicenseData& license_data,
|
|||||||
std::string serialized_file;
|
std::string serialized_file;
|
||||||
file.SerializeToString(&serialized_file);
|
file.SerializeToString(&serialized_file);
|
||||||
|
|
||||||
|
UniqueLock lock(reserved_license_ids_mutex_);
|
||||||
reserved_license_ids_.erase(license_data.key_set_id);
|
reserved_license_ids_.erase(license_data.key_set_id);
|
||||||
*result = StoreFileWithHash(license_data.key_set_id + kLicenseFileNameExt,
|
*result = StoreFileWithHash(license_data.key_set_id + kLicenseFileNameExt,
|
||||||
serialized_file);
|
serialized_file);
|
||||||
@@ -984,18 +988,21 @@ bool DeviceFiles::DeleteAllFiles() {
|
|||||||
|
|
||||||
bool DeviceFiles::LicenseExists(const std::string& key_set_id) {
|
bool DeviceFiles::LicenseExists(const std::string& key_set_id) {
|
||||||
RETURN_FALSE_IF_UNINITIALIZED();
|
RETURN_FALSE_IF_UNINITIALIZED();
|
||||||
|
UniqueLock lock(reserved_license_ids_mutex_);
|
||||||
return reserved_license_ids_.count(key_set_id) ||
|
return reserved_license_ids_.count(key_set_id) ||
|
||||||
FileExists(key_set_id + kLicenseFileNameExt);
|
FileExists(key_set_id + kLicenseFileNameExt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceFiles::ReserveLicenseId(const std::string& key_set_id) {
|
bool DeviceFiles::ReserveLicenseId(const std::string& key_set_id) {
|
||||||
RETURN_FALSE_IF_UNINITIALIZED();
|
RETURN_FALSE_IF_UNINITIALIZED();
|
||||||
|
UniqueLock lock(reserved_license_ids_mutex_);
|
||||||
reserved_license_ids_.insert(key_set_id);
|
reserved_license_ids_.insert(key_set_id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceFiles::UnreserveLicenseId(const std::string& key_set_id) {
|
bool DeviceFiles::UnreserveLicenseId(const std::string& key_set_id) {
|
||||||
RETURN_FALSE_IF_UNINITIALIZED();
|
RETURN_FALSE_IF_UNINITIALIZED();
|
||||||
|
UniqueLock lock(reserved_license_ids_mutex_);
|
||||||
reserved_license_ids_.erase(key_set_id);
|
reserved_license_ids_.erase(key_set_id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user