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:
John W. Bruce
2018-11-14 10:49:53 -08:00
parent fb4d53bae6
commit b182a7445e
35 changed files with 100 additions and 208 deletions

View File

@@ -21,7 +21,6 @@
#include "metrics.pb.h"
#include "OEMCryptoCENC.h"
#include "properties.h"
#include "scoped_ptr.h"
#include "string_conversions.h"
#include "test_base.h"
#include "test_printers.h"

View File

@@ -2,13 +2,15 @@
// source code may only be used and distributed under the Widevine Master
// License Agreement.
#include <memory>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "cdm_session.h"
#include "crypto_key.h"
#include "metrics.pb.h"
#include "properties.h"
#include "scoped_ptr.h"
#include "service_certificate.h"
#include "string_conversions.h"
#include "test_base.h"
@@ -191,7 +193,7 @@ class CdmSessionTest : public WvCdmTestBase {
}
metrics::SessionMetrics metrics_;
scoped_ptr<CdmSession> cdm_session_;
std::unique_ptr<CdmSession> cdm_session_;
MockCdmLicense* license_parser_;
metrics::CryptoMetrics crypto_metrics_;
NiceMock<MockCryptoSession>* crypto_session_;

View File

@@ -3,6 +3,7 @@
// License Agreement.
#include <arpa/inet.h>
#include <memory>
#include <string>
#include <gtest/gtest.h>
@@ -14,7 +15,6 @@
#include "log.h"
#include "metrics.pb.h"
#include "metrics_collections.h"
#include "scoped_ptr.h"
#include "test_base.h"
#include "test_printers.h"
#include "wv_cdm_types.h"
@@ -282,7 +282,7 @@ class CryptoSessionMetricsTest : public WvCdmTestBase {
TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
metrics::CryptoMetrics crypto_metrics;
scoped_ptr<CryptoSession> session(
std::unique_ptr<CryptoSession> session(
CryptoSession::MakeCryptoSession(&crypto_metrics));
session->Open(wvcdm::kLevelDefault);
// Exercise a method that will touch a metric.
@@ -340,7 +340,7 @@ TEST_F(CryptoSessionMetricsTest, OpenSessionValidMetrics) {
TEST_F(CryptoSessionMetricsTest, GetProvisioningTokenValidMetrics) {
metrics::CryptoMetrics crypto_metrics;
scoped_ptr<CryptoSession> session(
std::unique_ptr<CryptoSession> session(
CryptoSession::MakeCryptoSession(&crypto_metrics));
ASSERT_EQ(NO_ERROR, session->Open(wvcdm::kLevelDefault));

View File

@@ -20,7 +20,6 @@
#include "oemcrypto_session_tests_helper.h"
#include "oemcrypto_types.h"
#include "properties.h"
#include "scoped_ptr.h"
#include "string_conversions.h"
#include "test_base.h"
#include "test_printers.h"

View File

@@ -3,10 +3,12 @@
// License Agreement.
#include <errno.h>
#include <memory>
#include <gtest/gtest.h>
#include "http_socket.h"
#include "log.h"
#include "scoped_ptr.h"
#include "string_conversions.h"
#include "url_request.h"
@@ -90,7 +92,7 @@ class HttpSocketTest : public testing::Test {
return true;
}
scoped_ptr<HttpSocket> socket_;
std::unique_ptr<HttpSocket> socket_;
std::string domain_name_;
std::string resource_path_;
};

View File

@@ -2,6 +2,8 @@
// source code may only be used and distributed under the Widevine Master
// License Agreement.
#include <memory>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -10,7 +12,6 @@
#include "metrics_collections.h"
#include "policy_engine.h"
#include "mock_clock.h"
#include "scoped_ptr.h"
#include "test_base.h"
#include "test_printers.h"
#include "wv_cdm_event_listener.h"
@@ -215,7 +216,7 @@ class PolicyEngineConstraintsTest : public WvCdmTestBase {
expected_has_new_usable_key));
}
scoped_ptr<PolicyEngine> policy_engine_;
std::unique_ptr<PolicyEngine> policy_engine_;
MockClock* mock_clock_;
int64_t current_time_;
metrics::CryptoMetrics dummy_metrics_;

View File

@@ -5,6 +5,7 @@
#include <limits.h>
#include <algorithm>
#include <memory>
#include <sstream>
#include <gmock/gmock.h>
@@ -13,7 +14,6 @@
#include "license.h"
#include "mock_clock.h"
#include "policy_engine.h"
#include "scoped_ptr.h"
#include "test_base.h"
#include "test_printers.h"
#include "wv_cdm_event_listener.h"
@@ -185,7 +185,7 @@ class PolicyEngineTest : public WvCdmTestBase {
NiceMock<HdcpOnlyMockCryptoSession> crypto_session_;
StrictMock<MockCdmEventListener> mock_event_listener_;
MockClock* mock_clock_;
scoped_ptr<PolicyEngine> policy_engine_;
std::unique_ptr<PolicyEngine> policy_engine_;
License license_;
MockFunction<void(int i)> check_;
};