LibreOffice Module desktop (master)  1
dp_backend.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_REGISTRY_INC_DP_BACKEND_H
21 #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_REGISTRY_INC_DP_BACKEND_H
22 
23 #include <dp_misc.h>
24 #include <dp_shared.hxx>
25 #include <dp_interact.h>
26 #include <rtl/ref.hxx>
27 #include <cppuhelper/implbase.hxx>
28 #include <cppuhelper/compbase.hxx>
29 #include <com/sun/star/lang/XEventListener.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/deployment/XPackageRegistry.hpp>
32 #include <unordered_map>
33 #include <strings.hrc>
34 
35 namespace dp_registry::backend
36 {
37 
38 class PackageRegistryBackend;
39 
40 #define BACKEND_SERVICE_NAME "com.sun.star.deployment.PackageRegistryBackend"
41 
42 typedef ::cppu::WeakComponentImplHelper<
43  css::deployment::XPackage > t_PackageBase;
44 
45 
46 class Package : protected ::dp_misc::MutexHolder, public t_PackageBase
47 {
50  bool registerPackage,
51  bool startup,
52  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
53  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv );
54 
55 protected:
57  const OUString m_url;
58  OUString m_name;
59  OUString m_displayName;
60  const css::uno::Reference<css::deployment::XPackageTypeInfo> m_xPackageType;
61  const bool m_bRemoved;
62  //Only set if m_bRemoved = true;
63  const OUString m_identifier;
64 
65  void check() const;
66  void fireModified();
67  virtual void SAL_CALL disposing() override;
68 
69  void checkAborted(
70  ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel );
71 
72  // @@@ to be implemented by specific backend:
73  virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
75  ::osl::ResettableMutexGuard & guard,
76  ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
77  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
78  = 0;
79  virtual void processPackage_(
80  ::osl::ResettableMutexGuard & guard,
81  bool registerPackage,
82  bool startup,
83  ::rtl::Reference< ::dp_misc::AbortChannel > const & abortChannel,
84  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
85  = 0;
86 
87  virtual ~Package() override;
89  OUString const & url,
90  OUString const & name,
91  OUString const & displayName,
92  css::uno::Reference<css::deployment::XPackageTypeInfo> const &
93  xPackageType,
94  bool bRemoved,
95  OUString const & identifier);
96 
97 public:
98 
99  class TypeInfo :
100  public ::cppu::WeakImplHelper<css::deployment::XPackageTypeInfo>
101  {
102  const OUString m_mediaType;
103  const OUString m_fileFilter;
104  const OUString m_shortDescr;
105  public:
106  virtual ~TypeInfo() override;
107  TypeInfo( OUString const & mediaType,
108  OUString const & fileFilter,
109  OUString const & shortDescr )
110  : m_mediaType(mediaType), m_fileFilter(fileFilter),
111  m_shortDescr(shortDescr)
112  {}
113  // XPackageTypeInfo
114  virtual OUString SAL_CALL getMediaType() override;
115  virtual OUString SAL_CALL getDescription() override;
116  virtual OUString SAL_CALL getShortDescription() override;
117  virtual OUString SAL_CALL getFileFilter() override;
118  virtual css::uno::Any SAL_CALL getIcon( sal_Bool highContrast,
119  sal_Bool smallIcon ) override;
120  };
121 
122  // XComponent
123  virtual void SAL_CALL dispose() override;
124  virtual void SAL_CALL addEventListener(
125  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
126  virtual void SAL_CALL removeEventListener(
127  css::uno::Reference<css::lang::XEventListener> const & xListener ) override;
128 
129  // XModifyBroadcaster
130  virtual void SAL_CALL addModifyListener(
131  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
132  virtual void SAL_CALL removeModifyListener(
133  css::uno::Reference<css::util::XModifyListener> const & xListener ) override;
134 
135  // XPackage
136  virtual css::uno::Reference<css::task::XAbortChannel> SAL_CALL
137  createAbortChannel() override;
138  virtual css::beans::Optional< css::beans::Ambiguous<sal_Bool> >
139  SAL_CALL isRegistered(
140  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
141  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
142 
143  virtual ::sal_Int32 SAL_CALL checkPrerequisites(
144  const css::uno::Reference< css::task::XAbortChannel >& xAbortChannel,
145  const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv,
146  sal_Bool noLicenseChecking) override;
147 
148  virtual ::sal_Bool SAL_CALL checkDependencies(
149  const css::uno::Reference< css::ucb::XCommandEnvironment >& xCmdEnv ) override;
150 
151  virtual void SAL_CALL registerPackage(
152  sal_Bool startup,
153  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
154  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
155  virtual void SAL_CALL revokePackage(
156  sal_Bool startup,
157  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
158  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
159  virtual sal_Bool SAL_CALL isBundle() override;
160  virtual css::uno::Sequence< css::uno::Reference<css::deployment::XPackage> >
161  SAL_CALL getBundle(
162  css::uno::Reference<css::task::XAbortChannel> const & xAbortChannel,
163  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
164  virtual OUString SAL_CALL getName() override;
165  virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override;
166  virtual OUString SAL_CALL getVersion() override;
167  virtual OUString SAL_CALL getURL() override;
168  virtual OUString SAL_CALL getDisplayName() override;
169  virtual OUString SAL_CALL getDescription() override;
170  virtual OUString SAL_CALL getLicenseText() override;
171  virtual css::uno::Sequence< OUString > SAL_CALL
172  getUpdateInformationURLs() override;
173  virtual css::beans::StringPair SAL_CALL getPublisherInfo() override;
174  virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL
175  getIcon( sal_Bool bHighContrast ) override;
176  virtual css::uno::Reference<css::deployment::XPackageTypeInfo> SAL_CALL
177  getPackageType() override;
178  virtual void SAL_CALL exportTo(
179  OUString const & destFolderURL,
180  OUString const & newTitle,
181  sal_Int32 nameClashAction,
182  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
183  virtual OUString SAL_CALL getRepositoryName() override;
184  virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override;
185  virtual sal_Bool SAL_CALL isRemoved() override;
186 
187 };
188 
189 typedef ::cppu::WeakComponentImplHelper<
190  css::lang::XEventListener,
191  css::deployment::XPackageRegistry,
192  css::lang::XServiceInfo > t_BackendBase;
193 
194 
196  : protected ::dp_misc::MutexHolder, public t_BackendBase
197 {
198  //The map held originally WeakReferences. The map entries are removed in the disposing
199  //function, which is called when the XPackages are destructed or they are
200  //explicitly disposed. The latter happens, for example, when an extension is
201  //removed (see dp_manager.cxx). However, because of how the help systems work, now
202  // XPackageManager::getDeployedPackages is called often. This results in a lot
203  //of bindPackage calls which are costly. Therefore we keep hard references in
204  //the map now.
205  typedef std::unordered_map<
206  OUString, css::uno::Reference<css::deployment::XPackage> > t_string2ref;
207  t_string2ref m_bound;
208 
209 protected:
210  OUString m_cachePath;
211  css::uno::Reference<css::uno::XComponentContext> m_xComponentContext;
212 
213  OUString m_context;
214  // currently only for library containers:
215  enum class Context {
217  } m_eContext;
218 
219  static OUString StrCannotDetectMediaType() { return DpResId(RID_STR_CANNOT_DETECT_MEDIA_TYPE); }
220  static OUString StrUnsupportedMediaType() { return DpResId(RID_STR_UNSUPPORTED_MEDIA_TYPE); }
221 
222  // @@@ to be implemented by specific backend:
223  virtual css::uno::Reference<css::deployment::XPackage> bindPackage_(
224  OUString const & url, OUString const & mediaType,
225  bool bRemoved, OUString const & identifier,
226  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv )
227  = 0;
228 
229  void check();
230  virtual void SAL_CALL disposing() override;
231 
232  virtual ~PackageRegistryBackend() override;
234  css::uno::Sequence<css::uno::Any> const & args,
235  css::uno::Reference<css::uno::XComponentContext> const & xContext );
236 
237  /* creates a folder with a unique name.
238  If url is empty then it is created in the backend folder, otherwise
239  at a location relative to that folder specified by url.
240  */
241  OUString createFolder(
242  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv);
243  /* deletes folders and files.
244 
245  All folder all files which end with ".tmp" or ".tmp_" and which are
246  not used are deleted.
247  */
248  void deleteUnusedFolders(
249  std::vector< OUString> const & usedFolders);
250  /* deletes one folder with a "temporary" name and the corresponding
251  tmp file, which was used to derive the folder name.
252  */
253  static void deleteTempFolder(
254  OUString const & folderUrl);
255 
256 public:
257  static OUString StrRegisteringPackage() { return DpResId(RID_STR_REGISTERING_PACKAGE); }
258  static OUString StrRevokingPackage() { return DpResId(RID_STR_REVOKING_PACKAGE); }
259 
260  css::uno::Reference<css::uno::XComponentContext> const &
262 
263  OUString const & getCachePath() const { return m_cachePath; }
264  bool transientMode() const { return m_cachePath.isEmpty(); }
265 
266  const OUString& getContext() const {return m_context; }
267 
268  // XEventListener
269  virtual void SAL_CALL disposing( css::lang::EventObject const & evt ) override;
270 
271  // XPackageRegistry
272  virtual css::uno::Reference<css::deployment::XPackage> SAL_CALL bindPackage(
273  OUString const & url, OUString const & mediaType,
274  sal_Bool bRemoved, OUString const & identifier,
275  css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv ) override;
276 
277 // virtual void SAL_CALL packageRemoved(
278 // OUString const & url, OUString const & mediaType)
279 // throw (css::deployment::DeploymentException,
280 // css::uno::RuntimeException);
281 
282 };
283 
284 }
285 
286 
287 #endif
288 
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::deployment::XPackage > SAL_CALL bindPackage(OUString const &url, OUString const &mediaType, sal_Bool bRemoved, OUString const &identifier, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:136
void processPackage_impl(bool registerPackage, bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
Definition: dp_backend.cxx:603
virtual css::beans::Optional< css::beans::Ambiguous< sal_Bool > > isRegistered_(::osl::ResettableMutexGuard &guard,::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
virtual OUString SAL_CALL getFileFilter() override
Definition: dp_backend.cxx:755
void checkAborted(::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel)
Definition: dp_backend.cxx:391
PackageRegistryBackend * getMyBackend() const
Definition: dp_backend.cxx:699
std::unordered_map< OUString, css::uno::Reference< css::deployment::XPackage > > t_string2ref
Definition: dp_backend.h:206
virtual void SAL_CALL disposing() override
Definition: dp_backend.cxx:114
enum dp_registry::backend::PackageRegistryBackend::Context m_eContext
const OUString m_identifier
Definition: dp_backend.h:63
virtual css::uno::Sequence< css::uno::Reference< css::deployment::XPackage > > SAL_CALL getBundle(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:435
virtual void SAL_CALL removeEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_backend.cxx:365
virtual void SAL_CALL addEventListener(css::uno::Reference< css::lang::XEventListener > const &xListener) override
Definition: dp_backend.cxx:356
virtual ::sal_Int32 SAL_CALL checkPrerequisites(const css::uno::Reference< css::task::XAbortChannel > &xAbortChannel, const css::uno::Reference< css::ucb::XCommandEnvironment > &xCmdEnv, sal_Bool noLicenseChecking) override
Definition: dp_backend.cxx:415
virtual css::uno::Sequence< OUString > SAL_CALL getUpdateInformationURLs() override
Definition: dp_backend.cxx:495
virtual OUString SAL_CALL getRepositoryName() override
Definition: dp_backend.cxx:714
Package(::rtl::Reference< PackageRegistryBackend > const &myBackend, OUString const &url, OUString const &name, OUString const &displayName, css::uno::Reference< css::deployment::XPackageTypeInfo > const &xPackageType, bool bRemoved, OUString const &identifier)
Definition: dp_backend.cxx:299
void deleteUnusedFolders(std::vector< OUString > const &usedFolders)
Definition: dp_backend.cxx:247
virtual void SAL_CALL registerPackage(sal_Bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:679
virtual OUString SAL_CALL getDescription() override
Definition: dp_backend.cxx:744
virtual css::uno::Reference< css::deployment::XPackage > bindPackage_(OUString const &url, OUString const &mediaType, bool bRemoved, OUString const &identifier, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
virtual void SAL_CALL dispose() override
Definition: dp_backend.cxx:348
virtual sal_Bool SAL_CALL isRemoved() override
Definition: dp_backend.cxx:727
OUString createFolder(css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)
Definition: dp_backend.cxx:208
TypeInfo(OUString const &mediaType, OUString const &fileFilter, OUString const &shortDescr)
Definition: dp_backend.h:107
virtual OUString SAL_CALL getMediaType() override
Definition: dp_backend.cxx:738
::cppu::WeakComponentImplHelper< css::deployment::XPackage > t_PackageBase
Definition: dp_backend.h:43
virtual OUString SAL_CALL getName() override
Definition: dp_backend.cxx:443
const css::uno::Reference< css::deployment::XPackageTypeInfo > m_xPackageType
Definition: dp_backend.h:60
virtual void processPackage_(::osl::ResettableMutexGuard &guard, bool registerPackage, bool startup,::rtl::Reference< ::dp_misc::AbortChannel > const &abortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv)=0
virtual sal_Bool SAL_CALL isBundle() override
Definition: dp_backend.cxx:409
OUString const & getCachePath() const
Definition: dp_backend.h:263
PackageRegistryBackend(css::uno::Sequence< css::uno::Any > const &args, css::uno::Reference< css::uno::XComponentContext > const &xContext)
Definition: dp_backend.cxx:74
virtual void SAL_CALL exportTo(OUString const &destFolderURL, OUString const &newTitle, sal_Int32 nameClashAction, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:527
unsigned char sal_Bool
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
Definition: dp_backend.h:211
virtual OUString SAL_CALL getShortDescription() override
Definition: dp_backend.cxx:750
virtual void SAL_CALL revokePackage(sal_Bool startup, css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:690
virtual css::uno::Any SAL_CALL getIcon(sal_Bool highContrast, sal_Bool smallIcon) override
Definition: dp_backend.cxx:760
virtual void SAL_CALL removeModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_backend.cxx:383
virtual css::uno::Reference< css::task::XAbortChannel > SAL_CALL createAbortChannel() override
Definition: dp_backend.cxx:402
virtual css::beans::Optional< OUString > SAL_CALL getRegistrationDataURL() override
Definition: dp_backend.cxx:720
static uno::Reference< css::uno::XComponentContext > xContext
Definition: init.cxx:2174
virtual ::sal_Bool SAL_CALL checkDependencies(const css::uno::Reference< css::ucb::XCommandEnvironment > &xCmdEnv) override
Definition: dp_backend.cxx:426
virtual OUString SAL_CALL getVersion() override
Definition: dp_backend.cxx:457
virtual css::beans::StringPair SAL_CALL getPublisherInfo() override
Definition: dp_backend.cxx:503
static void deleteTempFolder(OUString const &folderUrl)
Definition: dp_backend.cxx:226
virtual void SAL_CALL addModifyListener(css::uno::Reference< css::util::XModifyListener > const &xListener) override
Definition: dp_backend.cxx:375
virtual css::beans::Optional< css::beans::Ambiguous< sal_Bool > > SAL_CALL isRegistered(css::uno::Reference< css::task::XAbortChannel > const &xAbortChannel, css::uno::Reference< css::ucb::XCommandEnvironment > const &xCmdEnv) override
Definition: dp_backend.cxx:572
::cppu::WeakComponentImplHelper< css::lang::XEventListener, css::deployment::XPackageRegistry, css::lang::XServiceInfo > t_BackendBase
Definition: dp_backend.h:192
css::uno::Reference< css::uno::XComponentContext > const & getComponentContext() const
Definition: dp_backend.h:261
const OUString & getContext() const
Definition: dp_backend.h:266
virtual OUString SAL_CALL getLicenseText() override
Definition: dp_backend.cxx:487
virtual OUString SAL_CALL getURL() override
Definition: dp_backend.cxx:465
virtual void SAL_CALL disposing() override
Definition: dp_backend.cxx:329
OUString DpResId(const char *pId)
Definition: dp_shared.hxx:37
virtual OUString SAL_CALL getDisplayName() override
Definition: dp_backend.cxx:471
virtual ~Package() override
Definition: dp_backend.cxx:294
::rtl::Reference< PackageRegistryBackend > m_myBackend
Definition: dp_backend.h:56
virtual css::uno::Reference< css::deployment::XPackageTypeInfo > SAL_CALL getPackageType() override
Definition: dp_backend.cxx:522
virtual css::beans::Optional< OUString > SAL_CALL getIdentifier() override
Definition: dp_backend.cxx:448
virtual OUString SAL_CALL getDescription() override
Definition: dp_backend.cxx:479
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getIcon(sal_Bool bHighContrast) override
Definition: dp_backend.cxx:512