Replace scoped_ptr With std::unique_ptr
(This is a merge of http://go/wvgerrit/65782) We have had our own scoped_ptr implementation that is used throughout the codebase. Now that we support C++11, we can replace these with std::unique_ptr. Doing this replacement exposed a few places where the two were not interchangeable. OEMCrypto Ref was doing some unsafe things with passing scoped_ptrs to functions and has been updated to use move semantics. And a few constructors were explicitly constructing a scoped_ptr with NULL, which is ambiguous with std::unique_ptr. These have been replaced with default constructor calls. Bug: 111851141 Test: CE CDM Unit Tests Test: Android Unit Tests Change-Id: I37d6d7aad4906709381c74f0c5439f826d2be768
This commit is contained in:
@@ -60,11 +60,12 @@ class UsagePropertySet : public CdmClientPropertySet {
|
||||
bool CdmEngine::seeded_ = false;
|
||||
|
||||
CdmEngine::CdmEngine(FileSystem* file_system, const std::string& spoid)
|
||||
: cert_provisioning_(NULL),
|
||||
: cert_provisioning_(),
|
||||
cert_provisioning_requested_security_level_(kLevelDefault),
|
||||
file_system_(file_system),
|
||||
spoid_(spoid),
|
||||
usage_session_(NULL),
|
||||
usage_session_(),
|
||||
usage_property_set_(),
|
||||
last_usage_information_update_time_(0) {
|
||||
assert(file_system);
|
||||
if (!seeded_) {
|
||||
@@ -126,7 +127,7 @@ CdmResponseType CdmEngine::OpenSession(
|
||||
|
||||
CloseExpiredReleaseSessions();
|
||||
|
||||
scoped_ptr<CdmSession> new_session(new CdmSession(file_system_,
|
||||
std::unique_ptr<CdmSession> new_session(new CdmSession(file_system_,
|
||||
metrics_.AddSession()));
|
||||
CdmResponseType sts = new_session->Init(property_set, forced_session_id,
|
||||
event_listener);
|
||||
@@ -491,7 +492,7 @@ CdmResponseType CdmEngine::QueryStatus(SecurityLevel security_level,
|
||||
const std::string& query_token,
|
||||
std::string* query_response) {
|
||||
LOGI("CdmEngine::QueryStatus");
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics()));
|
||||
CdmResponseType status;
|
||||
M_TIME(
|
||||
@@ -833,7 +834,7 @@ CdmResponseType CdmEngine::HandleProvisioningResponse(
|
||||
if (NULL == cert_provisioning_.get()) {
|
||||
// Certificate provisioning object has been released. Check if a concurrent
|
||||
// provisioning attempt has succeeded before declaring failure.
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics()));
|
||||
CdmResponseType status;
|
||||
M_TIME(
|
||||
@@ -889,7 +890,7 @@ bool CdmEngine::IsProvisioned(CdmSecurityLevel security_level) {
|
||||
CdmResponseType CdmEngine::Unprovision(CdmSecurityLevel security_level) {
|
||||
// Devices with baked-in DRM certs cannot be reprovisioned and therefore must
|
||||
// not be unprovisioned.
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics()));
|
||||
CdmClientTokenType token_type = kClientTokenUninitialized;
|
||||
CdmResponseType res = crypto_session->GetProvisioningMethod(
|
||||
@@ -923,7 +924,7 @@ CdmResponseType CdmEngine::Unprovision(CdmSecurityLevel security_level) {
|
||||
}
|
||||
|
||||
CdmResponseType CdmEngine::DeleteUsageTable(CdmSecurityLevel security_level) {
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics()));
|
||||
CdmResponseType status;
|
||||
M_TIME(
|
||||
@@ -1006,7 +1007,7 @@ CdmResponseType CdmEngine::DeleteUsageRecord(const std::string& app_id,
|
||||
}
|
||||
|
||||
// Got provider token. Remove from OEMCrypto.
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics()));
|
||||
CdmResponseType status = crypto_session->Open(
|
||||
security_level == kSecurityLevelL3 ? kLevel3 : kLevelDefault);
|
||||
@@ -1215,7 +1216,7 @@ CdmResponseType CdmEngine::RemoveAllUsageInfo(
|
||||
}
|
||||
|
||||
// Got at least one provider token. Remove from OEMCrypto.
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics()));
|
||||
CdmResponseType status = crypto_session->Open(
|
||||
security_level == kSecurityLevelL3 ? kLevel3 : kLevelDefault);
|
||||
@@ -1369,7 +1370,7 @@ CdmResponseType CdmEngine::RemoveUsageInfo(
|
||||
handle.DeleteUsageInfo(
|
||||
DeviceFiles::GetUsageInfoFileName(app_id),
|
||||
provider_session_token);
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics()));
|
||||
status = crypto_session->Open(
|
||||
static_cast<CdmSecurityLevel>(j) == kSecurityLevelL3
|
||||
@@ -1807,7 +1808,7 @@ void CdmEngine::DeleteAllUsageReportsUponFactoryReset() {
|
||||
|
||||
if (!file_system_->Exists(device_base_path_level1) &&
|
||||
!file_system_->Exists(device_base_path_level3)) {
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics()));
|
||||
CdmResponseType status;
|
||||
M_TIME(
|
||||
|
||||
@@ -2577,7 +2577,8 @@ void CryptoSession::IncrementIV(uint64_t increase_by,
|
||||
|
||||
// The factory will either be set by WvCdmTestBase, or a default factory is
|
||||
// created on the first call to MakeCryptoSession.
|
||||
scoped_ptr<CryptoSessionFactory> CryptoSession::factory_(NULL);
|
||||
std::unique_ptr<CryptoSessionFactory> CryptoSession::factory_ =
|
||||
std::unique_ptr<CryptoSessionFactory>();
|
||||
|
||||
CryptoSession* CryptoSession::MakeCryptoSession(
|
||||
metrics::CryptoMetrics* crypto_metrics) {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "file_store.h"
|
||||
@@ -28,7 +29,6 @@
|
||||
#include "log.h"
|
||||
#include "metrics_collections.h"
|
||||
#include "properties.h"
|
||||
#include "scoped_ptr.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
|
||||
using namespace wvoec3;
|
||||
@@ -938,7 +938,7 @@ class Adapter {
|
||||
}
|
||||
};
|
||||
|
||||
static wvcdm::scoped_ptr<Adapter> gAdapter;
|
||||
static std::unique_ptr<Adapter> gAdapter;
|
||||
} // namespace
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
@@ -16,7 +16,7 @@ bool Properties::oem_crypto_use_fifo_;
|
||||
bool Properties::oem_crypto_use_userspace_buffers_;
|
||||
bool Properties::provisioning_messages_are_binary_;
|
||||
bool Properties::allow_service_certificate_requests_;
|
||||
scoped_ptr<CdmClientPropertySetMap> Properties::session_property_set_;
|
||||
std::unique_ptr<CdmClientPropertySetMap> Properties::session_property_set_;
|
||||
|
||||
bool Properties::AddSessionPropertySet(
|
||||
const CdmSessionId& session_id, CdmClientPropertySet* property_set) {
|
||||
|
||||
@@ -282,7 +282,7 @@ CdmResponseType UsageTableHeader::MoveEntry(
|
||||
|
||||
// crypto_session points to an object whose scope is this method or a test
|
||||
// object whose scope is the lifetime of this class
|
||||
scoped_ptr<CryptoSession> scoped_crypto_session;
|
||||
std::unique_ptr<CryptoSession> scoped_crypto_session;
|
||||
CryptoSession* crypto_session = test_crypto_session_.get();
|
||||
if (crypto_session == NULL) {
|
||||
scoped_crypto_session.reset((CryptoSession::MakeCryptoSession(metrics)));
|
||||
@@ -476,7 +476,7 @@ CdmResponseType UsageTableHeader::Shrink(
|
||||
|
||||
// crypto_session points to an object whose scope is this method or a test
|
||||
// object whose scope is the lifetime of this class
|
||||
scoped_ptr<CryptoSession> scoped_crypto_session;
|
||||
std::unique_ptr<CryptoSession> scoped_crypto_session;
|
||||
CryptoSession* crypto_session = test_crypto_session_.get();
|
||||
if (crypto_session == NULL) {
|
||||
scoped_crypto_session.reset((CryptoSession::MakeCryptoSession(metrics)));
|
||||
@@ -549,7 +549,7 @@ bool UsageTableHeader::UpgradeLicensesFromUsageTable(
|
||||
|
||||
if (provider_session_token.empty()) continue;
|
||||
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics));
|
||||
CdmResponseType status = crypto_session->Open(requested_security_level_);
|
||||
|
||||
@@ -632,7 +632,7 @@ bool UsageTableHeader::UpgradeUsageInfoFromUsageTable(
|
||||
continue;
|
||||
}
|
||||
|
||||
scoped_ptr<CryptoSession> crypto_session(
|
||||
std::unique_ptr<CryptoSession> crypto_session(
|
||||
CryptoSession::MakeCryptoSession(metrics));
|
||||
CdmResponseType status = crypto_session->Open(requested_security_level_);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user