From f0a128283aeaeb75ee2f62d0f25ba42ac5b07073 Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 20 May 2016 16:53:07 -0700 Subject: Remove Release() from CFX_Barcode Review-Url: https://codereview.chromium.org/2000883002 --- xfa/fwl/basewidget/fwl_barcodeimp.cpp | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) (limited to 'xfa/fwl/basewidget/fwl_barcodeimp.cpp') diff --git a/xfa/fwl/basewidget/fwl_barcodeimp.cpp b/xfa/fwl/basewidget/fwl_barcodeimp.cpp index 57a3c93e9e..97ade357d3 100644 --- a/xfa/fwl/basewidget/fwl_barcodeimp.cpp +++ b/xfa/fwl/basewidget/fwl_barcodeimp.cpp @@ -32,12 +32,10 @@ FX_BOOL IFWL_Barcode::IsProtectedType() { CFWL_BarcodeImp::CFWL_BarcodeImp(const CFWL_WidgetImpProperties& properties, IFWL_Widget* pOuter) : CFWL_EditImp(properties, pOuter), - m_pBarcodeEngine(NULL), m_dwStatus(0), m_type(BC_UNKNOWN) {} -CFWL_BarcodeImp::~CFWL_BarcodeImp() { - ReleaseBarcodeEngine(); -} + +CFWL_BarcodeImp::~CFWL_BarcodeImp() {} FWL_Error CFWL_BarcodeImp::GetClassName(CFX_WideString& wsClass) const { wsClass = FWL_CLASS_Barcode; @@ -59,7 +57,7 @@ FWL_Error CFWL_BarcodeImp::Initialize() { FWL_Error CFWL_BarcodeImp::Finalize() { delete m_pDelegate; m_pDelegate = nullptr; - ReleaseBarcodeEngine(); + m_pBarcodeEngine.reset(); return CFWL_EditImp::Finalize(); } FWL_Error CFWL_BarcodeImp::Update() { @@ -182,29 +180,21 @@ void CFWL_BarcodeImp::CreateBarcodeEngine() { if (m_pBarcodeEngine || m_type == BC_UNKNOWN) return; - m_pBarcodeEngine = new CFX_Barcode; - if (!m_pBarcodeEngine->Create(m_type)) { - m_pBarcodeEngine->Release(); - m_pBarcodeEngine = nullptr; - } + std::unique_ptr pBarcode(new CFX_Barcode); + if (pBarcode->Create(m_type)) + m_pBarcodeEngine = std::move(pBarcode); } -void CFWL_BarcodeImp::ReleaseBarcodeEngine() { - if (m_pBarcodeEngine) { - m_pBarcodeEngine->Release(); - m_pBarcodeEngine = NULL; - } -} void CFWL_BarcodeImp::SetType(BC_TYPE type) { - if (m_type == type) { + if (m_type == type) return; - } - ReleaseBarcodeEngine(); + + m_pBarcodeEngine.reset(); m_type = type; m_dwStatus = XFA_BCS_NeedUpdate; } FWL_Error CFWL_BarcodeImp::SetText(const CFX_WideString& wsText) { - ReleaseBarcodeEngine(); + m_pBarcodeEngine.reset(); m_dwStatus = XFA_BCS_NeedUpdate; return CFWL_EditImp::SetText(wsText); } @@ -226,7 +216,7 @@ CFWL_BarcodeImpDelegate::CFWL_BarcodeImpDelegate(CFWL_BarcodeImp* pOwner) void CFWL_BarcodeImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { if (pEvent->GetClassID() == CFWL_EventType::TextChanged) { CFWL_BarcodeImp* pOwner = static_cast(m_pOwner); - pOwner->ReleaseBarcodeEngine(); + pOwner->m_pBarcodeEngine.reset(); pOwner->m_dwStatus = XFA_BCS_NeedUpdate; } CFWL_EditImpDelegate::OnProcessEvent(pEvent); -- cgit v1.2.3