summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-09-21 17:05:15 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-09-21 21:38:37 +0000
commitb872a93e5cd940dc28ad960b13b0cf01a6db3400 (patch)
tree057208e10b41e1cc3c2ac1b782af9394aadbe87d
parentaee0db0e6a12bdaacebeb8fb791f4e0d45e18a0d (diff)
downloadpdfium-b872a93e5cd940dc28ad960b13b0cf01a6db3400.tar.xz
Move CFX_WeakPtr to WeakPtr
This CL renames CFX_WeakPtr to WeakPtr and moves into the fxcrt namespace. Bug: pdfium:898 Change-Id: Ide50a8afeb1e987c48c8fbd103898745c9199d6a Reviewed-on: https://pdfium-review.googlesource.com/14621 Commit-Queue: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r--BUILD.gn4
-rw-r--r--core/fpdfapi/font/cpdf_fontencoding.cpp2
-rw-r--r--core/fpdfapi/font/cpdf_fontencoding.h4
-rw-r--r--core/fpdfapi/page/cpdf_streamparser.cpp2
-rw-r--r--core/fpdfapi/page/cpdf_streamparser.h6
-rw-r--r--core/fpdfapi/parser/cpdf_array.cpp3
-rw-r--r--core/fpdfapi/parser/cpdf_array.h4
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_dictionary.h8
-rw-r--r--core/fpdfapi/parser/cpdf_indirect_object_holder.h6
-rw-r--r--core/fpdfapi/parser/cpdf_name.cpp2
-rw-r--r--core/fpdfapi/parser/cpdf_name.h4
-rw-r--r--core/fpdfapi/parser/cpdf_string.cpp5
-rw-r--r--core/fpdfapi/parser/cpdf_string.h8
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.h6
-rw-r--r--core/fpdfdoc/cpdf_filespec.h2
-rw-r--r--core/fxcrt/weak_ptr.h (renamed from core/fxcrt/cfx_weak_ptr.h)32
-rw-r--r--core/fxcrt/weak_ptr_unittest.cpp (renamed from core/fxcrt/cfx_weak_ptr_unittest.cpp)81
19 files changed, 96 insertions, 91 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 7526fa0dac..3a95895f25 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -823,7 +823,6 @@ static_library("fxcrt") {
"core/fxcrt/cfx_memorystream.h",
"core/fxcrt/cfx_utf8decoder.cpp",
"core/fxcrt/cfx_utf8decoder.h",
- "core/fxcrt/cfx_weak_ptr.h",
"core/fxcrt/cfx_widetextbuf.cpp",
"core/fxcrt/cfx_widetextbuf.h",
"core/fxcrt/fx_bidi.cpp",
@@ -858,6 +857,7 @@ static_library("fxcrt") {
"core/fxcrt/string_pool_template.h",
"core/fxcrt/string_view_template.h",
"core/fxcrt/unowned_ptr.h",
+ "core/fxcrt/weak_ptr.h",
"core/fxcrt/widestring.cpp",
"core/fxcrt/widestring.h",
"core/fxcrt/xml/cxml_attritem.cpp",
@@ -1920,7 +1920,6 @@ test("pdfium_unittests") {
"core/fxcodec/jbig2/JBig2_BitStream_unittest.cpp",
"core/fxcodec/jbig2/JBig2_Image_unittest.cpp",
"core/fxcrt/bytestring_unittest.cpp",
- "core/fxcrt/cfx_weak_ptr_unittest.cpp",
"core/fxcrt/fx_bidi_unittest.cpp",
"core/fxcrt/fx_coordinates_unittest.cpp",
"core/fxcrt/fx_extension_unittest.cpp",
@@ -1934,6 +1933,7 @@ test("pdfium_unittests") {
"core/fxcrt/shared_copy_on_write_unittest.cpp",
"core/fxcrt/string_pool_template_unittest.cpp",
"core/fxcrt/unowned_ptr_unittest.cpp",
+ "core/fxcrt/weak_ptr_unittest.cpp",
"core/fxcrt/widestring_unittest.cpp",
"core/fxge/dib/cstretchengine_unittest.cpp",
"fpdfsdk/fpdfdoc_unittest.cpp",
diff --git a/core/fpdfapi/font/cpdf_fontencoding.cpp b/core/fpdfapi/font/cpdf_fontencoding.cpp
index 6290f20f5e..921d5842b8 100644
--- a/core/fpdfapi/font/cpdf_fontencoding.cpp
+++ b/core/fpdfapi/font/cpdf_fontencoding.cpp
@@ -1672,7 +1672,7 @@ bool CPDF_FontEncoding::IsIdentical(CPDF_FontEncoding* pAnother) const {
}
std::unique_ptr<CPDF_Object> CPDF_FontEncoding::Realize(
- CFX_WeakPtr<ByteStringPool> pPool) {
+ WeakPtr<ByteStringPool> pPool) {
int predefined = 0;
for (int cs = PDFFONT_ENCODING_WINANSI; cs < PDFFONT_ENCODING_ZAPFDINGBATS;
cs++) {
diff --git a/core/fpdfapi/font/cpdf_fontencoding.h b/core/fpdfapi/font/cpdf_fontencoding.h
index d96f787da1..cb99975b98 100644
--- a/core/fpdfapi/font/cpdf_fontencoding.h
+++ b/core/fpdfapi/font/cpdf_fontencoding.h
@@ -9,9 +9,9 @@
#include <memory>
-#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/string_pool_template.h"
+#include "core/fxcrt/weak_ptr.h"
#define PDFFONT_ENCODING_BUILTIN 0
#define PDFFONT_ENCODING_WINANSI 1
@@ -53,7 +53,7 @@ class CPDF_FontEncoding {
m_Unicodes[charcode] = unicode;
}
- std::unique_ptr<CPDF_Object> Realize(CFX_WeakPtr<ByteStringPool> pPool);
+ std::unique_ptr<CPDF_Object> Realize(WeakPtr<ByteStringPool> pPool);
public:
wchar_t m_Unicodes[256];
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index ffd76005e0..e9320cbc6f 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -107,7 +107,7 @@ CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize)
CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData,
uint32_t dwSize,
- const CFX_WeakPtr<ByteStringPool>& pPool)
+ const WeakPtr<ByteStringPool>& pPool)
: m_pBuf(pData), m_Size(dwSize), m_Pos(0), m_pPool(pPool) {}
CPDF_StreamParser::~CPDF_StreamParser() {}
diff --git a/core/fpdfapi/page/cpdf_streamparser.h b/core/fpdfapi/page/cpdf_streamparser.h
index 53d5dfd135..158726b026 100644
--- a/core/fpdfapi/page/cpdf_streamparser.h
+++ b/core/fpdfapi/page/cpdf_streamparser.h
@@ -14,8 +14,8 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/cpdf_object.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
-#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/string_pool_template.h"
+#include "core/fxcrt/weak_ptr.h"
class CPDF_StreamParser {
public:
@@ -24,7 +24,7 @@ class CPDF_StreamParser {
CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize);
CPDF_StreamParser(const uint8_t* pData,
uint32_t dwSize,
- const CFX_WeakPtr<ByteStringPool>& pPool);
+ const WeakPtr<ByteStringPool>& pPool);
~CPDF_StreamParser();
SyntaxType ParseNextElement();
@@ -56,7 +56,7 @@ class CPDF_StreamParser {
uint8_t m_WordBuffer[256];
uint32_t m_WordSize;
std::unique_ptr<CPDF_Object> m_pLastObj;
- CFX_WeakPtr<ByteStringPool> m_pPool;
+ WeakPtr<ByteStringPool> m_pPool;
};
#endif // CORE_FPDFAPI_PAGE_CPDF_STREAMPARSER_H_
diff --git a/core/fpdfapi/parser/cpdf_array.cpp b/core/fpdfapi/parser/cpdf_array.cpp
index f4907ffdf1..5a5cdc9be0 100644
--- a/core/fpdfapi/parser/cpdf_array.cpp
+++ b/core/fpdfapi/parser/cpdf_array.cpp
@@ -20,8 +20,7 @@
CPDF_Array::CPDF_Array() {}
-CPDF_Array::CPDF_Array(const CFX_WeakPtr<ByteStringPool>& pPool)
- : m_pPool(pPool) {}
+CPDF_Array::CPDF_Array(const WeakPtr<ByteStringPool>& pPool) : m_pPool(pPool) {}
CPDF_Array::~CPDF_Array() {
// Break cycles for cyclic references.
diff --git a/core/fpdfapi/parser/cpdf_array.h b/core/fpdfapi/parser/cpdf_array.h
index 3b18025b2d..bf8cb426c4 100644
--- a/core/fpdfapi/parser/cpdf_array.h
+++ b/core/fpdfapi/parser/cpdf_array.h
@@ -24,7 +24,7 @@ class CPDF_Array : public CPDF_Object {
std::vector<std::unique_ptr<CPDF_Object>>::const_iterator;
CPDF_Array();
- explicit CPDF_Array(const CFX_WeakPtr<ByteStringPool>& pPool);
+ explicit CPDF_Array(const WeakPtr<ByteStringPool>& pPool);
~CPDF_Array() override;
// CPDF_Object:
@@ -112,7 +112,7 @@ class CPDF_Array : public CPDF_Object {
std::set<const CPDF_Object*>* pVisited) const override;
std::vector<std::unique_ptr<CPDF_Object>> m_Objects;
- CFX_WeakPtr<ByteStringPool> m_pPool;
+ WeakPtr<ByteStringPool> m_pPool;
};
inline CPDF_Array* ToArray(CPDF_Object* obj) {
diff --git a/core/fpdfapi/parser/cpdf_dictionary.cpp b/core/fpdfapi/parser/cpdf_dictionary.cpp
index 570c57e557..5cdcf34f81 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.cpp
+++ b/core/fpdfapi/parser/cpdf_dictionary.cpp
@@ -22,9 +22,9 @@
#include "third_party/base/stl_util.h"
CPDF_Dictionary::CPDF_Dictionary()
- : CPDF_Dictionary(CFX_WeakPtr<ByteStringPool>()) {}
+ : CPDF_Dictionary(WeakPtr<ByteStringPool>()) {}
-CPDF_Dictionary::CPDF_Dictionary(const CFX_WeakPtr<ByteStringPool>& pPool)
+CPDF_Dictionary::CPDF_Dictionary(const WeakPtr<ByteStringPool>& pPool)
: m_pPool(pPool) {}
CPDF_Dictionary::~CPDF_Dictionary() {
diff --git a/core/fpdfapi/parser/cpdf_dictionary.h b/core/fpdfapi/parser/cpdf_dictionary.h
index a9ff353fbe..688e88e510 100644
--- a/core/fpdfapi/parser/cpdf_dictionary.h
+++ b/core/fpdfapi/parser/cpdf_dictionary.h
@@ -13,10 +13,10 @@
#include <utility>
#include "core/fpdfapi/parser/cpdf_object.h"
-#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/string_pool_template.h"
+#include "core/fxcrt/weak_ptr.h"
#include "third_party/base/ptr_util.h"
class CPDF_IndirectObjectHolder;
@@ -27,7 +27,7 @@ class CPDF_Dictionary : public CPDF_Object {
std::map<ByteString, std::unique_ptr<CPDF_Object>>::const_iterator;
CPDF_Dictionary();
- explicit CPDF_Dictionary(const CFX_WeakPtr<ByteStringPool>& pPool);
+ explicit CPDF_Dictionary(const WeakPtr<ByteStringPool>& pPool);
~CPDF_Dictionary() override;
// CPDF_Object:
@@ -97,7 +97,7 @@ class CPDF_Dictionary : public CPDF_Object {
const_iterator begin() const { return m_Map.begin(); }
const_iterator end() const { return m_Map.end(); }
- CFX_WeakPtr<ByteStringPool> GetByteStringPool() const { return m_pPool; }
+ WeakPtr<ByteStringPool> GetByteStringPool() const { return m_pPool; }
protected:
ByteString MaybeIntern(const ByteString& str);
@@ -105,7 +105,7 @@ class CPDF_Dictionary : public CPDF_Object {
bool bDirect,
std::set<const CPDF_Object*>* visited) const override;
- CFX_WeakPtr<ByteStringPool> m_pPool;
+ WeakPtr<ByteStringPool> m_pPool;
std::map<ByteString, std::unique_ptr<CPDF_Object>> m_Map;
};
diff --git a/core/fpdfapi/parser/cpdf_indirect_object_holder.h b/core/fpdfapi/parser/cpdf_indirect_object_holder.h
index ea70c4a351..57374b9cc2 100644
--- a/core/fpdfapi/parser/cpdf_indirect_object_holder.h
+++ b/core/fpdfapi/parser/cpdf_indirect_object_holder.h
@@ -14,9 +14,9 @@
#include <vector>
#include "core/fpdfapi/parser/cpdf_object.h"
-#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/string_pool_template.h"
+#include "core/fxcrt/weak_ptr.h"
#include "third_party/base/ptr_util.h"
class CPDF_IndirectObjectHolder {
@@ -58,7 +58,7 @@ class CPDF_IndirectObjectHolder {
uint32_t GetLastObjNum() const { return m_LastObjNum; }
void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; }
- CFX_WeakPtr<ByteStringPool> GetByteStringPool() const {
+ WeakPtr<ByteStringPool> GetByteStringPool() const {
return m_pByteStringPool;
}
@@ -72,7 +72,7 @@ class CPDF_IndirectObjectHolder {
uint32_t m_LastObjNum;
std::map<uint32_t, std::unique_ptr<CPDF_Object>> m_IndirectObjs;
std::vector<std::unique_ptr<CPDF_Object>> m_OrphanObjs;
- CFX_WeakPtr<ByteStringPool> m_pByteStringPool;
+ WeakPtr<ByteStringPool> m_pByteStringPool;
};
#endif // CORE_FPDFAPI_PARSER_CPDF_INDIRECT_OBJECT_HOLDER_H_
diff --git a/core/fpdfapi/parser/cpdf_name.cpp b/core/fpdfapi/parser/cpdf_name.cpp
index 0dd9890702..0607a30342 100644
--- a/core/fpdfapi/parser/cpdf_name.cpp
+++ b/core/fpdfapi/parser/cpdf_name.cpp
@@ -10,7 +10,7 @@
#include "core/fxcrt/fx_stream.h"
#include "third_party/base/ptr_util.h"
-CPDF_Name::CPDF_Name(CFX_WeakPtr<ByteStringPool> pPool, const ByteString& str)
+CPDF_Name::CPDF_Name(WeakPtr<ByteStringPool> pPool, const ByteString& str)
: m_Name(str) {
if (pPool)
m_Name = pPool->Intern(m_Name);
diff --git a/core/fpdfapi/parser/cpdf_name.h b/core/fpdfapi/parser/cpdf_name.h
index 8a1cf2b63b..880c10aedb 100644
--- a/core/fpdfapi/parser/cpdf_name.h
+++ b/core/fpdfapi/parser/cpdf_name.h
@@ -10,12 +10,12 @@
#include <memory>
#include "core/fpdfapi/parser/cpdf_object.h"
-#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/string_pool_template.h"
+#include "core/fxcrt/weak_ptr.h"
class CPDF_Name : public CPDF_Object {
public:
- CPDF_Name(CFX_WeakPtr<ByteStringPool> pPool, const ByteString& str);
+ CPDF_Name(WeakPtr<ByteStringPool> pPool, const ByteString& str);
~CPDF_Name() override;
// CPDF_Object:
diff --git a/core/fpdfapi/parser/cpdf_string.cpp b/core/fpdfapi/parser/cpdf_string.cpp
index 1539861622..851442e8b4 100644
--- a/core/fpdfapi/parser/cpdf_string.cpp
+++ b/core/fpdfapi/parser/cpdf_string.cpp
@@ -14,7 +14,7 @@
CPDF_String::CPDF_String() : m_bHex(false) {}
-CPDF_String::CPDF_String(CFX_WeakPtr<ByteStringPool> pPool,
+CPDF_String::CPDF_String(WeakPtr<ByteStringPool> pPool,
const ByteString& str,
bool bHex)
: m_String(str), m_bHex(bHex) {
@@ -22,8 +22,7 @@ CPDF_String::CPDF_String(CFX_WeakPtr<ByteStringPool> pPool,
m_String = pPool->Intern(m_String);
}
-CPDF_String::CPDF_String(CFX_WeakPtr<ByteStringPool> pPool,
- const WideString& str)
+CPDF_String::CPDF_String(WeakPtr<ByteStringPool> pPool, const WideString& str)
: m_String(PDF_EncodeText(str)), m_bHex(false) {
if (pPool)
m_String = pPool->Intern(m_String);
diff --git a/core/fpdfapi/parser/cpdf_string.h b/core/fpdfapi/parser/cpdf_string.h
index 6f762ae27b..b6aaacb043 100644
--- a/core/fpdfapi/parser/cpdf_string.h
+++ b/core/fpdfapi/parser/cpdf_string.h
@@ -10,18 +10,16 @@
#include <memory>
#include "core/fpdfapi/parser/cpdf_object.h"
-#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/string_pool_template.h"
+#include "core/fxcrt/weak_ptr.h"
class CPDF_String : public CPDF_Object {
public:
CPDF_String();
- CPDF_String(CFX_WeakPtr<ByteStringPool> pPool,
- const ByteString& str,
- bool bHex);
- CPDF_String(CFX_WeakPtr<ByteStringPool> pPool, const WideString& str);
+ CPDF_String(WeakPtr<ByteStringPool> pPool, const ByteString& str, bool bHex);
+ CPDF_String(WeakPtr<ByteStringPool> pPool, const WideString& str);
~CPDF_String() override;
// CPDF_Object:
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 7bea4c45fc..bf6d90ca9a 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -41,9 +41,9 @@ enum class ReadStatus { Normal, Backslash, Octal, FinishOctal, CarriageReturn };
int CPDF_SyntaxParser::s_CurrentRecursionDepth = 0;
CPDF_SyntaxParser::CPDF_SyntaxParser()
- : CPDF_SyntaxParser(CFX_WeakPtr<ByteStringPool>()) {}
+ : CPDF_SyntaxParser(WeakPtr<ByteStringPool>()) {}
-CPDF_SyntaxParser::CPDF_SyntaxParser(const CFX_WeakPtr<ByteStringPool>& pPool)
+CPDF_SyntaxParser::CPDF_SyntaxParser(const WeakPtr<ByteStringPool>& pPool)
: m_MetadataObjnum(0),
m_pFileAccess(nullptr),
m_pFileBuf(nullptr),
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h
index cb266837dc..2b642b5963 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.h
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.h
@@ -10,8 +10,8 @@
#include <algorithm>
#include <memory>
-#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/string_pool_template.h"
+#include "core/fxcrt/weak_ptr.h"
class CPDF_CryptoHandler;
class CPDF_Dictionary;
@@ -26,7 +26,7 @@ class CPDF_SyntaxParser {
enum class ParseType { kStrict, kLoose };
CPDF_SyntaxParser();
- explicit CPDF_SyntaxParser(const CFX_WeakPtr<ByteStringPool>& pPool);
+ explicit CPDF_SyntaxParser(const WeakPtr<ByteStringPool>& pPool);
~CPDF_SyntaxParser();
void InitParser(const RetainPtr<IFX_SeekableReadStream>& pFileAccess,
@@ -121,7 +121,7 @@ class CPDF_SyntaxParser {
RetainPtr<CPDF_CryptoHandler> m_pCryptoHandler;
uint8_t m_WordBuffer[257];
uint32_t m_WordSize;
- CFX_WeakPtr<ByteStringPool> m_pPool;
+ WeakPtr<ByteStringPool> m_pPool;
};
#endif // CORE_FPDFAPI_PARSER_CPDF_SYNTAX_PARSER_H_
diff --git a/core/fpdfdoc/cpdf_filespec.h b/core/fpdfdoc/cpdf_filespec.h
index b32207d273..deeccb9619 100644
--- a/core/fpdfdoc/cpdf_filespec.h
+++ b/core/fpdfdoc/cpdf_filespec.h
@@ -7,10 +7,10 @@
#ifndef CORE_FPDFDOC_CPDF_FILESPEC_H_
#define CORE_FPDFDOC_CPDF_FILESPEC_H_
-#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/string_pool_template.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "core/fxcrt/weak_ptr.h"
class CPDF_Dictionary;
class CPDF_Object;
diff --git a/core/fxcrt/cfx_weak_ptr.h b/core/fxcrt/weak_ptr.h
index da96000a1b..eb8523bd3d 100644
--- a/core/fxcrt/cfx_weak_ptr.h
+++ b/core/fxcrt/weak_ptr.h
@@ -4,8 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef CORE_FXCRT_CFX_WEAK_PTR_H_
-#define CORE_FXCRT_CFX_WEAK_PTR_H_
+#ifndef CORE_FXCRT_WEAK_PTR_H_
+#define CORE_FXCRT_WEAK_PTR_H_
#include <cstddef>
#include <memory>
@@ -14,31 +14,33 @@
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/retain_ptr.h"
+namespace fxcrt {
+
template <class T, class D = std::default_delete<T>>
-class CFX_WeakPtr {
+class WeakPtr {
public:
- CFX_WeakPtr() {}
- CFX_WeakPtr(const CFX_WeakPtr& that) : m_pHandle(that.m_pHandle) {}
- CFX_WeakPtr(CFX_WeakPtr&& that) noexcept { Swap(that); }
- explicit CFX_WeakPtr(std::unique_ptr<T, D> pObj)
+ WeakPtr() {}
+ WeakPtr(const WeakPtr& that) : m_pHandle(that.m_pHandle) {}
+ WeakPtr(WeakPtr&& that) noexcept { Swap(that); }
+ explicit WeakPtr(std::unique_ptr<T, D> pObj)
: m_pHandle(new Handle(std::move(pObj))) {}
// Deliberately implicit to allow passing nullptr.
// NOLINTNEXTLINE(runtime/explicit)
- CFX_WeakPtr(std::nullptr_t arg) {}
+ WeakPtr(std::nullptr_t arg) {}
explicit operator bool() const { return m_pHandle && !!m_pHandle->Get(); }
bool HasOneRef() const { return m_pHandle && m_pHandle->HasOneRef(); }
T* operator->() { return m_pHandle->Get(); }
const T* operator->() const { return m_pHandle->Get(); }
- CFX_WeakPtr& operator=(const CFX_WeakPtr& that) {
+ WeakPtr& operator=(const WeakPtr& that) {
m_pHandle = that.m_pHandle;
return *this;
}
- bool operator==(const CFX_WeakPtr& that) const {
+ bool operator==(const WeakPtr& that) const {
return m_pHandle == that.m_pHandle;
}
- bool operator!=(const CFX_WeakPtr& that) const { return !(*this == that); }
+ bool operator!=(const WeakPtr& that) const { return !(*this == that); }
T* Get() const { return m_pHandle ? m_pHandle->Get() : nullptr; }
void DeleteObject() {
@@ -51,7 +53,7 @@ class CFX_WeakPtr {
void Reset(std::unique_ptr<T, D> pObj) {
m_pHandle.Reset(new Handle(std::move(pObj)));
}
- void Swap(CFX_WeakPtr& that) { m_pHandle.Swap(that.m_pHandle); }
+ void Swap(WeakPtr& that) { m_pHandle.Swap(that.m_pHandle); }
private:
class Handle {
@@ -83,4 +85,8 @@ class CFX_WeakPtr {
RetainPtr<Handle> m_pHandle;
};
-#endif // CORE_FXCRT_CFX_WEAK_PTR_H_
+} // namespace fxcrt
+
+using fxcrt::WeakPtr;
+
+#endif // CORE_FXCRT_WEAK_PTR_H_
diff --git a/core/fxcrt/cfx_weak_ptr_unittest.cpp b/core/fxcrt/weak_ptr_unittest.cpp
index aafcf16b3d..22a723043b 100644
--- a/core/fxcrt/cfx_weak_ptr_unittest.cpp
+++ b/core/fxcrt/weak_ptr_unittest.cpp
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "core/fxcrt/cfx_weak_ptr.h"
+#include "core/fxcrt/weak_ptr.h"
#include <memory>
#include <utility>
@@ -10,11 +10,12 @@
#include "core/fxcrt/fx_memory.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace fxcrt {
namespace {
class PseudoDeletable;
-using WeakPtr = CFX_WeakPtr<PseudoDeletable, ReleaseDeleter<PseudoDeletable>>;
-using UniquePtr =
+using WeakTestPtr = WeakPtr<PseudoDeletable, ReleaseDeleter<PseudoDeletable>>;
+using UniqueTestPtr =
std::unique_ptr<PseudoDeletable, ReleaseDeleter<PseudoDeletable>>;
class PseudoDeletable {
@@ -24,52 +25,52 @@ class PseudoDeletable {
++delete_count_;
next_.Reset();
}
- void SetNext(const WeakPtr& next) { next_ = next; }
+ void SetNext(const WeakTestPtr& next) { next_ = next; }
int delete_count() const { return delete_count_; }
private:
int delete_count_;
- WeakPtr next_;
+ WeakTestPtr next_;
};
} // namespace
-TEST(fxcrt, WeakPtrNull) {
- WeakPtr ptr1;
+TEST(WeakPtr, Null) {
+ WeakTestPtr ptr1;
EXPECT_FALSE(ptr1);
- WeakPtr ptr2;
+ WeakTestPtr ptr2;
EXPECT_TRUE(ptr1 == ptr2);
EXPECT_FALSE(ptr1 != ptr2);
- WeakPtr ptr3(ptr1);
+ WeakTestPtr ptr3(ptr1);
EXPECT_TRUE(ptr1 == ptr3);
EXPECT_FALSE(ptr1 != ptr3);
- WeakPtr ptr4 = ptr1;
+ WeakTestPtr ptr4 = ptr1;
EXPECT_TRUE(ptr1 == ptr4);
EXPECT_FALSE(ptr1 != ptr4);
}
-TEST(fxcrt, WeakPtrNonNull) {
+TEST(WeakPtr, NonNull) {
PseudoDeletable thing;
EXPECT_EQ(0, thing.delete_count());
{
- UniquePtr unique(&thing);
- WeakPtr ptr1(std::move(unique));
+ UniqueTestPtr unique(&thing);
+ WeakTestPtr ptr1(std::move(unique));
EXPECT_TRUE(ptr1);
EXPECT_EQ(&thing, ptr1.Get());
- WeakPtr ptr2;
+ WeakTestPtr ptr2;
EXPECT_FALSE(ptr1 == ptr2);
EXPECT_TRUE(ptr1 != ptr2);
{
- WeakPtr ptr3(ptr1);
+ WeakTestPtr ptr3(ptr1);
EXPECT_TRUE(ptr1 == ptr3);
EXPECT_FALSE(ptr1 != ptr3);
EXPECT_EQ(&thing, ptr3.Get());
{
- WeakPtr ptr4 = ptr1;
+ WeakTestPtr ptr4 = ptr1;
EXPECT_TRUE(ptr1 == ptr4);
EXPECT_FALSE(ptr1 != ptr4);
EXPECT_EQ(&thing, ptr4.Get());
@@ -80,12 +81,12 @@ TEST(fxcrt, WeakPtrNonNull) {
EXPECT_EQ(1, thing.delete_count());
}
-TEST(fxcrt, WeakPtrResetNull) {
+TEST(WeakPtr, ResetNull) {
PseudoDeletable thing;
{
- UniquePtr unique(&thing);
- WeakPtr ptr1(std::move(unique));
- WeakPtr ptr2 = ptr1;
+ UniqueTestPtr unique(&thing);
+ WeakTestPtr ptr1(std::move(unique));
+ WeakTestPtr ptr2 = ptr1;
ptr1.Reset();
EXPECT_FALSE(ptr1);
EXPECT_EQ(nullptr, ptr1.Get());
@@ -98,14 +99,14 @@ TEST(fxcrt, WeakPtrResetNull) {
EXPECT_EQ(1, thing.delete_count());
}
-TEST(fxcrt, WeakPtrResetNonNull) {
+TEST(WeakPtr, ResetNonNull) {
PseudoDeletable thing1;
PseudoDeletable thing2;
{
- UniquePtr unique1(&thing1);
- WeakPtr ptr1(std::move(unique1));
- WeakPtr ptr2 = ptr1;
- UniquePtr unique2(&thing2);
+ UniqueTestPtr unique1(&thing1);
+ WeakTestPtr ptr1(std::move(unique1));
+ WeakTestPtr ptr2 = ptr1;
+ UniqueTestPtr unique2(&thing2);
ptr2.Reset(std::move(unique2));
EXPECT_TRUE(ptr1);
EXPECT_EQ(&thing1, ptr1.Get());
@@ -120,12 +121,12 @@ TEST(fxcrt, WeakPtrResetNonNull) {
EXPECT_EQ(1, thing2.delete_count());
}
-TEST(fxcrt, WeakPtrDeleteObject) {
+TEST(WeakPtr, DeleteObject) {
PseudoDeletable thing;
{
- UniquePtr unique(&thing);
- WeakPtr ptr1(std::move(unique));
- WeakPtr ptr2 = ptr1;
+ UniqueTestPtr unique(&thing);
+ WeakTestPtr ptr1(std::move(unique));
+ WeakTestPtr ptr2 = ptr1;
ptr1.DeleteObject();
EXPECT_FALSE(ptr1);
EXPECT_EQ(nullptr, ptr1.Get());
@@ -138,14 +139,14 @@ TEST(fxcrt, WeakPtrDeleteObject) {
EXPECT_EQ(1, thing.delete_count());
}
-TEST(fxcrt, WeakPtrCyclic) {
+TEST(WeakPtr, Cyclic) {
PseudoDeletable thing1;
PseudoDeletable thing2;
{
- UniquePtr unique1(&thing1);
- UniquePtr unique2(&thing2);
- WeakPtr ptr1(std::move(unique1));
- WeakPtr ptr2(std::move(unique2));
+ UniqueTestPtr unique1(&thing1);
+ UniqueTestPtr unique2(&thing2);
+ WeakTestPtr ptr1(std::move(unique1));
+ WeakTestPtr ptr2(std::move(unique2));
ptr1->SetNext(ptr2);
ptr2->SetNext(ptr1);
}
@@ -154,14 +155,14 @@ TEST(fxcrt, WeakPtrCyclic) {
EXPECT_EQ(0, thing2.delete_count());
}
-TEST(fxcrt, WeakPtrCyclicDeleteObject) {
+TEST(WeakPtr, CyclicDeleteObject) {
PseudoDeletable thing1;
PseudoDeletable thing2;
{
- UniquePtr unique1(&thing1);
- UniquePtr unique2(&thing2);
- WeakPtr ptr1(std::move(unique1));
- WeakPtr ptr2(std::move(unique2));
+ UniqueTestPtr unique1(&thing1);
+ UniqueTestPtr unique2(&thing2);
+ WeakTestPtr ptr1(std::move(unique1));
+ WeakTestPtr ptr2(std::move(unique2));
ptr1->SetNext(ptr2);
ptr2->SetNext(ptr1);
ptr1.DeleteObject();
@@ -171,3 +172,5 @@ TEST(fxcrt, WeakPtrCyclicDeleteObject) {
EXPECT_EQ(1, thing1.delete_count());
EXPECT_EQ(1, thing2.delete_count());
}
+
+} // namespace fxcrt