summaryrefslogtreecommitdiffstats
path: root/package/inc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-05-24 22:05:30 +0200
committerLuboš Luňák <l.lunak@collabora.com>2019-05-28 12:27:48 +0200
commit7cd3f267cfbf3655f6a7a395b80560ecd22e15f7 (patch)
treee14173cddc4e4fb5b0709a7ae64d90316da0b76a /package/inc
parenttry harder not to deflate small streams in a thread (diff)
downloadcore-7cd3f267cfbf3655f6a7a395b80560ecd22e15f7.tar.gz
core-7cd3f267cfbf3655f6a7a395b80560ecd22e15f7.zip
split out thread functionality from ZipOutputEntry
It can be easily separated out, it looked like hacked in. And I will need to do more refactoring of the class, so this shouldn't be more complex than necessary. Change-Id: I302da55409e9195274907ca4939c37fbb2427b18 Reviewed-on: https://gerrit.libreoffice.org/73031 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'package/inc')
-rw-r--r--package/inc/ZipOutputEntry.hxx51
-rw-r--r--package/inc/ZipOutputStream.hxx7
2 files changed, 36 insertions, 22 deletions
diff --git a/package/inc/ZipOutputEntry.hxx b/package/inc/ZipOutputEntry.hxx
index c35da5818062..af6528f04ea1 100644
--- a/package/inc/ZipOutputEntry.hxx
+++ b/package/inc/ZipOutputEntry.hxx
@@ -27,6 +27,7 @@
#include <com/sun/star/xml/crypto/XDigestContext.hpp>
#include <package/Deflater.hxx>
+#include <comphelper/threadpool.hxx>
#include "CRC32.hxx"
#include <atomic>
@@ -36,25 +37,20 @@ class ZipPackageStream;
class ZipOutputEntry
{
- // allow only DeflateThreadTask to change m_bFinished using setFinished()
- friend class DeflateThreadTask;
-
+protected:
css::uno::Sequence< sal_Int8 > m_aDeflateBuffer;
ZipUtils::Deflater m_aDeflater;
css::uno::Reference< css::uno::XComponentContext > m_xContext;
- OUString m_aTempURL;
css::uno::Reference< css::io::XOutputStream > m_xOutStream;
css::uno::Reference< css::xml::crypto::XCipherContext > m_xCipherContext;
css::uno::Reference< css::xml::crypto::XDigestContext > m_xDigestContext;
- std::exception_ptr m_aParallelDeflateException;
CRC32 m_aCRC;
ZipEntry *m_pCurrentEntry;
sal_Int16 m_nDigested;
ZipPackageStream* m_pCurrentStream;
bool const m_bEncryptCurrentEntry;
- std::atomic<bool> m_bFinished;
public:
ZipOutputEntry(
@@ -62,32 +58,49 @@ public:
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt);
- ~ZipOutputEntry();
+ ZipEntry* getZipEntry() { return m_pCurrentEntry; }
+ ZipPackageStream* getZipPackageStream() { return m_pCurrentStream; }
+ bool isEncrypt() { return m_bEncryptCurrentEntry; }
- /* This block of methods is for threaded zipping, where we compress to a temp stream, whose
- data is retrieved via getData */
+ void closeEntry();
+
+ void writeStream(const css::uno::Reference< css::io::XInputStream >& xInStream);
+ void write(const css::uno::Sequence< sal_Int8 >& rBuffer);
+
+protected:
ZipOutputEntry(
+ const css::uno::Reference< css::io::XOutputStream >& rxOutStream,
+ const css::uno::Reference< css::uno::XComponentContext >& rxContext,
+ ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt, bool checkStream);
+ void doDeflate();
+};
+
+// Class that runs the compression in a thread.
+class ZipOutputEntryInThread : public ZipOutputEntry
+{
+ class Task;
+ OUString m_aTempURL;
+ std::exception_ptr m_aParallelDeflateException;
+ std::atomic<bool> m_bFinished;
+
+public:
+ ZipOutputEntryInThread(
const css::uno::Reference< css::uno::XComponentContext >& rxContext,
ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt);
+ std::unique_ptr<comphelper::ThreadTask> createTask(
+ const std::shared_ptr<comphelper::ThreadTaskTag>& pTag,
+ const css::uno::Reference< css::io::XInputStream >& xInStream );
+ /* This block of methods is for threaded zipping, where we compress to a temp stream, whose
+ data is retrieved via getData */
void createBufferFile();
void setParallelDeflateException(const std::exception_ptr& exception) { m_aParallelDeflateException = exception; }
css::uno::Reference< css::io::XInputStream > getData() const;
const std::exception_ptr& getParallelDeflateException() const { return m_aParallelDeflateException; }
void closeBufferFile();
void deleteBufferFile();
-
- ZipEntry* getZipEntry() { return m_pCurrentEntry; }
- ZipPackageStream* getZipPackageStream() { return m_pCurrentStream; }
- bool isEncrypt() { return m_bEncryptCurrentEntry; }
-
- void closeEntry();
- void write(const css::uno::Sequence< sal_Int8 >& rBuffer);
-
bool isFinished() const { return m_bFinished; }
-
private:
void setFinished() { m_bFinished = true; }
- void doDeflate();
};
#endif
diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx
index ff7b66d64507..b527abde1443 100644
--- a/package/inc/ZipOutputStream.hxx
+++ b/package/inc/ZipOutputStream.hxx
@@ -29,6 +29,7 @@
struct ZipEntry;
class ZipOutputEntry;
+class ZipOutputEntryInThread;
class ZipPackageStream;
class ZipOutputStream
@@ -39,7 +40,7 @@ class ZipOutputStream
ByteChucker m_aChucker;
ZipEntry *m_pCurrentEntry;
- std::vector< ZipOutputEntry* > m_aEntries;
+ std::vector< ZipOutputEntryInThread* > m_aEntries;
std::exception_ptr m_aDeflateException;
public:
@@ -47,7 +48,7 @@ public:
const css::uno::Reference< css::io::XOutputStream > &xOStream );
~ZipOutputStream();
- void addDeflatingThreadTask( ZipOutputEntry *pEntry, std::unique_ptr<comphelper::ThreadTask> pThreadTask );
+ void addDeflatingThreadTask( ZipOutputEntryInThread *pEntry, std::unique_ptr<comphelper::ThreadTask> pThreadTask );
/// @throws css::io::IOException
/// @throws css::uno::RuntimeException
@@ -79,7 +80,7 @@ private:
void writeEXT( const ZipEntry &rEntry );
// ScheduledThread handling helpers
- void consumeScheduledThreadTaskEntry(std::unique_ptr<ZipOutputEntry> pCandidate);
+ void consumeScheduledThreadTaskEntry(std::unique_ptr<ZipOutputEntryInThread> pCandidate);
void consumeFinishedScheduledThreadTaskEntries();
public: