From 37b12ad873198a9644f3de0d2eff001285e1ad42 Mon Sep 17 00:00:00 2001 From: tsepez Date: Wed, 14 Dec 2016 19:50:23 -0800 Subject: Return unique_ptr from CXFA_FFApp::CreateDoc. Remove one unused CreateDoc variant. Review-Url: https://codereview.chromium.org/2576893002 --- fpdfsdk/fpdfview.cpp | 6 +++--- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 2 +- xfa/fxfa/app/xfa_ffapp.cpp | 18 +++++++----------- xfa/fxfa/xfa_ffapp.h | 6 ++---- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index b49be38716..c292384e88 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -890,10 +890,10 @@ DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha) { - std::unique_ptr pBitmap(new CFX_DIBitmap); - if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) { + auto pBitmap = pdfium::MakeUnique(); + if (!pBitmap->Create(width, height, alpha ? FXDIB_Argb : FXDIB_Rgb32)) return nullptr; - } + return pBitmap.release(); } diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 1995882388..7a0ffeb256 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -92,7 +92,7 @@ bool CPDFXFA_Context::LoadXFADoc() { if (!pApp) return false; - m_pXFADoc.reset(pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get())); + m_pXFADoc = pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get()); if (!m_pXFADoc) { SetLastError(FPDF_ERR_XFALOAD); return false; diff --git a/xfa/fxfa/app/xfa_ffapp.cpp b/xfa/fxfa/app/xfa_ffapp.cpp index 273b9f5b36..219f06e4ff 100644 --- a/xfa/fxfa/app/xfa_ffapp.cpp +++ b/xfa/fxfa/app/xfa_ffapp.cpp @@ -102,21 +102,17 @@ CXFA_FFDocHandler* CXFA_FFApp::GetDocHandler() { return m_pDocHandler.get(); } -CXFA_FFDoc* CXFA_FFApp::CreateDoc( +std::unique_ptr CXFA_FFApp::CreateDoc( IXFA_DocEnvironment* pDocEnvironment, - const CFX_RetainPtr& pStream) { - auto pDoc = pdfium::MakeUnique(this, pDocEnvironment); - return pDoc->OpenDoc(pStream) ? pDoc.release() : nullptr; -} - -CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocEnvironment* pDocEnvironment, - CPDF_Document* pPDFDoc) { + CPDF_Document* pPDFDoc) { if (!pPDFDoc) return nullptr; - std::unique_ptr pDoc(new CXFA_FFDoc(this, pDocEnvironment)); - bool bSuccess = pDoc->OpenDoc(pPDFDoc); - return bSuccess ? pDoc.release() : nullptr; + auto pDoc = pdfium::MakeUnique(this, pDocEnvironment); + if (!pDoc->OpenDoc(pPDFDoc)) + return nullptr; + + return pDoc; } void CXFA_FFApp::SetDefaultFontMgr(std::unique_ptr pFontMgr) { diff --git a/xfa/fxfa/xfa_ffapp.h b/xfa/fxfa/xfa_ffapp.h index bc6e948ebf..411fd2d273 100644 --- a/xfa/fxfa/xfa_ffapp.h +++ b/xfa/fxfa/xfa_ffapp.h @@ -35,10 +35,8 @@ class CXFA_FFApp { explicit CXFA_FFApp(IXFA_AppProvider* pProvider); ~CXFA_FFApp(); - CXFA_FFDoc* CreateDoc(IXFA_DocEnvironment* pDocEnvironment, - const CFX_RetainPtr& pStream); - CXFA_FFDoc* CreateDoc(IXFA_DocEnvironment* pDocEnvironment, - CPDF_Document* pPDFDoc); + std::unique_ptr CreateDoc(IXFA_DocEnvironment* pDocEnvironment, + CPDF_Document* pPDFDoc); void SetDefaultFontMgr(std::unique_ptr pFontMgr); CXFA_FFDocHandler* GetDocHandler(); -- cgit v1.2.3