summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-07-20 11:05:49 +0100
committerMichael Meeks <michael.meeks@collabora.com>2019-07-20 11:05:49 +0100
commit0a3b5b30c8bdc8c3e159edd1552713d55948dedc (patch)
tree0a883b5b88b3f725e273310a9d54b84c8ab51a5f
parent155956a22846ba7a65c2abe2a0aa9d62cc860cf7 (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
-rw-r--r--desktop/source/lib/init.cxx4
-rw-r--r--desktop/source/lib/lokclipboard.cxx33
-rw-r--r--desktop/source/lib/lokclipboard.hxx6
3 files changed, 37 insertions, 6 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index c09ae8329f9c..167b05bebf60 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1546,6 +1546,8 @@ static void doc_destroy(LibreOfficeKitDocument *pThis)
SolarMutexGuard aGuard;
+ LOKClipboardFactory::releaseClipboardForView(-1);
+
LibLODocument_Impl *pDocument = static_cast<LibLODocument_Impl*>(pThis);
delete pDocument;
}
@@ -4284,6 +4286,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..f53202903761 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 */)
{
diff --git a/desktop/source/lib/lokclipboard.hxx b/desktop/source/lib/lokclipboard.hxx
index 54c1b37945ff..1ade5c0a3e0b 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