From 833619b4441915c7c55085d44b3221eaef0d9800 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 7 Dec 2016 09:21:17 -0800 Subject: 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 --- core/fxcodec/codec/fx_codec_tiff.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'core/fxcodec/codec/fx_codec_tiff.cpp') diff --git a/core/fxcodec/codec/fx_codec_tiff.cpp b/core/fxcodec/codec/fx_codec_tiff.cpp index 8046f1cc39..be9c7d447f 100644 --- a/core/fxcodec/codec/fx_codec_tiff.cpp +++ b/core/fxcodec/codec/fx_codec_tiff.cpp @@ -8,8 +8,10 @@ #include "core/fxcodec/codec/codec_int.h" #include "core/fxcodec/fx_codec.h" +#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_safe_types.h" #include "core/fxge/fx_dib.h" +#include "third_party/base/ptr_util.h" extern "C" { #include "third_party/libtiff/tiffiop.h" @@ -20,7 +22,7 @@ class CCodec_TiffContext { CCodec_TiffContext(); ~CCodec_TiffContext(); - bool InitDecoder(IFX_SeekableReadStream* file_ptr); + bool InitDecoder(const CFX_RetainPtr& file_ptr); bool LoadFrameInfo(int32_t frame, int32_t* width, int32_t* height, @@ -29,7 +31,7 @@ class CCodec_TiffContext { CFX_DIBAttribute* pAttribute); bool Decode(CFX_DIBitmap* pDIBitmap); - IFX_SeekableReadStream* io_in() const { return m_io_in; } + CFX_RetainPtr io_in() const { return m_io_in; } uint32_t offset() const { return m_offset; } void set_offset(uint32_t offset) { m_offset = offset; } @@ -52,7 +54,7 @@ class CCodec_TiffContext { uint16_t bps, uint16_t spp); - IFX_SeekableReadStream* m_io_in; + CFX_RetainPtr m_io_in; uint32_t m_offset; TIFF* m_tif_ctx; }; @@ -215,7 +217,8 @@ CCodec_TiffContext::~CCodec_TiffContext() { TIFFClose(m_tif_ctx); } -bool CCodec_TiffContext::InitDecoder(IFX_SeekableReadStream* file_ptr) { +bool CCodec_TiffContext::InitDecoder( + const CFX_RetainPtr& file_ptr) { m_io_in = file_ptr; m_tif_ctx = tiff_open(this, "r"); return !!m_tif_ctx; @@ -462,13 +465,12 @@ bool CCodec_TiffContext::Decode(CFX_DIBitmap* pDIBitmap) { } CCodec_TiffContext* CCodec_TiffModule::CreateDecoder( - IFX_SeekableReadStream* file_ptr) { - CCodec_TiffContext* pDecoder = new CCodec_TiffContext; - if (!pDecoder->InitDecoder(file_ptr)) { - delete pDecoder; + const CFX_RetainPtr& file_ptr) { + auto pDecoder = pdfium::MakeUnique(); + if (!pDecoder->InitDecoder(file_ptr)) return nullptr; - } - return pDecoder; + + return pDecoder.release(); } bool CCodec_TiffModule::LoadFrameInfo(CCodec_TiffContext* ctx, -- cgit v1.2.3