summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_xml_parser.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-07 09:21:17 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-07 09:21:18 -0800
commit833619b4441915c7c55085d44b3221eaef0d9800 (patch)
tree68bf76e83078223ba03f490c2c13f484e40154d4 /core/fxcrt/fx_xml_parser.cpp
parent8f875507a986d10335e40a5f7c1679aff9770d0a (diff)
downloadpdfium-833619b4441915c7c55085d44b3221eaef0d9800.tar.xz
Refcount all the IFX_ stream classes all the time.
We can remove a lot of "bOwnsStream" logic in the process. Always pass these by const reference, in case the called method wants to hang on to the stream (one exception is where we stick a raw pointer into a void* slot in a context from another layer). Review-Url: https://codereview.chromium.org/2451493002
Diffstat (limited to 'core/fxcrt/fx_xml_parser.cpp')
-rw-r--r--core/fxcrt/fx_xml_parser.cpp70
1 files changed, 30 insertions, 40 deletions
diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp
index 803ba597e5..ab30926387 100644
--- a/core/fxcrt/fx_xml_parser.cpp
+++ b/core/fxcrt/fx_xml_parser.cpp
@@ -74,7 +74,6 @@ class CXML_DataBufAcc : public IFX_BufferedReadStream {
~CXML_DataBufAcc() override;
// IFX_BufferedReadStream
- void Release() override;
bool IsEOF() override;
FX_FILESIZE GetPosition() override;
size_t ReadBlock(void* buffer, size_t size) override;
@@ -94,10 +93,6 @@ CXML_DataBufAcc::CXML_DataBufAcc(const uint8_t* pBuffer, size_t size)
CXML_DataBufAcc::~CXML_DataBufAcc() {}
-void CXML_DataBufAcc::Release() {
- delete this;
-}
-
bool CXML_DataBufAcc::IsEOF() {
return m_dwCurPos >= m_dwSize;
}
@@ -135,11 +130,11 @@ FX_FILESIZE CXML_DataBufAcc::GetBlockOffset() {
class CXML_DataStmAcc : public IFX_BufferedReadStream {
public:
- explicit CXML_DataStmAcc(IFX_SeekableReadStream* pFileRead);
+ explicit CXML_DataStmAcc(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead);
~CXML_DataStmAcc() override;
// IFX_BufferedReadStream
- void Release() override;
bool IsEOF() override;
FX_FILESIZE GetPosition() override;
size_t ReadBlock(void* buffer, size_t size) override;
@@ -149,13 +144,14 @@ class CXML_DataStmAcc : public IFX_BufferedReadStream {
FX_FILESIZE GetBlockOffset() override;
private:
- IFX_SeekableReadStream* m_pFileRead;
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead;
uint8_t* m_pBuffer;
FX_FILESIZE m_nStart;
size_t m_dwSize;
};
-CXML_DataStmAcc::CXML_DataStmAcc(IFX_SeekableReadStream* pFileRead)
+CXML_DataStmAcc::CXML_DataStmAcc(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead)
: m_pFileRead(pFileRead), m_pBuffer(nullptr), m_nStart(0), m_dwSize(0) {
ASSERT(m_pFileRead);
}
@@ -164,10 +160,6 @@ CXML_DataStmAcc::~CXML_DataStmAcc() {
FX_Free(m_pBuffer);
}
-void CXML_DataStmAcc::Release() {
- delete this;
-}
-
bool CXML_DataStmAcc::IsEOF() {
return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize();
}
@@ -213,41 +205,34 @@ FX_FILESIZE CXML_DataStmAcc::GetBlockOffset() {
} // namespace
CXML_Parser::CXML_Parser()
- : m_pDataAcc(nullptr),
- m_bOwnedStream(false),
- m_nOffset(0),
+ : m_nOffset(0),
m_bSaveSpaceChars(false),
m_pBuffer(nullptr),
m_dwBufferSize(0),
m_nBufferOffset(0),
m_dwIndex(0) {}
-CXML_Parser::~CXML_Parser() {
- if (m_bOwnedStream) {
- m_pDataAcc->Release();
- }
-}
+CXML_Parser::~CXML_Parser() {}
bool CXML_Parser::Init(uint8_t* pBuffer, size_t size) {
- m_pDataAcc = new CXML_DataBufAcc(pBuffer, size);
- return Init(true);
+ m_pDataAcc.Reset(new CXML_DataBufAcc(pBuffer, size));
+ return Init();
}
-bool CXML_Parser::Init(IFX_SeekableReadStream* pFileRead) {
- m_pDataAcc = new CXML_DataStmAcc(pFileRead);
- return Init(true);
+bool CXML_Parser::Init(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead) {
+ m_pDataAcc.Reset(new CXML_DataStmAcc(pFileRead));
+ return Init();
}
-bool CXML_Parser::Init(IFX_BufferedReadStream* pBuffer) {
+bool CXML_Parser::Init(const CFX_RetainPtr<IFX_BufferedReadStream>& pBuffer) {
if (!pBuffer)
return false;
m_pDataAcc = pBuffer;
- return Init(false);
+ return Init();
}
-bool CXML_Parser::Init(bool bOwndedStream) {
- m_bOwnedStream = bOwndedStream;
+bool CXML_Parser::Init() {
m_nOffset = 0;
return ReadNextBlock();
}
@@ -701,24 +686,29 @@ CXML_Element* CXML_Element::Parse(const void* pBuffer,
}
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
-CXML_Element* CXML_Element::Parse(IFX_SeekableReadStream* pFile,
- bool bSaveSpaceChars,
- FX_FILESIZE* pParsedSize) {
+
+CXML_Element* CXML_Element::Parse(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
+ bool bSaveSpaceChars,
+ FX_FILESIZE* pParsedSize) {
CXML_Parser parser;
- if (!parser.Init(pFile)) {
+ if (!parser.Init(pFile))
return nullptr;
- }
+
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
-CXML_Element* CXML_Element::Parse(IFX_BufferedReadStream* pBuffer,
- bool bSaveSpaceChars,
- FX_FILESIZE* pParsedSize) {
+
+CXML_Element* CXML_Element::Parse(
+ const CFX_RetainPtr<IFX_BufferedReadStream>& pBuffer,
+ bool bSaveSpaceChars,
+ FX_FILESIZE* pParsedSize) {
CXML_Parser parser;
- if (!parser.Init(pBuffer)) {
+ if (!parser.Init(pBuffer))
return nullptr;
- }
+
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
+
CXML_Element::CXML_Element() : m_QSpaceName(), m_TagName(), m_AttrMap() {}
CXML_Element::CXML_Element(const CFX_ByteStringC& qSpace,
const CFX_ByteStringC& tagName)