diff options
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/ucp/webdav-curl/CurlSession.cxx | 43 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-curl/SerfLockStore.cxx | 35 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-curl/SerfLockStore.hxx | 12 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-curl/ucpdav1.component | 4 |
4 files changed, 82 insertions, 12 deletions
diff --git a/ucb/source/ucp/webdav-curl/CurlSession.cxx b/ucb/source/ucp/webdav-curl/CurlSession.cxx index e60bd6ef1d36..a80c19f6d690 100644 --- a/ucb/source/ucp/webdav-curl/CurlSession.cxx +++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx @@ -14,9 +14,13 @@ #include "UCBDeadPropertyValue.hxx" #include "webdavresponseparser.hxx" +#include <cppuhelper/implbase.hxx> +#include <comphelper/processfactory.hxx> #include <comphelper/attributelist.hxx> #include <comphelper/scopeguard.hxx> #include <comphelper/string.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/supportsservice.hxx> #include <o3tl/safeint.hxx> #include <o3tl/string_view.hxx> @@ -26,6 +30,7 @@ #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/io/Pipe.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/io/SequenceInputStream.hpp> #include <com/sun/star/io/SequenceOutputStream.hpp> #include <com/sun/star/xml/sax/Writer.hpp> @@ -2430,4 +2435,42 @@ auto CurlSession::NonInteractive_UNLOCK(OUString const& rURI) -> void } // namespace http_dav_ucp +namespace +{ +/// Manage lifecycle of global DAV worker threads +class WebDAVManager : public cppu::WeakImplHelper<css::lang::XServiceInfo>, + public comphelper::LibreOfficeKit::ThreadJoinable +{ +public: + WebDAVManager() {} + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override + { + return "com.sun.star.comp.WebDAVManager"; + } + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override + { + return cppu::supportsService(this, ServiceName); + } + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override + { + return { "com.sun.star.ucb.WebDAVManager" }; + } + + // comphelper::LibreOfficeKit::ThreadJoinable + virtual bool joinThreads() override { return g_Init.LockStore.joinThreads(); } + + virtual void startThreads() override { g_Init.LockStore.startThreads(); } +}; + +} // anonymous namespace + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +ucb_webdav_manager_get_implementation(css::uno::XComponentContext*, + css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new WebDAVManager()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ucb/source/ucp/webdav-curl/SerfLockStore.cxx b/ucb/source/ucp/webdav-curl/SerfLockStore.cxx index 6d7b89e9e687..cfa6f666b056 100644 --- a/ucb/source/ucp/webdav-curl/SerfLockStore.cxx +++ b/ucb/source/ucp/webdav-curl/SerfLockStore.cxx @@ -101,10 +101,8 @@ SerfLockStore::~SerfLockStore() } } -void SerfLockStore::startTicker() +void SerfLockStore::startTicker(std::unique_lock<std::mutex> & /* rGuard is held */) { - std::unique_lock aGuard( m_aMutex ); - if ( !m_pTickerThread.is() ) { m_pTickerThread = new TickerThread( *this ); @@ -112,7 +110,6 @@ void SerfLockStore::startTicker() } } - void SerfLockStore::stopTicker(std::unique_lock<std::mutex> & rGuard) { rtl::Reference<TickerThread> pTickerThread; @@ -122,6 +119,7 @@ void SerfLockStore::stopTicker(std::unique_lock<std::mutex> & rGuard) m_pTickerThread->finish(); // needs mutex // the TickerThread may run refreshLocks() at most once after this pTickerThread = m_pTickerThread; + m_pTickerThread.clear(); } @@ -133,6 +131,25 @@ void SerfLockStore::stopTicker(std::unique_lock<std::mutex> & rGuard) } } +bool SerfLockStore::joinThreads() +{ + std::unique_lock aGuard(m_aMutex); + // FIXME: cure could be worse than the problem; we don't + // want to block on a long-standing webdav lock refresh request. + // perhaps we should timeout on a condition instead if a request + // is in progress. + if (m_pTickerThread.is()) + stopTicker(aGuard); + return true; +} + +void SerfLockStore::startThreads() +{ + std::unique_lock aGuard( m_aMutex ); + if (!m_aLockInfoMap.empty()) + startTicker(aGuard); +} + OUString const* SerfLockStore::getLockTokenForURI(OUString const& rURI, css::ucb::Lock const*const pLock) { @@ -175,14 +192,12 @@ void SerfLockStore::addLock( const OUString& rURI, sal_Int32 nLastChanceToSendRefreshRequest ) { assert(rURI.startsWith("http://") || rURI.startsWith("https://")); - { - std::unique_lock aGuard( m_aMutex ); + std::unique_lock aGuard( m_aMutex ); - m_aLockInfoMap[ rURI ] - = LockInfo(sToken, rLock, xSession, nLastChanceToSendRefreshRequest); - } + m_aLockInfoMap[ rURI ] + = LockInfo(sToken, rLock, xSession, nLastChanceToSendRefreshRequest); - startTicker(); + startTicker(aGuard); } diff --git a/ucb/source/ucp/webdav-curl/SerfLockStore.hxx b/ucb/source/ucp/webdav-curl/SerfLockStore.hxx index 8b54901e1fb8..08a88746b0d0 100644 --- a/ucb/source/ucp/webdav-curl/SerfLockStore.hxx +++ b/ucb/source/ucp/webdav-curl/SerfLockStore.hxx @@ -26,6 +26,7 @@ #include <rtl/ustring.hxx> #include <com/sun/star/ucb/Lock.hpp> #include <utility> +#include <comphelper/lok.hxx> #include "CurlSession.hxx" @@ -57,7 +58,7 @@ struct LockInfo typedef std::map< OUString, LockInfo > LockInfoMap; -class SerfLockStore +class SerfLockStore : public comphelper::LibreOfficeKit::ThreadJoinable { std::mutex m_aMutex; rtl::Reference< TickerThread > m_pTickerThread; @@ -81,9 +82,16 @@ public: void refreshLocks(); + void joinThread(); + void restartThread(); + + // comphelper::LibreOfficeKit::ThreadJoinable + virtual bool joinThreads() override; + virtual void startThreads() override; + private: void removeLockImpl(std::unique_lock<std::mutex> & rGuard, const OUString& rURI); - void startTicker(); + void startTicker(std::unique_lock<std::mutex> & rGuard); void stopTicker(std::unique_lock<std::mutex> & rGuard); }; diff --git a/ucb/source/ucp/webdav-curl/ucpdav1.component b/ucb/source/ucp/webdav-curl/ucpdav1.component index bb16e3b3979d..678e860c1178 100644 --- a/ucb/source/ucp/webdav-curl/ucpdav1.component +++ b/ucb/source/ucp/webdav-curl/ucpdav1.component @@ -23,4 +23,8 @@ constructor="ucb_webdav_ContentProvider_get_implementation"> <service name="com.sun.star.ucb.WebDAVContentProvider"/> </implementation> + <implementation name="com.sun.star.comp.WebDAVManager" + constructor="ucb_webdav_manager_get_implementation" single-instance="true"> + <service name="com.sun.star.ucb.WebDAVManager"/> + </implementation> </component> |