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

Side by Side Diff: core/fxcrt/fx_xml_parser.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/fx_extension.cpp ('k') | xfa/fgas/crt/fgas_stream.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/xml_int.h" 7 #include "core/fxcrt/xml_int.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 bool g_FXCRT_XML_IsNameIntro(uint8_t ch) { 63 bool g_FXCRT_XML_IsNameIntro(uint8_t ch) {
64 return !!(g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameIntro); 64 return !!(g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameIntro);
65 } 65 }
66 66
67 bool g_FXCRT_XML_IsNameChar(uint8_t ch) { 67 bool g_FXCRT_XML_IsNameChar(uint8_t ch) {
68 return !!(g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameChar); 68 return !!(g_FXCRT_XML_ByteTypes[ch] & FXCRTM_XML_CHARTYPE_NameChar);
69 } 69 }
70 70
71 class CXML_DataBufAcc : public IFX_BufferedReadStream { 71 class CXML_DataBufAcc : public IFX_BufferedReadStream {
72 public: 72 public:
73 CXML_DataBufAcc(const uint8_t* pBuffer, size_t size); 73 template <typename T, typename... Args>
74 ~CXML_DataBufAcc() override; 74 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
75 75
76 // IFX_BufferedReadStream 76 // IFX_BufferedReadStream
77 bool IsEOF() override; 77 bool IsEOF() override;
78 FX_FILESIZE GetPosition() override; 78 FX_FILESIZE GetPosition() override;
79 size_t ReadBlock(void* buffer, size_t size) override; 79 size_t ReadBlock(void* buffer, size_t size) override;
80 bool ReadNextBlock(bool bRestart) override; 80 bool ReadNextBlock(bool bRestart) override;
81 const uint8_t* GetBlockBuffer() override; 81 const uint8_t* GetBlockBuffer() override;
82 size_t GetBlockSize() override; 82 size_t GetBlockSize() override;
83 FX_FILESIZE GetBlockOffset() override; 83 FX_FILESIZE GetBlockOffset() override;
84 84
85 private: 85 private:
86 CXML_DataBufAcc(const uint8_t* pBuffer, size_t size);
87 ~CXML_DataBufAcc() override;
88
86 const uint8_t* m_pBuffer; 89 const uint8_t* m_pBuffer;
87 size_t m_dwSize; 90 size_t m_dwSize;
88 size_t m_dwCurPos; 91 size_t m_dwCurPos;
89 }; 92 };
90 93
91 CXML_DataBufAcc::CXML_DataBufAcc(const uint8_t* pBuffer, size_t size) 94 CXML_DataBufAcc::CXML_DataBufAcc(const uint8_t* pBuffer, size_t size)
92 : m_pBuffer(pBuffer), m_dwSize(size), m_dwCurPos(0) {} 95 : m_pBuffer(pBuffer), m_dwSize(size), m_dwCurPos(0) {}
93 96
94 CXML_DataBufAcc::~CXML_DataBufAcc() {} 97 CXML_DataBufAcc::~CXML_DataBufAcc() {}
95 98
(...skipping 27 matching lines...) Expand all
123 size_t CXML_DataBufAcc::GetBlockSize() { 126 size_t CXML_DataBufAcc::GetBlockSize() {
124 return m_dwSize; 127 return m_dwSize;
125 } 128 }
126 129
127 FX_FILESIZE CXML_DataBufAcc::GetBlockOffset() { 130 FX_FILESIZE CXML_DataBufAcc::GetBlockOffset() {
128 return 0; 131 return 0;
129 } 132 }
130 133
131 class CXML_DataStmAcc : public IFX_BufferedReadStream { 134 class CXML_DataStmAcc : public IFX_BufferedReadStream {
132 public: 135 public:
133 explicit CXML_DataStmAcc( 136 template <typename T, typename... Args>
134 const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead); 137 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
135 ~CXML_DataStmAcc() override;
136 138
137 // IFX_BufferedReadStream 139 // IFX_BufferedReadStream
138 bool IsEOF() override; 140 bool IsEOF() override;
139 FX_FILESIZE GetPosition() override; 141 FX_FILESIZE GetPosition() override;
140 size_t ReadBlock(void* buffer, size_t size) override; 142 size_t ReadBlock(void* buffer, size_t size) override;
141 bool ReadNextBlock(bool bRestart) override; 143 bool ReadNextBlock(bool bRestart) override;
142 const uint8_t* GetBlockBuffer() override; 144 const uint8_t* GetBlockBuffer() override;
143 size_t GetBlockSize() override; 145 size_t GetBlockSize() override;
144 FX_FILESIZE GetBlockOffset() override; 146 FX_FILESIZE GetBlockOffset() override;
145 147
146 private: 148 private:
149 explicit CXML_DataStmAcc(
150 const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead);
151 ~CXML_DataStmAcc() override;
152
147 CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; 153 CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead;
148 uint8_t* m_pBuffer; 154 uint8_t* m_pBuffer;
149 FX_FILESIZE m_nStart; 155 FX_FILESIZE m_nStart;
150 size_t m_dwSize; 156 size_t m_dwSize;
151 }; 157 };
152 158
153 CXML_DataStmAcc::CXML_DataStmAcc( 159 CXML_DataStmAcc::CXML_DataStmAcc(
154 const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead) 160 const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead)
155 : m_pFileRead(pFileRead), m_pBuffer(nullptr), m_nStart(0), m_dwSize(0) { 161 : m_pFileRead(pFileRead), m_pBuffer(nullptr), m_nStart(0), m_dwSize(0) {
156 ASSERT(m_pFileRead); 162 ASSERT(m_pFileRead);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 : m_nOffset(0), 214 : m_nOffset(0),
209 m_bSaveSpaceChars(false), 215 m_bSaveSpaceChars(false),
210 m_pBuffer(nullptr), 216 m_pBuffer(nullptr),
211 m_dwBufferSize(0), 217 m_dwBufferSize(0),
212 m_nBufferOffset(0), 218 m_nBufferOffset(0),
213 m_dwIndex(0) {} 219 m_dwIndex(0) {}
214 220
215 CXML_Parser::~CXML_Parser() {} 221 CXML_Parser::~CXML_Parser() {}
216 222
217 bool CXML_Parser::Init(uint8_t* pBuffer, size_t size) { 223 bool CXML_Parser::Init(uint8_t* pBuffer, size_t size) {
218 m_pDataAcc.Reset(new CXML_DataBufAcc(pBuffer, size)); 224 m_pDataAcc = pdfium::MakeRetain<CXML_DataBufAcc>(pBuffer, size);
219 return Init(); 225 return Init();
220 } 226 }
221 227
222 bool CXML_Parser::Init(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead) { 228 bool CXML_Parser::Init(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead) {
223 m_pDataAcc.Reset(new CXML_DataStmAcc(pFileRead)); 229 m_pDataAcc = pdfium::MakeRetain<CXML_DataStmAcc>(pFileRead);
224 return Init(); 230 return Init();
225 } 231 }
226 232
227 bool CXML_Parser::Init(const CFX_RetainPtr<IFX_BufferedReadStream>& pBuffer) { 233 bool CXML_Parser::Init(const CFX_RetainPtr<IFX_BufferedReadStream>& pBuffer) {
228 if (!pBuffer) 234 if (!pBuffer)
229 return false; 235 return false;
230 236
231 m_pDataAcc = pBuffer; 237 m_pDataAcc = pBuffer;
232 return Init(); 238 return Init();
233 } 239 }
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 m_pMap->push_back({space, name, CFX_WideString(value)}); 953 m_pMap->push_back({space, name, CFX_WideString(value)});
948 } 954 }
949 955
950 int CXML_AttrMap::GetSize() const { 956 int CXML_AttrMap::GetSize() const {
951 return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0; 957 return m_pMap ? pdfium::CollectionSize<int>(*m_pMap) : 0;
952 } 958 }
953 959
954 CXML_AttrItem& CXML_AttrMap::GetAt(int index) const { 960 CXML_AttrItem& CXML_AttrMap::GetAt(int index) const {
955 return (*m_pMap)[index]; 961 return (*m_pMap)[index];
956 } 962 }
OLDNEW
« no previous file with comments | « core/fxcrt/fx_extension.cpp ('k') | xfa/fgas/crt/fgas_stream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698