Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2725)

Unified Diff: core/fxcrt/fx_extension.cpp

Issue 2560783003: Catch stray Retains() and Releases() outside of RetainPtr<>. (Closed)
Patch Set: override required per chrome style Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fxcrt/cfx_retain_ptr.h ('k') | core/fxcrt/fx_xml_parser.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_extension.cpp
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index cbbb86f26be6e62f33d72d9fa8f47a99943a79da..630d4da2aae960c829b32a17cc426ad8666c10d8 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -74,8 +74,8 @@ bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) {
class CFX_CRTFileStream final : public IFX_SeekableStream {
public:
- explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA);
- ~CFX_CRTFileStream() override;
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
// IFX_SeekableStream:
FX_FILESIZE GetSize() override;
@@ -87,6 +87,9 @@ class CFX_CRTFileStream final : public IFX_SeekableStream {
bool Flush() override;
private:
+ explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA);
+ ~CFX_CRTFileStream() override;
+
std::unique_ptr<IFXCRT_FileAccess> m_pFile;
};
@@ -133,9 +136,8 @@ bool CFX_CRTFileStream::Flush() {
class CFX_MemoryStream final : public IFX_MemoryStream {
public:
- explicit CFX_MemoryStream(bool bConsecutive);
- CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver);
- ~CFX_MemoryStream() override;
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
// IFX_MemoryStream
FX_FILESIZE GetSize() override;
@@ -154,6 +156,10 @@ class CFX_MemoryStream final : public IFX_MemoryStream {
void DetachBuffer() override;
private:
+ explicit CFX_MemoryStream(bool bConsecutive);
+ CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver);
+ ~CFX_MemoryStream() override;
+
bool ExpandBlocks(size_t size);
CFX_ArrayTemplate<uint8_t*> m_Blocks;
@@ -396,8 +402,7 @@ CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename(
std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
if (!pFA->Open(filename, dwModes))
return nullptr;
- return CFX_RetainPtr<IFX_SeekableStream>(
- new CFX_CRTFileStream(std::move(pFA)));
+ return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA));
}
// static
@@ -407,8 +412,7 @@ CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename(
std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
if (!pFA->Open(filename, dwModes))
return nullptr;
- return CFX_RetainPtr<IFX_SeekableStream>(
- new CFX_CRTFileStream(std::move(pFA)));
+ return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA));
}
// static
@@ -421,13 +425,12 @@ IFX_SeekableReadStream::CreateFromFilename(const FX_CHAR* filename) {
CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(uint8_t* pBuffer,
size_t dwSize,
bool bTakeOver) {
- return CFX_RetainPtr<IFX_MemoryStream>(
- new CFX_MemoryStream(pBuffer, dwSize, bTakeOver));
+ return pdfium::MakeRetain<CFX_MemoryStream>(pBuffer, dwSize, bTakeOver);
}
// static
CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(bool bConsecutive) {
- return CFX_RetainPtr<IFX_MemoryStream>(new CFX_MemoryStream(bConsecutive));
+ return pdfium::MakeRetain<CFX_MemoryStream>(bConsecutive);
}
FX_FLOAT FXSYS_tan(FX_FLOAT a) {
« no previous file with comments | « core/fxcrt/cfx_retain_ptr.h ('k') | core/fxcrt/fx_xml_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698