diff options
author | tsepez <tsepez@chromium.org> | 2016-05-19 17:31:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-19 17:31:01 -0700 |
commit | 411f1185f44b7862a9b1c16e588407ae197752dd (patch) | |
tree | c02ce8943cd41b857c198ef5e5bc7ef847368199 /core/fxcrt | |
parent | 1f36fa860a170081f66809d634ec7ab83d7cb25e (diff) | |
download | pdfium-411f1185f44b7862a9b1c16e588407ae197752dd.tar.xz |
Remove Release() from IFXCRT_FileAccess.
Remove some unused impls.
Review-Url: https://codereview.chromium.org/1994323002
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/extension.h | 9 | ||||
-rw-r--r-- | core/fxcrt/fx_extension.cpp | 39 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_platforms.cpp | 132 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_platforms.h | 42 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_posix.cpp | 9 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_posix.h | 1 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_windows.cpp | 8 | ||||
-rw-r--r-- | core/fxcrt/fxcrt_windows.h | 1 |
8 files changed, 28 insertions, 213 deletions
diff --git a/core/fxcrt/extension.h b/core/fxcrt/extension.h index b0e7b9e117..698bded9b6 100644 --- a/core/fxcrt/extension.h +++ b/core/fxcrt/extension.h @@ -8,17 +8,19 @@ #define CORE_FXCRT_EXTENSION_H_ #include <algorithm> +#include <memory> #include "core/fxcrt/include/fx_basic.h" #include "core/fxcrt/include/fx_safe_types.h" class IFXCRT_FileAccess { public: + static IFXCRT_FileAccess* Create(); virtual ~IFXCRT_FileAccess() {} + virtual FX_BOOL Open(const CFX_ByteStringC& fileName, uint32_t dwMode) = 0; virtual FX_BOOL Open(const CFX_WideStringC& fileName, uint32_t dwMode) = 0; virtual void Close() = 0; - virtual void Release() = 0; virtual FX_FILESIZE GetSize() const = 0; virtual FX_FILESIZE GetPosition() const = 0; virtual FX_FILESIZE SetPosition(FX_FILESIZE pos) = 0; @@ -31,7 +33,6 @@ class IFXCRT_FileAccess { virtual FX_BOOL Flush() = 0; virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0; }; -IFXCRT_FileAccess* FXCRT_FileAccess_Create(); #ifdef PDF_ENABLE_XFA class CFX_CRTFileAccess : public IFX_FileAccess { @@ -69,7 +70,7 @@ class CFX_CRTFileAccess : public IFX_FileAccess { class CFX_CRTFileStream final : public IFX_FileStream { public: - explicit CFX_CRTFileStream(IFXCRT_FileAccess* pFA); + explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA); ~CFX_CRTFileStream() override; // IFX_FileStream: @@ -86,7 +87,7 @@ class CFX_CRTFileStream final : public IFX_FileStream { FX_BOOL Flush() override; protected: - IFXCRT_FileAccess* m_pFile; + std::unique_ptr<IFXCRT_FileAccess> m_pFile; uint32_t m_dwCount; }; diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index 1dddf09fd6..197022362f 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -4,6 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com +#include <utility> + #include "core/fxcrt/extension.h" #include "core/fxcrt/include/fx_basic.h" #include "core/fxcrt/include/fx_ext.h" @@ -14,14 +16,10 @@ #include <ctime> #endif -CFX_CRTFileStream::CFX_CRTFileStream(IFXCRT_FileAccess* pFA) - : m_pFile(pFA), m_dwCount(1) {} +CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA) + : m_pFile(std::move(pFA)), m_dwCount(1) {} -CFX_CRTFileStream::~CFX_CRTFileStream() { - if (m_pFile) { - m_pFile->Release(); - } -} +CFX_CRTFileStream::~CFX_CRTFileStream() {} IFX_FileStream* CFX_CRTFileStream::Retain() { m_dwCount++; @@ -83,27 +81,18 @@ IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) { #endif // PDF_ENABLE_XFA IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) { - IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); - if (!pFA) { - return NULL; - } - if (!pFA->Open(filename, dwModes)) { - pFA->Release(); - return NULL; - } - return new CFX_CRTFileStream(pFA); + std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); + if (!pFA->Open(filename, dwModes)) + return nullptr; + return new CFX_CRTFileStream(std::move(pFA)); } + IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, uint32_t dwModes) { - IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); - if (!pFA) { - return NULL; - } - if (!pFA->Open(filename, dwModes)) { - pFA->Release(); - return NULL; - } - return new CFX_CRTFileStream(pFA); + std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); + if (!pFA->Open(filename, dwModes)) + return nullptr; + return new CFX_CRTFileStream(std::move(pFA)); } IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename) { return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); diff --git a/core/fxcrt/fxcrt_platforms.cpp b/core/fxcrt/fxcrt_platforms.cpp deleted file mode 100644 index 8f134c751d..0000000000 --- a/core/fxcrt/fxcrt_platforms.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "core/fxcrt/fxcrt_platforms.h" - -#include "core/fxcrt/include/fx_basic.h" - -#if (_FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ && \ - _FXM_PLATFORM_ != _FXM_PLATFORM_LINUX_ && \ - _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ && \ - _FXM_PLATFORM_ != _FXM_PLATFORM_ANDROID_) -IFXCRT_FileAccess* FXCRT_FileAccess_Create() { - return new CFXCRT_FileAccess_CRT; -} -void FXCRT_GetFileModeString(uint32_t dwModes, CFX_ByteString& bsMode) { - if (dwModes & FX_FILEMODE_ReadOnly) { - bsMode = "rb"; - } else if (dwModes & FX_FILEMODE_Truncate) { - bsMode = "w+b"; - } else { - bsMode = "a+b"; - } -} -void FXCRT_GetFileModeString(uint32_t dwModes, CFX_WideString& wsMode) { - if (dwModes & FX_FILEMODE_ReadOnly) { - wsMode = FX_WSTRC(L"rb"); - } else if (dwModes & FX_FILEMODE_Truncate) { - wsMode = FX_WSTRC(L"w+b"); - } else { - wsMode = FX_WSTRC(L"a+b"); - } -} -CFXCRT_FileAccess_CRT::CFXCRT_FileAccess_CRT() : m_hFile(NULL) {} -CFXCRT_FileAccess_CRT::~CFXCRT_FileAccess_CRT() { - Close(); -} -FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_ByteStringC& fileName, - uint32_t dwMode) { - if (m_hFile) { - return FALSE; - } - CFX_ByteString strMode; - FXCRT_GetFileModeString(dwMode, strMode); - m_hFile = FXSYS_fopen(fileName.c_str(), strMode.c_str()); - return m_hFile != NULL; -} -FX_BOOL CFXCRT_FileAccess_CRT::Open(const CFX_WideStringC& fileName, - uint32_t dwMode) { - if (m_hFile) { - return FALSE; - } - CFX_WideString strMode; - FXCRT_GetFileModeString(dwMode, strMode); - m_hFile = FXSYS_wfopen(fileName.raw_str(), strMode.c_str()); - return m_hFile != NULL; -} -void CFXCRT_FileAccess_CRT::Close() { - if (!m_hFile) { - return; - } - FXSYS_fclose(m_hFile); - m_hFile = NULL; -} -void CFXCRT_FileAccess_CRT::Release() { - delete this; -} -FX_FILESIZE CFXCRT_FileAccess_CRT::GetSize() const { - if (!m_hFile) { - return 0; - } - FX_FILESIZE pos = (FX_FILESIZE)FXSYS_ftell(m_hFile); - FXSYS_fseek(m_hFile, 0, FXSYS_SEEK_END); - FX_FILESIZE size = (FX_FILESIZE)FXSYS_ftell(m_hFile); - FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET); - return size; -} -FX_FILESIZE CFXCRT_FileAccess_CRT::GetPosition() const { - if (!m_hFile) { - return (FX_FILESIZE)-1; - } - return (FX_FILESIZE)FXSYS_ftell(m_hFile); -} -FX_FILESIZE CFXCRT_FileAccess_CRT::SetPosition(FX_FILESIZE pos) { - if (!m_hFile) { - return (FX_FILESIZE)-1; - } - FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET); - return (FX_FILESIZE)FXSYS_ftell(m_hFile); -} -size_t CFXCRT_FileAccess_CRT::Read(void* pBuffer, size_t szBuffer) { - if (!m_hFile) { - return 0; - } - return FXSYS_fread(pBuffer, 1, szBuffer, m_hFile); -} -size_t CFXCRT_FileAccess_CRT::Write(const void* pBuffer, size_t szBuffer) { - if (!m_hFile) { - return 0; - } - return FXSYS_fwrite(pBuffer, 1, szBuffer, m_hFile); -} -size_t CFXCRT_FileAccess_CRT::ReadPos(void* pBuffer, - size_t szBuffer, - FX_FILESIZE pos) { - if (!m_hFile) { - return (FX_FILESIZE)-1; - } - FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET); - return FXSYS_fread(pBuffer, 1, szBuffer, m_hFile); -} -size_t CFXCRT_FileAccess_CRT::WritePos(const void* pBuffer, - size_t szBuffer, - FX_FILESIZE pos) { - if (!m_hFile) { - return (FX_FILESIZE)-1; - } - FXSYS_fseek(m_hFile, pos, FXSYS_SEEK_SET); - return FXSYS_fwrite(pBuffer, 1, szBuffer, m_hFile); -} -FX_BOOL CFXCRT_FileAccess_CRT::Flush() { - if (!m_hFile) { - return FALSE; - } - return !FXSYS_fflush(m_hFile); -} -FX_BOOL CFXCRT_FileAccess_CRT::Truncate(FX_FILESIZE szFile) { - return FALSE; -} -#endif diff --git a/core/fxcrt/fxcrt_platforms.h b/core/fxcrt/fxcrt_platforms.h deleted file mode 100644 index 736c116625..0000000000 --- a/core/fxcrt/fxcrt_platforms.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FXCRT_FXCRT_PLATFORMS_H_ -#define CORE_FXCRT_FXCRT_PLATFORMS_H_ - -#include "core/fxcrt/extension.h" - -#if _FX_OS_ == _FX_ANDROID_ -void FXCRT_GetFileModeString(uint32_t dwModes, CFX_ByteString& bsMode); -void FXCRT_GetFileModeString(uint32_t dwModes, CFX_WideString& wsMode); -class CFXCRT_FileAccess_CRT : public IFXCRT_FileAccess { - public: - CFXCRT_FileAccess_CRT(); - ~CFXCRT_FileAccess_CRT() override; - - // IFXCRT_FileAccess - FX_BOOL Open(const CFX_ByteStringC& fileName, uint32_t dwMode) override; - FX_BOOL Open(const CFX_WideStringC& fileName, uint32_t dwMode) override; - void Close() override; - void Release() override; - FX_FILESIZE GetSize() const override; - FX_FILESIZE GetPosition() const override; - FX_FILESIZE SetPosition(FX_FILESIZE pos) override; - size_t Read(void* pBuffer, size_t szBuffer) override; - size_t Write(const void* pBuffer, size_t szBuffer) override; - size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) override; - size_t WritePos(const void* pBuffer, - size_t szBuffer, - FX_FILESIZE pos) override; - FX_BOOL Flush() override; - FX_BOOL Truncate(FX_FILESIZE szFile) override; - - protected: - FXSYS_FILE* m_hFile; -}; -#endif - -#endif // CORE_FXCRT_FXCRT_PLATFORMS_H_ diff --git a/core/fxcrt/fxcrt_posix.cpp b/core/fxcrt/fxcrt_posix.cpp index 9237acef6b..053f89c2c9 100644 --- a/core/fxcrt/fxcrt_posix.cpp +++ b/core/fxcrt/fxcrt_posix.cpp @@ -11,9 +11,12 @@ #if _FXM_PLATFORM_ == _FXM_PLATFORM_LINUX_ || \ _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ || \ _FXM_PLATFORM_ == _FXM_PLATFORM_ANDROID_ -IFXCRT_FileAccess* FXCRT_FileAccess_Create() { + +// static +IFXCRT_FileAccess* IFXCRT_FileAccess::Create() { return new CFXCRT_FileAccess_Posix; } + void FXCRT_Posix_GetFileMode(uint32_t dwModes, int32_t& nFlags, int32_t& nMasks) { @@ -54,9 +57,6 @@ void CFXCRT_FileAccess_Posix::Close() { close(m_nFD); m_nFD = -1; } -void CFXCRT_FileAccess_Posix::Release() { - delete this; -} FX_FILESIZE CFXCRT_FileAccess_Posix::GetSize() const { if (m_nFD < 0) { return 0; @@ -127,4 +127,5 @@ FX_BOOL CFXCRT_FileAccess_Posix::Truncate(FX_FILESIZE szFile) { } return !ftruncate(m_nFD, szFile); } + #endif diff --git a/core/fxcrt/fxcrt_posix.h b/core/fxcrt/fxcrt_posix.h index 969707a7b9..37f6548d40 100644 --- a/core/fxcrt/fxcrt_posix.h +++ b/core/fxcrt/fxcrt_posix.h @@ -21,7 +21,6 @@ class CFXCRT_FileAccess_Posix : public IFXCRT_FileAccess { FX_BOOL Open(const CFX_ByteStringC& fileName, uint32_t dwMode) override; FX_BOOL Open(const CFX_WideStringC& fileName, uint32_t dwMode) override; void Close() override; - void Release() override; FX_FILESIZE GetSize() const override; FX_FILESIZE GetPosition() const override; FX_FILESIZE SetPosition(FX_FILESIZE pos) override; diff --git a/core/fxcrt/fxcrt_windows.cpp b/core/fxcrt/fxcrt_windows.cpp index eb584ca804..d4b4e50c2c 100644 --- a/core/fxcrt/fxcrt_windows.cpp +++ b/core/fxcrt/fxcrt_windows.cpp @@ -9,9 +9,12 @@ #include "core/fxcrt/include/fx_string.h" #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ -IFXCRT_FileAccess* FXCRT_FileAccess_Create() { + +// static +IFXCRT_FileAccess* IFXCRT_FileAccess::Create() { return new CFXCRT_FileAccess_Win64; } + void FXCRT_Windows_GetFileMode(uint32_t dwMode, uint32_t& dwAccess, uint32_t& dwShare, @@ -75,9 +78,6 @@ void CFXCRT_FileAccess_Win64::Close() { ::CloseHandle(m_hFile); m_hFile = NULL; } -void CFXCRT_FileAccess_Win64::Release() { - delete this; -} FX_FILESIZE CFXCRT_FileAccess_Win64::GetSize() const { if (!m_hFile) { return 0; diff --git a/core/fxcrt/fxcrt_windows.h b/core/fxcrt/fxcrt_windows.h index 7444446d45..19cef0adc2 100644 --- a/core/fxcrt/fxcrt_windows.h +++ b/core/fxcrt/fxcrt_windows.h @@ -19,7 +19,6 @@ class CFXCRT_FileAccess_Win64 : public IFXCRT_FileAccess { FX_BOOL Open(const CFX_ByteStringC& fileName, uint32_t dwMode) override; FX_BOOL Open(const CFX_WideStringC& fileName, uint32_t dwMode) override; void Close() override; - void Release() override; FX_FILESIZE GetSize() const override; FX_FILESIZE GetPosition() const override; FX_FILESIZE SetPosition(FX_FILESIZE pos) override; |