diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-07-20 11:05:49 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-08-02 11:41:49 -0400 |
commit | ab8a6d596f2850b600bc3bc2f08f008b96fc65cd (patch) | |
tree | a189ee8bc4fc12208c537daa2bc3ef3c4f23181e /desktop | |
parent | c3816a0c85839404d3042ce46635a11ada8a41e3 (diff) |
lok: cleanup clipboards associated with a view on destruction.
Also defer destruction potentially indefinitely for bad users who
quit without destroying views, documents, shutting down nicely etc.
Change-Id: Ieea6ad00b2983d372b745179bfe3b884c3c64eb0
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/lib/init.cxx | 4 | ||||
-rw-r--r-- | desktop/source/lib/lokclipboard.cxx | 35 | ||||
-rw-r--r-- | desktop/source/lib/lokclipboard.hxx | 6 |
3 files changed, 38 insertions, 7 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index bb938443861f..6b0e8863bbd9 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1650,6 +1650,8 @@ static void doc_destroy(LibreOfficeKitDocument *pThis) SolarMutexGuard aGuard; + LOKClipboardFactory::releaseClipboardForView(-1); + LibLODocument_Impl *pDocument = static_cast<LibLODocument_Impl*>(pThis); delete pDocument; } @@ -4369,6 +4371,8 @@ static void doc_destroyView(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pThis SolarMutexGuard aGuard; SetLastExceptionMsg(); + LOKClipboardFactory::releaseClipboardForView(nId); + SfxLokHelper::destroyView(nId); } diff --git a/desktop/source/lib/lokclipboard.cxx b/desktop/source/lib/lokclipboard.cxx index ef52a4596c43..18b728c2343a 100644 --- a/desktop/source/lib/lokclipboard.cxx +++ b/desktop/source/lib/lokclipboard.cxx @@ -8,14 +8,16 @@ */ #include "lokclipboard.hxx" +#include <vcl/lazydelete.hxx> #include <sfx2/lokhelper.hxx> #include <cppuhelper/supportsservice.hxx> using namespace css; using namespace css::uno; -osl::Mutex LOKClipboardFactory::gMutex; -std::unordered_map<int, rtl::Reference<LOKClipboard>> LOKClipboardFactory::gClipboards; +/* static */ osl::Mutex LOKClipboardFactory::gMutex; +static vcl::DeleteOnDeinit<std::unordered_map<int, rtl::Reference<LOKClipboard>>> +gClipboards(new std::unordered_map<int, rtl::Reference<LOKClipboard>>); rtl::Reference<LOKClipboard> LOKClipboardFactory::getClipboardForCurView() { @@ -23,18 +25,39 @@ rtl::Reference<LOKClipboard> LOKClipboardFactory::getClipboardForCurView() osl::MutexGuard aGuard(gMutex); - auto it = gClipboards.find(nViewId); - if (it != gClipboards.end()) + auto it = gClipboards.get()->find(nViewId); + if (it != gClipboards.get()->end()) { SAL_INFO("lok", "Got clip: " << it->second.get() << " from " << nViewId); return it->second; } rtl::Reference<LOKClipboard> xClip(new LOKClipboard()); - gClipboards[nViewId] = xClip; + (*gClipboards.get())[nViewId] = xClip; SAL_INFO("lok", "Created clip: " << xClip.get() << " for viewId " << nViewId); return xClip; } +/// FIXME: should really copy and stash its content for a bit. +void LOKClipboardFactory::releaseClipboardForView(int nViewId) +{ + osl::MutexGuard aGuard(gMutex); + + if (nViewId < 0) // clear all + { + gClipboards.get()->clear(); + SAL_INFO("lok", "Released all clipboards on doc destroy\n"); + } + else + { + auto it = gClipboards.get()->find(nViewId); + if (it != gClipboards.get()->end()) + { + gClipboards.get()->erase(it); + SAL_INFO("lok", "Released clip: " << it->second.get() << " for destroyed " << nViewId); + } + } +} + uno::Reference<uno::XInterface> SAL_CALL LOKClipboardFactory::createInstanceWithArguments(const Sequence<Any>& /* rArgs */) { @@ -178,7 +201,7 @@ LOKTransferable::LOKTransferable(const size_t nInCount, const char** pInMimeType uno::Any SAL_CALL LOKTransferable::getTransferData(const datatransfer::DataFlavor& rFlavor) { - assert(m_aContent.size() == (size_t)m_aFlavors.getLength()); + assert(m_aContent.size() == static_cast<size_t>(m_aFlavors.getLength())); for (size_t i = 0; i < m_aContent.size(); ++i) { if (m_aFlavors[i].MimeType == rFlavor.MimeType) diff --git a/desktop/source/lib/lokclipboard.hxx b/desktop/source/lib/lokclipboard.hxx index e6f7876d4836..90e41176fee4 100644 --- a/desktop/source/lib/lokclipboard.hxx +++ b/desktop/source/lib/lokclipboard.hxx @@ -92,7 +92,6 @@ public: class LOKClipboardFactory : public ::cppu::WeakComponentImplHelper<css::lang::XSingleServiceFactory> { static osl::Mutex gMutex; - static std::unordered_map<int, rtl::Reference<LOKClipboard>> gClipboards; public: LOKClipboardFactory() @@ -106,7 +105,12 @@ public: } css::uno::Reference<css::uno::XInterface> SAL_CALL createInstanceWithArguments(const css::uno::Sequence<css::uno::Any>& /* rArgs */) override; + + /// Fetch clipboard from the gobal pool. static rtl::Reference<LOKClipboard> getClipboardForCurView(); + + /// Release a clipboard before its document dies, nViewId of -1 clears all. + static void releaseClipboardForView(int nViewId); }; #endif |