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

Unified Diff: core/fxcrt/fx_xml_parser.cpp

Issue 2451493002: Refcount all the IFX_ stream classes all the time. (Closed)
Patch Set: Clean up cast expression 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/fx_xml.h ('k') | core/fxcrt/xml_int.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_xml_parser.cpp
diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp
index 803ba597e528127aa1627b8d161c99f7e83749cf..ab309263878fadf7df61d0ffa5f9c1fb5518c6e9 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)
« no previous file with comments | « core/fxcrt/fx_xml.h ('k') | core/fxcrt/xml_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698