summaryrefslogtreecommitdiff
path: root/desktop/source/lib/lokclipboard.cxx
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-08-02 11:41:49 -0400
commitab8a6d596f2850b600bc3bc2f08f008b96fc65cd (patch)
treea189ee8bc4fc12208c537daa2bc3ef3c4f23181e /desktop/source/lib/lokclipboard.cxx
parentc3816a0c85839404d3042ce46635a11ada8a41e3 (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/source/lib/lokclipboard.cxx')
-rw-r--r--desktop/source/lib/lokclipboard.cxx35
1 files changed, 29 insertions, 6 deletions
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)