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

Side by Side Diff: core/fxcrt/fx_extension.cpp

Issue 1994323002: Remove Release() from IFXCRT_FileAccess (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « core/fxcrt/extension.h ('k') | core/fxcrt/fxcrt_posix.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxcrt/extension.h" 7 #include "core/fxcrt/extension.h"
8 #include "core/fxcrt/include/fx_basic.h" 8 #include "core/fxcrt/include/fx_basic.h"
9 #include "core/fxcrt/include/fx_ext.h" 9 #include "core/fxcrt/include/fx_ext.h"
10 10
11 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 11 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
12 #include <wincrypt.h> 12 #include <wincrypt.h>
13 #else 13 #else
14 #include <ctime> 14 #include <ctime>
15 #endif 15 #endif
16 16
17 CFX_CRTFileStream::CFX_CRTFileStream(IFXCRT_FileAccess* pFA) 17 CFX_CRTFileStream::CFX_CRTFileStream(IFXCRT_FileAccess* pFA)
18 : m_pFile(pFA), m_dwCount(1) {} 18 : m_pFile(pFA), m_dwCount(1) {}
19 19
20 CFX_CRTFileStream::~CFX_CRTFileStream() { 20 CFX_CRTFileStream::~CFX_CRTFileStream() {}
21 if (m_pFile) {
22 m_pFile->Release();
23 }
24 }
25 21
26 IFX_FileStream* CFX_CRTFileStream::Retain() { 22 IFX_FileStream* CFX_CRTFileStream::Retain() {
27 m_dwCount++; 23 m_dwCount++;
28 return this; 24 return this;
29 } 25 }
30 26
31 void CFX_CRTFileStream::Release() { 27 void CFX_CRTFileStream::Release() {
32 uint32_t nCount = --m_dwCount; 28 uint32_t nCount = --m_dwCount;
33 if (!nCount) { 29 if (!nCount) {
34 delete this; 30 delete this;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 pFA = new CFX_CRTFileAccess; 72 pFA = new CFX_CRTFileAccess;
77 if (NULL == pFA) 73 if (NULL == pFA)
78 return NULL; 74 return NULL;
79 75
80 pFA->Init(wsPath); 76 pFA->Init(wsPath);
81 return pFA; 77 return pFA;
82 } 78 }
83 #endif // PDF_ENABLE_XFA 79 #endif // PDF_ENABLE_XFA
84 80
85 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) { 81 IFX_FileStream* FX_CreateFileStream(const FX_CHAR* filename, uint32_t dwModes) {
86 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); 82 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
87 if (!pFA) { 83 if (!pFA)
Lei Zhang 2016/05/19 22:50:05 IFXCRT_FileAccess::Create() can't fail.
Tom Sepez 2016/05/19 23:18:31 Done.
88 return NULL; 84 return nullptr;
89 } 85 if (!pFA->Open(filename, dwModes))
90 if (!pFA->Open(filename, dwModes)) { 86 return nullptr;
91 pFA->Release(); 87 return new CFX_CRTFileStream(pFA.release());
Lei Zhang 2016/05/19 22:50:05 CFX_CRTFileStream should take a unique_ptr. The on
Tom Sepez 2016/05/19 23:18:31 Done.
92 return NULL;
93 }
94 return new CFX_CRTFileStream(pFA);
95 } 88 }
89
96 IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename, 90 IFX_FileStream* FX_CreateFileStream(const FX_WCHAR* filename,
97 uint32_t dwModes) { 91 uint32_t dwModes) {
98 IFXCRT_FileAccess* pFA = FXCRT_FileAccess_Create(); 92 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
99 if (!pFA) { 93 if (!pFA)
100 return NULL; 94 return nullptr;
101 } 95 if (!pFA->Open(filename, dwModes))
102 if (!pFA->Open(filename, dwModes)) { 96 return nullptr;
103 pFA->Release(); 97 return new CFX_CRTFileStream(pFA.release());
104 return NULL;
105 }
106 return new CFX_CRTFileStream(pFA);
107 } 98 }
108 IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename) { 99 IFX_FileRead* FX_CreateFileRead(const FX_CHAR* filename) {
109 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); 100 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
110 } 101 }
111 IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename) { 102 IFX_FileRead* FX_CreateFileRead(const FX_WCHAR* filename) {
112 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly); 103 return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
113 } 104 }
114 IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer, 105 IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer,
115 size_t dwSize, 106 size_t dwSize,
116 FX_BOOL bTakeOver) { 107 FX_BOOL bTakeOver) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 b = ((const uint8_t*)pGUID)[i]; 354 b = ((const uint8_t*)pGUID)[i];
364 *pBuf++ = gs_FX_pHexChars[b >> 4]; 355 *pBuf++ = gs_FX_pHexChars[b >> 4];
365 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; 356 *pBuf++ = gs_FX_pHexChars[b & 0x0F];
366 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { 357 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) {
367 *pBuf++ = L'-'; 358 *pBuf++ = L'-';
368 } 359 }
369 } 360 }
370 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); 361 bsStr.ReleaseBuffer(bSeparator ? 36 : 32);
371 } 362 }
372 #endif // PDF_ENABLE_XFA 363 #endif // PDF_ENABLE_XFA
OLDNEW
« no previous file with comments | « core/fxcrt/extension.h ('k') | core/fxcrt/fxcrt_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698