LibreOffice Module desktop (master)  1
dp_manager.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_MANAGER_DP_MANAGER_H
21 #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_MANAGER_DP_MANAGER_H
22 
23 #include <dp_misc.h>
24 #include "dp_activepackages.hxx"
25 #include <cppuhelper/compbase.hxx>
26 #include <cppuhelper/implbase.hxx>
27 #include <ucbhelper/content.hxx>
28 #include <com/sun/star/deployment/XPackageRegistry.hpp>
29 #include <com/sun/star/deployment/XPackageManager.hpp>
30 #include <memory>
31 
32 
33 namespace dp_manager {
34 
35 typedef ::cppu::WeakComponentImplHelper<
36  css::deployment::XPackageManager > t_pm_helper;
37 
38 
39 class PackageManagerImpl final : private ::dp_misc::MutexHolder, public t_pm_helper
40 {
41  css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
42  OUString m_context;
45  OUString m_registryCache;
46  bool m_readOnly;
47 
48  OUString m_activePackages;
50  std::unique_ptr< ActivePackages > m_activePackagesDB;
51  //This mutex is only used for synchronization in addPackage
52  ::osl::Mutex m_addMutex;
53  css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile;
54  inline void logIntern( css::uno::Any const & status );
55  void fireModified();
56 
57  css::uno::Reference<css::deployment::XPackageRegistry> m_xRegistry;
58 
59  void initRegistryBackends();
61  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
62  OUString detectMediaType(
63  ::ucbhelper::Content const & ucbContent, bool throw_exc = true );
64  OUString insertToActivationLayer(
65  css::uno::Sequence<css::beans::NamedValue> const & properties,
66  OUString const & mediaType,
67  ::ucbhelper::Content const & sourceContent,
68  OUString const & title, ActivePackages::Data * dbData );
70  OUString const & id, ActivePackages::Data const & dbData );
71 
72  static void deletePackageFromCache(
73  css::uno::Reference<css::deployment::XPackage> const & xPackage,
74  OUString const & destFolder );
75 
76  bool isInstalled(
77  css::uno::Reference<css::deployment::XPackage> const & package);
78 
80  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
81  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
82 
84  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
85  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
86 
88  : public ::cppu::WeakImplHelper< css::ucb::XCommandEnvironment,
89  css::ucb::XProgressHandler >
90  {
91  css::uno::Reference<css::ucb::XProgressHandler> m_xLogFile;
92  css::uno::Reference<css::ucb::XProgressHandler> m_xUserProgress;
93  css::uno::Reference<css::task::XInteractionHandler>
95 
96  public:
97  virtual ~CmdEnvWrapperImpl() override;
99  css::uno::Reference<css::ucb::XCommandEnvironment>
100  const & xUserCmdEnv,
101  css::uno::Reference<css::ucb::XProgressHandler> const & xLogFile );
102 
103  // XCommandEnvironment
104  virtual css::uno::Reference<css::task::XInteractionHandler> SAL_CALL
105  getInteractionHandler() override;
106  virtual css::uno::Reference<css::ucb::XProgressHandler> SAL_CALL
107  getProgressHandler() override;
108 
109  // XProgressHandler
110  virtual void SAL_CALL push( css::uno::Any const & Status ) override;
111  virtual void SAL_CALL update( css::uno::Any const & Status ) override;
112  virtual void SAL_CALL pop() override;
113  };
114 
115  inline void check();
116  virtual void SAL_CALL disposing() override;
117 
118  virtual ~PackageManagerImpl() override;
120  css::uno::Reference<css::uno::XComponentContext>
121  const & xComponentContext, OUString const & context )
122  : t_pm_helper( getMutex() ),
123  m_xComponentContext( xComponentContext ),
124  m_context( context ),
125  m_readOnly( true )
126  {}
127 
128 public:
129  static css::uno::Reference<css::deployment::XPackageManager> create(
130  css::uno::Reference<css::uno::XComponentContext>
131  const & xComponentContext, OUString const & context );
132 
133  // XComponent
134  virtual void SAL_CALL dispose() override;
135  virtual void SAL_CALL addEventListener(
136  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
137  virtual void SAL_CALL removeEventListener(
138  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
139 
140  // XModifyBroadcaster
141  virtual void SAL_CALL addModifyListener(
142  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
143  virtual void SAL_CALL removeModifyListener(
144  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
145 
146  // XPackageManager
147  virtual OUString SAL_CALL getContext() override;
148  virtual css::uno::Sequence<
149  css::uno::Reference<css::deployment::XPackageTypeInfo> > SAL_CALL
150  getSupportedPackageTypes() override;
151 
152  virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
153  createAbortChannel() override;
154 
155  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL addPackage(
156  OUString const & url,
157  css::uno::Sequence<css::beans::NamedValue> const & properties,
158  OUString const & mediaType,
159  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
160  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
161 
162  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL importExtension(
163  css::uno::Reference<css::deployment::XPackage> const & extension,
164  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
165  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
166 
167  virtual void SAL_CALL removePackage(
168  OUString const & id, OUString const & fileName,
169  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
170  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
171 
172  OUString getDeployPath( ActivePackages::Data const & data );
173  css::uno::Reference<css::deployment::XPackage> getDeployedPackage_(
174  OUString const & id, OUString const & fileName,
175  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
176  css::uno::Reference<css::deployment::XPackage> getDeployedPackage_(
177  OUString const & id, ActivePackages::Data const & data,
178  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
179  bool ignoreAlienPlatforms = false );
180  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL
182  OUString const & id, OUString const & fileName,
183  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
184 
185  css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
187  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
188  virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
189  SAL_CALL getDeployedPackages(
190  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
191  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
192 
193  virtual void SAL_CALL reinstallDeployedPackages(
194  sal_Bool force,
195  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
196  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
197 
198  virtual ::sal_Bool SAL_CALL isReadOnly( ) override;
199 
200  virtual ::sal_Bool SAL_CALL synchronize(
201  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
202  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
203 
204  virtual css::uno::Sequence<css::uno::Reference<css::deployment::XPackage> > SAL_CALL
206  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv) override;
207 
208  virtual sal_Int32 SAL_CALL checkPrerequisites(
209  css::uno::Reference<css::deployment::XPackage> const & extension,
210  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
211  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
212  };
213 
214 
216 {
217  ::osl::MutexGuard guard( getMutex() );
218  if (rBHelper.bInDispose || rBHelper.bDisposed)
219  throw css::lang::DisposedException(
220  "PackageManager instance has already been disposed!",
221  static_cast< ::cppu::OWeakObject * >(this) );
222 }
223 
224 
225 inline void PackageManagerImpl::logIntern( css::uno::Any const & status )
226 {
227  if (m_xLogFile.is())
228  m_xLogFile->update( status );
229 }
230 
231 }
232 
233 #endif
234 
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex & getMutex() const
Definition: dp_misc.h:40
virtual void SAL_CALL dispose() override
Definition: dp_manager.cxx:501
virtual void SAL_CALL reinstallDeployedPackages(sal_Bool force, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual css::uno::Reference< css::task::XAbortChannel > SAL_CALL createAbortChannel() override
Definition: dp_manager.cxx:543
css::uno::Reference< css::deployment::XPackageRegistry > m_xRegistry
Definition: dp_manager.h:57
virtual sal_Int32 SAL_CALL checkPrerequisites(css::uno::Reference< css::deployment::XPackage > const &extension, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual ~PackageManagerImpl() override
Definition: dp_manager.cxx:456
void logIntern(css::uno::Any const &status)
Definition: dp_manager.h:225
virtual ::sal_Bool SAL_CALL synchronize(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_manager.cxx:518
OUString detectMediaType(::ucbhelper::Content const &ucbContent, bool throw_exc=true)
Definition: dp_manager.cxx:567
virtual void SAL_CALL removePackage(OUString const &id, OUString const &fileName, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_manager.cxx:863
static void deletePackageFromCache(css::uno::Reference< css::deployment::XPackage > const &xPackage, OUString const &destFolder)
Definition: dp_manager.cxx:846
void insertToActivationLayerDB(OUString const &id, ActivePackages::Data const &dbData)
Definition: dp_manager.cxx:672
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getDeployedPackages(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
virtual ::sal_Bool SAL_CALL isReadOnly() override
std::unique_ptr< ActivePackages > m_activePackagesDB
Definition: dp_manager.h:50
css::uno::Reference< css::task::XInteractionHandler > m_xUserInteractionHandler
Definition: dp_manager.h:94
virtual void SAL_CALL push(css::uno::Any const &Status) override
bool isInstalled(css::uno::Reference< css::deployment::XPackage > const &package)
Definition: dp_manager.cxx:684
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
Definition: dp_manager.h:41
virtual css::uno::Reference< css::task::XInteractionHandler > SAL_CALL getInteractionHandler() override
unsigned char sal_Bool
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_manager.cxx:509
virtual css::uno::Reference< css::ucb::XProgressHandler > SAL_CALL getProgressHandler() override
css::uno::Reference< css::deployment::XPackage > getDeployedPackage_(OUString const &id, OUString const &fileName, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
css::uno::Reference< css::ucb::XProgressHandler > m_xLogFile
Definition: dp_manager.h:91
CmdEnvWrapperImpl(css::uno::Reference< css::ucb::XCommandEnvironment > const &xUserCmdEnv, css::uno::Reference< css::ucb::XProgressHandler > const &xLogFile)
css::uno::Reference< css::ucb::XProgressHandler > m_xUserProgress
Definition: dp_manager.h:92
::cppu::WeakComponentImplHelper< css::deployment::XPackageManager > t_pm_helper
Definition: dp_manager.h:36
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL importExtension(css::uno::Reference< css::deployment::XPackage > const &extension, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_manager.cxx:699
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL addPackage(OUString const &url, css::uno::Sequence< css::beans::NamedValue > const &properties, OUString const &mediaType, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_manager.cxx:711
virtual void SAL_CALL addModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_manager.cxx:551
static css::uno::Reference< css::deployment::XPackageManager > create(css::uno::Reference< css::uno::XComponentContext > const &xComponentContext, OUString const &context)
Definition: dp_manager.cxx:343
bool synchronizeAddedExtensions(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
virtual OUString SAL_CALL getContext() override
Definition: dp_manager.cxx:528
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackageTypeInfo > > SAL_CALL getSupportedPackageTypes() override
Definition: dp_manager.cxx:536
OUString getDeployPath(ActivePackages::Data const &data)
Definition: dp_manager.cxx:947
PackageManagerImpl(css::uno::Reference< css::uno::XComponentContext > const &xComponentContext, OUString const &context)
Definition: dp_manager.h:119
virtual void SAL_CALL removeModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_manager.cxx:559
bool synchronizeRemovedExtensions(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
OUString insertToActivationLayer(css::uno::Sequence< css::beans::NamedValue > const &properties, OUString const &mediaType,::ucbhelper::Content const &sourceContent, OUString const &title, ActivePackages::Data *dbData)
Definition: dp_manager.cxx:605
virtual void SAL_CALL update(css::uno::Any const &Status) override
void initActivationLayer(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
Definition: dp_manager.cxx:115
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getExtensionsWithUnacceptedLicenses(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
css::uno::Reference< css::ucb::XProgressHandler > m_xLogFile
Definition: dp_manager.h:53
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL getDeployedPackage(OUString const &id, OUString const &fileName, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > getDeployedPackages_(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
virtual void SAL_CALL disposing() override
Definition: dp_manager.cxx:473