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