From d902366ac89b4806beaeac966b472ce6268712c6 Mon Sep 17 00:00:00 2001 From: "John W. Bruce" Date: Wed, 14 Nov 2018 10:45:57 -0800 Subject: [PATCH 1/4] override, Don't OVERRIDE (This is a merge of http://go/wvgerrit/65263) Now that C++11 is mandatory, we can drop the OVERRIDE macro which was inconsistently used in the codebase in favor of using the override keyword directly. Bug: 111851141 Test: CE CDM Unit Tests Test: Android Build Change-Id: I0b7559624b84feb19740afd63463dadd243412b0 --- .../cdm/core/include/content_key_session.h | 15 +++++++------- .../core/include/entitlement_key_session.h | 7 +++---- libwvdrmengine/cdm/core/include/override.h | 20 ------------------- 3 files changed, 10 insertions(+), 32 deletions(-) delete mode 100644 libwvdrmengine/cdm/core/include/override.h diff --git a/libwvdrmengine/cdm/core/include/content_key_session.h b/libwvdrmengine/cdm/core/include/content_key_session.h index 005dc09e..c3f73255 100644 --- a/libwvdrmengine/cdm/core/include/content_key_session.h +++ b/libwvdrmengine/cdm/core/include/content_key_session.h @@ -7,7 +7,6 @@ #include "key_session.h" #include "metrics_collections.h" -#include "override.h" #include "timer_metric.h" namespace wvcdm { @@ -21,14 +20,14 @@ class ContentKeySession : public KeySession { cipher_mode_(kCipherModeCtr) {} virtual ~ContentKeySession() {} - virtual KeySessionType Type() OVERRIDE { return kDefault; } + virtual KeySessionType Type() override { return kDefault; } // Generate Derived Keys for ContentKeySession - virtual bool GenerateDerivedKeys(const std::string& message) OVERRIDE; + virtual bool GenerateDerivedKeys(const std::string& message) override; // Generate Derived Keys (from session key) for ContentKeySession virtual bool GenerateDerivedKeys(const std::string& message, - const std::string& session_key) OVERRIDE; + const std::string& session_key) override; // Load Keys for ContentKeySession virtual OEMCryptoResult LoadKeys(const std::string& message, @@ -38,22 +37,22 @@ class ContentKeySession : public KeySession { const std::vector& keys, const std::string& provider_session_token, CdmCipherMode* cipher_mode, - const std::string& srm_requirement) OVERRIDE; + const std::string& srm_requirement) override; virtual OEMCryptoResult LoadEntitledContentKeys( - const std::vector&) OVERRIDE { + const std::vector&) override { return OEMCrypto_ERROR_INVALID_CONTEXT; } // Select Key for ContentKeySession virtual OEMCryptoResult SelectKey(const std::string& key_id, - CdmCipherMode cipher_mode) OVERRIDE; + CdmCipherMode cipher_mode) override; // Decrypt for ContentKeySession virtual OEMCryptoResult Decrypt( const CdmDecryptionParameters& params, OEMCrypto_DestBufferDesc& buffer_descriptor, - OEMCrypto_CENCEncryptPatternDesc& pattern_descriptor) OVERRIDE; + OEMCrypto_CENCEncryptPatternDesc& pattern_descriptor) override; protected: virtual OEMCryptoResult LoadKeysAsLicenseType( diff --git a/libwvdrmengine/cdm/core/include/entitlement_key_session.h b/libwvdrmengine/cdm/core/include/entitlement_key_session.h index 518962a8..a052432d 100644 --- a/libwvdrmengine/cdm/core/include/entitlement_key_session.h +++ b/libwvdrmengine/cdm/core/include/entitlement_key_session.h @@ -12,7 +12,6 @@ #include "content_key_session.h" #include "crypto_key.h" #include "metrics_collections.h" -#include "override.h" namespace wvcdm { @@ -32,11 +31,11 @@ class EntitlementKeySession : public ContentKeySession { const std::vector& keys, const std::string& provider_session_token, CdmCipherMode* cipher_mode, - const std::string& srm_requirement) OVERRIDE; + const std::string& srm_requirement) override; virtual OEMCryptoResult LoadEntitledContentKeys( - const std::vector& keys) OVERRIDE; + const std::vector& keys) override; virtual OEMCryptoResult SelectKey(const std::string& key_id, - CdmCipherMode cipher_mode) OVERRIDE; + CdmCipherMode cipher_mode) override; private: // The object returned by this function contains raw pointers to the passed-in diff --git a/libwvdrmengine/cdm/core/include/override.h b/libwvdrmengine/cdm/core/include/override.h deleted file mode 100644 index c913ceca..00000000 --- a/libwvdrmengine/cdm/core/include/override.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. -// TODO: Import to core/, use everywhere. -#ifndef WVCDM_CDM_OVERRIDE_H_ -#define WVCDM_CDM_OVERRIDE_H_ - -#define GCC_HAS_OVERRIDE ( \ - (__GNUC__ > 4) || \ - (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) \ -) - -#if !defined(DISABLE_OVERRIDE_KEYWORD) && \ - (defined(COMPILER_MSVC) || defined(__clang__) || GCC_HAS_OVERRIDE) -#define OVERRIDE override -#else -#define OVERRIDE -#endif - -#endif // WVCDM_CDM_OVERRIDE_H_ From 39cfe6037f5722ddb354008e09a363d794379d2d Mon Sep 17 00:00:00 2001 From: "John W. Bruce" Date: Wed, 14 Nov 2018 10:47:53 -0800 Subject: [PATCH 2/4] Replace UniquePtr with std::unique_ptr (This is a merge of http://go/wvgerrit/65264) Now that we have C++11, we can remove Android's hand-rolled UniquePtr in favor of std::unique_ptr. Bug: 111851141 Test: Android Unit Tests Change-Id: I96c2015aa2422da66a4bcbefb927dacc5f6e782f --- libwvdrmengine/cdm/include/UniquePtr.h | 229 ------------------ .../include/wv_content_decryption_module.h | 4 +- 2 files changed, 2 insertions(+), 231 deletions(-) delete mode 100644 libwvdrmengine/cdm/include/UniquePtr.h diff --git a/libwvdrmengine/cdm/include/UniquePtr.h b/libwvdrmengine/cdm/include/UniquePtr.h deleted file mode 100644 index a5cd794d..00000000 --- a/libwvdrmengine/cdm/include/UniquePtr.h +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UNIQUE_PTR_H_included -#define UNIQUE_PTR_H_included - -#include // For NULL. - -// Default deleter for pointer types. -template -struct DefaultDelete { - enum { type_must_be_complete = sizeof(T) }; - DefaultDelete() {} - void operator()(T* p) const { - delete p; - } -}; - -// Default deleter for array types. -template -struct DefaultDelete { - enum { type_must_be_complete = sizeof(T) }; - void operator()(T* p) const { - delete[] p; - } -}; - -// A smart pointer that deletes the given pointer on destruction. -// Equivalent to C++0x's std::unique_ptr (a combination of boost::scoped_ptr -// and boost::scoped_array). -// Named to be in keeping with Android style but also to avoid -// collision with any other implementation, until we can switch over -// to unique_ptr. -// Use thus: -// UniquePtr c(new C); -template > -class UniquePtr { -public: - // Construct a new UniquePtr, taking ownership of the given raw pointer. - explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) { - } - - ~UniquePtr() { - reset(); - } - - // Accessors. - T& operator*() const { return *mPtr; } - T* operator->() const { return mPtr; } - T* get() const { return mPtr; } - - // Returns the raw pointer and hands over ownership to the caller. - // The pointer will not be deleted by UniquePtr. - T* release() __attribute__((warn_unused_result)) { - T* result = mPtr; - mPtr = NULL; - return result; - } - - // Takes ownership of the given raw pointer. - // If this smart pointer previously owned a different raw pointer, that - // raw pointer will be freed. - void reset(T* ptr = NULL) { - if (ptr != mPtr) { - D()(mPtr); - mPtr = ptr; - } - } - -private: - // The raw pointer. - T* mPtr; - - // Comparing unique pointers is probably a mistake, since they're unique. - template bool operator==(const UniquePtr& p) const; - template bool operator!=(const UniquePtr& p) const; - - UniquePtr(const UniquePtr&) = delete; - UniquePtr & operator=(const UniquePtr&) = delete; -}; - -// Partial specialization for array types. Like std::unique_ptr, this removes -// operator* and operator-> but adds operator[]. -template -class UniquePtr { -public: - explicit UniquePtr(T* ptr = NULL) : mPtr(ptr) { - } - - ~UniquePtr() { - reset(); - } - - T& operator[](size_t i) const { - return mPtr[i]; - } - T* get() const { return mPtr; } - - T* release() __attribute__((warn_unused_result)) { - T* result = mPtr; - mPtr = NULL; - return result; - } - - void reset(T* ptr = NULL) { - if (ptr != mPtr) { - D()(mPtr); - mPtr = ptr; - } - } - -private: - T* mPtr; - - UniquePtr(const UniquePtr&) = delete; - UniquePtr & operator=(const UniquePtr&) = delete; -}; - -#if UNIQUE_PTR_TESTS - -// Run these tests with: -// g++ -g -DUNIQUE_PTR_TESTS -x c++ UniquePtr.h && ./a.out - -#include - -static void assert(bool b) { - if (!b) { - fprintf(stderr, "FAIL\n"); - abort(); - } - fprintf(stderr, "OK\n"); -} -static int cCount = 0; -struct C { - C() { ++cCount; } - ~C() { --cCount; } -}; -static bool freed = false; -struct Freer { - void operator()(int* p) { - assert(*p == 123); - free(p); - freed = true; - } -}; - -int main(int argc, char* argv[]) { - // - // UniquePtr tests... - // - - // Can we free a single object? - { - UniquePtr c(new C); - assert(cCount == 1); - } - assert(cCount == 0); - // Does release work? - C* rawC; - { - UniquePtr c(new C); - assert(cCount == 1); - rawC = c.release(); - } - assert(cCount == 1); - delete rawC; - // Does reset work? - { - UniquePtr c(new C); - assert(cCount == 1); - c.reset(new C); - assert(cCount == 1); - } - assert(cCount == 0); - - // - // UniquePtr tests... - // - - // Can we free an array? - { - UniquePtr cs(new C[4]); - assert(cCount == 4); - } - assert(cCount == 0); - // Does release work? - { - UniquePtr c(new C[4]); - assert(cCount == 4); - rawC = c.release(); - } - assert(cCount == 4); - delete[] rawC; - // Does reset work? - { - UniquePtr c(new C[4]); - assert(cCount == 4); - c.reset(new C[2]); - assert(cCount == 2); - } - assert(cCount == 0); - - // - // Custom deleter tests... - // - assert(!freed); - { - UniquePtr i(reinterpret_cast(malloc(sizeof(int)))); - *i = 123; - } - assert(freed); - return 0; -} -#endif - -#endif // UNIQUE_PTR_H_included diff --git a/libwvdrmengine/cdm/include/wv_content_decryption_module.h b/libwvdrmengine/cdm/include/wv_content_decryption_module.h index b03f05e7..c035a2c9 100644 --- a/libwvdrmengine/cdm/include/wv_content_decryption_module.h +++ b/libwvdrmengine/cdm/include/wv_content_decryption_module.h @@ -6,8 +6,8 @@ #define CDM_BASE_WV_CONTENT_DECRYPTION_MODULE_H_ #include +#include -#include #include #include "cdm_identifier.h" @@ -144,7 +144,7 @@ class WvContentDecryptionModule : public android::RefBase, public TimerHandler { CdmInfo(); FileSystem file_system; - UniquePtr cdm_engine; + std::unique_ptr cdm_engine; }; // Finds the CdmEngine instance for the given identifier, creating one if From fb4d53bae6c61f2e1e20160c27e0b32a3e290e0f Mon Sep 17 00:00:00 2001 From: "John W. Bruce" Date: Wed, 14 Nov 2018 10:48:47 -0800 Subject: [PATCH 3/4] Replace shared_ptr With std::shared_ptr (This is a merge of http://go/wvgerrit/65783) Straightforward patch to replace our shared_ptr implementation with std::shared_ptr, which works identically for all our use cases. Bug: 111851141 Test: CE CDM Unit Tests Test: Android Unit Tests Change-Id: I9e8624dd3cab70a45941a45eb553c1ea0c077d2f --- .../build_and_run_all_unit_tests.sh | 1 - .../cdm/core/include/cdm_session_map.h | 9 +- libwvdrmengine/cdm/core/include/shared_ptr.h | 209 ------------------ libwvdrmengine/cdm/core/src/cdm_engine.cpp | 45 ++-- .../cdm/core/src/cdm_session_map.cpp | 6 +- .../cdm/core/test/shared_ptr_test.cpp | 130 ----------- .../cdm/metrics/include/event_metric.h | 1 - libwvdrmengine/cdm/test/Android.mk | 4 - libwvdrmengine/run_all_unit_tests.sh | 1 - 9 files changed, 29 insertions(+), 377 deletions(-) delete mode 100644 libwvdrmengine/cdm/core/include/shared_ptr.h delete mode 100644 libwvdrmengine/cdm/core/test/shared_ptr_test.cpp diff --git a/libwvdrmengine/build_and_run_all_unit_tests.sh b/libwvdrmengine/build_and_run_all_unit_tests.sh index 238cb736..4136209c 100755 --- a/libwvdrmengine/build_and_run_all_unit_tests.sh +++ b/libwvdrmengine/build_and_run_all_unit_tests.sh @@ -104,7 +104,6 @@ try_adb_push policy_engine_constraints_unittest try_adb_push policy_engine_unittest try_adb_push request_license_test try_adb_push service_certificate_unittest -try_adb_push shared_ptr_test try_adb_push timer_unittest try_adb_push usage_table_header_unittest try_adb_push value_metric_unittest diff --git a/libwvdrmengine/cdm/core/include/cdm_session_map.h b/libwvdrmengine/cdm/core/include/cdm_session_map.h index ac0bacdf..4bec39c2 100644 --- a/libwvdrmengine/cdm/core/include/cdm_session_map.h +++ b/libwvdrmengine/cdm/core/include/cdm_session_map.h @@ -12,12 +12,11 @@ #include "cdm_session.h" #include "disallow_copy_and_assign.h" #include "lock.h" -#include "shared_ptr.h" #include "wv_cdm_types.h" namespace wvcdm { -typedef std::list > CdmSessionList; +typedef std::list > CdmSessionList; // TODO(rfrias): Concurrency protection for this class has moved to CdmEngine. // Add it back when locks to control access to session usage and destruction @@ -40,16 +39,16 @@ class CdmSessionMap { size_t Size() const { return sessions_.size(); } bool FindSession(const CdmSessionId& id, - shared_ptr* session); + std::shared_ptr* session); void GetSessionList(CdmSessionList& sessions); private: - typedef std::map > + typedef std::map > CdmIdToSessionMap; bool FindSessionNoLock(const CdmSessionId& session_id, - shared_ptr* session); + std::shared_ptr* session); CdmIdToSessionMap sessions_; diff --git a/libwvdrmengine/cdm/core/include/shared_ptr.h b/libwvdrmengine/cdm/core/include/shared_ptr.h deleted file mode 100644 index c1596150..00000000 --- a/libwvdrmengine/cdm/core/include/shared_ptr.h +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. -// -// from google3/util/gtl/shared_ptr.h -// from protobuf/src/google/protobuf/stubs/shared_ptr.h - -#ifndef WVCDM_CORE_SHARED_PTR_H__ -#define WVCDM_CORE_SHARED_PTR_H__ - -#include // for swap -#include -#include - -#include "lock.h" -#include "wv_cdm_types.h" - -namespace wvcdm { - -extern Lock shared_ptr_ref_count_lock_; - -} // namespace wvcdm - -namespace { - -bool Barrier_AtomicIncrement(volatile uint32_t* ptr, uint32_t value) { - *ptr += value; - return *ptr; -} -bool NoBarrier_AtomicIncrement(volatile uint32_t* ptr, uint32_t value) { - *ptr += value; - return *ptr; -} - -inline bool RefCountDec(volatile uint32_t *ptr) { - wvcdm::AutoLock auto_lock(wvcdm::shared_ptr_ref_count_lock_); - return Barrier_AtomicIncrement(ptr, -1) != 0; -} - -inline void RefCountInc(volatile uint32_t *ptr) { - wvcdm::AutoLock auto_lock(wvcdm::shared_ptr_ref_count_lock_); - NoBarrier_AtomicIncrement(ptr, 1); -} - -} // namespace - -namespace wvcdm { - -template class shared_ptr; - -// This class is an internal implementation detail for shared_ptr. If two -// shared_ptrs point to the same object, they also share a control block. -// An "empty" shared_pointer refers to NULL and also has a NULL control block. -// It contains all of the state that's needed for reference counting or any -// other kind of resource management. In this implementation the control block -// consists of a single reference count (the number of shared_ptrs that -// share ownership of the object). -class SharedPtrControlBlock { - template friend class shared_ptr; - private: - SharedPtrControlBlock() : refcount_(1) {} - uint32_t refcount_; -}; - -// Forward declaration. The class is defined below. -template class enable_shared_from_this; - -template -class shared_ptr { - public: - typedef T element_type; - - shared_ptr() : ptr_(NULL), control_block_(NULL) {} - - explicit shared_ptr(T* ptr) - : ptr_(ptr), - control_block_(ptr != NULL ? new SharedPtrControlBlock : NULL) { - } - - // Copy constructor: makes this object a copy of ptr, and increments - // the reference count. - template - shared_ptr(const shared_ptr& ptr) - : ptr_(NULL), - control_block_(NULL) { - Initialize(ptr); - } - // Need non-templated version to prevent the compiler-generated default - shared_ptr(const shared_ptr& ptr) - : ptr_(NULL), - control_block_(NULL) { - Initialize(ptr); - } - - // Assignment operator. Replaces the existing shared_ptr with ptr. - // Increment ptr's reference count and decrement the one being replaced. - template - shared_ptr& operator=(const shared_ptr& ptr) { - if (ptr_ != ptr.ptr_) { - shared_ptr me(ptr); // will hold our previous state to be destroyed. - swap(me); - } - return *this; - } - - // Need non-templated version to prevent the compiler-generated default - shared_ptr& operator=(const shared_ptr& ptr) { - if (ptr_ != ptr.ptr_) { - shared_ptr me(ptr); // will hold our previous state to be destroyed. - swap(me); - } - return *this; - } - - ~shared_ptr() { - if (ptr_ != NULL) { - if (!RefCountDec(&control_block_->refcount_)) { - delete ptr_; - delete control_block_; - } - } - } - - // Replaces underlying raw pointer with the one passed in. The reference - // count is set to one (or zero if the pointer is NULL) for the pointer - // being passed in and decremented for the one being replaced. - // - // If you have a compilation error with this code, make sure you aren't - // passing NULL, nullptr, or 0 to this function. Call reset without an - // argument to reset to a null ptr. - template - void reset(Y* p) { - if (p != ptr_) { - shared_ptr tmp(p); - tmp.swap(*this); - } - } - - void reset() { - reset(static_cast(NULL)); - } - - // Exchanges the contents of this with the contents of r. This function - // supports more efficient swapping since it eliminates the need for a - // temporary shared_ptr object. - void swap(shared_ptr& r) { - using std::swap; // http://go/using-std-swap - swap(ptr_, r.ptr_); - swap(control_block_, r.control_block_); - } - - // The following function is useful for gaining access to the underlying - // pointer when a shared_ptr remains in scope so the reference-count is - // known to be > 0 (e.g. for parameter passing). - T* get() const { - return ptr_; - } - - T& operator*() const { - return *ptr_; - } - - T* operator->() const { - return ptr_; - } - - long use_count() const { - return control_block_ ? control_block_->refcount_ : 1; - } - - bool unique() const { - return use_count() == 1; - } - - private: - // If r is non-empty, initialize *this to share ownership with r, - // increasing the underlying reference count. - // If r is empty, *this remains empty. - // Requires: this is empty, namely this->ptr_ == NULL. - template - void Initialize(const shared_ptr& r) { - // This performs a static_cast on r.ptr_ to U*, which is a no-op since it - // is already a U*. So initialization here requires that r.ptr_ is - // implicitly convertible to T*. - InitializeWithStaticCast(r); - } - - // Initializes *this as described in Initialize, but additionally performs a - // static_cast from r.ptr_ (V*) to U*. - // NOTE(gfc): We'd need a more general form to support const_pointer_cast and - // dynamic_pointer_cast, but those operations are sufficiently discouraged - // that supporting static_pointer_cast is sufficient. - template - void InitializeWithStaticCast(const shared_ptr& r) { - if (r.control_block_ != NULL) { - RefCountInc(&r.control_block_->refcount_); - - ptr_ = static_cast(r.ptr_); - control_block_ = r.control_block_; - } - } - - T* ptr_; - SharedPtrControlBlock* control_block_; -}; - -} // namespace wvcdm - -#endif // WVCDM_CORE_SHARED_PTR_H__ diff --git a/libwvdrmengine/cdm/core/src/cdm_engine.cpp b/libwvdrmengine/cdm/core/src/cdm_engine.cpp index ecc16d0d..5dd0e106 100644 --- a/libwvdrmengine/cdm/core/src/cdm_engine.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_engine.cpp @@ -5,10 +5,11 @@ #include "cdm_engine.h" #include -#include #include #include +#include +#include #include #include "cdm_session.h" @@ -30,8 +31,6 @@ const size_t kUsageReportsPerRequest = 1; namespace wvcdm { -Lock shared_ptr_ref_count_lock_; - class UsagePropertySet : public CdmClientPropertySet { public: UsagePropertySet() {} @@ -261,7 +260,7 @@ CdmResponseType CdmEngine::GenerateKeyRequest( id = iter->second.first; } - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(id, &session)) { LOGE("CdmEngine::GenerateKeyRequest: session_id not found = %s", id.c_str()); @@ -337,7 +336,7 @@ CdmResponseType CdmEngine::AddKey(const CdmSessionId& session_id, id = iter->second.first; } - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(id, &session)) { LOGE("CdmEngine::AddKey: session id not found = %s", id.c_str()); return SESSION_NOT_FOUND_3; @@ -381,7 +380,7 @@ CdmResponseType CdmEngine::RestoreKey(const CdmSessionId& session_id, return EMPTY_KEYSET_ID_ENG_4; } - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::RestoreKey: session_id not found = %s ", session_id.c_str()); @@ -404,7 +403,7 @@ CdmResponseType CdmEngine::RestoreKey(const CdmSessionId& session_id, CdmResponseType CdmEngine::RemoveKeys(const CdmSessionId& session_id) { LOGI("CdmEngine::RemoveKeys"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::RemoveKeys: session_id not found = %s", session_id.c_str()); @@ -419,7 +418,7 @@ CdmResponseType CdmEngine::RemoveKeys(const CdmSessionId& session_id) { CdmResponseType CdmEngine::RemoveLicense(const CdmSessionId& session_id) { LOGI("CdmEngine::RemoveLicense"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("session_id not found = %s", session_id.c_str()); return SESSION_NOT_FOUND_19; @@ -432,7 +431,7 @@ CdmResponseType CdmEngine::GenerateRenewalRequest( const CdmSessionId& session_id, CdmKeyRequest* key_request) { LOGI("CdmEngine::GenerateRenewalRequest"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::GenerateRenewalRequest: session_id not found = %s", session_id.c_str()); @@ -461,7 +460,7 @@ CdmResponseType CdmEngine::RenewKey(const CdmSessionId& session_id, const CdmKeyResponse& key_data) { LOGI("CdmEngine::RenewKey"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::RenewKey: session_id not found = %s", session_id.c_str()); return SESSION_NOT_FOUND_7; @@ -653,7 +652,7 @@ CdmResponseType CdmEngine::QueryStatus(SecurityLevel security_level, CdmResponseType CdmEngine::QuerySessionStatus(const CdmSessionId& session_id, CdmQueryMap* query_response) { LOGI("CdmEngine::QuerySessionStatus"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::QuerySessionStatus: session_id not found = %s", session_id.c_str()); @@ -664,7 +663,7 @@ CdmResponseType CdmEngine::QuerySessionStatus(const CdmSessionId& session_id, bool CdmEngine::IsReleaseSession(const CdmSessionId& session_id) { LOGI("CdmEngine::IsReleaseSession"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::IsReleaseSession: session_id not found = %s", session_id.c_str()); @@ -675,7 +674,7 @@ bool CdmEngine::IsReleaseSession(const CdmSessionId& session_id) { bool CdmEngine::IsOfflineSession(const CdmSessionId& session_id) { LOGI("CdmEngine::IsOfflineSession"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::IsOfflineSession: session_id not found = %s", session_id.c_str()); @@ -687,7 +686,7 @@ bool CdmEngine::IsOfflineSession(const CdmSessionId& session_id) { CdmResponseType CdmEngine::QueryKeyStatus(const CdmSessionId& session_id, CdmQueryMap* query_response) { LOGI("CdmEngine::QueryKeyStatus"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::QueryKeyStatus: session_id not found = %s", session_id.c_str()); @@ -704,7 +703,7 @@ CdmResponseType CdmEngine::QueryKeyAllowedUsage(const CdmSessionId& session_id, LOGE("CdmEngine::QueryKeyAllowedUsage: no response destination"); return PARAMETER_NULL; } - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::QueryKeyAllowedUsage: session_id not found = %s", session_id.c_str()); @@ -755,7 +754,7 @@ CdmResponseType CdmEngine::QueryKeyAllowedUsage(const std::string& key_id, CdmResponseType CdmEngine::QueryOemCryptoSessionId( const CdmSessionId& session_id, CdmQueryMap* query_response) { LOGI("CdmEngine::QueryOemCryptoSessionId"); - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::QueryOemCryptoSessionId: session_id not found = %s", session_id.c_str()); @@ -1424,7 +1423,7 @@ CdmResponseType CdmEngine::LoadUsageSession(const CdmKeySetId& key_set_id, return EMPTY_KEYSET_ID_ENG_5; } - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(key_set_id, &session)) { LOGE("CdmEngine::LoadUsageSession: session_id not found = %s ", key_set_id.c_str()); @@ -1510,7 +1509,7 @@ CdmResponseType CdmEngine::Decrypt(const CdmSessionId& session_id, } AutoLock lock(session_map_lock_); - shared_ptr session; + std::shared_ptr session; if (session_id.empty()) { CdmSessionList sessions; session_map_.GetSessionList(sessions); @@ -1551,7 +1550,7 @@ CdmResponseType CdmEngine::GenericEncrypt( LOGE("CdmEngine::GenericEncrypt: no out_buffer provided"); return PARAMETER_NULL; } - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::GenericEncrypt: session_id not found = %s ", session_id.c_str()); @@ -1569,7 +1568,7 @@ CdmResponseType CdmEngine::GenericDecrypt( LOGE("CdmEngine::GenericDecrypt: no out_buffer provided"); return PARAMETER_NULL; } - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::GenericDecrypt: session_id not found = %s ", session_id.c_str()); @@ -1586,7 +1585,7 @@ CdmResponseType CdmEngine::GenericSign( LOGE("CdmEngine::GenericSign: no signature buffer provided"); return PARAMETER_NULL; } - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::GenericSign: session_id not found = %s ", session_id.c_str()); @@ -1599,7 +1598,7 @@ CdmResponseType CdmEngine::GenericVerify( const std::string& session_id, const std::string& message, const std::string& key_id, CdmSigningAlgorithm algorithm, const std::string& signature) { - shared_ptr session; + std::shared_ptr session; if (!session_map_.FindSession(session_id, &session)) { LOGE("CdmEngine::GenericVerify: session_id not found = %s ", session_id.c_str()); @@ -1660,7 +1659,7 @@ bool CdmEngine::FindSessionForKey(const KeyId& key_id, bool CdmEngine::NotifyResolution(const CdmSessionId& session_id, uint32_t width, uint32_t height) { - shared_ptr session; + std::shared_ptr session; if (session_map_.FindSession(session_id, &session)) { session->NotifyResolution(width, height); return true; diff --git a/libwvdrmengine/cdm/core/src/cdm_session_map.cpp b/libwvdrmengine/cdm/core/src/cdm_session_map.cpp index e94a3173..5cf4eae2 100644 --- a/libwvdrmengine/cdm/core/src/cdm_session_map.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_session_map.cpp @@ -29,7 +29,7 @@ void CdmSessionMap::Add(const std::string& id, CdmSession* session) { } bool CdmSessionMap::CloseSession(const std::string& id) { - shared_ptr session; + std::shared_ptr session; if (!FindSessionNoLock(id, &session)) { return false; } @@ -43,12 +43,12 @@ bool CdmSessionMap::Exists(const std::string& id) { } bool CdmSessionMap::FindSession(const CdmSessionId& id, - shared_ptr* session) { + std::shared_ptr* session) { return FindSessionNoLock(id, session); } bool CdmSessionMap::FindSessionNoLock(const CdmSessionId& session_id, - shared_ptr* session) { + std::shared_ptr* session) { CdmIdToSessionMap::iterator iter = sessions_.find(session_id); if (iter == sessions_.end()) { return false; diff --git a/libwvdrmengine/cdm/core/test/shared_ptr_test.cpp b/libwvdrmengine/cdm/core/test/shared_ptr_test.cpp deleted file mode 100644 index 2cf977cd..00000000 --- a/libwvdrmengine/cdm/core/test/shared_ptr_test.cpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. - -#include -#include -#include -#include - -#include "shared_ptr.h" - -#include "log.h" - -namespace wvcdm { - -class SharedPtrTest : public testing::Test { - public: - - static void NoteDeletion() { - deletions++; - } - - class Dummy { - public: - explicit Dummy(int v) : value_(v) { exists_ = true; } - ~Dummy() { - NoteDeletion(); - exists_ = false; - } - bool exists() { return exists_; } - int getValue() { return value_; } - void setValue(int v) { value_ = v; } - private: - bool exists_; - int value_; - }; - - static void ExpectedDeletions(int count) { - ASSERT_TRUE(deletions == count); - deletions = 0; - } - - virtual void SetUpTest() { - deletions = 0; - } - virtual void TearDownTest() { - deletions = 0; - } - private: - static int deletions; -}; - -int SharedPtrTest::deletions = 0; - -TEST_F(SharedPtrTest, NullSingletonCreate) { - shared_ptr sd1; - ASSERT_TRUE(sd1.unique()); - ASSERT_TRUE(sd1.get() == NULL); - ExpectedDeletions(0); -} - -TEST_F(SharedPtrTest, SingletonCreate) { - { - Dummy* d1 = new Dummy(42); - shared_ptr sd1(d1); - ASSERT_TRUE(sd1.unique()); - ASSERT_TRUE(sd1.get() == d1); - ASSERT_TRUE(sd1->getValue() == 42); - } - ExpectedDeletions(1); -} - -TEST_F(SharedPtrTest, ResetToNull) { - Dummy* d1 = new Dummy(42); - shared_ptr sd1(d1); - ASSERT_TRUE(sd1->getValue() == 42); - sd1.reset(); - ExpectedDeletions(1); - ASSERT_TRUE(sd1.get() == NULL); -} - -TEST_F(SharedPtrTest, SharedCreate) { - { - Dummy* d1 = new Dummy(42); - shared_ptr sd1(d1); - { - shared_ptr sd2(sd1); - ASSERT_FALSE(sd1.unique()); - ASSERT_TRUE(sd1.get() == d1); - ASSERT_TRUE(sd2.get() == d1); - ASSERT_TRUE(sd1.use_count() == 2); - } - ExpectedDeletions(0); - ASSERT_TRUE(sd1.use_count() == 1); - } - ExpectedDeletions(1); -} - -TEST_F(SharedPtrTest, SharedInstance) { - Dummy* d1 = new Dummy(42); - { - shared_ptr sd1(d1); - { - shared_ptr sd2(sd1); - ASSERT_FALSE(sd1.unique()); - ASSERT_TRUE(sd1.get() == d1); - ASSERT_TRUE(sd2.get() == d1); - sd2->setValue(55); - ASSERT_TRUE(sd1.use_count() == 2); - } - ExpectedDeletions(0); - ASSERT_TRUE(sd1.use_count() == 1); - ASSERT_TRUE(sd1->getValue() == 55); - } - ExpectedDeletions(1); -} - -TEST_F(SharedPtrTest, Reset) { - { - Dummy* d1 = new Dummy(42); - Dummy* d2 = new Dummy(96); - shared_ptr sd1(d1); - sd1.reset(d2); - ExpectedDeletions(1); - ASSERT_TRUE(sd1->getValue() == 96); - } - ExpectedDeletions(1); -} - -} // namespace wvcdm diff --git a/libwvdrmengine/cdm/metrics/include/event_metric.h b/libwvdrmengine/cdm/metrics/include/event_metric.h index 52fb1c24..020249d9 100644 --- a/libwvdrmengine/cdm/metrics/include/event_metric.h +++ b/libwvdrmengine/cdm/metrics/include/event_metric.h @@ -17,7 +17,6 @@ #include "log.h" #include "metrics.pb.h" #include "pow2bucket.h" -#include "shared_ptr.h" namespace wvcdm { namespace metrics { diff --git a/libwvdrmengine/cdm/test/Android.mk b/libwvdrmengine/cdm/test/Android.mk index 2db10120..d5ca8117 100644 --- a/libwvdrmengine/cdm/test/Android.mk +++ b/libwvdrmengine/cdm/test/Android.mk @@ -107,10 +107,6 @@ test_name := service_certificate_unittest test_src_dir := ../core/test include $(LOCAL_PATH)/unit-test.mk -test_name := shared_ptr_test -test_src_dir := ../core/test -include $(LOCAL_PATH)/unit-test.mk - test_name := timer_unittest test_src_dir := . include $(LOCAL_PATH)/unit-test.mk diff --git a/libwvdrmengine/run_all_unit_tests.sh b/libwvdrmengine/run_all_unit_tests.sh index 33343955..dc5752e1 100755 --- a/libwvdrmengine/run_all_unit_tests.sh +++ b/libwvdrmengine/run_all_unit_tests.sh @@ -102,7 +102,6 @@ adb_shell_run license_unittest adb_shell_run policy_engine_constraints_unittest adb_shell_run policy_engine_unittest adb_shell_run service_certificate_unittest -adb_shell_run shared_ptr_test adb_shell_run timer_unittest adb_shell_run usage_table_header_unittest adb_shell_run value_metric_unittest From b182a7445ed22bc9dcce2408d236b5869a0460d4 Mon Sep 17 00:00:00 2001 From: "John W. Bruce" Date: Wed, 14 Nov 2018 10:49:53 -0800 Subject: [PATCH 4/4] 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 --- libwvdrmengine/cdm/core/include/cdm_engine.h | 7 +- libwvdrmengine/cdm/core/include/cdm_session.h | 10 +-- .../core/include/certificate_provisioning.h | 6 +- .../cdm/core/include/crypto_session.h | 6 +- .../cdm/core/include/device_files.h | 1 - libwvdrmengine/cdm/core/include/license.h | 6 +- .../cdm/core/include/policy_engine.h | 6 +- libwvdrmengine/cdm/core/include/properties.h | 4 +- libwvdrmengine/cdm/core/include/scoped_ptr.h | 67 ------------------- .../cdm/core/include/service_certificate.h | 3 +- .../cdm/core/include/usage_table_header.h | 8 +-- libwvdrmengine/cdm/core/src/cdm_engine.cpp | 23 ++++--- .../cdm/core/src/crypto_session.cpp | 3 +- .../core/src/oemcrypto_adapter_dynamic.cpp | 4 +- libwvdrmengine/cdm/core/src/properties.cpp | 2 +- .../cdm/core/src/usage_table_header.cpp | 8 +-- .../cdm/core/test/cdm_engine_test.cpp | 1 - .../cdm/core/test/cdm_session_unittest.cpp | 6 +- .../cdm/core/test/crypto_session_unittest.cpp | 6 +- .../cdm/core/test/generic_crypto_unittest.cpp | 1 - .../cdm/core/test/http_socket_test.cpp | 6 +- .../policy_engine_constraints_unittest.cpp | 5 +- .../cdm/core/test/policy_engine_unittest.cpp | 4 +- .../metrics/test/counter_metric_unittest.cpp | 1 - .../metrics/test/event_metric_unittest.cpp | 1 - .../metrics/test/value_metric_unittest.cpp | 12 ++-- .../oemcrypto/ref/src/oemcrypto_auth_ref.h | 2 +- .../oemcrypto_engine_device_properties.cpp | 6 +- .../oemcrypto_engine_device_properties_L1.cpp | 10 +-- ...emcrypto_engine_device_properties_cert.cpp | 4 +- ...crypto_engine_device_properties_prov30.cpp | 10 +-- .../ref/src/oemcrypto_engine_ref.cpp | 7 +- .../oemcrypto/ref/src/oemcrypto_engine_ref.h | 9 ++- .../oemcrypto/ref/src/oemcrypto_ref.cpp | 5 +- .../oemcrypto/ref/src/oemcrypto_scoped_ptr.h | 48 ------------- 35 files changed, 100 insertions(+), 208 deletions(-) delete mode 100644 libwvdrmengine/cdm/core/include/scoped_ptr.h delete mode 100644 libwvdrmengine/oemcrypto/ref/src/oemcrypto_scoped_ptr.h diff --git a/libwvdrmengine/cdm/core/include/cdm_engine.h b/libwvdrmengine/cdm/core/include/cdm_engine.h index d7ac3af0..56254216 100644 --- a/libwvdrmengine/cdm/core/include/cdm_engine.h +++ b/libwvdrmengine/cdm/core/include/cdm_engine.h @@ -19,7 +19,6 @@ #include "lock.h" #include "metrics_collections.h" #include "oemcrypto_adapter.h" -#include "scoped_ptr.h" #include "service_certificate.h" #include "wv_cdm_constants.h" #include "wv_cdm_types.h" @@ -325,7 +324,7 @@ class CdmEngine { CdmSessionMap session_map_; CdmReleaseKeySetMap release_key_sets_; - scoped_ptr cert_provisioning_; + std::unique_ptr cert_provisioning_; SecurityLevel cert_provisioning_requested_security_level_; FileSystem* file_system_; Clock clock_; @@ -334,8 +333,8 @@ class CdmEngine { static bool seeded_; // usage related variables - scoped_ptr usage_session_; - scoped_ptr usage_property_set_; + std::unique_ptr usage_session_; + std::unique_ptr usage_property_set_; int64_t last_usage_information_update_time_; // Protect release_key_sets_ from non-thread-safe operations. diff --git a/libwvdrmengine/cdm/core/include/cdm_session.h b/libwvdrmengine/cdm/core/include/cdm_session.h index 04e7ef74..8eaf949f 100644 --- a/libwvdrmengine/cdm/core/include/cdm_session.h +++ b/libwvdrmengine/cdm/core/include/cdm_session.h @@ -5,6 +5,7 @@ #ifndef WVCDM_CORE_CDM_SESSION_H_ #define WVCDM_CORE_CDM_SESSION_H_ +#include #include #include #include @@ -18,7 +19,6 @@ #include "metrics_collections.h" #include "oemcrypto_adapter.h" #include "policy_engine.h" -#include "scoped_ptr.h" #include "timer_metric.h" #include "wv_cdm_types.h" @@ -228,10 +228,10 @@ class CdmSession { bool closed_; // Session closed, but final shared_ptr has not been released. CdmSessionId session_id_; FileSystem* file_system_; - scoped_ptr license_parser_; - scoped_ptr crypto_session_; - scoped_ptr policy_engine_; - scoped_ptr file_handle_; + std::unique_ptr license_parser_; + std::unique_ptr crypto_session_; + std::unique_ptr policy_engine_; + std::unique_ptr file_handle_; bool license_received_; bool is_offline_; bool is_release_; diff --git a/libwvdrmengine/cdm/core/include/certificate_provisioning.h b/libwvdrmengine/cdm/core/include/certificate_provisioning.h index 1468f204..b0aeaef6 100644 --- a/libwvdrmengine/cdm/core/include/certificate_provisioning.h +++ b/libwvdrmengine/cdm/core/include/certificate_provisioning.h @@ -5,6 +5,7 @@ #ifndef WVCDM_CORE_CERTIFICATE_PROVISIONING_H_ #define WVCDM_CORE_CERTIFICATE_PROVISIONING_H_ +#include #include #include "crypto_session.h" @@ -12,7 +13,6 @@ #include "license_protocol.pb.h" #include "metrics_collections.h" #include "oemcrypto_adapter.h" -#include "scoped_ptr.h" #include "service_certificate.h" #include "wv_cdm_types.h" @@ -53,9 +53,9 @@ class CertificateProvisioning { video_widevine::SignedProvisioningMessage::ProtocolVersion GetProtocolVersion(); - scoped_ptr crypto_session_; + std::unique_ptr crypto_session_; CdmCertificateType cert_type_; - scoped_ptr service_certificate_; + std::unique_ptr service_certificate_; CORE_DISALLOW_COPY_AND_ASSIGN(CertificateProvisioning); }; diff --git a/libwvdrmengine/cdm/core/include/crypto_session.h b/libwvdrmengine/cdm/core/include/crypto_session.h index ed46c1c3..d421ba18 100644 --- a/libwvdrmengine/cdm/core/include/crypto_session.h +++ b/libwvdrmengine/cdm/core/include/crypto_session.h @@ -6,6 +6,7 @@ #define WVCDM_CORE_CRYPTO_SESSION_H_ #include +#include #include #include @@ -15,7 +16,6 @@ #include "lock.h" #include "metrics_collections.h" #include "oemcrypto_adapter.h" -#include "scoped_ptr.h" #include "timer_metric.h" #include "wv_cdm_types.h" @@ -295,7 +295,7 @@ class CryptoSession { SubLicenseSessionMap sub_license_oec_sessions_; // Used for sub license sessions. std::string wrapped_key_; - scoped_ptr key_session_; + std::unique_ptr key_session_; OEMCryptoBufferType destination_buffer_type_; bool is_destination_buffer_type_valid_; @@ -313,7 +313,7 @@ class CryptoSession { CdmCipherMode cipher_mode_; uint32_t api_version_; - static scoped_ptr factory_; + static std::unique_ptr factory_; CORE_DISALLOW_COPY_AND_ASSIGN(CryptoSession); }; diff --git a/libwvdrmengine/cdm/core/include/device_files.h b/libwvdrmengine/cdm/core/include/device_files.h index 82ceeb16..cf780d9c 100644 --- a/libwvdrmengine/cdm/core/include/device_files.h +++ b/libwvdrmengine/cdm/core/include/device_files.h @@ -13,7 +13,6 @@ #include "device_files.pb.h" #include "disallow_copy_and_assign.h" -#include "scoped_ptr.h" #include "wv_cdm_types.h" #if defined(UNIT_TEST) diff --git a/libwvdrmengine/cdm/core/include/license.h b/libwvdrmengine/cdm/core/include/license.h index 12d041d5..01cd5d10 100644 --- a/libwvdrmengine/cdm/core/include/license.h +++ b/libwvdrmengine/cdm/core/include/license.h @@ -5,12 +5,12 @@ #ifndef WVCDM_CORE_LICENSE_H_ #define WVCDM_CORE_LICENSE_H_ +#include #include #include "disallow_copy_and_assign.h" #include "initialization_data.h" #include "license_protocol.pb.h" -#include "scoped_ptr.h" #include "service_certificate.h" #include "wv_cdm_types.h" @@ -121,7 +121,7 @@ class CdmLicense { CdmClientTokenType client_token_type_; std::string device_id_; const CdmSessionId session_id_; - scoped_ptr stored_init_data_; + std::unique_ptr stored_init_data_; bool initialized_; std::set loaded_keys_; std::string provider_session_token_; @@ -135,7 +135,7 @@ class CdmLicense { // Used for certificate based licensing CdmKeyMessage key_request_; - scoped_ptr clock_; + std::unique_ptr clock_; // For testing // CdmLicense takes ownership of the clock. diff --git a/libwvdrmengine/cdm/core/include/policy_engine.h b/libwvdrmengine/cdm/core/include/policy_engine.h index 5511be05..48436fea 100644 --- a/libwvdrmengine/cdm/core/include/policy_engine.h +++ b/libwvdrmengine/cdm/core/include/policy_engine.h @@ -6,12 +6,12 @@ #define WVCDM_CORE_POLICY_ENGINE_H_ #include +#include #include #include "disallow_copy_and_assign.h" #include "license_key_status.h" #include "license_protocol.pb.h" -#include "scoped_ptr.h" #include "wv_cdm_types.h" namespace wvcdm { @@ -212,14 +212,14 @@ class PolicyEngine { // Keys associated with license - holds allowed usage, usage constraints, // and current status (CdmKeyStatus) - scoped_ptr license_keys_; + std::unique_ptr license_keys_; // Device checks int64_t next_device_check_; uint32_t current_resolution_; CryptoSession* crypto_session_; - scoped_ptr clock_; + std::unique_ptr clock_; CORE_DISALLOW_COPY_AND_ASSIGN(PolicyEngine); }; diff --git a/libwvdrmengine/cdm/core/include/properties.h b/libwvdrmengine/cdm/core/include/properties.h index d6777c4e..6efdf7a3 100644 --- a/libwvdrmengine/cdm/core/include/properties.h +++ b/libwvdrmengine/cdm/core/include/properties.h @@ -6,12 +6,12 @@ #define WVCDM_CORE_PROPERTIES_H_ #include +#include #include #include "cdm_client_property_set.h" #include "disallow_copy_and_assign.h" #include "lock.h" -#include "scoped_ptr.h" #include "wv_cdm_types.h" #if defined(UNIT_TEST) @@ -115,7 +115,7 @@ class Properties { static bool use_certificates_as_identification_; static bool provisioning_messages_are_binary_; static bool allow_service_certificate_requests_; - static scoped_ptr session_property_set_; + static std::unique_ptr session_property_set_; CORE_DISALLOW_COPY_AND_ASSIGN(Properties); }; diff --git a/libwvdrmengine/cdm/core/include/scoped_ptr.h b/libwvdrmengine/cdm/core/include/scoped_ptr.h deleted file mode 100644 index cfff35f8..00000000 --- a/libwvdrmengine/cdm/core/include/scoped_ptr.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. -// -// A simple and partial implementation of scoped_ptr class. -// The implementation is copied from gtest/include/gtest/internal/gtest-port.h. -// -#ifndef WVCDM_CORE_SCOPED_PTR_H_ -#define WVCDM_CORE_SCOPED_PTR_H_ - -#include "disallow_copy_and_assign.h" - -namespace wvcdm { - -// A scoped_ptr is like a T*, except that the destructor of scoped_ptr -// automatically deletes the pointer it holds (if any). -// That is, scoped_ptr owns the T object that it points to. -// Like a T*, a scoped_ptr may hold either NULL or a pointer to a T object. -// Also like T*, scoped_ptr is thread-compatible, and once you -// dereference it, you get the thread safety guarantees of T. -// -// The size of scoped_ptr is small. On most compilers, sizeof(scoped_ptr) -// == sizeof(T*). -// -// Current implementation targets having a strict subset of C++11's -// unique_ptr<> features. Known deficiencies include not supporting move-only -// deleteres, function pointers as deleters, and deleters with reference -// types. - -// This implementation of scoped_ptr is PARTIAL, e.g. it does not support move, -// custom deleter etc. -template -class scoped_ptr { - public: - typedef T element_type; - - explicit scoped_ptr(T* p = NULL) : ptr_(p) {} - ~scoped_ptr() { reset(); } - - T& operator*() const { return *ptr_; } - T* operator->() const { return ptr_; } - T* get() const { return ptr_; } - - T* release() { - T* const ptr = ptr_; - ptr_ = NULL; - return ptr; - } - - void reset(T* p = NULL) { - if (p != ptr_) { - if (sizeof(T) > 0) { // Makes sure T is a complete type. - delete ptr_; - } - ptr_ = p; - } - } - - private: - T* ptr_; - - CORE_DISALLOW_COPY_AND_ASSIGN(scoped_ptr); -}; - -} // namespace wvcdm - -#endif // WVCDM_CORE_SCOPED_PTR_H_ diff --git a/libwvdrmengine/cdm/core/include/service_certificate.h b/libwvdrmengine/cdm/core/include/service_certificate.h index a76c95f8..b11ee3d1 100644 --- a/libwvdrmengine/cdm/core/include/service_certificate.h +++ b/libwvdrmengine/cdm/core/include/service_certificate.h @@ -18,7 +18,6 @@ #include "disallow_copy_and_assign.h" #include "license_protocol.pb.h" #include "privacy_crypto.h" -#include "scoped_ptr.h" #include "wv_cdm_types.h" namespace wvcdm { @@ -79,7 +78,7 @@ class ServiceCertificate { std::string provider_id_; // Public key. - scoped_ptr public_key_; + std::unique_ptr public_key_; CORE_DISALLOW_COPY_AND_ASSIGN(ServiceCertificate); }; diff --git a/libwvdrmengine/cdm/core/include/usage_table_header.h b/libwvdrmengine/cdm/core/include/usage_table_header.h index 6b3ca861..7bf6456c 100644 --- a/libwvdrmengine/cdm/core/include/usage_table_header.h +++ b/libwvdrmengine/cdm/core/include/usage_table_header.h @@ -5,6 +5,7 @@ #ifndef WVCDM_CORE_USAGE_TABLE_HEADER_H_ #define WVCDM_CORE_USAGE_TABLE_HEADER_H_ +#include #include #include @@ -14,7 +15,6 @@ #include "file_store.h" #include "lock.h" #include "metrics_collections.h" -#include "scoped_ptr.h" #include "wv_cdm_types.h" namespace wvcdm { @@ -100,8 +100,8 @@ class UsageTableHeader { // This handle and file system is only to be used when accessing // usage_table_header. Usage entries should use the file system provided // by CdmSession. - scoped_ptr file_handle_; - scoped_ptr file_system_; + std::unique_ptr file_handle_; + std::unique_ptr file_system_; CdmSecurityLevel security_level_; SecurityLevel requested_security_level_; @@ -131,7 +131,7 @@ class UsageTableHeader { } // Test related data members - scoped_ptr test_crypto_session_; + std::unique_ptr test_crypto_session_; CORE_DISALLOW_COPY_AND_ASSIGN(UsageTableHeader); }; diff --git a/libwvdrmengine/cdm/core/src/cdm_engine.cpp b/libwvdrmengine/cdm/core/src/cdm_engine.cpp index 5dd0e106..6cb92813 100644 --- a/libwvdrmengine/cdm/core/src/cdm_engine.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_engine.cpp @@ -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 new_session(new CdmSession(file_system_, + std::unique_ptr 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 crypto_session( + std::unique_ptr 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 crypto_session( + std::unique_ptr 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 crypto_session( + std::unique_ptr 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 crypto_session( + std::unique_ptr 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 crypto_session( + std::unique_ptr 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 crypto_session( + std::unique_ptr 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 crypto_session( + std::unique_ptr crypto_session( CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics())); status = crypto_session->Open( static_cast(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 crypto_session( + std::unique_ptr crypto_session( CryptoSession::MakeCryptoSession(metrics_.GetCryptoMetrics())); CdmResponseType status; M_TIME( diff --git a/libwvdrmengine/cdm/core/src/crypto_session.cpp b/libwvdrmengine/cdm/core/src/crypto_session.cpp index 42d09941..b43bfc7b 100644 --- a/libwvdrmengine/cdm/core/src/crypto_session.cpp +++ b/libwvdrmengine/cdm/core/src/crypto_session.cpp @@ -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 CryptoSession::factory_(NULL); +std::unique_ptr CryptoSession::factory_ = + std::unique_ptr(); CryptoSession* CryptoSession::MakeCryptoSession( metrics::CryptoMetrics* crypto_metrics) { diff --git a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp index 5df23f45..f5c5f3ab 100644 --- a/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp +++ b/libwvdrmengine/cdm/core/src/oemcrypto_adapter_dynamic.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #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 gAdapter; +static std::unique_ptr gAdapter; } // namespace namespace wvcdm { diff --git a/libwvdrmengine/cdm/core/src/properties.cpp b/libwvdrmengine/cdm/core/src/properties.cpp index 94da7ab2..84778df9 100644 --- a/libwvdrmengine/cdm/core/src/properties.cpp +++ b/libwvdrmengine/cdm/core/src/properties.cpp @@ -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 Properties::session_property_set_; +std::unique_ptr Properties::session_property_set_; bool Properties::AddSessionPropertySet( const CdmSessionId& session_id, CdmClientPropertySet* property_set) { diff --git a/libwvdrmengine/cdm/core/src/usage_table_header.cpp b/libwvdrmengine/cdm/core/src/usage_table_header.cpp index cb463ed0..73158814 100644 --- a/libwvdrmengine/cdm/core/src/usage_table_header.cpp +++ b/libwvdrmengine/cdm/core/src/usage_table_header.cpp @@ -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 scoped_crypto_session; + std::unique_ptr 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 scoped_crypto_session; + std::unique_ptr 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 crypto_session( + std::unique_ptr crypto_session( CryptoSession::MakeCryptoSession(metrics)); CdmResponseType status = crypto_session->Open(requested_security_level_); @@ -632,7 +632,7 @@ bool UsageTableHeader::UpgradeUsageInfoFromUsageTable( continue; } - scoped_ptr crypto_session( + std::unique_ptr crypto_session( CryptoSession::MakeCryptoSession(metrics)); CdmResponseType status = crypto_session->Open(requested_security_level_); diff --git a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp index 6428ad3c..58c0ae67 100644 --- a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp +++ b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp @@ -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" diff --git a/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp b/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp index dc62ce21..d5df0451 100644 --- a/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp @@ -2,13 +2,15 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. +#include + #include #include + #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 cdm_session_; + std::unique_ptr cdm_session_; MockCdmLicense* license_parser_; metrics::CryptoMetrics crypto_metrics_; NiceMock* crypto_session_; diff --git a/libwvdrmengine/cdm/core/test/crypto_session_unittest.cpp b/libwvdrmengine/cdm/core/test/crypto_session_unittest.cpp index 8666259c..c7262c33 100644 --- a/libwvdrmengine/cdm/core/test/crypto_session_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/crypto_session_unittest.cpp @@ -3,6 +3,7 @@ // License Agreement. #include +#include #include #include @@ -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 session( + std::unique_ptr 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 session( + std::unique_ptr session( CryptoSession::MakeCryptoSession(&crypto_metrics)); ASSERT_EQ(NO_ERROR, session->Open(wvcdm::kLevelDefault)); diff --git a/libwvdrmengine/cdm/core/test/generic_crypto_unittest.cpp b/libwvdrmengine/cdm/core/test/generic_crypto_unittest.cpp index e3bd7050..b04a9ea8 100644 --- a/libwvdrmengine/cdm/core/test/generic_crypto_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/generic_crypto_unittest.cpp @@ -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" diff --git a/libwvdrmengine/cdm/core/test/http_socket_test.cpp b/libwvdrmengine/cdm/core/test/http_socket_test.cpp index 4e631d32..d089dcbc 100644 --- a/libwvdrmengine/cdm/core/test/http_socket_test.cpp +++ b/libwvdrmengine/cdm/core/test/http_socket_test.cpp @@ -3,10 +3,12 @@ // License Agreement. #include +#include + #include + #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 socket_; + std::unique_ptr socket_; std::string domain_name_; std::string resource_path_; }; diff --git a/libwvdrmengine/cdm/core/test/policy_engine_constraints_unittest.cpp b/libwvdrmengine/cdm/core/test/policy_engine_constraints_unittest.cpp index b1eb7719..141c6522 100644 --- a/libwvdrmengine/cdm/core/test/policy_engine_constraints_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/policy_engine_constraints_unittest.cpp @@ -2,6 +2,8 @@ // source code may only be used and distributed under the Widevine Master // License Agreement. +#include + #include #include @@ -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 policy_engine_; + std::unique_ptr policy_engine_; MockClock* mock_clock_; int64_t current_time_; metrics::CryptoMetrics dummy_metrics_; diff --git a/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp b/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp index da2dd59a..364e8480 100644 --- a/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -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 crypto_session_; StrictMock mock_event_listener_; MockClock* mock_clock_; - scoped_ptr policy_engine_; + std::unique_ptr policy_engine_; License license_; MockFunction check_; }; diff --git a/libwvdrmengine/cdm/metrics/test/counter_metric_unittest.cpp b/libwvdrmengine/cdm/metrics/test/counter_metric_unittest.cpp index b728391a..ea760eb1 100644 --- a/libwvdrmengine/cdm/metrics/test/counter_metric_unittest.cpp +++ b/libwvdrmengine/cdm/metrics/test/counter_metric_unittest.cpp @@ -6,7 +6,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "scoped_ptr.h" #include "string_conversions.h" using drm_metrics::TestMetrics; diff --git a/libwvdrmengine/cdm/metrics/test/event_metric_unittest.cpp b/libwvdrmengine/cdm/metrics/test/event_metric_unittest.cpp index 09e6c889..8441e4c3 100644 --- a/libwvdrmengine/cdm/metrics/test/event_metric_unittest.cpp +++ b/libwvdrmengine/cdm/metrics/test/event_metric_unittest.cpp @@ -6,7 +6,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "scoped_ptr.h" #include "string_conversions.h" using drm_metrics::TestMetrics; diff --git a/libwvdrmengine/cdm/metrics/test/value_metric_unittest.cpp b/libwvdrmengine/cdm/metrics/test/value_metric_unittest.cpp index 7c0e53a2..a6ec6c75 100644 --- a/libwvdrmengine/cdm/metrics/test/value_metric_unittest.cpp +++ b/libwvdrmengine/cdm/metrics/test/value_metric_unittest.cpp @@ -2,6 +2,7 @@ // // Unit tests for ValueMetric. +#include #include #include "value_metric.h" @@ -9,7 +10,6 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "metrics.pb.h" -#include "scoped_ptr.h" namespace wvcdm { namespace metrics { @@ -18,7 +18,7 @@ TEST(ValueMetricTest, StringValue) { ValueMetric metric; metric.Record("foo"); - wvcdm::scoped_ptr metric_proto(metric.ToProto()); + std::unique_ptr metric_proto(metric.ToProto()); ASSERT_EQ("foo", metric_proto->string_value()); ASSERT_FALSE(metric_proto->has_error_code()); } @@ -27,7 +27,7 @@ TEST(ValueMetricTest, DoubleValue) { ValueMetric metric; metric.Record(42.0); - wvcdm::scoped_ptr metric_proto(metric.ToProto()); + std::unique_ptr metric_proto(metric.ToProto()); ASSERT_EQ(42.0, metric_proto->double_value()); ASSERT_FALSE(metric_proto->has_error_code()); } @@ -36,7 +36,7 @@ TEST(ValueMetricTest, Int32Value) { ValueMetric metric; metric.Record(42); - wvcdm::scoped_ptr metric_proto(metric.ToProto()); + std::unique_ptr metric_proto(metric.ToProto()); ASSERT_EQ(42, metric_proto->int_value()); ASSERT_FALSE(metric_proto->has_error_code()); } @@ -45,7 +45,7 @@ TEST(ValueMetricTest, Int64Value) { ValueMetric metric; metric.Record(42); - wvcdm::scoped_ptr metric_proto(metric.ToProto()); + std::unique_ptr metric_proto(metric.ToProto()); ASSERT_EQ(42, metric_proto->int_value()); ASSERT_FALSE(metric_proto->has_error_code()); } @@ -55,7 +55,7 @@ TEST(ValueMetricTest, SetError) { metric.Record(42); metric.SetError(7); - wvcdm::scoped_ptr metric_proto(metric.ToProto()); + std::unique_ptr metric_proto(metric.ToProto()); ASSERT_EQ(7, metric_proto->error_code()); ASSERT_FALSE(metric_proto->has_int_value()); } diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.h index 6bdeb84c..61b85aaa 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_auth_ref.h @@ -8,6 +8,7 @@ #define OEMCRYPTO_AUTH_REF_H_ #include +#include #include #include @@ -17,7 +18,6 @@ #include "oemcrypto_key_ref.h" #include "oemcrypto_keybox_ref.h" #include "oemcrypto_rsa_key_shared.h" -#include "oemcrypto_scoped_ptr.h" #include "oemcrypto_types.h" namespace wvoec_ref { diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties.cpp index 20d8f026..a3bdf4e3 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties.cpp @@ -7,11 +7,13 @@ #include "oemcrypto_engine_ref.h" +#include + namespace wvoec_ref { CryptoEngine* CryptoEngine::MakeCryptoEngine( - scoped_ptr file_system) { - return new CryptoEngine(file_system); + std::unique_ptr&& file_system) { + return new CryptoEngine(std::move(file_system)); } } // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_L1.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_L1.cpp index 749e2e66..5e92a88a 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_L1.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_L1.cpp @@ -8,12 +8,14 @@ // level 1 device. #include "oemcrypto_engine_ref.h" +#include + namespace wvoec_ref { class L1CryptoEngine : public CryptoEngine { public: - explicit L1CryptoEngine(scoped_ptr file_system) - : CryptoEngine(file_system) {} + explicit L1CryptoEngine(std::unique_ptr&& file_system) + : CryptoEngine(std::move(file_system)) {} bool config_local_display_only() { return true; } @@ -31,8 +33,8 @@ class L1CryptoEngine : public CryptoEngine { }; CryptoEngine* CryptoEngine::MakeCryptoEngine( - scoped_ptr file_system) { - return new L1CryptoEngine(file_system); + std::unique_ptr&& file_system) { + return new L1CryptoEngine(std::move(file_system)); } } // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_cert.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_cert.cpp index 73809f5d..df17c885 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_cert.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_cert.cpp @@ -15,7 +15,7 @@ namespace wvoec_ref { class CertOnlyCryptoEngine : public CryptoEngine { public: - explicit CertOnlyCryptoEngine(scoped_ptr file_system) + explicit CertOnlyCryptoEngine(std::unique_ptr file_system) : CryptoEngine(file_system) {} bool config_local_display_only() { return true; } @@ -30,7 +30,7 @@ class CertOnlyCryptoEngine : public CryptoEngine { }; CryptoEngine* CryptoEngine::MakeCryptoEngine( - scoped_ptr file_system) { + std::unique_ptr file_system) { return new CertOnlyCryptoEngine(file_system); } diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_prov30.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_prov30.cpp index dacd9793..fe78fe61 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_prov30.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_device_properties_prov30.cpp @@ -12,6 +12,8 @@ #include +#include + #include "log.h" #include "oem_cert.h" @@ -19,8 +21,8 @@ namespace wvoec_ref { class Prov30CryptoEngine : public CryptoEngine { public: - explicit Prov30CryptoEngine(scoped_ptr file_system) - : CryptoEngine(file_system) {} + explicit Prov30CryptoEngine(std::unique_ptr&& file_system) + : CryptoEngine(std::move(file_system)) {} bool config_local_display_only() { return true; } @@ -77,8 +79,8 @@ class Prov30CryptoEngine : public CryptoEngine { }; CryptoEngine* CryptoEngine::MakeCryptoEngine( - scoped_ptr file_system) { - return new Prov30CryptoEngine(file_system); + std::unique_ptr&& file_system) { + return new Prov30CryptoEngine(std::move(file_system)); } } // namespace wvoec_ref diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp index 4f225db8..5606883a 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -27,10 +28,10 @@ namespace wvoec_ref { // all configurations. See the files oemcrypto_engine_device_properties*.cpp // for methods that are configured for specific configurations. -CryptoEngine::CryptoEngine(scoped_ptr file_system) +CryptoEngine::CryptoEngine(std::unique_ptr&& file_system) : root_of_trust_(config_provisioning_method()), - file_system_(file_system), - usage_table_(NULL) { + file_system_(std::move(file_system)), + usage_table_() { ERR_load_crypto_strings(); } diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.h index 60c9d096..58f443be 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.h +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_engine_ref.h @@ -21,7 +21,6 @@ #include "oemcrypto_auth_ref.h" #include "oemcrypto_key_ref.h" #include "oemcrypto_rsa_key_shared.h" -#include "oemcrypto_scoped_ptr.h" #include "oemcrypto_session.h" #include "oemcrypto_usage_table_ref.h" #include "oemcrypto_types.h" @@ -38,7 +37,7 @@ class CryptoEngine { // NOTE: The caller must instantiate a FileSystem object - ownership // will be transferred to the new CryptoEngine object. static CryptoEngine* MakeCryptoEngine( - scoped_ptr file_system); + std::unique_ptr&& file_system); virtual ~CryptoEngine(); @@ -189,15 +188,15 @@ class CryptoEngine { } protected: - explicit CryptoEngine(scoped_ptr file_system); + explicit CryptoEngine(std::unique_ptr&& file_system); virtual SessionContext* MakeSession(SessionId sid); virtual UsageTable* MakeUsageTable(); uint8_t* destination_; ActiveSessions sessions_; AuthenticationRoot root_of_trust_; wvcdm::Lock session_table_lock_; - scoped_ptr file_system_; - scoped_ptr usage_table_; + std::unique_ptr file_system_; + std::unique_ptr usage_table_; CORE_DISALLOW_COPY_AND_ASSIGN(CryptoEngine); }; diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_ref.cpp b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_ref.cpp index a3941385..9ddf2c98 100644 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_ref.cpp +++ b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_ref.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "file_store.h" #include "log.h" @@ -64,8 +65,8 @@ extern "C" OEMCryptoResult OEMCrypto_Initialize(void) { } // NOTE: This requires a compatible Filesystem implementation. // NOTE: Ownership of the FileSystem object is transferred to CryptoEngine - scoped_ptr fs(new wvcdm::FileSystem()); - crypto_engine = CryptoEngine::MakeCryptoEngine(fs); + std::unique_ptr fs(new wvcdm::FileSystem()); + crypto_engine = CryptoEngine::MakeCryptoEngine(std::move(fs)); if (!crypto_engine || !crypto_engine->Initialize()) { LOGE("[OEMCrypto_Initialize(): failed]"); diff --git a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_scoped_ptr.h b/libwvdrmengine/oemcrypto/ref/src/oemcrypto_scoped_ptr.h deleted file mode 100644 index 8e56fa03..00000000 --- a/libwvdrmengine/oemcrypto/ref/src/oemcrypto_scoped_ptr.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2018 Google LLC. All Rights Reserved. This file and proprietary -// source code may only be used and distributed under the Widevine Master -// License Agreement. -#ifndef OEMCRYPTO_SCOPED_PTR_H_ -#define OEMCRYPTO_SCOPED_PTR_H_ - -#include -#include - -#include - -namespace wvoec_ref { - -// TODO(fredgc, jfore): scoped_ptr may not be the best name for this smart -// pointer type. It basically works like auto_ptr which is deprecated. -#if __cplusplus < 201103L - -template -class scoped_ptr { - public: - explicit scoped_ptr(T* p = NULL) : ptr_(p) {} - T* get() const { return ptr_.get(); } - void reset(T* p = NULL) { ptr_.reset(p); } - - private: - std::auto_ptr ptr_; -}; - -#else - -template -class scoped_ptr { - public: - explicit scoped_ptr(T* p = nullptr) : ptr_(p) {} - scoped_ptr(scoped_ptr& r) { ptr_ = std::move(r.ptr_); } - T& operator*() const { return *ptr_; } - T* operator->() const { return ptr_.get(); } - T* get() const { return ptr_.get(); } - void reset(T* p = NULL) { ptr_.reset(p); } - - private: - std::unique_ptr ptr_; -}; -#endif - -} // namespace wvoec_ref - -#endif // OEMCRYPTO_SCOPED_PTR_H_