35#include <com/sun/star/frame/Desktop.hpp>
36#include <com/sun/star/frame/XTerminateListener.hpp>
37#include <com/sun/star/task/XJob.hpp>
48class InitUpdateCheckJobThread :
public osl::Thread
51 InitUpdateCheckJobThread(
const uno::Reference< uno::XComponentContext > &xContext,
52 const uno::Sequence< beans::NamedValue > &xParameters,
55 virtual void SAL_CALL
run()
override;
57 void setTerminating();
60 osl::Condition m_aCondition;
61 uno::Reference<uno::XComponentContext>
m_xContext;
62 uno::Sequence<beans::NamedValue> m_xParameters;
71 public ::cppu::WeakImplHelper< task::XJob, lang::XServiceInfo, frame::XTerminateListener >
73 virtual ~UpdateCheckJob()
override;
78 css::uno::Reference<css::uno::XComponentContext>
const & context,
79 css::uno::Reference<css::frame::XDesktop2>
const &
desktop):
84 virtual uno::Any SAL_CALL execute(
const uno::Sequence<beans::NamedValue>&)
override;
92 virtual void SAL_CALL disposing( css::lang::EventObject
const & evt )
override;
95 virtual void SAL_CALL queryTermination( lang::EventObject
const & evt )
override;
96 virtual void SAL_CALL notifyTermination( lang::EventObject
const & evt )
override;
99 uno::Reference<uno::XComponentContext>
m_xContext;
102 uno::Reference< frame::XDesktop2 >
m_xDesktop;
103 std::unique_ptr< InitUpdateCheckJobThread > m_pInitThread;
105 void handleExtensionUpdates(
const uno::Sequence< beans::NamedValue > &rListProp );
106 void terminateAndJoinThread();
109InitUpdateCheckJobThread::InitUpdateCheckJobThread(
110 const uno::Reference< uno::XComponentContext > &xContext,
111 const uno::Sequence< beans::NamedValue > &xParameters,
114 m_xParameters( xParameters ),
115 m_bShowDialog( bShowDialog ),
116 m_bTerminating( false )
122void SAL_CALL InitUpdateCheckJobThread::run()
124 osl_setThreadName(
"InitUpdateCheckJobThread");
126 if (!m_bShowDialog) {
127 TimeValue tv = { 25, 0 };
128 m_aCondition.wait( &tv );
129 if ( m_bTerminating )
141 if (!m_bShowDialog) {
142 std::scoped_lock l(m_mutex);
143 m_controller = aController;
145 aController->initialize( m_xParameters,
m_xContext );
148 aController->showDialog(
true );
149 }
catch (
const uno::Exception &) {
153 std::scoped_lock l(m_mutex);
154 m_controller.clear();
159void InitUpdateCheckJobThread::setTerminating() {
160 m_bTerminating =
true;
164 std::scoped_lock l(m_mutex);
165 std::swap(controller, m_controller);
167 if (controller.is()) {
168 controller->waitForUpdateCheckFinished();
172UpdateCheckJob::~UpdateCheckJob()
177UpdateCheckJob::execute(
const uno::Sequence<beans::NamedValue>& namedValues)
179 for ( sal_Int32 n=namedValues.getLength(); n-- > 0; )
181 if ( namedValues[ n ].Name ==
"DynamicData" )
183 uno::Sequence<beans::NamedValue> aListProp;
184 if ( namedValues[n].Value >>= aListProp )
186 for ( sal_Int32 i=aListProp.getLength(); i-- > 0; )
188 if ( aListProp[ i ].Name ==
"updateList" )
190 handleExtensionUpdates( aListProp );
198 uno::Sequence<beans::NamedValue> aConfig =
199 getValue< uno::Sequence<beans::NamedValue> > (namedValues,
"JobConfig");
205 uno::Sequence<beans::NamedValue> aEnvironment =
206 getValue< uno::Sequence<beans::NamedValue> > (namedValues,
"Environment");
208 OUString aEventName = getValue< OUString > (aEnvironment,
"EventName");
210 auto thread = std::make_unique<InitUpdateCheckJobThread >(
212 aEventName !=
"onFirstVisibleTask");
214 std::scoped_lock l(m_mutex);
215 m_pInitThread = std::move(thread);
222void UpdateCheckJob::handleExtensionUpdates(
const uno::Sequence< beans::NamedValue > &rListProp )
225 uno::Sequence< uno::Sequence< OUString > > aList =
226 getValue< uno::Sequence< uno::Sequence< OUString > > > ( rListProp,
"updateList" );
227 bool bPrepareOnly = getValue< bool > ( rListProp,
"prepareOnly" );
239 if ( ! aController.is() )
242 aController->setHasExtensionUpdates( bHasUpdates );
244 if ( ! aController->hasOfficeUpdate() )
252 catch(
const uno::Exception& )
260UpdateCheckJob::getImplementationName()
262 return "vnd.sun.UpdateCheck";
266uno::Sequence< OUString > SAL_CALL
267UpdateCheckJob::getSupportedServiceNames()
269 return {
"com.sun.star.setup.UpdateCheck" };
273UpdateCheckJob::supportsService( OUString
const & serviceName )
280void SAL_CALL UpdateCheckJob::disposing( lang::EventObject
const & rEvt )
282 css::uno::Reference<css::frame::XDesktop2>
desktop;
284 std::scoped_lock l(m_mutex);
285 if ( rEvt.Source == m_xDesktop ) {
286 std::swap(m_xDesktop,
desktop);
292 terminateAndJoinThread();
293 desktop->removeTerminateListener(
this );
299void SAL_CALL UpdateCheckJob::queryTermination( lang::EventObject
const & )
303void UpdateCheckJob::terminateAndJoinThread()
305 std::unique_ptr<InitUpdateCheckJobThread> thread;
307 std::scoped_lock l(m_mutex);
308 std::swap(m_pInitThread, thread);
310 if (thread !=
nullptr)
312 thread->setTerminating();
317void SAL_CALL UpdateCheckJob::notifyTermination( lang::EventObject
const & )
319 terminateAndJoinThread();
324extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
326 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
328 css::uno::Reference<css::frame::XDesktop2>
desktop(
329 css::frame::Desktop::create(context));
331 desktop->addTerminateListener(job);
332 return cppu::acquire(job.get());
Reference< XDesktop2 > m_xDesktop
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XComponentContext > m_xContext
def run(arg=None, arg2=-1)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_update_UpdateCheckJob_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
@ UPDATESTATE_EXT_UPD_AVAIL
@ UPDATESTATE_NO_UPDATE_AVAIL
bool storeExtensionUpdateInfos(const uno::Reference< uno::XComponentContext > &rxContext, const uno::Sequence< uno::Sequence< OUString > > &rUpdateInfos)
bool checkForPendingUpdates(const uno::Reference< uno::XComponentContext > &rxContext)