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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxcrt/extension.h" 7 #include "core/fxcrt/extension.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) { 67 bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) {
68 m_path = wsPath; 68 m_path = wsPath;
69 m_RefCount = 1; 69 m_RefCount = 1;
70 return true; 70 return true;
71 } 71 }
72 72
73 #endif // PDF_ENABLE_XFA 73 #endif // PDF_ENABLE_XFA
74 74
75 class CFX_CRTFileStream final : public IFX_SeekableStream { 75 class CFX_CRTFileStream final : public IFX_SeekableStream {
76 public: 76 public:
77 explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA); 77 template <typename T, typename... Args>
78 ~CFX_CRTFileStream() override; 78 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
79 79
80 // IFX_SeekableStream: 80 // IFX_SeekableStream:
81 FX_FILESIZE GetSize() override; 81 FX_FILESIZE GetSize() override;
82 bool IsEOF() override; 82 bool IsEOF() override;
83 FX_FILESIZE GetPosition() override; 83 FX_FILESIZE GetPosition() override;
84 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; 84 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
85 size_t ReadBlock(void* buffer, size_t size) override; 85 size_t ReadBlock(void* buffer, size_t size) override;
86 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; 86 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override;
87 bool Flush() override; 87 bool Flush() override;
88 88
89 private: 89 private:
90 explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA);
91 ~CFX_CRTFileStream() override;
92
90 std::unique_ptr<IFXCRT_FileAccess> m_pFile; 93 std::unique_ptr<IFXCRT_FileAccess> m_pFile;
91 }; 94 };
92 95
93 CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA) 96 CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA)
94 : m_pFile(std::move(pFA)) {} 97 : m_pFile(std::move(pFA)) {}
95 98
96 CFX_CRTFileStream::~CFX_CRTFileStream() {} 99 CFX_CRTFileStream::~CFX_CRTFileStream() {}
97 100
98 FX_FILESIZE CFX_CRTFileStream::GetSize() { 101 FX_FILESIZE CFX_CRTFileStream::GetSize() {
99 return m_pFile->GetSize(); 102 return m_pFile->GetSize();
(...skipping 26 matching lines...) Expand all
126 bool CFX_CRTFileStream::Flush() { 129 bool CFX_CRTFileStream::Flush() {
127 return m_pFile->Flush(); 130 return m_pFile->Flush();
128 } 131 }
129 132
130 #define FX_MEMSTREAM_BlockSize (64 * 1024) 133 #define FX_MEMSTREAM_BlockSize (64 * 1024)
131 #define FX_MEMSTREAM_Consecutive 0x01 134 #define FX_MEMSTREAM_Consecutive 0x01
132 #define FX_MEMSTREAM_TakeOver 0x02 135 #define FX_MEMSTREAM_TakeOver 0x02
133 136
134 class CFX_MemoryStream final : public IFX_MemoryStream { 137 class CFX_MemoryStream final : public IFX_MemoryStream {
135 public: 138 public:
136 explicit CFX_MemoryStream(bool bConsecutive); 139 template <typename T, typename... Args>
137 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver); 140 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
138 ~CFX_MemoryStream() override;
139 141
140 // IFX_MemoryStream 142 // IFX_MemoryStream
141 FX_FILESIZE GetSize() override; 143 FX_FILESIZE GetSize() override;
142 bool IsEOF() override; 144 bool IsEOF() override;
143 FX_FILESIZE GetPosition() override; 145 FX_FILESIZE GetPosition() override;
144 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; 146 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
145 size_t ReadBlock(void* buffer, size_t size) override; 147 size_t ReadBlock(void* buffer, size_t size) override;
146 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; 148 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override;
147 bool Flush() override; 149 bool Flush() override;
148 bool IsConsecutive() const override; 150 bool IsConsecutive() const override;
149 void EstimateSize(size_t nInitSize, size_t nGrowSize) override; 151 void EstimateSize(size_t nInitSize, size_t nGrowSize) override;
150 uint8_t* GetBuffer() const override; 152 uint8_t* GetBuffer() const override;
151 void AttachBuffer(uint8_t* pBuffer, 153 void AttachBuffer(uint8_t* pBuffer,
152 size_t nSize, 154 size_t nSize,
153 bool bTakeOver = false) override; 155 bool bTakeOver = false) override;
154 void DetachBuffer() override; 156 void DetachBuffer() override;
155 157
156 private: 158 private:
159 explicit CFX_MemoryStream(bool bConsecutive);
160 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver);
161 ~CFX_MemoryStream() override;
162
157 bool ExpandBlocks(size_t size); 163 bool ExpandBlocks(size_t size);
158 164
159 CFX_ArrayTemplate<uint8_t*> m_Blocks; 165 CFX_ArrayTemplate<uint8_t*> m_Blocks;
160 size_t m_nTotalSize; 166 size_t m_nTotalSize;
161 size_t m_nCurSize; 167 size_t m_nCurSize;
162 size_t m_nCurPos; 168 size_t m_nCurPos;
163 size_t m_nGrowSize; 169 size_t m_nGrowSize;
164 uint32_t m_dwFlags; 170 uint32_t m_dwFlags;
165 }; 171 };
166 172
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 395 }
390 #endif // PDF_ENABLE_XFA 396 #endif // PDF_ENABLE_XFA
391 397
392 // static 398 // static
393 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( 399 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename(
394 const FX_CHAR* filename, 400 const FX_CHAR* filename,
395 uint32_t dwModes) { 401 uint32_t dwModes) {
396 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); 402 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
397 if (!pFA->Open(filename, dwModes)) 403 if (!pFA->Open(filename, dwModes))
398 return nullptr; 404 return nullptr;
399 return CFX_RetainPtr<IFX_SeekableStream>( 405 return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA));
400 new CFX_CRTFileStream(std::move(pFA)));
401 } 406 }
402 407
403 // static 408 // static
404 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( 409 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename(
405 const FX_WCHAR* filename, 410 const FX_WCHAR* filename,
406 uint32_t dwModes) { 411 uint32_t dwModes) {
407 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); 412 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
408 if (!pFA->Open(filename, dwModes)) 413 if (!pFA->Open(filename, dwModes))
409 return nullptr; 414 return nullptr;
410 return CFX_RetainPtr<IFX_SeekableStream>( 415 return pdfium::MakeRetain<CFX_CRTFileStream>(std::move(pFA));
411 new CFX_CRTFileStream(std::move(pFA)));
412 } 416 }
413 417
414 // static 418 // static
415 CFX_RetainPtr<IFX_SeekableReadStream> 419 CFX_RetainPtr<IFX_SeekableReadStream>
416 IFX_SeekableReadStream::CreateFromFilename(const FX_CHAR* filename) { 420 IFX_SeekableReadStream::CreateFromFilename(const FX_CHAR* filename) {
417 return IFX_SeekableStream::CreateFromFilename(filename, FX_FILEMODE_ReadOnly); 421 return IFX_SeekableStream::CreateFromFilename(filename, FX_FILEMODE_ReadOnly);
418 } 422 }
419 423
420 // static 424 // static
421 CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(uint8_t* pBuffer, 425 CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(uint8_t* pBuffer,
422 size_t dwSize, 426 size_t dwSize,
423 bool bTakeOver) { 427 bool bTakeOver) {
424 return CFX_RetainPtr<IFX_MemoryStream>( 428 return pdfium::MakeRetain<CFX_MemoryStream>(pBuffer, dwSize, bTakeOver);
425 new CFX_MemoryStream(pBuffer, dwSize, bTakeOver));
426 } 429 }
427 430
428 // static 431 // static
429 CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(bool bConsecutive) { 432 CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(bool bConsecutive) {
430 return CFX_RetainPtr<IFX_MemoryStream>(new CFX_MemoryStream(bConsecutive)); 433 return pdfium::MakeRetain<CFX_MemoryStream>(bConsecutive);
431 } 434 }
432 435
433 FX_FLOAT FXSYS_tan(FX_FLOAT a) { 436 FX_FLOAT FXSYS_tan(FX_FLOAT a) {
434 return (FX_FLOAT)tan(a); 437 return (FX_FLOAT)tan(a);
435 } 438 }
436 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) { 439 FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x) {
437 return FXSYS_log(x) / FXSYS_log(b); 440 return FXSYS_log(x) / FXSYS_log(b);
438 } 441 }
439 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr, 442 FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
440 int32_t iLength, 443 int32_t iLength,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 b = ((const uint8_t*)pGUID)[i]; 677 b = ((const uint8_t*)pGUID)[i];
675 *pBuf++ = gs_FX_pHexChars[b >> 4]; 678 *pBuf++ = gs_FX_pHexChars[b >> 4];
676 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; 679 *pBuf++ = gs_FX_pHexChars[b & 0x0F];
677 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { 680 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) {
678 *pBuf++ = L'-'; 681 *pBuf++ = L'-';
679 } 682 }
680 } 683 }
681 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); 684 bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
682 } 685 }
683 #endif // PDF_ENABLE_XFA 686 #endif // PDF_ENABLE_XFA
OLDNEW
« 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